From bd5af9ea31501d85ced48cff410a77c3200ee972 Mon Sep 17 00:00:00 2001 From: dan Date: Wed, 20 Jan 2016 16:36:10 +0000 Subject: [PATCH 01/75] Add a -detail option to the loadfts5.tcl script. For creating tables with the detail= option set. FossilOrigin-Name: 81e830e21f81b6428209afa0b8f42f2fd9bd7aab --- ext/fts5/tool/loadfts5.tcl | 10 ++++++++++ manifest | 12 ++++++------ manifest.uuid | 2 +- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/ext/fts5/tool/loadfts5.tcl b/ext/fts5/tool/loadfts5.tcl index 4a5aa37250..96fd69260e 100644 --- a/ext/fts5/tool/loadfts5.tcl +++ b/ext/fts5/tool/loadfts5.tcl @@ -49,6 +49,7 @@ proc usage {} { puts stderr " -prefix PREFIX (comma separated prefix= argument)" puts stderr " -trans N (commit after N inserts - 0 == never)" puts stderr " -hashsize N (set the fts5 hashsize parameter to N)" + puts stderr " -detail MODE (detail mode for fts5 tables)" exit 1 } @@ -61,6 +62,7 @@ set O(crisismerge) -1 set O(prefix) "" set O(trans) 0 set O(hashsize) -1 +set O(detail) full if {[llength $argv]<2} usage set nOpt [expr {[llength $argv]-2}] @@ -113,6 +115,11 @@ for {set i 0} {$i < $nOpt} {incr i} { set O(hashsize) [lindex $argv $i] } + -detail { + if { [incr i]>=$nOpt } usage + set O(detail) [lindex $argv $i] + } + default { usage } @@ -129,6 +136,9 @@ db eval "PRAGMA page_size=4096" db eval BEGIN set pref "" if {$O(prefix)!=""} { set pref ", prefix='$O(prefix)'" } + if {$O(vtab)=="fts5"} { + append pref ", detail=$O(detail)" + } catch { db eval "CREATE VIRTUAL TABLE t1 USING $O(vtab) (path, content$O(tok)$pref)" db eval "INSERT INTO t1(t1, rank) VALUES('pgsz', 4050);" diff --git a/manifest b/manifest index 705d2ce2ea..1fd7c7c1ba 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sproblem\sin\sautoconf/configure.ac\scausing\s--enable-readline\sto\sfail\sif\slibedit\swas\snot\spresent. -D 2016-01-20T15:19:56.944 +C Add\sa\s-detail\soption\sto\sthe\sloadfts5.tcl\sscript.\sFor\screating\stables\swith\sthe\sdetail=\soption\sset. +D 2016-01-20T16:36:10.587 F Makefile.in a476545d0c8626224d0bacac85c6e2967474af81 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 01e855f958932d0d3ed62ec675fc63e2cef61fcb @@ -190,7 +190,7 @@ F ext/fts5/test/fts5version.test 978f59541d8cef7e8591f8be2115ec5ccb863e2e F ext/fts5/test/fts5vocab.test 480d780aa6b699816c5066225fbd86f3a0239477 F ext/fts5/tool/fts5speed.tcl aaee41894b552df8fbf8616aad003b2ea9ba3221 F ext/fts5/tool/fts5txt2db.tcl c374c4c4797e8cdfadabdfaeeb5412dcd6686e84 -F ext/fts5/tool/loadfts5.tcl 4cc2d6af43b58d4fac05bc4fdabd0e5862c3b2c1 +F ext/fts5/tool/loadfts5.tcl 95b03429ee6b138645703c6ca192c3ac96eaf093 F ext/fts5/tool/mkfts5c.tcl d1c2a9ab8e0ec690a52316f33dd9b1d379942f45 F ext/fts5/tool/showfts5.tcl d54da0e067306663e2d5d523965ca487698e722c F ext/icu/README.txt d9fbbad0c2f647c3fdf715fc9fd64af53aedfc43 @@ -1419,7 +1419,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 204432ee72fda8e82d244c4aa18de7ec4811b8e1 -R 88c735abd00a694aa5831ac3200d7df4 +P e8adeb64d4e463772feb58dbd6f00715b92e735c +R 98a9c0dcd39e5c05ab4c041a240f6511 U dan -Z 23cee0c6751a379626b5009d557e2a86 +Z b7cb5f97fd28535e6bf47b6d39323aaf diff --git a/manifest.uuid b/manifest.uuid index 48f168413c..d46650e968 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -e8adeb64d4e463772feb58dbd6f00715b92e735c \ No newline at end of file +81e830e21f81b6428209afa0b8f42f2fd9bd7aab \ No newline at end of file From b5a5a23e92dfd32b30cdfc5d8909438bdd46f4ee Mon Sep 17 00:00:00 2001 From: mistachkin Date: Wed, 20 Jan 2016 18:47:59 +0000 Subject: [PATCH 02/75] Add 'rbu' to the clean targets. FossilOrigin-Name: f60f025027ab3acdbc97701f81ff9c11c8463022 --- Makefile.in | 1 + Makefile.msc | 2 +- main.mk | 1 + manifest | 18 +++++++++--------- manifest.uuid | 2 +- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/Makefile.in b/Makefile.in index 005d529594..6859dcf854 100644 --- a/Makefile.in +++ b/Makefile.in @@ -1218,6 +1218,7 @@ clean: rm -f sqlite3_analyzer$(TEXE) sqlite3_analyzer.c rm -f sqlite-*-output.vsix rm -f mptester mptester.exe + rm -f rbu rbu.exe rm -f fuzzershell fuzzershell.exe rm -f fuzzcheck fuzzcheck.exe rm -f sqldiff sqldiff.exe diff --git a/Makefile.msc b/Makefile.msc index c8275fde25..160323a103 100644 --- a/Makefile.msc +++ b/Makefile.msc @@ -1863,7 +1863,7 @@ clean: del /Q testfixture.exe test.db 2>NUL del /Q LogEst.exe fts3view.exe rollback-test.exe showdb.exe 2>NUL del /Q showjournal.exe showstat4.exe showwal.exe speedtest1.exe 2>NUL - del /Q mptester.exe wordcount.exe 2>NUL + del /Q mptester.exe wordcount.exe rbu.exe 2>NUL del /Q sqlite3.exe sqlite3.dll sqlite3.def 2>NUL del /Q sqlite3.c sqlite3-*.c 2>NUL del /Q sqlite3rc.h 2>NUL diff --git a/main.mk b/main.mk index 934cd36a4e..1dda2d153f 100644 --- a/main.mk +++ b/main.mk @@ -892,6 +892,7 @@ clean: rm -f showwal showwal.exe rm -f speedtest1 speedtest1.exe rm -f wordcount wordcount.exe + rm -f rbu rbu.exe rm -f sqlite3.c sqlite3-*.c fts?amal.c tclsqlite3.c rm -f sqlite3rc.h rm -f shell.c sqlite3ext.h diff --git a/manifest b/manifest index 1fd7c7c1ba..7d2bd65367 100644 --- a/manifest +++ b/manifest @@ -1,8 +1,8 @@ -C Add\sa\s-detail\soption\sto\sthe\sloadfts5.tcl\sscript.\sFor\screating\stables\swith\sthe\sdetail=\soption\sset. -D 2016-01-20T16:36:10.587 -F Makefile.in a476545d0c8626224d0bacac85c6e2967474af81 +C Add\s'rbu'\sto\sthe\sclean\stargets. +D 2016-01-20T18:47:59.553 +F Makefile.in 7be88f5b473891e3a8c07245ed60535fcda4f9ee F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 -F Makefile.msc 01e855f958932d0d3ed62ec675fc63e2cef61fcb +F Makefile.msc c5ead4aa22ff6f528c755b07ed1e31184ac5b3d2 F README.md 8ecc12493ff9f820cdea6520a9016001cb2e59b7 F VERSION 866588d1edf0ccb5b0d33896974338f97564f719 F aclocal.m4 a5c22d164aff7ed549d53a90fa56d56955281f50 @@ -269,7 +269,7 @@ F ext/userauth/userauth.c 5fa3bdb492f481bbc1709fc83c91ebd13460c69e F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 x F ltmain.sh 3ff0879076df340d2e23ae905484d8c15d5fdea8 F magic.txt 8273bf49ba3b0c8559cb2774495390c31fd61c60 -F main.mk 8670f56454bdc59d5e33397bf8c7e43eb33af50c +F main.mk 960071a0bceb043bc5627573986154f507931f33 F mkso.sh fd21c06b063bb16a5d25deea1752c2da6ac3ed83 F mptest/config01.test 3c6adcbc50b991866855f1977ff172eb6d901271 F mptest/config02.test 4415dfe36c48785f751e16e32c20b077c28ae504 @@ -1419,7 +1419,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P e8adeb64d4e463772feb58dbd6f00715b92e735c -R 98a9c0dcd39e5c05ab4c041a240f6511 -U dan -Z b7cb5f97fd28535e6bf47b6d39323aaf +P 81e830e21f81b6428209afa0b8f42f2fd9bd7aab +R 48465c96540143107ca11194f4f37f5c +U mistachkin +Z 6a809d8da8a8f3c2b9daa12aa587edb1 diff --git a/manifest.uuid b/manifest.uuid index d46650e968..849ae0e2a6 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -81e830e21f81b6428209afa0b8f42f2fd9bd7aab \ No newline at end of file +f60f025027ab3acdbc97701f81ff9c11c8463022 \ No newline at end of file From 9c0c57a4ca66af40e70f61e042bf477458abe2c4 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 21 Jan 2016 15:55:37 +0000 Subject: [PATCH 03/75] Improved comments on the FORDELETE hint. No logic changes. FossilOrigin-Name: a3cec529f0238e4ca1196fec420f2de80d28db78 --- manifest | 18 +++++++++--------- manifest.uuid | 2 +- src/btree.h | 16 +++++++++++++--- src/sqliteInt.h | 2 +- src/where.c | 11 +++++------ 5 files changed, 29 insertions(+), 20 deletions(-) diff --git a/manifest b/manifest index 7d2bd65367..d459ef1f26 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\s'rbu'\sto\sthe\sclean\stargets. -D 2016-01-20T18:47:59.553 +C Improved\scomments\son\sthe\sFORDELETE\shint.\s\sNo\slogic\schanges. +D 2016-01-21T15:55:37.704 F Makefile.in 7be88f5b473891e3a8c07245ed60535fcda4f9ee F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc c5ead4aa22ff6f528c755b07ed1e31184ac5b3d2 @@ -289,7 +289,7 @@ F src/backup.c 2869a76c03eb393ee795416e2387005553df72bc F src/bitvec.c 1a78d450a17c5016710eec900bedfc5729bf9bdf F src/btmutex.c bc87dd3b062cc26edfe79918de2200ccb8d41e73 F src/btree.c f224ae877fde69d1a9d430f502edaf8502752dbe -F src/btree.h 68ef301795e00cdf1d3ab93abc44a43b7fe771e0 +F src/btree.h 526137361963e746949ab966a910c7f455ac6b04 F src/btreeInt.h c18b7d2a3494695133e4e60ee36061d37f45d9a5 F src/build.c 31af80bba31ac159967951ef58f3144cc7db9d70 F src/callback.c 29ae4faba226c7ebb9aee93016b5ce8a8f071261 @@ -350,7 +350,7 @@ F src/shell.c dcd7a83645ef2a58ee9c6d0ea4714d877d7835c4 F src/sqlite.h.in 214476a62012e578f42133a9a3b4f97a9aa421a3 F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h dfbe62ffd95b99afe2140d8c35b180d11924072d -F src/sqliteInt.h 8c1debffeeb1579bdc264d54c72c05892e23b7ee +F src/sqliteInt.h 0403328581127bc8ad2f9cc7af2c3bb23d5316da F src/sqliteLimit.h 216557999cb45f2e3578ed53ebefe228d779cb46 F src/status.c 70912d7be68e9e2dbc4010c93d344af61d4c59ba F src/table.c 51b46b2a62d1b3a959633d593b89bab5e2c9155e @@ -424,7 +424,7 @@ F src/vxworks.h 974e7d9a98f602d6310d563e1dc4e08f9fc48e47 F src/wal.c d21b99fd1458159d0b1ecdccc8ee6ada4fdc4c54 F src/wal.h 2f7c831cf3b071fa548bf2d5cac640846a7ff19c F src/walker.c 0f142b5bd3ed2041fc52d773880748b212e63354 -F src/where.c bb69654f841ae7af0a20cc6fb8f0ac57901c31be +F src/where.c af9bf5dcec1a0e52726c550924aa91d837166251 F src/whereInt.h 78b6b4de94db84aecbdc07fe3e38f648eb391e9a F src/wherecode.c 8dee26eb181ea9daa8b1a4d96f34c0860aaf99bd F src/whereexpr.c 197a448b52073aee43eca3a2233fc113369eb2d4 @@ -1419,7 +1419,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 81e830e21f81b6428209afa0b8f42f2fd9bd7aab -R 48465c96540143107ca11194f4f37f5c -U mistachkin -Z 6a809d8da8a8f3c2b9daa12aa587edb1 +P f60f025027ab3acdbc97701f81ff9c11c8463022 +R 58c662ebb54c7087fe70ba0b9b653627 +U drh +Z 656e64b9ebb4ed29ac85ca9fad2e65b0 diff --git a/manifest.uuid b/manifest.uuid index 849ae0e2a6..80d0db3e83 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -f60f025027ab3acdbc97701f81ff9c11c8463022 \ No newline at end of file +a3cec529f0238e4ca1196fec420f2de80d28db78 \ No newline at end of file diff --git a/src/btree.h b/src/btree.h index 2f398e7bba..37a9915eda 100644 --- a/src/btree.h +++ b/src/btree.h @@ -199,14 +199,24 @@ int sqlite3BtreeNewDb(Btree *p); ** Flags passed as the third argument to sqlite3BtreeCursor(). ** ** For read-only cursors the wrFlag argument is always zero. For read-write -** cursors it may be set to either (BTREE_WRCSR|BTREE_FORDELETE) or -** (BTREE_WRCSR). If the BTREE_FORDELETE flag is set, then the cursor will +** cursors it may be set to either (BTREE_WRCSR|BTREE_FORDELETE) or just +** (BTREE_WRCSR). If the BTREE_FORDELETE bit is set, then the cursor will ** only be used by SQLite for the following: ** -** * to seek to and delete specific entries, and/or +** * to seek to and then delete specific entries, and/or ** ** * to read values that will be used to create keys that other ** BTREE_FORDELETE cursors will seek to and delete. +** +** The BTREE_FORDELETE flag is an optimization hint. It is not used by +** by this, the native b-tree engine of SQLite, but it is available to +** alternative storage engines that might be substituted in place of this +** b-tree system. For alternative storage engines in which a delete of +** the main table row automatically deletes corresponding index rows, +** the FORDELETE flag hint allows those alternative storage engines to +** skip a lot of work. Namely: FORDELETE cursors may treat all SEEK +** and DELETE operations as no-ops, and any READ operation against a +** FORDELETE cursor may return a null row: 0x01 0x00. */ #define BTREE_WRCSR 0x00000004 /* read-write cursor */ #define BTREE_FORDELETE 0x00000008 /* Cursor is for seek/delete only */ diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 8ab59b4679..b536b8ab28 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -2857,7 +2857,7 @@ struct AuthContext { #define OPFLAG_TYPEOFARG 0x80 /* OP_Column only used for typeof() */ #define OPFLAG_BULKCSR 0x01 /* OP_Open** used to open bulk cursor */ #define OPFLAG_SEEKEQ 0x02 /* OP_Open** cursor uses EQ seek only */ -#define OPFLAG_FORDELETE 0x08 /* OP_Open is opening for-delete csr */ +#define OPFLAG_FORDELETE 0x08 /* OP_Open should use BTREE_FORDELETE */ #define OPFLAG_P2ISREG 0x10 /* P2 to OP_Open** is a register number */ #define OPFLAG_PERMUTE 0x01 /* OP_Compare: use the permutation */ diff --git a/src/where.c b/src/where.c index 2cb8334ffb..8c8dfbb7b6 100644 --- a/src/where.c +++ b/src/where.c @@ -4014,7 +4014,7 @@ WhereInfo *sqlite3WhereBegin( int ii; /* Loop counter */ sqlite3 *db; /* Database connection */ int rc; /* Return code */ - u8 bFordelete = 0; + u8 bFordelete = 0; /* OPFLAG_FORDELETE or zero, as appropriate */ assert( (wctrlFlags & WHERE_ONEPASS_MULTIROW)==0 || ( (wctrlFlags & WHERE_ONEPASS_DESIRED)!=0 @@ -4259,16 +4259,15 @@ WhereInfo *sqlite3WhereBegin( /* If the caller is an UPDATE or DELETE statement that is requesting ** to use a one-pass algorithm, determine if this is appropriate. - ** The one-pass algorithm only works if the WHERE clause constrains - ** the statement to update or delete a single row. */ assert( (wctrlFlags & WHERE_ONEPASS_DESIRED)==0 || pWInfo->nLevel==1 ); if( (wctrlFlags & WHERE_ONEPASS_DESIRED)!=0 ){ int wsFlags = pWInfo->a[0].pWLoop->wsFlags; int bOnerow = (wsFlags & WHERE_ONEROW)!=0; - if( bOnerow || ( (wctrlFlags & WHERE_ONEPASS_MULTIROW) - && 0==(wsFlags & WHERE_VIRTUALTABLE) - )){ + if( bOnerow + || ((wctrlFlags & WHERE_ONEPASS_MULTIROW)!=0 + && 0==(wsFlags & WHERE_VIRTUALTABLE)) + ){ pWInfo->eOnePass = bOnerow ? ONEPASS_SINGLE : ONEPASS_MULTI; if( HasRowid(pTabList->a[0].pTab) && (wsFlags & WHERE_IDX_ONLY) ){ if( wctrlFlags & WHERE_ONEPASS_MULTIROW ){ From e807bdba86b39f5996683c14842c705e3f6e25d6 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 21 Jan 2016 17:06:33 +0000 Subject: [PATCH 04/75] Add a new hint bit on the flags parameter of sqlite3BtreeDelete(). The new BTREE_IDXDELETE bit indicates that the call is to delete an index entry corresponding to a table row that has already been deleted. FossilOrigin-Name: ac2cbadd8000947c097da5b00c00090fe58fdcff --- manifest | 23 +++++++++++++---------- manifest.uuid | 2 +- src/btree.c | 41 +++++++++++++++++++++++++++++------------ src/btree.h | 7 ++++++- src/delete.c | 5 ++++- src/sqliteInt.h | 5 ++++- src/vdbe.c | 23 ++++++++++++++++------- 7 files changed, 73 insertions(+), 33 deletions(-) diff --git a/manifest b/manifest index d459ef1f26..084be630fe 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Improved\scomments\son\sthe\sFORDELETE\shint.\s\sNo\slogic\schanges. -D 2016-01-21T15:55:37.704 +C Add\sa\snew\shint\sbit\son\sthe\sflags\sparameter\sof\ssqlite3BtreeDelete().\s\sThe\snew\nBTREE_IDXDELETE\sbit\sindicates\sthat\sthe\scall\sis\sto\sdelete\san\sindex\sentry\s\ncorresponding\sto\sa\stable\srow\sthat\shas\salready\sbeen\sdeleted. +D 2016-01-21T17:06:33.267 F Makefile.in 7be88f5b473891e3a8c07245ed60535fcda4f9ee F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc c5ead4aa22ff6f528c755b07ed1e31184ac5b3d2 @@ -288,8 +288,8 @@ F src/auth.c b56c78ebe40a2110fd361379f7e8162d23f92240 F src/backup.c 2869a76c03eb393ee795416e2387005553df72bc F src/bitvec.c 1a78d450a17c5016710eec900bedfc5729bf9bdf F src/btmutex.c bc87dd3b062cc26edfe79918de2200ccb8d41e73 -F src/btree.c f224ae877fde69d1a9d430f502edaf8502752dbe -F src/btree.h 526137361963e746949ab966a910c7f455ac6b04 +F src/btree.c 97cf881292e085ee71faf44f7167b6312965b562 +F src/btree.h c5dfbbc59226fa5fcc2b03befa85fe10ef23c1b5 F src/btreeInt.h c18b7d2a3494695133e4e60ee36061d37f45d9a5 F src/build.c 31af80bba31ac159967951ef58f3144cc7db9d70 F src/callback.c 29ae4faba226c7ebb9aee93016b5ce8a8f071261 @@ -297,7 +297,7 @@ F src/complete.c addcd8160b081131005d5bc2d34adf20c1c5c92f F src/ctime.c 60e135af364d777a9ab41c97e5e89cd224da6198 F src/date.c 997651e3ee6c2818fbf7fcdb7156cef9eb3ece20 F src/dbstat.c ffd63fc8ba7541476ced189b95e95d7f2bc63f78 -F src/delete.c 00af9f08a15ddc5cba5962d3d3e5bf2d67b2e7da +F src/delete.c f02e46234c5fc86f6c03ae34dc0ba48e93cd5029 F src/expr.c df0d7c3230d59abd679da22ff5ce4cfd0e3a0e63 F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb F src/fkey.c e18b3dff7d47c7bcac5ac4fc178a89b9fd322b44 @@ -350,7 +350,7 @@ F src/shell.c dcd7a83645ef2a58ee9c6d0ea4714d877d7835c4 F src/sqlite.h.in 214476a62012e578f42133a9a3b4f97a9aa421a3 F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h dfbe62ffd95b99afe2140d8c35b180d11924072d -F src/sqliteInt.h 0403328581127bc8ad2f9cc7af2c3bb23d5316da +F src/sqliteInt.h 46e0bac7a3cdab96e8b5afd1436accc25d2c3d6a F src/sqliteLimit.h 216557999cb45f2e3578ed53ebefe228d779cb46 F src/status.c 70912d7be68e9e2dbc4010c93d344af61d4c59ba F src/table.c 51b46b2a62d1b3a959633d593b89bab5e2c9155e @@ -410,7 +410,7 @@ F src/update.c 17332f9fe818cbc0444c36a811800af8498af4c3 F src/utf.c 32d7f82aa921322f3e1c956f4b58f019ebd2c6b3 F src/util.c e802e8e311a0d6c48cd1b3e89db164f6f0248d70 F src/vacuum.c 2ddd5cad2a7b9cef7f9e431b8c7771634c6b1701 -F src/vdbe.c b90d9d38e5e0260c2eafa3cb4c2274d8ea94da27 +F src/vdbe.c e21a506d17a7397cba16c162d8c9c96e9769c68e F src/vdbe.h 7a733ea8aac1b77305a67698e784fa3484ee3337 F src/vdbeInt.h 42eefa4f9e7432b9968d321b44e48821ec13b189 F src/vdbeapi.c ffae8f5af4570fbd548504e815e9fb7227f0822e @@ -1419,7 +1419,10 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P f60f025027ab3acdbc97701f81ff9c11c8463022 -R 58c662ebb54c7087fe70ba0b9b653627 +P a3cec529f0238e4ca1196fec420f2de80d28db78 +R 76198b2176fddd32b1fb9b7a5f18b4c8 +T *branch * btree-fordelete-flag +T *sym-btree-fordelete-flag * +T -sym-trunk * U drh -Z 656e64b9ebb4ed29ac85ca9fad2e65b0 +Z c987d8ca8053309611f1f75e6c6acde5 diff --git a/manifest.uuid b/manifest.uuid index 80d0db3e83..57018fb84b 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -a3cec529f0238e4ca1196fec420f2de80d28db78 \ No newline at end of file +ac2cbadd8000947c097da5b00c00090fe58fdcff \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index 4e6f6478af..89144e7a84 100644 --- a/src/btree.c +++ b/src/btree.c @@ -4049,13 +4049,13 @@ int sqlite3BtreeSavepoint(Btree *p, int op, int iSavepoint){ ** on the database already. If a write-cursor is requested, then ** the caller is assumed to have an open write transaction. ** -** If wrFlag==0, then the cursor can only be used for reading. -** If wrFlag==1, then the cursor can be used for reading or for -** writing if other conditions for writing are also met. These -** are the conditions that must be met in order for writing to -** be allowed: +** If the BTREE_WRCSR bit of wrFlag is clear, then the cursor can only +** be used for reading. If the BTREE_WRCSR bit is set, then the cursor +** can be used for reading or for writing if other conditions for writing +** are also met. These are the conditions that must be met in order +** for writing to be allowed: ** -** 1: The cursor must have been opened with wrFlag==1 +** 1: The cursor must have been opened with wrFlag containing BTREE_WRCSR ** ** 2: Other database connections that share the same pager cache ** but which are not in the READ_UNCOMMITTED state may not have @@ -4067,6 +4067,16 @@ int sqlite3BtreeSavepoint(Btree *p, int op, int iSavepoint){ ** ** 4: There must be an active transaction. ** +** The BTREE_FORDELETE bit of wrFlag may optionally be set if BTREE_WRCSR +** is set. If FORDELETE is set, that is a hint to the implementation that +** this cursor will only be used to seek to and delete entries of an index +** as part of a larger DELETE statement. The FORDELETE hint is not used by +** this implementation. But in a hypothetical alternative storage engine +** in which index entries are automatically deleted when corresponding table +** rows are deleted, the FORDELETE flag is a hint that all SEEK and DELETE +** operations on this cursor can be no-ops and all READ operations can +** return a null row (2-bytes: 0x01 0x00). +** ** No checking is done to make sure that page iTable really is the ** root page of a b-tree. If it is not, then the cursor acquired ** will not work correctly. @@ -8082,13 +8092,18 @@ end_insert: /* ** Delete the entry that the cursor is pointing to. ** -** If the second parameter is zero, then the cursor is left pointing at an -** arbitrary location after the delete. If it is non-zero, then the cursor -** is left in a state such that the next call to BtreeNext() or BtreePrev() -** moves it to the same row as it would if the call to BtreeDelete() had -** been omitted. +** If the BTREE_SAVEPOSITION bit of the flags parameter is zero, then +** the cursor is left pointing at an arbitrary location after the delete. +** But if that bit is set, then the cursor is left in a state such that +** the next call to BtreeNext() or BtreePrev() moves it to the same row +** as it would have been on if the call to BtreeDelete() had been omitted. +** +** The BTREE_IDXDELETE bit of flags indicates that this is a delete of +** an index entry where the corresponding table row has already been deleted. +** The BTREE_IDXDELETE bit is a hint that is not used by this implementation, +** but which might be used by alternative storage engines. */ -int sqlite3BtreeDelete(BtCursor *pCur, int bPreserve){ +int sqlite3BtreeDelete(BtCursor *pCur, u8 flags){ Btree *p = pCur->pBtree; BtShared *pBt = p->pBt; int rc; /* Return code */ @@ -8098,6 +8113,7 @@ int sqlite3BtreeDelete(BtCursor *pCur, int bPreserve){ int iCellDepth; /* Depth of node containing pCell */ u16 szCell; /* Size of the cell being deleted */ int bSkipnext = 0; /* Leaf cursor in SKIPNEXT state */ + u8 bPreserve = flags & BTREE_SAVEPOSITION; /* Keep cursor valid */ assert( cursorOwnsBtShared(pCur) ); assert( pBt->inTransaction==TRANS_WRITE ); @@ -8107,6 +8123,7 @@ int sqlite3BtreeDelete(BtCursor *pCur, int bPreserve){ assert( !hasReadConflicts(p, pCur->pgnoRoot) ); assert( pCur->aiIdx[pCur->iPage]apPage[pCur->iPage]->nCell ); assert( pCur->eState==CURSOR_VALID ); + assert( (flags & ~(BTREE_SAVEPOSITION | BTREE_IDXDELETE))==0 ); iCellDepth = pCur->iPage; iCellIdx = pCur->aiIdx[iCellDepth]; diff --git a/src/btree.h b/src/btree.h index 37a9915eda..416faca651 100644 --- a/src/btree.h +++ b/src/btree.h @@ -245,7 +245,12 @@ int sqlite3BtreeMovetoUnpacked( ); int sqlite3BtreeCursorHasMoved(BtCursor*); int sqlite3BtreeCursorRestore(BtCursor*, int*); -int sqlite3BtreeDelete(BtCursor*, int); +int sqlite3BtreeDelete(BtCursor*, u8 flags); + +/* Allowed flags for the 2nd argument to sqlite3BtreeDelete() */ +#define BTREE_SAVEPOSITION 0x02 /* Leave cursor pointing at NEXT or PREV */ +#define BTREE_IDXDELETE 0x04 /* this is index, table row already deleted */ + int sqlite3BtreeInsert(BtCursor*, const void *pKey, i64 nKey, const void *pData, int nData, int nZero, int bias, int seekResult); diff --git a/src/delete.c b/src/delete.c index ed273bde81..98c49c9930 100644 --- a/src/delete.c +++ b/src/delete.c @@ -718,6 +718,7 @@ void sqlite3GenerateRowDelete( ** a view (in which case the only effect of the DELETE statement is to ** fire the INSTEAD OF triggers). */ if( pTab->pSelect==0 ){ + u8 p5 = 0; sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur,0,iIdxNoSeek); sqlite3VdbeAddOp2(v, OP_Delete, iDataCur, (count?OPFLAG_NCHANGE:0)); if( count ){ @@ -725,8 +726,10 @@ void sqlite3GenerateRowDelete( } if( iIdxNoSeek>=0 ){ sqlite3VdbeAddOp1(v, OP_Delete, iIdxNoSeek); + if( eMode!=ONEPASS_OFF ) p5 = OPFLAG_IDXDELETE; } - sqlite3VdbeChangeP5(v, eMode==ONEPASS_MULTI); + if( eMode==ONEPASS_MULTI ) p5 |= OPFLAG_SAVEPOSITION; + sqlite3VdbeChangeP5(v, p5); } /* Do any ON CASCADE, SET NULL or SET DEFAULT operations required to diff --git a/src/sqliteInt.h b/src/sqliteInt.h index b536b8ab28..25aff00151 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -2847,7 +2847,8 @@ struct AuthContext { /* ** Bitfield flags for P5 value in various opcodes. */ -#define OPFLAG_NCHANGE 0x01 /* Set to update db->nChange */ +#define OPFLAG_NCHANGE 0x01 /* OP_Insert: Set to update db->nChange */ + /* Also used in P2 (not P5) of OP_Delete */ #define OPFLAG_EPHEM 0x01 /* OP_Column: Ephemeral output is ok */ #define OPFLAG_LASTROWID 0x02 /* Set to update db->lastRowid */ #define OPFLAG_ISUPDATE 0x04 /* This OP_Insert is an sql UPDATE */ @@ -2860,6 +2861,8 @@ struct AuthContext { #define OPFLAG_FORDELETE 0x08 /* OP_Open should use BTREE_FORDELETE */ #define OPFLAG_P2ISREG 0x10 /* P2 to OP_Open** is a register number */ #define OPFLAG_PERMUTE 0x01 /* OP_Compare: use the permutation */ +#define OPFLAG_SAVEPOSITION 0x02 /* OP_Delete: keep cursor position */ +#define OPFLAG_IDXDELETE 0x04 /* OP_Delete: index in a DELETE op */ /* * Each trigger present in the database schema is stored as an instance of diff --git a/src/vdbe.c b/src/vdbe.c index c6d5f7b0cc..c290097da2 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -4341,14 +4341,20 @@ case OP_InsertInt: { ** ** Delete the record at which the P1 cursor is currently pointing. ** -** If the P5 parameter is non-zero, the cursor will be left pointing at -** either the next or the previous record in the table. If it is left -** pointing at the next record, then the next Next instruction will be a -** no-op. As a result, in this case it is OK to delete a record from within a -** Next loop. If P5 is zero, then the cursor is left in an undefined state. +** If the OPFLAG_SAVEPOSITION bit of the P5 parameter is set, then +** the cursor will be left pointing at either the next or the previous +** record in the table. If it is left pointing at the next record, then +** the next Next instruction will be a no-op. As a result, in this case +** it is ok to delete a record from within a Next loop. If +** OPFLAG_SAVEPOSITION bit of P5 is clear, then the cursor will be +** left in an undefined state. ** -** If the OPFLAG_NCHANGE flag of P2 is set, then the row change count is -** incremented (otherwise not). +** If the OPFLAG_IDXDELETE bit is set on P5, that indicates that this +** delete is on an index cursor where the corresponding table row has +** already been deleted. +** +** If the OPFLAG_NCHANGE flag of P2 (NB: P2 not P5) is set, then the row +** change count is incremented (otherwise not). ** ** P1 must not be pseudo-table. It has to be a real table with ** multiple rows. @@ -4385,6 +4391,9 @@ case OP_Delete: { } #endif + assert( (pOp->p5 & ~(OPFLAG_SAVEPOSITION|OPFLAG_IDXDELETE))==0 ); + assert( OPFLAG_SAVEPOSITION==BTREE_SAVEPOSITION ); + assert( OPFLAG_IDXDELETE==BTREE_IDXDELETE ); rc = sqlite3BtreeDelete(pC->uc.pCursor, pOp->p5); pC->cacheStatus = CACHE_STALE; From 153d3e91dbace8dc0c56ef7a80ea1e282208e3c5 Mon Sep 17 00:00:00 2001 From: mistachkin Date: Thu, 21 Jan 2016 18:56:10 +0000 Subject: [PATCH 05/75] Fix typo in 'Makefile.in'. FossilOrigin-Name: 29a51c6dcc0ef7cab51aba0024e9c5bec89c6973 --- Makefile.in | 4 ++-- manifest | 14 +++++++------- manifest.uuid | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Makefile.in b/Makefile.in index 6859dcf854..a07279c3c9 100644 --- a/Makefile.in +++ b/Makefile.in @@ -1180,9 +1180,9 @@ lib_install: libsqlite3.la $(INSTALL) -d $(DESTDIR)$(libdir) $(LTINSTALL) libsqlite3.la $(DESTDIR)$(libdir) -install: sqlite3$(BEXE) lib_install sqlite3.h sqlite3.pc ${HAVE_TCL:1=tcl_install} +install: sqlite3$(TEXE) lib_install sqlite3.h sqlite3.pc ${HAVE_TCL:1=tcl_install} $(INSTALL) -d $(DESTDIR)$(bindir) - $(LTINSTALL) sqlite3$(BEXE) $(DESTDIR)$(bindir) + $(LTINSTALL) sqlite3$(TEXE) $(DESTDIR)$(bindir) $(INSTALL) -d $(DESTDIR)$(includedir) $(INSTALL) -m 0644 sqlite3.h $(DESTDIR)$(includedir) $(INSTALL) -m 0644 $(TOP)/src/sqlite3ext.h $(DESTDIR)$(includedir) diff --git a/manifest b/manifest index d459ef1f26..94fd201a3d 100644 --- a/manifest +++ b/manifest @@ -1,6 +1,6 @@ -C Improved\scomments\son\sthe\sFORDELETE\shint.\s\sNo\slogic\schanges. -D 2016-01-21T15:55:37.704 -F Makefile.in 7be88f5b473891e3a8c07245ed60535fcda4f9ee +C Fix\stypo\sin\s'Makefile.in'. +D 2016-01-21T18:56:10.840 +F Makefile.in 027c1603f255390c43a426671055a31c0a65fdb4 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc c5ead4aa22ff6f528c755b07ed1e31184ac5b3d2 F README.md 8ecc12493ff9f820cdea6520a9016001cb2e59b7 @@ -1419,7 +1419,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P f60f025027ab3acdbc97701f81ff9c11c8463022 -R 58c662ebb54c7087fe70ba0b9b653627 -U drh -Z 656e64b9ebb4ed29ac85ca9fad2e65b0 +P a3cec529f0238e4ca1196fec420f2de80d28db78 +R 0153ee59df704041be1869f598c173fa +U mistachkin +Z cab32b4afad5b6a6884b5ccdb88994ac diff --git a/manifest.uuid b/manifest.uuid index 80d0db3e83..47bf74ce33 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -a3cec529f0238e4ca1196fec420f2de80d28db78 \ No newline at end of file +29a51c6dcc0ef7cab51aba0024e9c5bec89c6973 \ No newline at end of file From edcb4ebba1553304c3a14f127b1991a11f2b1bb0 Mon Sep 17 00:00:00 2001 From: mistachkin Date: Fri, 22 Jan 2016 01:25:15 +0000 Subject: [PATCH 06/75] MSVC makefile enhancements for use with the Windows 10 SDK. FossilOrigin-Name: ac2e9d3de54d299f92fc35927b6df6d3aaa2dc59 --- Makefile.msc | 119 +++++++++++++++++++++++++++++++++++++++----------- manifest | 12 ++--- manifest.uuid | 2 +- 3 files changed, 100 insertions(+), 33 deletions(-) diff --git a/Makefile.msc b/Makefile.msc index 160323a103..3ac19c2f73 100644 --- a/Makefile.msc +++ b/Makefile.msc @@ -130,6 +130,12 @@ FOR_WINRT = 0 FOR_UAP = 0 !ENDIF +# Set this non-0 to compile binaries suitable for Windows 10. +# +!IFNDEF FOR_WIN10 +FOR_WIN10 = 0 +!ENDIF + # Set this non-0 to skip attempting to look for and/or link with the Tcl # runtime library. # @@ -186,6 +192,31 @@ DEBUG = 0 OPTIMIZATIONS = 2 !ENDIF +# This is the name to use for the SQLite dynamic link library (DLL). +# +!IFNDEF SQLITE3DLL +SQLITE3DLL = sqlite3.dll +!ENDIF + +# This is the name to use for the SQLite import library (LIB). +# +!IFNDEF SQLITE3LIB +SQLITE3LIB = sqlite3.lib +!ENDIF + +# This is the name to use for the SQLite shell executable (EXE). +# +!IFNDEF SQLITE3EXE +SQLITE3EXE = sqlite3.exe +!ENDIF + +# This is the argument used to set the program database (PDB) file for the +# SQLite shell executable (EXE). +# +!IFNDEF SQLITE3EXEPDB +SQLITE3EXEPDB = /pdb:sqlite3sh.pdb +!ENDIF + # These are the "standard" SQLite compilation options used when compiling for # the Windows platform. # @@ -195,6 +226,19 @@ OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_RTREE=1 OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_COLUMN_METADATA=1 !ENDIF +# These are the "extended" SQLite compilation options used when compiling for +# the Windows 10 platform. +# +!IFNDEF EXT_FEATURE_FLAGS +!IF $(FOR_WIN10)!=0 +EXT_FEATURE_FLAGS = $(EXT_FEATURE_FLAGS) -DSQLITE_ENABLE_FTS4=1 +EXT_FEATURE_FLAGS = $(EXT_FEATURE_FLAGS) -DSQLITE_SYSTEM_MALLOC=1 +EXT_FEATURE_FLAGS = $(EXT_FEATURE_FLAGS) -DSQLITE_OMIT_LOCALTIME=1 +!ELSE +EXT_FEATURE_FLAGS = +!ENDIF +!ENDIF + ############################################################################### ############################### END OF OPTIONS ################################ ############################################################################### @@ -327,9 +371,18 @@ TCC = $(CC) -nologo -W4 -DINCLUDE_MSVC_H=1 $(CCOPTS) $(TCCOPTS) TCC = $(CC) -nologo -W3 $(CCOPTS) $(TCCOPTS) !ENDIF -TCC = $(TCC) -DSQLITE_OS_WIN=1 -I. -I$(TOP) -I$(TOP)\src -fp:precise +TCC = $(TCC) -DSQLITE_OS_WIN=1 -I$(TOP) -I$(TOP)\src -fp:precise RCC = $(RC) -DSQLITE_OS_WIN=1 -I$(TOP) -I$(TOP)\src $(RCOPTS) $(RCCOPTS) +# Adjust the names of the primary targets for use with Windows 10. +# +!IF $(FOR_WIN10)!=0 +SQLITE3DLL = winsqlite3.dll +SQLITE3LIB = winsqlite3.lib +SQLITE3EXE = winsqlite3shell.exe +SQLITE3EXEPDB = +!ENDIF + # Check if we want to use the "stdcall" calling convention when compiling. # This is not supported by the compilers for non-x86 platforms. It should # also be noted here that building any target with these "stdcall" options @@ -337,7 +390,7 @@ RCC = $(RC) -DSQLITE_OS_WIN=1 -I$(TOP) -I$(TOP)\src $(RCOPTS) $(RCCOPTS) # to how the Tcl library functions are declared and exported (i.e. without # an explicit calling convention, which results in "cdecl"). # -!IF $(USE_STDCALL)!=0 +!IF $(USE_STDCALL)!=0 || $(FOR_WIN10)!=0 !IF "$(PLATFORM)"=="x86" CORE_CCONV_OPTS = -Gz -DSQLITE_CDECL=__cdecl -DSQLITE_STDCALL=__stdcall SHELL_CCONV_OPTS = -Gz -DSQLITE_CDECL=__cdecl -DSQLITE_STDCALL=__stdcall @@ -358,7 +411,7 @@ SHELL_CCONV_OPTS = # These are additional compiler options used for the core library. # !IFNDEF CORE_COMPILE_OPTS -!IF $(DYNAMIC_SHELL)!=0 +!IF $(DYNAMIC_SHELL)!=0 || $(FOR_WIN10)!=0 CORE_COMPILE_OPTS = $(CORE_CCONV_OPTS) -DSQLITE_API=__declspec(dllexport) !ELSE CORE_COMPILE_OPTS = $(CORE_CCONV_OPTS) @@ -369,7 +422,7 @@ CORE_COMPILE_OPTS = $(CORE_CCONV_OPTS) # when linking. # !IFNDEF CORE_LINK_DEP -!IF $(DYNAMIC_SHELL)!=0 +!IF $(DYNAMIC_SHELL)!=0 || $(FOR_WIN10)!=0 CORE_LINK_DEP = !ELSE CORE_LINK_DEP = sqlite3.def @@ -379,7 +432,7 @@ CORE_LINK_DEP = sqlite3.def # These are additional linker options used for the core library. # !IFNDEF CORE_LINK_OPTS -!IF $(DYNAMIC_SHELL)!=0 +!IF $(DYNAMIC_SHELL)!=0 || $(FOR_WIN10)!=0 CORE_LINK_OPTS = !ELSE CORE_LINK_OPTS = /DEF:sqlite3.def @@ -389,7 +442,7 @@ CORE_LINK_OPTS = /DEF:sqlite3.def # These are additional compiler options used for the shell executable. # !IFNDEF SHELL_COMPILE_OPTS -!IF $(DYNAMIC_SHELL)!=0 +!IF $(DYNAMIC_SHELL)!=0 || $(FOR_WIN10)!=0 SHELL_COMPILE_OPTS = -DSQLITE_SHELL_JSON1 $(SHELL_CCONV_OPTS) -DSQLITE_API=__declspec(dllimport) !ELSE SHELL_COMPILE_OPTS = -DSQLITE_SHELL_JSON1 $(SHELL_CCONV_OPTS) @@ -399,8 +452,8 @@ SHELL_COMPILE_OPTS = -DSQLITE_SHELL_JSON1 $(SHELL_CCONV_OPTS) # This is the core library that the shell executable should depend on. # !IFNDEF SHELL_CORE_DEP -!IF $(DYNAMIC_SHELL)!=0 -SHELL_CORE_DEP = sqlite3.dll +!IF $(DYNAMIC_SHELL)!=0 || $(FOR_WIN10)!=0 +SHELL_CORE_DEP = $(SQLITE3DLL) !ELSE SHELL_CORE_DEP = libsqlite3.lib !ENDIF @@ -409,8 +462,8 @@ SHELL_CORE_DEP = libsqlite3.lib # This is the core library that the shell executable should link with. # !IFNDEF SHELL_CORE_LIB -!IF $(DYNAMIC_SHELL)!=0 -SHELL_CORE_LIB = sqlite3.lib +!IF $(DYNAMIC_SHELL)!=0 || $(FOR_WIN10)!=0 +SHELL_CORE_LIB = $(SQLITE3LIB) !ELSE SHELL_CORE_LIB = libsqlite3.lib !ENDIF @@ -441,6 +494,13 @@ TCC = $(TCC) -DWINAPI_FAMILY=WINAPI_FAMILY_APP RCC = $(RCC) -DWINAPI_FAMILY=WINAPI_FAMILY_APP !ENDIF +# C compiler options for Windows 10 (needs Visual Studio 2015). +# +!IF $(FOR_WIN10)!=0 +TCC = $(TCC) /guard:cf -D_ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE +BCC = $(BCC) /guard:cf -D_ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE +!ENDIF + # Also, we need to dynamically link to the correct MSVC runtime # when compiling for WinRT (e.g. debug or release) OR if the # USE_CRT_DLL option is set to force dynamically linking to the @@ -498,7 +558,7 @@ BCC = $(BCC) -DNDEBUG RCC = $(RCC) -DNDEBUG !ENDIF -!IF $(DEBUG)>0 || $(API_ARMOR)!=0 +!IF $(DEBUG)>0 || $(API_ARMOR)!=0 || $(FOR_WIN10)!=0 TCC = $(TCC) -DSQLITE_ENABLE_API_ARMOR=1 RCC = $(RCC) -DSQLITE_ENABLE_API_ARMOR=1 !ENDIF @@ -659,8 +719,8 @@ REQ_FEATURE_FLAGS = $(REQ_FEATURE_FLAGS) -DSQLITE_WIN32_USE_UUID=1 # Add the required and optional SQLite compilation options into the command # lines used to invoke the MSVC code and resource compilers. # -TCC = $(TCC) $(REQ_FEATURE_FLAGS) $(OPT_FEATURE_FLAGS) -RCC = $(RCC) $(REQ_FEATURE_FLAGS) $(OPT_FEATURE_FLAGS) +TCC = $(TCC) $(REQ_FEATURE_FLAGS) $(OPT_FEATURE_FLAGS) $(EXT_FEATURE_FLAGS) +RCC = $(RCC) $(REQ_FEATURE_FLAGS) $(OPT_FEATURE_FLAGS) $(EXT_FEATURE_FLAGS) # Add in any optional parameters specified on the commane line, e.g. # nmake /f Makefile.msc all "OPTS=-DSQLITE_ENABLE_FOO=1 -DSQLITE_OMIT_FOO=1" @@ -1203,7 +1263,7 @@ EXTHDR = $(EXTHDR) \ # TESTPROGS = \ testfixture.exe \ - sqlite3.exe \ + $(SQLITE3EXE) \ sqlite3_analyzer.exe \ sqldiff.exe @@ -1217,7 +1277,10 @@ FUZZDATA = \ # Extra compiler options for various shell tools # -SHELL_COMPILE_OPTS = -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS5 +!IF $(FOR_WIN10)==0 +SHELL_COMPILE_OPTS = $(SHELL_COMPILE_OPTS) -DSQLITE_ENABLE_FTS5 +!ENDIF + FUZZERSHELL_COMPILE_OPTS = -DSQLITE_ENABLE_JSON1 FUZZCHECK_COMPILE_OPTS = -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_MEMSYS5 @@ -1228,7 +1291,7 @@ TESTOPTS = --verbose=file --output=test-out.txt # This is the default Makefile target. The objects listed here # are what get build when you type just "make" with no arguments. # -all: dll libsqlite3.lib sqlite3.exe libtclsqlite3.lib +all: dll libsqlite3.lib shell libtclsqlite3.lib libsqlite3.lib: $(LIBOBJ) $(LTLIB) $(LTLIBOPTS) /OUT:$@ $(LIBOBJ) $(TLIBS) @@ -1236,9 +1299,9 @@ libsqlite3.lib: $(LIBOBJ) libtclsqlite3.lib: tclsqlite.lo libsqlite3.lib $(LTLIB) $(LTLIBOPTS) $(LTLIBPATHS) /OUT:$@ tclsqlite.lo libsqlite3.lib $(LIBTCLSTUB) $(TLIBS) -sqlite3.exe: $(TOP)\src\shell.c $(SHELL_CORE_DEP) $(LIBRESOBJS) sqlite3.h - $(LTLINK) $(SHELL_COMPILE_OPTS) $(SHELL_COMPILE_OPTS) $(READLINE_FLAGS) $(TOP)\src\shell.c \ - /link /pdb:sqlite3sh.pdb $(LDFLAGS) $(LTLINKOPTS) $(SHELL_LINK_OPTS) $(LTLIBPATHS) $(LIBRESOBJS) $(LIBREADLINE) $(LTLIBS) $(TLIBS) +$(SQLITE3EXE): $(TOP)\src\shell.c $(SHELL_CORE_DEP) $(LIBRESOBJS) sqlite3.h + $(LTLINK) $(SHELL_COMPILE_OPTS) $(READLINE_FLAGS) $(TOP)\src\shell.c \ + /link $(SQLITE3EXEPDB) $(LDFLAGS) $(LTLINKOPTS) $(SHELL_LINK_OPTS) $(LTLIBPATHS) $(LIBRESOBJS) $(LIBREADLINE) $(LTLIBS) $(TLIBS) sqldiff.exe: $(TOP)\tool\sqldiff.c sqlite3.c sqlite3.h $(LTLINK) $(NO_WARN) $(TOP)\tool\sqldiff.c sqlite3.c /link $(LDFLAGS) $(LTLINKOPTS) @@ -1592,7 +1655,7 @@ parse.h: parse.c parse.c: $(TOP)\src\parse.y lemon.exe $(TOP)\tool\addopcodes.tcl del /Q parse.y parse.h parse.h.temp 2>NUL copy $(TOP)\src\parse.y . - .\lemon.exe $(REQ_FEATURE_FLAGS) $(OPT_FEATURE_FLAGS) $(OPTS) parse.y + .\lemon.exe $(REQ_FEATURE_FLAGS) $(OPT_FEATURE_FLAGS) $(EXT_FEATURE_FLAGS) $(OPTS) parse.y move parse.h parse.h.temp $(TCLSH_CMD) $(TOP)\tool\addopcodes.tcl parse.h.temp > parse.h @@ -1603,7 +1666,7 @@ sqlite3ext.h: .target_source copy tsrc\sqlite3ext.h . mkkeywordhash.exe: $(TOP)\tool\mkkeywordhash.c - $(BCC) $(NO_WARN) -Fe$@ $(REQ_FEATURE_FLAGS) $(OPT_FEATURE_FLAGS) $(OPTS) \ + $(BCC) $(NO_WARN) -Fe$@ $(REQ_FEATURE_FLAGS) $(OPT_FEATURE_FLAGS) $(EXT_FEATURE_FLAGS) $(OPTS) \ $(TOP)\tool\mkkeywordhash.c /link $(LDFLAGS) $(NLTLINKOPTS) $(NLTLIBPATHS) keywordhash.h: $(TOP)\tool\mkkeywordhash.c mkkeywordhash.exe @@ -1698,7 +1761,7 @@ FTS5_SRC = \ fts5parse.c: $(TOP)\ext\fts5\fts5parse.y lemon.exe copy $(TOP)\ext\fts5\fts5parse.y . del /Q fts5parse.h 2>NUL - .\lemon.exe $(REQ_FEATURE_FLAGS) $(OPT_FEATURE_FLAGS) $(OPTS) fts5parse.y + .\lemon.exe $(REQ_FEATURE_FLAGS) $(OPT_FEATURE_FLAGS) $(EXT_FEATURE_FLAGS) $(OPTS) fts5parse.y fts5parse.h: fts5parse.c @@ -1759,7 +1822,7 @@ fulltestonly: $(TESTPROGS) fuzztest @set PATH=$(LIBTCLPATH);$(PATH) .\testfixture.exe $(TOP)\test\full.test -queryplantest: testfixture.exe sqlite3.exe +queryplantest: testfixture.exe shell @set PATH=$(LIBTCLPATH);$(PATH) .\testfixture.exe $(TOP)\test\permutations.test queryplanner $(TESTOPTS) @@ -1864,7 +1927,7 @@ clean: del /Q LogEst.exe fts3view.exe rollback-test.exe showdb.exe 2>NUL del /Q showjournal.exe showstat4.exe showwal.exe speedtest1.exe 2>NUL del /Q mptester.exe wordcount.exe rbu.exe 2>NUL - del /Q sqlite3.exe sqlite3.dll sqlite3.def 2>NUL + del /Q $(SQLITE3EXE) $(SQLITE3DLL) sqlite3.def 2>NUL del /Q sqlite3.c sqlite3-*.c 2>NUL del /Q sqlite3rc.h 2>NUL del /Q shell.c sqlite3ext.h 2>NUL @@ -1873,9 +1936,13 @@ clean: del /Q fuzzershell.exe fuzzcheck.exe sqldiff.exe 2>NUL del /Q fts5.* fts5parse.* 2>NUL +# Shell executable. +# +shell: $(SQLITE3EXE) + # Dynamic link library section. # -dll: sqlite3.dll +dll: $(SQLITE3DLL) sqlite3.def: libsqlite3.lib echo EXPORTS > sqlite3.def @@ -1883,5 +1950,5 @@ sqlite3.def: libsqlite3.lib | $(TCLSH_CMD) $(TOP)\tool\replace.tcl include "^\s+1 _?(sqlite3_.*)$$" \1 \ | sort >> sqlite3.def -sqlite3.dll: $(LIBOBJ) $(LIBRESOBJS) $(CORE_LINK_DEP) +$(SQLITE3DLL): $(LIBOBJ) $(LIBRESOBJS) $(CORE_LINK_DEP) $(LD) $(LDFLAGS) $(LTLINKOPTS) $(LTLIBPATHS) /DLL $(CORE_LINK_OPTS) /OUT:$@ $(LIBOBJ) $(LIBRESOBJS) $(LTLIBS) $(TLIBS) diff --git a/manifest b/manifest index 94fd201a3d..67cd5b4802 100644 --- a/manifest +++ b/manifest @@ -1,8 +1,8 @@ -C Fix\stypo\sin\s'Makefile.in'. -D 2016-01-21T18:56:10.840 +C MSVC\smakefile\senhancements\sfor\suse\swith\sthe\sWindows\s10\sSDK. +D 2016-01-22T01:25:15.110 F Makefile.in 027c1603f255390c43a426671055a31c0a65fdb4 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 -F Makefile.msc c5ead4aa22ff6f528c755b07ed1e31184ac5b3d2 +F Makefile.msc 89b2e9780d97a6a3d7c89c4ad04d093787be3dc2 F README.md 8ecc12493ff9f820cdea6520a9016001cb2e59b7 F VERSION 866588d1edf0ccb5b0d33896974338f97564f719 F aclocal.m4 a5c22d164aff7ed549d53a90fa56d56955281f50 @@ -1419,7 +1419,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P a3cec529f0238e4ca1196fec420f2de80d28db78 -R 0153ee59df704041be1869f598c173fa +P 29a51c6dcc0ef7cab51aba0024e9c5bec89c6973 +R 9e26ae539c690ec3cae729a6d81b3775 U mistachkin -Z cab32b4afad5b6a6884b5ccdb88994ac +Z d4ab6d93e282614aa0160682fbcc0beb diff --git a/manifest.uuid b/manifest.uuid index 47bf74ce33..5f1ffc501a 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -29a51c6dcc0ef7cab51aba0024e9c5bec89c6973 \ No newline at end of file +ac2e9d3de54d299f92fc35927b6df6d3aaa2dc59 \ No newline at end of file From 5d4d941e94546ee93fe1b1823e903afc6b1f598c Mon Sep 17 00:00:00 2001 From: mistachkin Date: Fri, 22 Jan 2016 03:54:36 +0000 Subject: [PATCH 07/75] Further refinements to the MSVC makefile. FossilOrigin-Name: 67625b963a6f5a0c6dff1a04a323e693569c2d94 --- Makefile.msc | 126 +++++++++++++++++++++++++++++--------------------- manifest | 12 ++--- manifest.uuid | 2 +- 3 files changed, 81 insertions(+), 59 deletions(-) diff --git a/Makefile.msc b/Makefile.msc index 3ac19c2f73..a75045fc98 100644 --- a/Makefile.msc +++ b/Makefile.msc @@ -130,7 +130,7 @@ FOR_WINRT = 0 FOR_UAP = 0 !ENDIF -# Set this non-0 to compile binaries suitable for Windows 10. +# Set this non-0 to compile binaries suitable for the Windows 10 platform. # !IFNDEF FOR_WIN10 FOR_WIN10 = 0 @@ -192,6 +192,24 @@ DEBUG = 0 OPTIMIZATIONS = 2 !ENDIF +# Set the source code file to be used by executables and libraries when +# they need the amalgamation. +# +!IFNDEF SQLITE3C +!IF $(SPLIT_AMALGAMATION)!=0 +SQLITE3C = sqlite3-all.c +!ELSE +SQLITE3C = sqlite3.c +!ENDIF +!ENDIF + +# Set the include code file to be used by executables and libraries when +# they need SQLite. +# +!IFNDEF SQLITE3H +SQLITE3H = sqlite3.h +!ENDIF + # This is the name to use for the SQLite dynamic link library (DLL). # !IFNDEF SQLITE3DLL @@ -443,9 +461,20 @@ CORE_LINK_OPTS = /DEF:sqlite3.def # !IFNDEF SHELL_COMPILE_OPTS !IF $(DYNAMIC_SHELL)!=0 || $(FOR_WIN10)!=0 -SHELL_COMPILE_OPTS = -DSQLITE_SHELL_JSON1 $(SHELL_CCONV_OPTS) -DSQLITE_API=__declspec(dllimport) +SHELL_COMPILE_OPTS = $(SHELL_CCONV_OPTS) -DSQLITE_API=__declspec(dllimport) !ELSE -SHELL_COMPILE_OPTS = -DSQLITE_SHELL_JSON1 $(SHELL_CCONV_OPTS) +SHELL_COMPILE_OPTS = $(SHELL_CCONV_OPTS) +!ENDIF +!ENDIF + +# This is the source code that the shell executable should be compiled +# with. +# +!IFNDEF SHELL_CORE_SRC +!IF $(DYNAMIC_SHELL)!=0 || $(FOR_WIN10)!=0 +SHELL_CORE_SRC = +!ELSE +SHELL_CORE_SRC = $(SQLITE3C) !ENDIF !ENDIF @@ -455,7 +484,7 @@ SHELL_COMPILE_OPTS = -DSQLITE_SHELL_JSON1 $(SHELL_CCONV_OPTS) !IF $(DYNAMIC_SHELL)!=0 || $(FOR_WIN10)!=0 SHELL_CORE_DEP = $(SQLITE3DLL) !ELSE -SHELL_CORE_DEP = libsqlite3.lib +SHELL_CORE_DEP = !ENDIF !ENDIF @@ -465,7 +494,7 @@ SHELL_CORE_DEP = libsqlite3.lib !IF $(DYNAMIC_SHELL)!=0 || $(FOR_WIN10)!=0 SHELL_CORE_LIB = $(SQLITE3LIB) !ELSE -SHELL_CORE_LIB = libsqlite3.lib +SHELL_CORE_LIB = !ENDIF !ENDIF @@ -494,7 +523,7 @@ TCC = $(TCC) -DWINAPI_FAMILY=WINAPI_FAMILY_APP RCC = $(RCC) -DWINAPI_FAMILY=WINAPI_FAMILY_APP !ENDIF -# C compiler options for Windows 10 (needs Visual Studio 2015). +# C compiler options for the Windows 10 platform (needs MSVC 2015). # !IF $(FOR_WIN10)!=0 TCC = $(TCC) /guard:cf -D_ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE @@ -506,7 +535,7 @@ BCC = $(BCC) /guard:cf -D_ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE # USE_CRT_DLL option is set to force dynamically linking to the # MSVC runtime library. # -!IF $(FOR_WINRT)!=0 || $(USE_CRT_DLL)!=0 +!IF $(FOR_WINRT)!=0 || $(FOR_WIN10)!=0 || $(USE_CRT_DLL)!=0 !IF $(DEBUG)>1 TCC = $(TCC) -MDd BCC = $(BCC) -MDd @@ -1084,7 +1113,7 @@ SRC5 = \ opcodes.h \ parse.c \ parse.h \ - sqlite3.h + $(SQLITE3H) # All source code files. # @@ -1228,7 +1257,7 @@ HDR = \ $(TOP)\src\pcache.h \ parse.h \ $(TOP)\src\pragma.h \ - sqlite3.h \ + $(SQLITE3H) \ $(TOP)\src\sqlite3ext.h \ $(TOP)\src\sqliteInt.h \ $(TOP)\src\sqliteLimit.h \ @@ -1275,16 +1304,20 @@ FUZZDATA = \ $(TOP)\test\fuzzdata3.db \ $(TOP)\test\fuzzdata4.db -# Extra compiler options for various shell tools +# Additional compiler options for the shell. These are only effective +# when the shell is not being dynamically linked. # -!IF $(FOR_WIN10)==0 -SHELL_COMPILE_OPTS = $(SHELL_COMPILE_OPTS) -DSQLITE_ENABLE_FTS5 +!IF $(DYNAMIC_SHELL)==0 && $(FOR_WIN10)==0 +SHELL_COMPILE_OPTS = $(SHELL_COMPILE_OPTS) -DSQLITE_SHELL_JSON1 -DSQLITE_ENABLE_FTS5 !ENDIF +# Extra compiler options for various test tools. +# +MPTESTER_COMPILE_OPTS = -DSQLITE_SHELL_JSON1 -DSQLITE_ENABLE_FTS5 FUZZERSHELL_COMPILE_OPTS = -DSQLITE_ENABLE_JSON1 FUZZCHECK_COMPILE_OPTS = -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_MEMSYS5 -# Standard options to testfixture +# Standard options to testfixture. # TESTOPTS = --verbose=file --output=test-out.txt @@ -1299,23 +1332,21 @@ libsqlite3.lib: $(LIBOBJ) libtclsqlite3.lib: tclsqlite.lo libsqlite3.lib $(LTLIB) $(LTLIBOPTS) $(LTLIBPATHS) /OUT:$@ tclsqlite.lo libsqlite3.lib $(LIBTCLSTUB) $(TLIBS) -$(SQLITE3EXE): $(TOP)\src\shell.c $(SHELL_CORE_DEP) $(LIBRESOBJS) sqlite3.h - $(LTLINK) $(SHELL_COMPILE_OPTS) $(READLINE_FLAGS) $(TOP)\src\shell.c \ +$(SQLITE3EXE): $(TOP)\src\shell.c $(SHELL_CORE_DEP) $(LIBRESOBJS) $(SHELL_CORE_SRC) $(SQLITE3H) + $(LTLINK) $(SHELL_COMPILE_OPTS) $(READLINE_FLAGS) $(TOP)\src\shell.c $(SHELL_CORE_SRC) \ /link $(SQLITE3EXEPDB) $(LDFLAGS) $(LTLINKOPTS) $(SHELL_LINK_OPTS) $(LTLIBPATHS) $(LIBRESOBJS) $(LIBREADLINE) $(LTLIBS) $(TLIBS) -sqldiff.exe: $(TOP)\tool\sqldiff.c sqlite3.c sqlite3.h - $(LTLINK) $(NO_WARN) $(TOP)\tool\sqldiff.c sqlite3.c /link $(LDFLAGS) $(LTLINKOPTS) +sqldiff.exe: $(TOP)\tool\sqldiff.c $(SQLITE3C) $(SQLITE3H) + $(LTLINK) $(NO_WARN) $(TOP)\tool\sqldiff.c $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS) -fuzzershell.exe: $(TOP)\tool\fuzzershell.c sqlite3.c sqlite3.h - $(LTLINK) $(NO_WARN) $(FUZZERSHELL_COMPILE_OPTS) \ - $(TOP)\tool\fuzzershell.c sqlite3.c /link $(LDFLAGS) $(LTLINKOPTS) +fuzzershell.exe: $(TOP)\tool\fuzzershell.c $(SQLITE3C) $(SQLITE3H) + $(LTLINK) $(NO_WARN) $(FUZZERSHELL_COMPILE_OPTS) $(TOP)\tool\fuzzershell.c $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS) -fuzzcheck.exe: $(TOP)\test\fuzzcheck.c sqlite3.c sqlite3.h - $(LTLINK) $(NO_WARN) $(FUZZCHECK_COMPILE_OPTS) $(TOP)\test\fuzzcheck.c sqlite3.c /link $(LDFLAGS) $(LTLINKOPTS) +fuzzcheck.exe: $(TOP)\test\fuzzcheck.c $(SQLITE3C) $(SQLITE3H) + $(LTLINK) $(NO_WARN) $(FUZZCHECK_COMPILE_OPTS) $(TOP)\test\fuzzcheck.c $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS) -mptester.exe: $(TOP)\mptest\mptest.c $(SHELL_CORE_DEP) $(LIBRESOBJS) sqlite3.h - $(LTLINK) $(NO_WARN) $(SHELL_COMPILE_OPTS) $(TOP)\mptest\mptest.c \ - /link $(LDFLAGS) $(LTLINKOPTS) $(LTLIBPATHS) $(SHELL_LINK_OPTS) $(LIBRESOBJS) $(LIBREADLINE) $(LTLIBS) $(TLIBS) +mptester.exe: $(TOP)\mptest\mptest.c $(SQLITE3C) $(SQLITE3H) + $(LTLINK) $(NO_WARN) $(MPTESTER_COMPILE_OPTS) $(TOP)\mptest\mptest.c $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS) MPTEST1 = mptester mptest.db $(TOP)\mptest\crash01.test --repeat 20 MPTEST2 = mptester mptest.db $(TOP)\mptest\multiwrite01.test --repeat 20 @@ -1359,15 +1390,6 @@ sqlite3.c: .target_source sqlite3ext.h $(TOP)\tool\mksqlite3c.tcl sqlite3-all.c: sqlite3.c $(TOP)\tool\split-sqlite3c.tcl $(TCLSH_CMD) $(TOP)\tool\split-sqlite3c.tcl -# Set the source code file to be used by executables and libraries when -# they need the amalgamation. -# -!IF $(SPLIT_AMALGAMATION)!=0 -SQLITE3C = sqlite3-all.c -!ELSE -SQLITE3C = sqlite3.c -!ENDIF - # Rule to build the amalgamation # sqlite3.lo: $(SQLITE3C) @@ -1637,7 +1659,7 @@ tclsqlite.lo: $(TOP)\src\tclsqlite.c $(HDR) tclsqlite-shell.lo: $(TOP)\src\tclsqlite.c $(HDR) $(LTCOMPILE) $(NO_WARN) -DTCLSH=1 -DBUILD_sqlite -I$(TCLINCDIR) -c $(TOP)\src\tclsqlite.c -tclsqlite3.exe: tclsqlite-shell.lo $(SQLITE3C) $(LIBRESOBJS) +tclsqlite3.exe: tclsqlite-shell.lo $(SQLITE3C) $(SQLITE3H) $(LIBRESOBJS) $(LTLINK) $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS) $(LTLIBPATHS) /OUT:$@ tclsqlite-shell.lo $(LIBRESOBJS) $(LTLIBS) $(TLIBS) # Rules to build opcodes.c and opcodes.h @@ -1659,8 +1681,8 @@ parse.c: $(TOP)\src\parse.y lemon.exe $(TOP)\tool\addopcodes.tcl move parse.h parse.h.temp $(TCLSH_CMD) $(TOP)\tool\addopcodes.tcl parse.h.temp > parse.h -sqlite3.h: $(TOP)\src\sqlite.h.in $(TOP)\manifest.uuid $(TOP)\VERSION - $(TCLSH_CMD) $(TOP)\tool\mksqlite3h.tcl $(TOP:\=/) > sqlite3.h +$(SQLITE3H): $(TOP)\src\sqlite.h.in $(TOP)\manifest.uuid $(TOP)\VERSION + $(TCLSH_CMD) $(TOP)\tool\mksqlite3h.tcl $(TOP:\=/) > $(SQLITE3H) sqlite3ext.h: .target_source copy tsrc\sqlite3ext.h . @@ -1800,7 +1822,7 @@ TESTFIXTURE_SRC = $(TESTSRC) $(TOP)\src\tclsqlite.c $(TESTFIXTURE_SRC0) TESTFIXTURE_SRC = $(TESTSRC) $(TOP)\src\tclsqlite.c $(TESTFIXTURE_SRC1) !ENDIF -testfixture.exe: $(TESTFIXTURE_SRC) $(LIBRESOBJS) $(HDR) +testfixture.exe: $(TESTFIXTURE_SRC) $(SQLITE3H) $(LIBRESOBJS) $(HDR) $(LTLINK) -DSQLITE_NO_SYNC=1 $(TESTFIXTURE_FLAGS) \ -DBUILD_sqlite -I$(TCLINCDIR) \ $(TESTFIXTURE_SRC) \ @@ -1849,7 +1871,7 @@ smoketest: $(TESTPROGS) @set PATH=$(LIBTCLPATH);$(PATH) .\testfixture.exe $(TOP)\test\main.test $(TESTOPTS) -sqlite3_analyzer.c: $(SQLITE3C) $(TOP)\src\tclsqlite.c $(TOP)\tool\spaceanal.tcl +sqlite3_analyzer.c: $(SQLITE3C) $(SQLITE3H) $(TOP)\src\tclsqlite.c $(TOP)\tool\spaceanal.tcl echo #define TCLSH 2 > $@ echo #define SQLITE_ENABLE_DBSTAT_VTAB 1 >> $@ copy $@ + $(SQLITE3C) + $(TOP)\src\tclsqlite.c $@ @@ -1868,49 +1890,49 @@ testloadext.lo: $(TOP)\src\test_loadext.c testloadext.dll: testloadext.lo $(LD) $(LDFLAGS) $(LTLINKOPTS) $(LTLIBPATHS) /DLL /OUT:$@ testloadext.lo -showdb.exe: $(TOP)\tool\showdb.c $(SQLITE3C) +showdb.exe: $(TOP)\tool\showdb.c $(SQLITE3C) $(SQLITE3H) $(LTLINK) $(NO_WARN) -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION -Fe$@ \ $(TOP)\tool\showdb.c $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS) -showstat4.exe: $(TOP)\tool\showstat4.c $(SQLITE3C) +showstat4.exe: $(TOP)\tool\showstat4.c $(SQLITE3C) $(SQLITE3H) $(LTLINK) $(NO_WARN) -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION -Fe$@ \ $(TOP)\tool\showstat4.c $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS) -showjournal.exe: $(TOP)\tool\showjournal.c $(SQLITE3C) +showjournal.exe: $(TOP)\tool\showjournal.c $(SQLITE3C) $(SQLITE3H) $(LTLINK) $(NO_WARN) -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION -Fe$@ \ $(TOP)\tool\showjournal.c $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS) -showwal.exe: $(TOP)\tool\showwal.c $(SQLITE3C) +showwal.exe: $(TOP)\tool\showwal.c $(SQLITE3C) $(SQLITE3H) $(LTLINK) $(NO_WARN) -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION -Fe$@ \ $(TOP)\tool\showwal.c $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS) -fts3view.exe: $(TOP)\ext\fts3\tool\fts3view.c $(SQLITE3C) +fts3view.exe: $(TOP)\ext\fts3\tool\fts3view.c $(SQLITE3C) $(SQLITE3H) $(LTLINK) $(NO_WARN) -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION -Fe$@ \ $(TOP)\ext\fts3\tool\fts3view.c $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS) -rollback-test.exe: $(TOP)\tool\rollback-test.c $(SQLITE3C) +rollback-test.exe: $(TOP)\tool\rollback-test.c $(SQLITE3C) $(SQLITE3H) $(LTLINK) $(NO_WARN) -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION -Fe$@ \ $(TOP)\tool\rollback-test.c $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS) -LogEst.exe: $(TOP)\tool\logest.c sqlite3.h +LogEst.exe: $(TOP)\tool\logest.c $(SQLITE3H) $(LTLINK) $(NO_WARN) -Fe$@ $(TOP)\tool\LogEst.c /link $(LDFLAGS) $(LTLINKOPTS) -wordcount.exe: $(TOP)\test\wordcount.c $(SQLITE3C) +wordcount.exe: $(TOP)\test\wordcount.c $(SQLITE3C) $(SQLITE3H) $(LTLINK) $(NO_WARN) -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION -Fe$@ \ $(TOP)\test\wordcount.c $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS) -speedtest1.exe: $(TOP)\test\speedtest1.c $(SQLITE3C) +speedtest1.exe: $(TOP)\test\speedtest1.c $(SQLITE3C) $(SQLITE3H) $(LTLINK) $(NO_WARN) -DSQLITE_OMIT_LOAD_EXTENSION -Fe$@ \ $(TOP)\test\speedtest1.c $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS) -rbu.exe: $(TOP)\ext\rbu\rbu.c $(TOP)\ext\rbu\sqlite3rbu.c $(SQLITE3C) - $(LTLINK) $(NO_WARN) -DSQLITE_ENABLE_RBU -Fe$@ $(TOP)\ext\rbu\rbu.c $(SQLITE3C) \ - /link $(LDFLAGS) $(LTLINKOPTS) +rbu.exe: $(TOP)\ext\rbu\rbu.c $(TOP)\ext\rbu\sqlite3rbu.c $(SQLITE3C) $(SQLITE3H) + $(LTLINK) $(NO_WARN) -DSQLITE_ENABLE_RBU -Fe$@ \ + $(TOP)\ext\rbu\rbu.c $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS) clean: del /Q *.exp *.lo *.ilk *.lib *.obj *.ncb *.pdb *.sdf *.suo 2>NUL del /Q *.bsc *.cod *.da *.bb *.bbg gmon.out 2>NUL - del /Q sqlite3.h opcodes.c opcodes.h 2>NUL + del /Q $(SQLITE3C) $(SQLITE3H) opcodes.c opcodes.h 2>NUL del /Q lemon.* lempar.c parse.* 2>NUL del /Q mkkeywordhash.* keywordhash.h 2>NUL del /Q notasharedlib.* 2>NUL diff --git a/manifest b/manifest index 67cd5b4802..c364abf8fa 100644 --- a/manifest +++ b/manifest @@ -1,8 +1,8 @@ -C MSVC\smakefile\senhancements\sfor\suse\swith\sthe\sWindows\s10\sSDK. -D 2016-01-22T01:25:15.110 +C Further\srefinements\sto\sthe\sMSVC\smakefile. +D 2016-01-22T03:54:36.710 F Makefile.in 027c1603f255390c43a426671055a31c0a65fdb4 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 -F Makefile.msc 89b2e9780d97a6a3d7c89c4ad04d093787be3dc2 +F Makefile.msc 7e45640ca31116b24372d30a4e087078db22fcd8 F README.md 8ecc12493ff9f820cdea6520a9016001cb2e59b7 F VERSION 866588d1edf0ccb5b0d33896974338f97564f719 F aclocal.m4 a5c22d164aff7ed549d53a90fa56d56955281f50 @@ -1419,7 +1419,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 29a51c6dcc0ef7cab51aba0024e9c5bec89c6973 -R 9e26ae539c690ec3cae729a6d81b3775 +P ac2e9d3de54d299f92fc35927b6df6d3aaa2dc59 +R 2fd39a9f583616f965419daf8ad2c68a U mistachkin -Z d4ab6d93e282614aa0160682fbcc0beb +Z 2b921b34884313de5b54030da9770cbb diff --git a/manifest.uuid b/manifest.uuid index 5f1ffc501a..51b2a1dd73 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ac2e9d3de54d299f92fc35927b6df6d3aaa2dc59 \ No newline at end of file +67625b963a6f5a0c6dff1a04a323e693569c2d94 \ No newline at end of file From d7d305a25aaa60ce55f9e6ec1840b39309282015 Mon Sep 17 00:00:00 2001 From: mistachkin Date: Fri, 22 Jan 2016 04:22:36 +0000 Subject: [PATCH 08/75] Enable FTS4 when building the shell with the MSVC makefile. FossilOrigin-Name: e4c07df557cd50786b05eecf011bf94708e6e31b --- Makefile.msc | 2 +- manifest | 12 ++++++------ manifest.uuid | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Makefile.msc b/Makefile.msc index a75045fc98..3621d4f92b 100644 --- a/Makefile.msc +++ b/Makefile.msc @@ -1308,7 +1308,7 @@ FUZZDATA = \ # when the shell is not being dynamically linked. # !IF $(DYNAMIC_SHELL)==0 && $(FOR_WIN10)==0 -SHELL_COMPILE_OPTS = $(SHELL_COMPILE_OPTS) -DSQLITE_SHELL_JSON1 -DSQLITE_ENABLE_FTS5 +SHELL_COMPILE_OPTS = $(SHELL_COMPILE_OPTS) -DSQLITE_SHELL_JSON1 -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS5 !ENDIF # Extra compiler options for various test tools. diff --git a/manifest b/manifest index c364abf8fa..5d0ee23cca 100644 --- a/manifest +++ b/manifest @@ -1,8 +1,8 @@ -C Further\srefinements\sto\sthe\sMSVC\smakefile. -D 2016-01-22T03:54:36.710 +C Enable\sFTS4\swhen\sbuilding\sthe\sshell\swith\sthe\sMSVC\smakefile. +D 2016-01-22T04:22:36.961 F Makefile.in 027c1603f255390c43a426671055a31c0a65fdb4 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 -F Makefile.msc 7e45640ca31116b24372d30a4e087078db22fcd8 +F Makefile.msc d2b93511a969c0c8fcf52aeb5e426571e8c610d2 F README.md 8ecc12493ff9f820cdea6520a9016001cb2e59b7 F VERSION 866588d1edf0ccb5b0d33896974338f97564f719 F aclocal.m4 a5c22d164aff7ed549d53a90fa56d56955281f50 @@ -1419,7 +1419,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P ac2e9d3de54d299f92fc35927b6df6d3aaa2dc59 -R 2fd39a9f583616f965419daf8ad2c68a +P 67625b963a6f5a0c6dff1a04a323e693569c2d94 +R a9194694e295a05f59bbd77f1c470bc0 U mistachkin -Z 2b921b34884313de5b54030da9770cbb +Z bf1c280948a8257fdbbacb5c97da93b0 diff --git a/manifest.uuid b/manifest.uuid index 51b2a1dd73..533751ec8a 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -67625b963a6f5a0c6dff1a04a323e693569c2d94 \ No newline at end of file +e4c07df557cd50786b05eecf011bf94708e6e31b \ No newline at end of file From b5c557b87e0e54f39ade09a73dc0b7cb13d2c93d Mon Sep 17 00:00:00 2001 From: dan Date: Fri, 22 Jan 2016 15:44:07 +0000 Subject: [PATCH 09/75] Have the dbstat module dequote any argument passed to the CREATE VIRTUAL TABLE statement before attempting to match it against the names of attached databases. FossilOrigin-Name: e60461e984b8df09256bb0d733dbfae52568a145 --- manifest | 16 ++++++------ manifest.uuid | 2 +- src/dbstat.c | 6 ++++- test/stat.test | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 80 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index 5d0ee23cca..c4697a9a83 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Enable\sFTS4\swhen\sbuilding\sthe\sshell\swith\sthe\sMSVC\smakefile. -D 2016-01-22T04:22:36.961 +C Have\sthe\sdbstat\smodule\sdequote\sany\sargument\spassed\sto\sthe\sCREATE\sVIRTUAL\sTABLE\sstatement\sbefore\sattempting\sto\smatch\sit\sagainst\sthe\snames\sof\sattached\sdatabases. +D 2016-01-22T15:44:07.317 F Makefile.in 027c1603f255390c43a426671055a31c0a65fdb4 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc d2b93511a969c0c8fcf52aeb5e426571e8c610d2 @@ -296,7 +296,7 @@ F src/callback.c 29ae4faba226c7ebb9aee93016b5ce8a8f071261 F src/complete.c addcd8160b081131005d5bc2d34adf20c1c5c92f F src/ctime.c 60e135af364d777a9ab41c97e5e89cd224da6198 F src/date.c 997651e3ee6c2818fbf7fcdb7156cef9eb3ece20 -F src/dbstat.c ffd63fc8ba7541476ced189b95e95d7f2bc63f78 +F src/dbstat.c d33af6b426449d7bfd5b3d9f77911c20d1c8abdc F src/delete.c 00af9f08a15ddc5cba5962d3d3e5bf2d67b2e7da F src/expr.c df0d7c3230d59abd679da22ff5ce4cfd0e3a0e63 F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb @@ -1052,7 +1052,7 @@ F test/spellfix3.test f7bf7b3482971473d32b6b00f6944c5c066cff97 F test/sqldiff1.test 8f6bc7c6a5b3585d350d779c6078869ba402f8f5 F test/sqllimits1.test a74ee2a3740b9f9c2437c246d8fb77354862a142 F test/sqllog.test a8faa2df39610a037dd372ed872d124260d32953 -F test/stat.test 8de91498c99f5298b303f70f1d1f3b9557af91bf +F test/stat.test fafe6e82dfdb97d8c8be31cd83e36e973079ce0f F test/statfault.test f525a7bf633e50afd027700e9a486090684b1ac1 F test/stmt.test 25d64e3dbf9a3ce89558667d7f39d966fe2a71b9 F test/subquery.test d7268d193dd33d5505df965399d3a594e76ae13f @@ -1419,7 +1419,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 67625b963a6f5a0c6dff1a04a323e693569c2d94 -R a9194694e295a05f59bbd77f1c470bc0 -U mistachkin -Z bf1c280948a8257fdbbacb5c97da93b0 +P e4c07df557cd50786b05eecf011bf94708e6e31b +R ccbd95b5668f9b5a41b204404932d800 +U dan +Z ad5fc4f27f7e976928da8b4460d48d82 diff --git a/manifest.uuid b/manifest.uuid index 533751ec8a..800a36102e 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -e4c07df557cd50786b05eecf011bf94708e6e31b \ No newline at end of file +e60461e984b8df09256bb0d733dbfae52568a145 \ No newline at end of file diff --git a/src/dbstat.c b/src/dbstat.c index ae55d6b803..e404c71dd3 100644 --- a/src/dbstat.c +++ b/src/dbstat.c @@ -149,7 +149,11 @@ static int statConnect( int iDb; if( argc>=4 ){ - iDb = sqlite3FindDbName(db, argv[3]); + char *zDb = sqlite3DbStrDup(db, argv[3]); + if( zDb==0 ) return SQLITE_NOMEM; + sqlite3Dequote(zDb); + iDb = sqlite3FindDbName(db, zDb); + sqlite3DbFree(db, zDb); if( iDb<0 ){ *pzErr = sqlite3_mprintf("no such database: %s", argv[3]); return SQLITE_ERROR; diff --git a/test/stat.test b/test/stat.test index 57c1b9eae1..14751bd6ff 100644 --- a/test/stat.test +++ b/test/stat.test @@ -14,6 +14,7 @@ set testdir [file dirname $argv0] source $testdir/tester.tcl +set testprefix stat ifcapable !vtab||!compound { finish_test @@ -184,4 +185,69 @@ do_catchsql_test stat-6.1 { CREATE VIRTUAL TABLE temp.s2 USING dbstat(mainx); } {1 {no such database: mainx}} +#------------------------------------------------------------------------- +# Test that the argument passed to the dbstat constructor is dequoted +# before it is matched against the names of attached databases. +# +forcedelete test.db2 +do_execsql_test 7.1 { + ATTACH 'test.db2' AS '123'; + CREATE TABLE "123".x1(a, b); + INSERT INTO x1 VALUES(1, 2); +} + +do_execsql_test 7.1.1 { + SELECT * FROM dbstat('123'); +} { + sqlite_master / 1 leaf 1 37 875 37 0 1024 + x1 / 2 leaf 1 4 1008 4 1024 1024 +} +do_execsql_test 7.1.2 { + SELECT * FROM dbstat(123); +} { + sqlite_master / 1 leaf 1 37 875 37 0 1024 + x1 / 2 leaf 1 4 1008 4 1024 1024 +} +do_execsql_test 7.1.3 { + CREATE VIRTUAL TABLE x2 USING dbstat('123'); + SELECT * FROM x2; +} { + sqlite_master / 1 leaf 1 37 875 37 0 1024 + x1 / 2 leaf 1 4 1008 4 1024 1024 +} +do_execsql_test 7.1.4 { + CREATE VIRTUAL TABLE x3 USING dbstat(123); + SELECT * FROM x3; +} { + sqlite_master / 1 leaf 1 37 875 37 0 1024 + x1 / 2 leaf 1 4 1008 4 1024 1024 +} + +do_execsql_test 7.2 { + DETACH 123; + DROP TABLE x2; + DROP TABLE x3; + ATTACH 'test.db2' AS '123corp'; +} +do_execsql_test 7.2.1 { + SELECT * FROM dbstat('123corp'); +} { + sqlite_master / 1 leaf 1 37 875 37 0 1024 + x1 / 2 leaf 1 4 1008 4 1024 1024 +} +do_catchsql_test 7.2.2 { + SELECT * FROM dbstat(123corp); +} {1 {unrecognized token: "123corp"}} +do_execsql_test 7.2.3 { + CREATE VIRTUAL TABLE x2 USING dbstat('123corp'); + SELECT * FROM x2; +} { + sqlite_master / 1 leaf 1 37 875 37 0 1024 + x1 / 2 leaf 1 4 1008 4 1024 1024 +} +do_catchsql_test 7.2.4 { + CREATE VIRTUAL TABLE x3 USING dbstat(123corp); + SELECT * FROM x3; +} {1 {unrecognized token: "123corp"}} + finish_test From 40aced5c654a3f3322f49fa9e4b2116f43167790 Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 22 Jan 2016 17:48:09 +0000 Subject: [PATCH 10/75] Add the sqlite3TokenInit() utility function. FossilOrigin-Name: 7323175337b7ba85ac932ca892b28860f6a5b688 --- manifest | 28 ++++++++++++++-------------- manifest.uuid | 2 +- src/build.c | 6 ++---- src/dbstat.c | 8 +++----- src/expr.c | 3 +-- src/fkey.c | 8 +++----- src/select.c | 3 +-- src/sqliteInt.h | 1 + src/trigger.c | 3 +-- src/util.c | 8 ++++++++ 10 files changed, 35 insertions(+), 35 deletions(-) diff --git a/manifest b/manifest index c4697a9a83..6c3814c3d9 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Have\sthe\sdbstat\smodule\sdequote\sany\sargument\spassed\sto\sthe\sCREATE\sVIRTUAL\sTABLE\sstatement\sbefore\sattempting\sto\smatch\sit\sagainst\sthe\snames\sof\sattached\sdatabases. -D 2016-01-22T15:44:07.317 +C Add\sthe\ssqlite3TokenInit()\sutility\sfunction. +D 2016-01-22T17:48:09.470 F Makefile.in 027c1603f255390c43a426671055a31c0a65fdb4 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc d2b93511a969c0c8fcf52aeb5e426571e8c610d2 @@ -291,16 +291,16 @@ F src/btmutex.c bc87dd3b062cc26edfe79918de2200ccb8d41e73 F src/btree.c f224ae877fde69d1a9d430f502edaf8502752dbe F src/btree.h 526137361963e746949ab966a910c7f455ac6b04 F src/btreeInt.h c18b7d2a3494695133e4e60ee36061d37f45d9a5 -F src/build.c 31af80bba31ac159967951ef58f3144cc7db9d70 +F src/build.c b4eba1e84752ec9cae7ff3dacd5a8b6d1ab8deb9 F src/callback.c 29ae4faba226c7ebb9aee93016b5ce8a8f071261 F src/complete.c addcd8160b081131005d5bc2d34adf20c1c5c92f F src/ctime.c 60e135af364d777a9ab41c97e5e89cd224da6198 F src/date.c 997651e3ee6c2818fbf7fcdb7156cef9eb3ece20 -F src/dbstat.c d33af6b426449d7bfd5b3d9f77911c20d1c8abdc +F src/dbstat.c b2ec6793eef97aebb4d171d490a4ffdfa9f2475c F src/delete.c 00af9f08a15ddc5cba5962d3d3e5bf2d67b2e7da -F src/expr.c df0d7c3230d59abd679da22ff5ce4cfd0e3a0e63 +F src/expr.c d10c1cdef5810cdbf73adc9f9b383684230b360a F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb -F src/fkey.c e18b3dff7d47c7bcac5ac4fc178a89b9fd322b44 +F src/fkey.c c66d3e5b35d4d95b5c1e2ee6c12f5df13a7f9ad6 F src/func.c ba6c03f9e440f5693086c08ee88e6e60212b3504 F src/global.c bd5a0af3f30b0c01be6db756c626cd3c33a3d260 F src/hash.c 4263fbc955f26c2e8cdc0cf214bc42435aa4e4f5 @@ -345,12 +345,12 @@ F src/printf.c af589a27b7d40f6f4f704e9eea99f02f18ad6d32 F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c 9f7ce3a3c087afb7597b7c916c99126ff3f12f0c F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e -F src/select.c 718954db86277d696c520fe671148db1e9c4ed3c +F src/select.c 1db9a902e89201a0ae3ff5243a7a3f37842a3937 F src/shell.c dcd7a83645ef2a58ee9c6d0ea4714d877d7835c4 F src/sqlite.h.in 214476a62012e578f42133a9a3b4f97a9aa421a3 F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h dfbe62ffd95b99afe2140d8c35b180d11924072d -F src/sqliteInt.h 0403328581127bc8ad2f9cc7af2c3bb23d5316da +F src/sqliteInt.h 74e10a74116df0aec9d4a3e134f1a86cc34c2f14 F src/sqliteLimit.h 216557999cb45f2e3578ed53ebefe228d779cb46 F src/status.c 70912d7be68e9e2dbc4010c93d344af61d4c59ba F src/table.c 51b46b2a62d1b3a959633d593b89bab5e2c9155e @@ -405,10 +405,10 @@ F src/test_wsd.c 41cadfd9d97fe8e3e4e44f61a4a8ccd6f7ca8fe9 F src/threads.c bbfb74450643cb5372a43ad4f6cffd7e9dfcecb0 F src/tokenize.c 5606871a377f390af7040ec3c12e0d183512d785 F src/treeview.c 78842e90c1f71269e7a73a1d4221b6fe360bab66 -F src/trigger.c 056e51182a3677434423e3be0c74e61b90b4a663 +F src/trigger.c 72d876b2d0c66604a112362bdae07dae9b104816 F src/update.c 17332f9fe818cbc0444c36a811800af8498af4c3 F src/utf.c 32d7f82aa921322f3e1c956f4b58f019ebd2c6b3 -F src/util.c e802e8e311a0d6c48cd1b3e89db164f6f0248d70 +F src/util.c 72d40df0a52d3f30b462a15f0e094fcbade6dc82 F src/vacuum.c 2ddd5cad2a7b9cef7f9e431b8c7771634c6b1701 F src/vdbe.c b90d9d38e5e0260c2eafa3cb4c2274d8ea94da27 F src/vdbe.h 7a733ea8aac1b77305a67698e784fa3484ee3337 @@ -1419,7 +1419,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P e4c07df557cd50786b05eecf011bf94708e6e31b -R ccbd95b5668f9b5a41b204404932d800 -U dan -Z ad5fc4f27f7e976928da8b4460d48d82 +P e60461e984b8df09256bb0d733dbfae52568a145 +R 03ab6310cefadc63b5c7c7da966c2348 +U drh +Z 0c42ba520d71deaa3e0a21b23ff67f9d diff --git a/manifest.uuid b/manifest.uuid index 800a36102e..e9fd60917b 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -e60461e984b8df09256bb0d733dbfae52568a145 \ No newline at end of file +7323175337b7ba85ac932ca892b28860f6a5b688 \ No newline at end of file diff --git a/src/build.c b/src/build.c index f7074ab417..06f5433e37 100644 --- a/src/build.c +++ b/src/build.c @@ -1708,8 +1708,7 @@ static void convertToWithoutRowidTable(Parse *pParse, Table *pTab){ if( pTab->iPKey>=0 ){ ExprList *pList; Token ipkToken; - ipkToken.z = pTab->aCol[pTab->iPKey].zName; - ipkToken.n = sqlite3Strlen30(ipkToken.z); + sqlite3TokenInit(&ipkToken, pTab->aCol[pTab->iPKey].zName); pList = sqlite3ExprListAppend(pParse, 0, sqlite3ExprAlloc(db, TK_ID, &ipkToken, 0)); if( pList==0 ) return; @@ -3057,8 +3056,7 @@ Index *sqlite3CreateIndex( */ if( pList==0 ){ Token prevCol; - prevCol.z = pTab->aCol[pTab->nCol-1].zName; - prevCol.n = sqlite3Strlen30(prevCol.z); + sqlite3TokenInit(&prevCol, pTab->aCol[pTab->nCol-1].zName); pList = sqlite3ExprListAppend(pParse, 0, sqlite3ExprAlloc(db, TK_ID, &prevCol, 0)); if( pList==0 ) goto exit_create_index; diff --git a/src/dbstat.c b/src/dbstat.c index e404c71dd3..5e42cdfe38 100644 --- a/src/dbstat.c +++ b/src/dbstat.c @@ -149,11 +149,9 @@ static int statConnect( int iDb; if( argc>=4 ){ - char *zDb = sqlite3DbStrDup(db, argv[3]); - if( zDb==0 ) return SQLITE_NOMEM; - sqlite3Dequote(zDb); - iDb = sqlite3FindDbName(db, zDb); - sqlite3DbFree(db, zDb); + Token nm; + sqlite3TokenInit(&nm, (char*)argv[3]); + iDb = sqlite3FindDb(db, &nm); if( iDb<0 ){ *pzErr = sqlite3_mprintf("no such database: %s", argv[3]); return SQLITE_ERROR; diff --git a/src/expr.c b/src/expr.c index 403e81cf34..c91db2834f 100644 --- a/src/expr.c +++ b/src/expr.c @@ -85,8 +85,7 @@ Expr *sqlite3ExprAddCollateToken( Expr *sqlite3ExprAddCollateString(Parse *pParse, Expr *pExpr, const char *zC){ Token s; assert( zC!=0 ); - s.z = zC; - s.n = sqlite3Strlen30(s.z); + sqlite3TokenInit(&s, (char*)zC); return sqlite3ExprAddCollateToken(pParse, pExpr, &s, 0); } diff --git a/src/fkey.c b/src/fkey.c index 2abd06c693..7eb188924d 100644 --- a/src/fkey.c +++ b/src/fkey.c @@ -1192,11 +1192,9 @@ static Trigger *fkActionTrigger( assert( iFromCol>=0 ); assert( pIdx!=0 || (pTab->iPKey>=0 && pTab->iPKeynCol) ); assert( pIdx==0 || pIdx->aiColumn[i]>=0 ); - tToCol.z = pTab->aCol[pIdx ? pIdx->aiColumn[i] : pTab->iPKey].zName; - tFromCol.z = pFKey->pFrom->aCol[iFromCol].zName; - - tToCol.n = sqlite3Strlen30(tToCol.z); - tFromCol.n = sqlite3Strlen30(tFromCol.z); + sqlite3TokenInit(&tToCol, + pTab->aCol[pIdx ? pIdx->aiColumn[i] : pTab->iPKey].zName); + sqlite3TokenInit(&tFromCol, pFKey->pFrom->aCol[iFromCol].zName); /* Create the expression "OLD.zToCol = zFromCol". It is important ** that the "OLD.zToCol" term is on the LHS of the = operator, so diff --git a/src/select.c b/src/select.c index 9eb6279c10..ffc0ec2415 100644 --- a/src/select.c +++ b/src/select.c @@ -4438,8 +4438,7 @@ static int selectExpander(Walker *pWalker, Select *p){ pExpr = pRight; } pNew = sqlite3ExprListAppend(pParse, pNew, pExpr); - sColname.z = zColname; - sColname.n = sqlite3Strlen30(zColname); + sqlite3TokenInit(&sColname, zColname); sqlite3ExprListSetName(pParse, pNew, &sColname, 0); if( pNew && (p->selFlags & SF_NestedFrom)!=0 ){ struct ExprList_item *pX = &pNew->a[pNew->nExpr-1]; diff --git a/src/sqliteInt.h b/src/sqliteInt.h index b536b8ab28..1a8a5d3a5b 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -3322,6 +3322,7 @@ char *sqlite3VMPrintf(sqlite3*,const char*, va_list); void sqlite3SetString(char **, sqlite3*, const char*); void sqlite3ErrorMsg(Parse*, const char*, ...); int sqlite3Dequote(char*); +void sqlite3TokenInit(Token*,char*); int sqlite3KeywordCode(const unsigned char*, int); int sqlite3RunParser(Parse*, const char*, char **); void sqlite3FinishCoding(Parse*); diff --git a/src/trigger.c b/src/trigger.c index 48d6772992..4bfb55af69 100644 --- a/src/trigger.c +++ b/src/trigger.c @@ -287,8 +287,7 @@ void sqlite3FinishTrigger( pStepList->pTrig = pTrig; pStepList = pStepList->pNext; } - nameToken.z = pTrig->zName; - nameToken.n = sqlite3Strlen30(nameToken.z); + sqlite3TokenInit(&nameToken, pTrig->zName); sqlite3FixInit(&sFix, pParse, iDb, "trigger", &nameToken); if( sqlite3FixTriggerStep(&sFix, pTrig->step_list) || sqlite3FixExpr(&sFix, pTrig->pWhen) diff --git a/src/util.c b/src/util.c index b4c5e62bb3..96f7c7f3dc 100644 --- a/src/util.c +++ b/src/util.c @@ -234,6 +234,14 @@ int sqlite3Dequote(char *z){ return j; } +/* +** Generate a Token object from a string +*/ +void sqlite3TokenInit(Token *p, char *z){ + p->z = z; + p->n = sqlite3Strlen30(z); +} + /* Convenient short-hand */ #define UpperToLower sqlite3UpperToLower From c3dfa5eba74db8eae0dddff1424b24e7f5873dbe Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 22 Jan 2016 19:44:03 +0000 Subject: [PATCH 11/75] Reenable the xCurrentTime and xGetLastError methods on the unix VFSes as long as SQLITE_OMIT_DEPRECATED is not defined. FossilOrigin-Name: c11c85fdb6514cae54bb44945cc197dcaba72307 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/os_unix.c | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 6c3814c3d9..566db8de82 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sthe\ssqlite3TokenInit()\sutility\sfunction. -D 2016-01-22T17:48:09.470 +C Reenable\sthe\sxCurrentTime\sand\sxGetLastError\smethods\son\sthe\sunix\sVFSes\sas\slong\nas\sSQLITE_OMIT_DEPRECATED\sis\snot\sdefined. +D 2016-01-22T19:44:03.065 F Makefile.in 027c1603f255390c43a426671055a31c0a65fdb4 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc d2b93511a969c0c8fcf52aeb5e426571e8c610d2 @@ -329,7 +329,7 @@ F src/os.c 8fd25588eeba74068d41102d26810e216999b6c8 F src/os.h 3e57a24e2794a94d3cf2342c6d9a884888cd96bf F src/os_common.h abdb9a191a367793268fe553d25bab894e986a0e F src/os_setup.h c9d4553b5aaa6f73391448b265b89bed0b890faa -F src/os_unix.c b509b49b40a269e7b75ab511b6e92b2dc9444359 +F src/os_unix.c 0eb7f469fcd4e1fbedf30060438e26b839ec5486 F src/os_win.c 386fba30419e8458b13209781c2af5590eab2811 F src/os_win.h eb7a47aa17b26b77eb97e4823f20a00b8bda12ca F src/pager.c f4e9ac39fbb1e0fde97af85c0f4e00eb90764b67 @@ -1419,7 +1419,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P e60461e984b8df09256bb0d733dbfae52568a145 -R 03ab6310cefadc63b5c7c7da966c2348 +P 7323175337b7ba85ac932ca892b28860f6a5b688 +R 4fcfc780a1da751b6f90e6d6f3ced841 U drh -Z 0c42ba520d71deaa3e0a21b23ff67f9d +Z 703592c4495d8a71fd67fbd54e7f3927 diff --git a/manifest.uuid b/manifest.uuid index e9fd60917b..a853332581 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -7323175337b7ba85ac932ca892b28860f6a5b688 \ No newline at end of file +c11c85fdb6514cae54bb44945cc197dcaba72307 \ No newline at end of file diff --git a/src/os_unix.c b/src/os_unix.c index 5bd6116945..ee9b55674b 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -6187,7 +6187,7 @@ static int unixCurrentTimeInt64(sqlite3_vfs *NotUsed, sqlite3_int64 *piNow){ return rc; } -#if 0 /* Not used */ +#ifndef SQLITE_OMIT_DEPRECATED /* ** Find the current time (in Universal Coordinated Time). Write the ** current time and date as a Julian Day number into *prNow and @@ -6205,7 +6205,7 @@ static int unixCurrentTime(sqlite3_vfs *NotUsed, double *prNow){ # define unixCurrentTime 0 #endif -#if 0 /* Not used */ +#ifndef SQLITE_OMIT_DEPRECATED /* ** We added the xGetLastError() method with the intention of providing ** better low-level error messages when operating-system problems come up From 795502d26c770c06b1d8d586fd316a6e374ed1d6 Mon Sep 17 00:00:00 2001 From: dan Date: Fri, 22 Jan 2016 19:48:34 +0000 Subject: [PATCH 12/75] Experimental performance enhancements for fts5. FossilOrigin-Name: b5a57b812fd6a734cf2a342bf0b730ae18912d73 --- ext/fts5/fts5Int.h | 10 +- ext/fts5/fts5_expr.c | 42 ++-- ext/fts5/fts5_index.c | 389 +++++++++++++++++++++++++++----------- ext/fts5/fts5_vocab.c | 56 +++--- ext/fts5/test/fts5ac.test | 1 - manifest | 25 +-- manifest.uuid | 2 +- 7 files changed, 355 insertions(+), 170 deletions(-) diff --git a/ext/fts5/fts5Int.h b/ext/fts5/fts5Int.h index b2f0d6c34e..7c50da9656 100644 --- a/ext/fts5/fts5Int.h +++ b/ext/fts5/fts5Int.h @@ -315,6 +315,12 @@ void sqlite3Fts5TermsetFree(Fts5Termset*); typedef struct Fts5Index Fts5Index; typedef struct Fts5IndexIter Fts5IndexIter; +struct Fts5IndexIter { + i64 iRowid; + const u8 *pData; + int nData; +}; + /* ** Values used as part of the flags argument passed to IndexQuery(). */ @@ -396,6 +402,8 @@ void sqlite3Fts5IterClose(Fts5IndexIter*); const char *sqlite3Fts5IterTerm(Fts5IndexIter*, int*); int sqlite3Fts5IterNextScan(Fts5IndexIter*); +int sqlite3Fts5IterCollist(Fts5IndexIter*, const u8 **, int*); + /* ** Insert or remove data to or from the index. Each time a document is @@ -469,8 +477,6 @@ int sqlite3Fts5IndexMerge(Fts5Index *p, int nMerge); int sqlite3Fts5IndexLoadConfig(Fts5Index *p); -int sqlite3Fts5IterCollist(Fts5IndexIter*, const u8 **, int*); - /* ** End of interface to code in fts5_index.c. **************************************************************************/ diff --git a/ext/fts5/fts5_expr.c b/ext/fts5/fts5_expr.c index c51ed7939c..290baf4e2c 100644 --- a/ext/fts5/fts5_expr.c +++ b/ext/fts5/fts5_expr.c @@ -323,11 +323,15 @@ static int fts5ExprSynonymList( const u8 *a; int n; - if( bCollist ){ + if( 0 && bCollist ){ rc = sqlite3Fts5IterCollist(pIter, &a, &n); }else{ i64 dummy; +#if 0 rc = sqlite3Fts5IterPoslist(pIter, pColset, &a, &n, &dummy); +#endif + a = pIter->pData; + n = pIter->nData; } if( rc!=SQLITE_OK ) goto synonym_poslist_out; @@ -436,7 +440,12 @@ static int fts5ExprPhraseIsMatch( pTerm, 0, pColset, pNode->iRowid, &bFlag, (u8**)&a, &n ); }else{ + Fts5IndexIter *pIter = pTerm->pIter; +#if 0 rc = sqlite3Fts5IterPoslist(pTerm->pIter, pColset, &a, &n, &dummy); +#endif + a = pIter->pData; + n = pIter->nData; } if( rc!=SQLITE_OK ) goto ismatch_out; sqlite3Fts5PoslistReaderInit(a, n, &aIter[i]); @@ -775,6 +784,7 @@ static int fts5ExprNearTest( for(pTerm=&pPhrase->aTerm[0]; pTerm; pTerm=pTerm->pSynonym){ Fts5IndexIter *pIter = pTerm->pIter; if( sqlite3Fts5IterEof(pIter)==0 ){ +#if 0 int n; i64 iRowid; rc = sqlite3Fts5IterPoslist(pIter, pNear->pColset, 0, &n, &iRowid); @@ -784,6 +794,10 @@ static int fts5ExprNearTest( }else if( iRowid==pNode->iRowid && n>0 ){ pPhrase->poslist.n = 1; } +#endif + if( pIter->iRowid==pNode->iRowid && pIter->nData>0 ){ + pPhrase->poslist.n = 1; + } } } return pPhrase->poslist.n; @@ -800,9 +814,13 @@ static int fts5ExprNearTest( rc = fts5ExprPhraseIsMatch(pNode, pNear->pColset, pPhrase, &bMatch); if( bMatch==0 ) break; }else{ + Fts5IndexIter *pIter = pPhrase->aTerm[0].pIter; + fts5BufferSet(&rc, &pPhrase->poslist, pIter->nData, pIter->pData); +#if 0 rc = sqlite3Fts5IterPoslistBuffer( pPhrase->aTerm[0].pIter, &pPhrase->poslist ); +#endif } } @@ -823,21 +841,20 @@ static int fts5ExprTokenTest( ** fts5_index.c iterator object. This is much faster than synthesizing ** a new poslist the way we have to for more complicated phrase or NEAR ** expressions. */ - Fts5ExprNearset *pNear = pNode->pNear; - Fts5ExprPhrase *pPhrase = pNear->apPhrase[0]; + Fts5ExprPhrase *pPhrase = pNode->pNear->apPhrase[0]; Fts5IndexIter *pIter = pPhrase->aTerm[0].pIter; - Fts5Colset *pColset = pNear->pColset; - int rc; assert( pNode->eType==FTS5_TERM ); - assert( pNear->nPhrase==1 && pPhrase->nTerm==1 ); + assert( pNode->pNear->nPhrase==1 && pPhrase->nTerm==1 ); assert( pPhrase->aTerm[0].pSynonym==0 ); - rc = sqlite3Fts5IterPoslist(pIter, pColset, - (const u8**)&pPhrase->poslist.p, (int*)&pPhrase->poslist.n, &pNode->iRowid - ); + pPhrase->poslist.n = pIter->nData; + if( pExpr->pConfig->eDetail==FTS5_DETAIL_FULL ){ + pPhrase->poslist.p = (u8*)pIter->pData; + } + pNode->iRowid = pIter->iRowid; pNode->bNomatch = (pPhrase->poslist.n==0); - return rc; + return SQLITE_OK; } /* @@ -2484,6 +2501,8 @@ int sqlite3Fts5ExprPhraseCollist( int rc = SQLITE_OK; assert( iPhrase>=0 && iPhrasenPhrase ); + assert( pExpr->pConfig->eDetail==FTS5_DETAIL_COLUMNS ); + if( pNode->bEof==0 && pNode->iRowid==pExpr->pRoot->iRowid && pPhrase->poslist.n>0 @@ -2503,7 +2522,8 @@ int sqlite3Fts5ExprPhraseCollist( *ppCollist = a; } }else{ - sqlite3Fts5IterCollist(pPhrase->aTerm[0].pIter, ppCollist, pnCollist); + *ppCollist = pPhrase->aTerm[0].pIter->pData; + *pnCollist = pPhrase->aTerm[0].pIter->nData; } }else{ *ppCollist = 0; diff --git a/ext/fts5/fts5_index.c b/ext/fts5/fts5_index.c index fc11a23413..2ea57b04f9 100644 --- a/ext/fts5/fts5_index.c +++ b/ext/fts5/fts5_index.c @@ -261,6 +261,7 @@ typedef struct Fts5Data Fts5Data; typedef struct Fts5DlidxIter Fts5DlidxIter; typedef struct Fts5DlidxLvl Fts5DlidxLvl; typedef struct Fts5DlidxWriter Fts5DlidxWriter; +typedef struct Fts5Iter Fts5Iter; typedef struct Fts5PageWriter Fts5PageWriter; typedef struct Fts5SegIter Fts5SegIter; typedef struct Fts5DoclistIter Fts5DoclistIter; @@ -503,10 +504,16 @@ struct Fts5SegIter { ** Used by sqlite3Fts5IterPoslist() when the poslist needs to be buffered. ** There is no way to tell if this is populated or not. */ -struct Fts5IndexIter { +struct Fts5Iter { + Fts5IndexIter base; /* Base class containing output vars */ + Fts5Index *pIndex; /* Index that owns this iterator */ Fts5Structure *pStruct; /* Database structure for this iterator */ Fts5Buffer poslist; /* Buffer containing current poslist */ + Fts5Colset *pColset; /* Restrict matches to these columns */ + + /* Invoked to set output variables. */ + void (*xSetOutputs)(Fts5Iter*, Fts5SegIter*); int nSeg; /* Size of aSeg[] array */ int bRev; /* True to iterate in reverse order */ @@ -1752,7 +1759,7 @@ static void fts5SegIterReverseNewPage(Fts5Index *p, Fts5SegIter *pIter){ ** points to a delete marker. A delete marker is an entry with a 0 byte ** position-list. */ -static int fts5MultiIterIsEmpty(Fts5Index *p, Fts5IndexIter *pIter){ +static int fts5MultiIterIsEmpty(Fts5Index *p, Fts5Iter *pIter){ Fts5SegIter *pSeg = &pIter->aSeg[pIter->aFirst[1].iFirst]; return (p->rc==SQLITE_OK && pSeg->pLeaf && pSeg->nPos==0); } @@ -2406,7 +2413,7 @@ static void fts5SegIterClear(Fts5SegIter *pIter){ ** two iterators. */ static void fts5AssertComparisonResult( - Fts5IndexIter *pIter, + Fts5Iter *pIter, Fts5SegIter *p1, Fts5SegIter *p2, Fts5CResult *pRes @@ -2447,7 +2454,7 @@ static void fts5AssertComparisonResult( ** statement used to verify that the contents of the pIter->aFirst[] array ** are correct. */ -static void fts5AssertMultiIterSetup(Fts5Index *p, Fts5IndexIter *pIter){ +static void fts5AssertMultiIterSetup(Fts5Index *p, Fts5Iter *pIter){ if( p->rc==SQLITE_OK ){ Fts5SegIter *pFirst = &pIter->aSeg[ pIter->aFirst[1].iFirst ]; int i; @@ -2492,7 +2499,7 @@ static void fts5AssertMultiIterSetup(Fts5Index *p, Fts5IndexIter *pIter){ ** to a key that is a duplicate of another, higher priority, ** segment-iterator in the pSeg->aSeg[] array. */ -static int fts5MultiIterDoCompare(Fts5IndexIter *pIter, int iOut){ +static int fts5MultiIterDoCompare(Fts5Iter *pIter, int iOut){ int i1; /* Index of left-hand Fts5SegIter */ int i2; /* Index of right-hand Fts5SegIter */ int iRes; @@ -2638,7 +2645,7 @@ static void fts5SegIterNextFrom( /* ** Free the iterator object passed as the second argument. */ -static void fts5MultiIterFree(Fts5Index *p, Fts5IndexIter *pIter){ +static void fts5MultiIterFree(Fts5Index *p, Fts5Iter *pIter){ if( pIter ){ int i; for(i=0; inSeg; i++){ @@ -2652,7 +2659,7 @@ static void fts5MultiIterFree(Fts5Index *p, Fts5IndexIter *pIter){ static void fts5MultiIterAdvanced( Fts5Index *p, /* FTS5 backend to iterate within */ - Fts5IndexIter *pIter, /* Iterator to update aFirst[] array for */ + Fts5Iter *pIter, /* Iterator to update aFirst[] array for */ int iChanged, /* Index of sub-iterator just advanced */ int iMinset /* Minimum entry in aFirst[] to set */ ){ @@ -2680,8 +2687,9 @@ static void fts5MultiIterAdvanced( */ static int fts5MultiIterAdvanceRowid( Fts5Index *p, /* FTS5 backend to iterate within */ - Fts5IndexIter *pIter, /* Iterator to update aFirst[] array for */ - int iChanged /* Index of sub-iterator just advanced */ + Fts5Iter *pIter, /* Iterator to update aFirst[] array for */ + int iChanged, /* Index of sub-iterator just advanced */ + Fts5SegIter **ppFirst ){ Fts5SegIter *pNew = &pIter->aSeg[iChanged]; @@ -2714,13 +2722,14 @@ static int fts5MultiIterAdvanceRowid( } } + *ppFirst = pNew; return 0; } /* ** Set the pIter->bEof variable based on the state of the sub-iterators. */ -static void fts5MultiIterSetEof(Fts5IndexIter *pIter){ +static void fts5MultiIterSetEof(Fts5Iter *pIter){ Fts5SegIter *pSeg = &pIter->aSeg[ pIter->aFirst[1].iFirst ]; pIter->bEof = pSeg->pLeaf==0; pIter->iSwitchRowid = pSeg->iRowid; @@ -2735,39 +2744,44 @@ static void fts5MultiIterSetEof(Fts5IndexIter *pIter){ */ static void fts5MultiIterNext( Fts5Index *p, - Fts5IndexIter *pIter, + Fts5Iter *pIter, int bFrom, /* True if argument iFrom is valid */ i64 iFrom /* Advance at least as far as this */ ){ - if( p->rc==SQLITE_OK ){ - int bUseFrom = bFrom; - do { - int iFirst = pIter->aFirst[1].iFirst; - int bNewTerm = 0; - Fts5SegIter *pSeg = &pIter->aSeg[iFirst]; - assert( p->rc==SQLITE_OK ); - if( bUseFrom && pSeg->pDlidx ){ - fts5SegIterNextFrom(p, pSeg, iFrom); - }else{ - pSeg->xNext(p, pSeg, &bNewTerm); - } + int bUseFrom = bFrom; + while( p->rc==SQLITE_OK ){ + int iFirst = pIter->aFirst[1].iFirst; + int bNewTerm = 0; + Fts5SegIter *pSeg = &pIter->aSeg[iFirst]; + assert( p->rc==SQLITE_OK ); + if( bUseFrom && pSeg->pDlidx ){ + fts5SegIterNextFrom(p, pSeg, iFrom); + }else{ + pSeg->xNext(p, pSeg, &bNewTerm); + } - if( pSeg->pLeaf==0 || bNewTerm - || fts5MultiIterAdvanceRowid(p, pIter, iFirst) - ){ - fts5MultiIterAdvanced(p, pIter, iFirst, 1); - fts5MultiIterSetEof(pIter); - } - fts5AssertMultiIterSetup(p, pIter); + if( pSeg->pLeaf==0 || bNewTerm + || fts5MultiIterAdvanceRowid(p, pIter, iFirst, &pSeg) + ){ + fts5MultiIterAdvanced(p, pIter, iFirst, 1); + fts5MultiIterSetEof(pIter); + pSeg = &pIter->aSeg[pIter->aFirst[1].iFirst]; + if( pSeg->pLeaf==0 ) return; + } - bUseFrom = 0; - }while( pIter->bSkipEmpty && fts5MultiIterIsEmpty(p, pIter) ); + fts5AssertMultiIterSetup(p, pIter); + assert( pSeg==&pIter->aSeg[pIter->aFirst[1].iFirst] && pSeg->pLeaf ); + if( pIter->bSkipEmpty==0 || pSeg->nPos ){ + pIter->xSetOutputs(pIter, pSeg); + return; + } + bUseFrom = 0; } } static void fts5MultiIterNext2( Fts5Index *p, - Fts5IndexIter *pIter, + Fts5Iter *pIter, int *pbNewTerm /* OUT: True if *might* be new term */ ){ assert( pIter->bSkipEmpty ); @@ -2780,7 +2794,7 @@ static void fts5MultiIterNext2( assert( p->rc==SQLITE_OK ); pSeg->xNext(p, pSeg, &bNewTerm); if( pSeg->pLeaf==0 || bNewTerm - || fts5MultiIterAdvanceRowid(p, pIter, iFirst) + || fts5MultiIterAdvanceRowid(p, pIter, iFirst, &pSeg) ){ fts5MultiIterAdvanced(p, pIter, iFirst, 1); fts5MultiIterSetEof(pIter); @@ -2794,17 +2808,19 @@ static void fts5MultiIterNext2( } } +static void fts5IterSetOutputs_Noop(Fts5Iter *pIter, Fts5SegIter *pSeg){ +} -static Fts5IndexIter *fts5MultiIterAlloc( +static Fts5Iter *fts5MultiIterAlloc( Fts5Index *p, /* FTS5 backend to iterate within */ int nSeg ){ - Fts5IndexIter *pNew; + Fts5Iter *pNew; int nSlot; /* Power of two >= nSeg */ for(nSlot=2; nSlotaSeg[] */ sizeof(Fts5CResult) * nSlot /* pNew->aFirst[] */ ); @@ -2812,12 +2828,13 @@ static Fts5IndexIter *fts5MultiIterAlloc( pNew->nSeg = nSlot; pNew->aFirst = (Fts5CResult*)&pNew->aSeg[nSlot]; pNew->pIndex = p; + pNew->xSetOutputs = fts5IterSetOutputs_Noop; } return pNew; } /* -** Allocate a new Fts5IndexIter object. +** Allocate a new Fts5Iter object. ** ** The new object will be used to iterate through data in structure pStruct. ** If iLevel is -ve, then all data in all segments is merged. Or, if iLevel @@ -2835,14 +2852,14 @@ static void fts5MultiIterNew( const u8 *pTerm, int nTerm, /* Term to seek to (or NULL/0) */ int iLevel, /* Level to iterate (-1 for all) */ int nSegment, /* Number of segments to merge (iLevel>=0) */ - Fts5IndexIter **ppOut /* New object */ + Fts5Iter **ppOut /* New object */ ){ int nSeg = 0; /* Number of segment-iters in use */ int iIter = 0; /* */ int iSeg; /* Used to iterate through segments */ Fts5Buffer buf = {0,0,0}; /* Buffer used by fts5SegIterSeekInit() */ Fts5StructureLevel *pLvl; - Fts5IndexIter *pNew; + Fts5Iter *pNew; assert( (pTerm==0 && nTerm==0) || iLevel<0 ); @@ -2917,16 +2934,16 @@ static void fts5MultiIterNew( } /* -** Create an Fts5IndexIter that iterates through the doclist provided +** Create an Fts5Iter that iterates through the doclist provided ** as the second argument. */ static void fts5MultiIterNew2( Fts5Index *p, /* FTS5 backend to iterate within */ Fts5Data *pData, /* Doclist to iterate through */ int bDesc, /* True for descending rowid order */ - Fts5IndexIter **ppOut /* New object */ + Fts5Iter **ppOut /* New object */ ){ - Fts5IndexIter *pNew; + Fts5Iter *pNew; pNew = fts5MultiIterAlloc(p, 2); if( pNew ){ Fts5SegIter *pIter = &pNew->aSeg[1]; @@ -2961,7 +2978,7 @@ static void fts5MultiIterNew2( ** Return true if the iterator is at EOF or if an error has occurred. ** False otherwise. */ -static int fts5MultiIterEof(Fts5Index *p, Fts5IndexIter *pIter){ +static int fts5MultiIterEof(Fts5Index *p, Fts5Iter *pIter){ assert( p->rc || (pIter->aSeg[ pIter->aFirst[1].iFirst ].pLeaf==0)==pIter->bEof ); @@ -2973,7 +2990,7 @@ static int fts5MultiIterEof(Fts5Index *p, Fts5IndexIter *pIter){ ** to. If the iterator points to EOF when this function is called the ** results are undefined. */ -static i64 fts5MultiIterRowid(Fts5IndexIter *pIter){ +static i64 fts5MultiIterRowid(Fts5Iter *pIter){ assert( pIter->aSeg[ pIter->aFirst[1].iFirst ].pLeaf ); return pIter->aSeg[ pIter->aFirst[1].iFirst ].iRowid; } @@ -2983,7 +3000,7 @@ static i64 fts5MultiIterRowid(Fts5IndexIter *pIter){ */ static void fts5MultiIterNextFrom( Fts5Index *p, - Fts5IndexIter *pIter, + Fts5Iter *pIter, i64 iMatch ){ while( 1 ){ @@ -3000,7 +3017,7 @@ static void fts5MultiIterNextFrom( ** Return a pointer to a buffer containing the term associated with the ** entry that the iterator currently points to. */ -static const u8 *fts5MultiIterTerm(Fts5IndexIter *pIter, int *pn){ +static const u8 *fts5MultiIterTerm(Fts5Iter *pIter, int *pn){ Fts5SegIter *p = &pIter->aSeg[ pIter->aFirst[1].iFirst ]; *pn = p->term.n; return p->term.p; @@ -3582,7 +3599,7 @@ static void fts5WriteInit( ** incremental merge operation. This function is called if the incremental ** merge step has finished but the input has not been completely exhausted. */ -static void fts5TrimSegments(Fts5Index *p, Fts5IndexIter *pIter){ +static void fts5TrimSegments(Fts5Index *p, Fts5Iter *pIter){ int i; Fts5Buffer buf; memset(&buf, 0, sizeof(Fts5Buffer)); @@ -3660,7 +3677,7 @@ static void fts5IndexMergeLevel( Fts5Structure *pStruct = *ppStruct; Fts5StructureLevel *pLvl = &pStruct->aLevel[iLvl]; Fts5StructureLevel *pLvlOut; - Fts5IndexIter *pIter = 0; /* Iterator to read input data */ + Fts5Iter *pIter = 0; /* Iterator to read input data */ int nRem = pnRem ? *pnRem : 0; /* Output leaf pages left to write */ int nInput; /* Number of input segments */ Fts5SegWriter writer; /* Writer object */ @@ -4342,7 +4359,7 @@ static int fts5IndexExtractCol( static int fts5AppendRowid( Fts5Index *p, i64 iDelta, - Fts5IndexIter *pMulti, + Fts5Iter *pMulti, Fts5Colset *pColset, Fts5Buffer *pBuf ){ @@ -4367,7 +4384,7 @@ static int fts5AppendRowid( static int fts5AppendPoslist( Fts5Index *p, i64 iDelta, - Fts5IndexIter *pMulti, + Fts5Iter *pMulti, Fts5Colset *pColset, Fts5Buffer *pBuf ){ @@ -4645,14 +4662,14 @@ static void fts5SetupPrefixIter( const u8 *pToken, /* Buffer containing prefix to match */ int nToken, /* Size of buffer pToken in bytes */ Fts5Colset *pColset, /* Restrict matches to these columns */ - Fts5IndexIter **ppIter /* OUT: New iterator */ + Fts5Iter **ppIter /* OUT: New iterator */ ){ Fts5Structure *pStruct; Fts5Buffer *aBuf; const int nBuf = 32; void (*xMerge)(Fts5Index*, Fts5Buffer*, Fts5Buffer*); - int (*xAppend)(Fts5Index*, i64, Fts5IndexIter*, Fts5Colset*, Fts5Buffer*); + int (*xAppend)(Fts5Index*, i64, Fts5Iter*, Fts5Colset*, Fts5Buffer*); if( p->pConfig->eDetail==FTS5_DETAIL_NONE ){ xMerge = fts5MergeRowidLists; xAppend = fts5AppendRowid; @@ -4668,7 +4685,7 @@ static void fts5SetupPrefixIter( const int flags = FTS5INDEX_QUERY_SCAN; int i; i64 iLastRowid = 0; - Fts5IndexIter *p1 = 0; /* Iterator used to gather data from index */ + Fts5Iter *p1 = 0; /* Iterator used to gather data from index */ Fts5Data *pData; Fts5Buffer doclist; int bNewTerm = 1; @@ -4932,6 +4949,154 @@ int sqlite3Fts5IndexWrite( return rc; } + +static int fts5IndexExtractColset ( + Fts5Colset *pColset, /* Colset to filter on */ + const u8 *pPos, int nPos, /* Position list */ + Fts5Buffer *pBuf /* Output buffer */ +){ + int rc = SQLITE_OK; + int i; + + fts5BufferZero(pBuf); + for(i=0; inCol; i++){ + const u8 *pSub = pPos; + int nSub = fts5IndexExtractCol(&pSub, nPos, pColset->aiCol[i]); + if( nSub ){ + fts5BufferAppendBlob(&rc, pBuf, nSub, pSub); + } + } + return rc; +} + +/* +** xSetOutputs callback used by detail=none tables. +*/ +static void fts5IterSetOutputs_None(Fts5Iter *pIter, Fts5SegIter *pSeg){ + assert( pIter->pIndex->pConfig->eDetail==FTS5_DETAIL_NONE ); + pIter->base.iRowid = pSeg->iRowid; + pIter->base.nData = pSeg->nPos; +} + +/* +** xSetOutputs callback used by detail=full and detail=col tables when no +** column filters are specified. +*/ +static void fts5IterSetOutputs_Nocolset(Fts5Iter *pIter, Fts5SegIter *pSeg){ + pIter->base.iRowid = pSeg->iRowid; + pIter->base.nData = pSeg->nPos; + + assert( pIter->pIndex->pConfig->eDetail!=FTS5_DETAIL_NONE ); + assert( pIter->pColset==0 || pIter->bFiltered ); + + if( pSeg->iLeafOffset+pSeg->nPos<=pSeg->pLeaf->szLeaf ){ + /* All data is stored on the current page. Populate the output + ** variables to point into the body of the page object. */ + pIter->base.pData = &pSeg->pLeaf->p[pSeg->iLeafOffset]; + }else{ + /* The data is distributed over two or more pages. Copy it into the + ** Fts5Iter.poslist buffer and then set the output pointer to point + ** to this buffer. */ + fts5BufferZero(&pIter->poslist); + fts5SegiterPoslist(pIter->pIndex, pSeg, 0, &pIter->poslist); + pIter->base.pData = pIter->poslist.p; + } +} + +/* +** xSetOutputs callback used by detail=col when there is a column filter. +*/ +static void fts5IterSetOutputs_Col(Fts5Iter *pIter, Fts5SegIter *pSeg){ + Fts5Colset *pColset = pIter->pColset; + pIter->base.iRowid = pSeg->iRowid; + + assert( pIter->pIndex->pConfig->eDetail==FTS5_DETAIL_COLUMNS ); + assert( pColset ); + + if( pSeg->iLeafOffset+pSeg->nPos<=pSeg->pLeaf->szLeaf && 0 ){ + /* All data is stored on the current page. Populate the output + ** variables to point into the body of the page object. */ + Fts5PoslistWriter writer = {0}; + const u8 *a = &pSeg->pLeaf->p[pSeg->iLeafOffset]; + int n = pSeg->nPos; + int iCol = 0; + i64 iPos = 0; + int iOff = 0; + + fts5BufferZero(&pIter->poslist); + while( 0==sqlite3Fts5PoslistNext64(a, n, &iOff, &iPos) ){ + if( iPos==pColset->aiCol[iCol] ){ + sqlite3Fts5PoslistWriterAppend(&pIter->poslist, &writer, iPos); + if( ++iCol>=pColset->nCol ) break; + } + } + + }else{ + /* The data is distributed over two or more pages. Copy it into the + ** Fts5Iter.poslist buffer and then set the output pointer to point + ** to this buffer. */ + fts5BufferZero(&pIter->poslist); + fts5SegiterPoslist(pIter->pIndex, pSeg, pColset, &pIter->poslist); + } + + pIter->base.pData = pIter->poslist.p; + pIter->base.nData = pIter->poslist.n; +} + +/* +** xSetOutputs callback used by detail=full when there is a column filter. +*/ +static void fts5IterSetOutputs_Full(Fts5Iter *pIter, Fts5SegIter *pSeg){ + Fts5Colset *pColset = pIter->pColset; + pIter->base.iRowid = pSeg->iRowid; + + assert( pIter->pIndex->pConfig->eDetail==FTS5_DETAIL_FULL ); + assert( pColset ); + + if( pSeg->iLeafOffset+pSeg->nPos<=pSeg->pLeaf->szLeaf ){ + /* All data is stored on the current page. Populate the output + ** variables to point into the body of the page object. */ + const u8 *a = &pSeg->pLeaf->p[pSeg->iLeafOffset]; + if( pColset->nCol==1 ){ + pIter->base.nData = fts5IndexExtractCol(&a, pSeg->nPos,pColset->aiCol[0]); + pIter->base.pData = a; + }else{ + fts5BufferZero(&pIter->poslist); + fts5IndexExtractColset(pColset, a, pSeg->nPos, &pIter->poslist); + pIter->base.pData = pIter->poslist.p; + pIter->base.nData = pIter->poslist.n; + } + }else{ + /* The data is distributed over two or more pages. Copy it into the + ** Fts5Iter.poslist buffer and then set the output pointer to point + ** to this buffer. */ + fts5BufferZero(&pIter->poslist); + fts5SegiterPoslist(pIter->pIndex, pSeg, pColset, &pIter->poslist); + pIter->base.pData = pIter->poslist.p; + pIter->base.nData = pIter->poslist.n; + } +} + +static void fts5IterSetOutputCb(Fts5Iter *pIter){ + int eDetail = pIter->pIndex->pConfig->eDetail; + if( eDetail==FTS5_DETAIL_NONE ){ + pIter->xSetOutputs = fts5IterSetOutputs_None; + } + + else if( pIter->pColset==0 || pIter->bFiltered ){ + pIter->xSetOutputs = fts5IterSetOutputs_Nocolset; + } + + else if( eDetail==FTS5_DETAIL_FULL ){ + pIter->xSetOutputs = fts5IterSetOutputs_Full; + } + + else{ + assert( eDetail==FTS5_DETAIL_COLUMNS ); + pIter->xSetOutputs = fts5IterSetOutputs_Col; + } +} + /* ** Open a new iterator to iterate though all rowid that match the ** specified token or token prefix. @@ -4944,22 +5109,27 @@ int sqlite3Fts5IndexQuery( Fts5IndexIter **ppIter /* OUT: New iterator object */ ){ Fts5Config *pConfig = p->pConfig; - Fts5IndexIter *pRet = 0; - int iIdx = 0; + Fts5Iter *pRet = 0; Fts5Buffer buf = {0, 0, 0}; /* If the QUERY_SCAN flag is set, all other flags must be clear. */ assert( (flags & FTS5INDEX_QUERY_SCAN)==0 || flags==FTS5INDEX_QUERY_SCAN ); if( sqlite3Fts5BufferSize(&p->rc, &buf, nToken+1)==0 ){ + int iIdx = 0; /* Index to search */ memcpy(&buf.p[1], pToken, nToken); -#ifdef SQLITE_DEBUG - /* If the QUERY_TEST_NOIDX flag was specified, then this must be a + /* Figure out which index to search and set iIdx accordingly. If this + ** is a prefix query for which there is no prefix index, set iIdx to + ** greater than pConfig->nPrefix to indicate that the query will be + ** satisfied by scanning multiple terms in the main index. + ** + ** If the QUERY_TEST_NOIDX flag was specified, then this must be a ** prefix-query. Instead of using a prefix-index (if one exists), ** evaluate the prefix query using the main FTS index. This is used ** for internal sanity checking by the integrity-check in debug ** mode only. */ +#ifdef SQLITE_DEBUG if( pConfig->bPrefixIndex==0 || (flags & FTS5INDEX_QUERY_TEST_NOIDX) ){ assert( flags & FTS5INDEX_QUERY_PREFIX ); iIdx = 1+pConfig->nPrefix; @@ -4973,6 +5143,7 @@ int sqlite3Fts5IndexQuery( } if( iIdx<=pConfig->nPrefix ){ + /* Straight index lookup */ Fts5Structure *pStruct = fts5StructureRead(p); buf.p[0] = (u8)(FTS5_MAIN_PREFIX + iIdx); if( pStruct ){ @@ -4980,17 +5151,25 @@ int sqlite3Fts5IndexQuery( fts5StructureRelease(pStruct); } }else{ + /* Scan multiple terms in the main index */ int bDesc = (flags & FTS5INDEX_QUERY_DESC)!=0; buf.p[0] = FTS5_MAIN_PREFIX; fts5SetupPrefixIter(p, bDesc, buf.p, nToken+1, pColset, &pRet); } + if( p->rc==SQLITE_OK ){ + Fts5SegIter *pSeg = &pRet->aSeg[pRet->aFirst[1].iFirst]; + pRet->pColset = pColset; + fts5IterSetOutputCb(pRet); + if( pSeg->pLeaf ) pRet->xSetOutputs(pRet, pSeg); + } if( p->rc ){ - sqlite3Fts5IterClose(pRet); + sqlite3Fts5IterClose(&pRet->base); pRet = 0; fts5CloseReader(p); } - *ppIter = pRet; + + *ppIter = &pRet->base; sqlite3Fts5BufferFree(&buf); } return fts5IndexReturn(p); @@ -5000,14 +5179,15 @@ int sqlite3Fts5IndexQuery( ** Return true if the iterator passed as the only argument is at EOF. */ int sqlite3Fts5IterEof(Fts5IndexIter *pIter){ - assert( pIter->pIndex->rc==SQLITE_OK ); - return pIter->bEof; + assert( ((Fts5Iter*)pIter)->pIndex->rc==SQLITE_OK ); + return ((Fts5Iter*)pIter)->bEof; } /* ** Move to the next matching rowid. */ -int sqlite3Fts5IterNext(Fts5IndexIter *pIter){ +int sqlite3Fts5IterNext(Fts5IndexIter *pIndexIter){ + Fts5Iter *pIter = (Fts5Iter*)pIndexIter; assert( pIter->pIndex->rc==SQLITE_OK ); fts5MultiIterNext(pIter->pIndex, pIter, 0, 0); return fts5IndexReturn(pIter->pIndex); @@ -5016,7 +5196,8 @@ int sqlite3Fts5IterNext(Fts5IndexIter *pIter){ /* ** Move to the next matching term/rowid. Used by the fts5vocab module. */ -int sqlite3Fts5IterNextScan(Fts5IndexIter *pIter){ +int sqlite3Fts5IterNextScan(Fts5IndexIter *pIndexIter){ + Fts5Iter *pIter = (Fts5Iter*)pIndexIter; Fts5Index *p = pIter->pIndex; assert( pIter->pIndex->rc==SQLITE_OK ); @@ -5039,7 +5220,8 @@ int sqlite3Fts5IterNextScan(Fts5IndexIter *pIter){ ** definition of "at or after" depends on whether this iterator iterates ** in ascending or descending rowid order. */ -int sqlite3Fts5IterNextFrom(Fts5IndexIter *pIter, i64 iMatch){ +int sqlite3Fts5IterNextFrom(Fts5IndexIter *pIndexIter, i64 iMatch){ + Fts5Iter *pIter = (Fts5Iter*)pIndexIter; fts5MultiIterNextFrom(pIter->pIndex, pIter, iMatch); return fts5IndexReturn(pIter->pIndex); } @@ -5047,41 +5229,21 @@ int sqlite3Fts5IterNextFrom(Fts5IndexIter *pIter, i64 iMatch){ /* ** Return the current rowid. */ -i64 sqlite3Fts5IterRowid(Fts5IndexIter *pIter){ - return fts5MultiIterRowid(pIter); +i64 sqlite3Fts5IterRowid(Fts5IndexIter *pIndexIter){ + return fts5MultiIterRowid((Fts5Iter*)pIndexIter); } /* ** Return the current term. */ -const char *sqlite3Fts5IterTerm(Fts5IndexIter *pIter, int *pn){ +const char *sqlite3Fts5IterTerm(Fts5IndexIter *pIndexIter, int *pn){ int n; - const char *z = (const char*)fts5MultiIterTerm(pIter, &n); + const char *z = (const char*)fts5MultiIterTerm((Fts5Iter*)pIndexIter, &n); *pn = n-1; return &z[1]; } -static int fts5IndexExtractColset ( - Fts5Colset *pColset, /* Colset to filter on */ - const u8 *pPos, int nPos, /* Position list */ - Fts5Buffer *pBuf /* Output buffer */ -){ - int rc = SQLITE_OK; - int i; - - fts5BufferZero(pBuf); - for(i=0; inCol; i++){ - const u8 *pSub = pPos; - int nSub = fts5IndexExtractCol(&pSub, nPos, pColset->aiCol[i]); - if( nSub ){ - fts5BufferAppendBlob(&rc, pBuf, nSub, pSub); - } - } - return rc; -} - - /* ** Return a pointer to a buffer containing a copy of the position list for ** the current entry. Output variable *pn is set to the size of the buffer @@ -5091,12 +5253,13 @@ static int fts5IndexExtractColset ( ** field that starts the position list on disk. */ int sqlite3Fts5IterPoslist( - Fts5IndexIter *pIter, + Fts5IndexIter *pIndexIter, Fts5Colset *pColset, /* Column filter (or NULL) */ const u8 **pp, /* OUT: Pointer to position-list data */ int *pn, /* OUT: Size of position-list in bytes */ i64 *piRowid /* OUT: Current rowid */ ){ + Fts5Iter *pIter = (Fts5Iter*)pIndexIter; Fts5SegIter *pSeg = &pIter->aSeg[ pIter->aFirst[1].iFirst ]; int eDetail = pIter->pIndex->pConfig->eDetail; @@ -5133,10 +5296,11 @@ int sqlite3Fts5IterPoslist( } int sqlite3Fts5IterCollist( - Fts5IndexIter *pIter, + Fts5IndexIter *pIndexIter, const u8 **pp, /* OUT: Pointer to position-list data */ int *pn /* OUT: Size of position-list in bytes */ ){ + Fts5Iter *pIter = (Fts5Iter*)pIndexIter; assert( pIter->pIndex->pConfig->eDetail==FTS5_DETAIL_COLUMNS ); *pp = pIter->poslist.p; *pn = pIter->poslist.n; @@ -5148,7 +5312,8 @@ int sqlite3Fts5IterCollist( ** copies the position list into the buffer supplied as the second ** argument. */ -int sqlite3Fts5IterPoslistBuffer(Fts5IndexIter *pIter, Fts5Buffer *pBuf){ +int sqlite3Fts5IterPoslistBuffer(Fts5IndexIter *pIndexIter, Fts5Buffer *pBuf){ + Fts5Iter *pIter = (Fts5Iter*)pIndexIter; Fts5Index *p = pIter->pIndex; Fts5SegIter *pSeg = &pIter->aSeg[ pIter->aFirst[1].iFirst ]; assert( p->rc==SQLITE_OK ); @@ -5160,8 +5325,9 @@ int sqlite3Fts5IterPoslistBuffer(Fts5IndexIter *pIter, Fts5Buffer *pBuf){ /* ** Close an iterator opened by an earlier call to sqlite3Fts5IndexQuery(). */ -void sqlite3Fts5IterClose(Fts5IndexIter *pIter){ - if( pIter ){ +void sqlite3Fts5IterClose(Fts5IndexIter *pIndexIter){ + if( pIndexIter ){ + Fts5Iter *pIter = (Fts5Iter*)pIndexIter; Fts5Index *pIndex = pIter->pIndex; fts5MultiIterFree(pIter->pIndex, pIter); fts5CloseReader(pIndex); @@ -5328,35 +5494,30 @@ static int fts5QueryCksum( ){ int eDetail = p->pConfig->eDetail; u64 cksum = *pCksum; - Fts5IndexIter *pIdxIter = 0; - Fts5Buffer buf = {0, 0, 0}; - int rc = sqlite3Fts5IndexQuery(p, z, n, flags, 0, &pIdxIter); + Fts5IndexIter *pIter = 0; + int rc = sqlite3Fts5IndexQuery(p, z, n, flags, 0, &pIter); - while( rc==SQLITE_OK && 0==sqlite3Fts5IterEof(pIdxIter) ){ - i64 rowid = sqlite3Fts5IterRowid(pIdxIter); + while( rc==SQLITE_OK && 0==sqlite3Fts5IterEof(pIter) ){ + i64 rowid = sqlite3Fts5IterRowid(pIter); if( eDetail==FTS5_DETAIL_NONE ){ cksum ^= sqlite3Fts5IndexEntryCksum(rowid, 0, 0, iIdx, z, n); }else{ - rc = sqlite3Fts5IterPoslistBuffer(pIdxIter, &buf); - if( rc==SQLITE_OK ){ - Fts5PoslistReader sReader; - for(sqlite3Fts5PoslistReaderInit(buf.p, buf.n, &sReader); - sReader.bEof==0; - sqlite3Fts5PoslistReaderNext(&sReader) - ){ - int iCol = FTS5_POS2COLUMN(sReader.iPos); - int iOff = FTS5_POS2OFFSET(sReader.iPos); - cksum ^= sqlite3Fts5IndexEntryCksum(rowid, iCol, iOff, iIdx, z, n); - } + Fts5PoslistReader sReader; + for(sqlite3Fts5PoslistReaderInit(pIter->pData, pIter->nData, &sReader); + sReader.bEof==0; + sqlite3Fts5PoslistReaderNext(&sReader) + ){ + int iCol = FTS5_POS2COLUMN(sReader.iPos); + int iOff = FTS5_POS2OFFSET(sReader.iPos); + cksum ^= sqlite3Fts5IndexEntryCksum(rowid, iCol, iOff, iIdx, z, n); } } if( rc==SQLITE_OK ){ - rc = sqlite3Fts5IterNext(pIdxIter); + rc = sqlite3Fts5IterNext(pIter); } } - sqlite3Fts5IterClose(pIdxIter); - fts5BufferFree(&buf); + sqlite3Fts5IterClose(pIter); *pCksum = cksum; return rc; @@ -5661,7 +5822,7 @@ int sqlite3Fts5IndexIntegrityCheck(Fts5Index *p, u64 cksum){ int eDetail = p->pConfig->eDetail; u64 cksum2 = 0; /* Checksum based on contents of indexes */ Fts5Buffer poslist = {0,0,0}; /* Buffer used to hold a poslist */ - Fts5IndexIter *pIter; /* Used to iterate through entire index */ + Fts5Iter *pIter; /* Used to iterate through entire index */ Fts5Structure *pStruct; /* Index structure */ #ifdef SQLITE_DEBUG diff --git a/ext/fts5/fts5_vocab.c b/ext/fts5/fts5_vocab.c index ddc5576c5d..17aa5816c4 100644 --- a/ext/fts5/fts5_vocab.c +++ b/ext/fts5/fts5_vocab.c @@ -412,28 +412,29 @@ static int fts5VocabNextMethod(sqlite3_vtab_cursor *pCursor){ i64 iPos = 0; /* 64-bit position read from poslist */ int iOff = 0; /* Current offset within position list */ + pPos = pCsr->pIter->pData; + nPos = pCsr->pIter->nData; switch( pCsr->pConfig->eDetail ){ case FTS5_DETAIL_FULL: - rc = sqlite3Fts5IterPoslist(pCsr->pIter, 0, &pPos, &nPos, &dummy); - if( rc==SQLITE_OK ){ - if( pTab->eType==FTS5_VOCAB_ROW ){ - while( 0==sqlite3Fts5PoslistNext64(pPos, nPos, &iOff, &iPos) ){ - pCsr->aCnt[0]++; - } - pCsr->aDoc[0]++; - }else{ - int iCol = -1; - while( 0==sqlite3Fts5PoslistNext64(pPos, nPos, &iOff, &iPos) ){ - int ii = FTS5_POS2COLUMN(iPos); - pCsr->aCnt[ii]++; - if( iCol!=ii ){ - if( ii>=nCol ){ - rc = FTS5_CORRUPT; - break; - } - pCsr->aDoc[ii]++; - iCol = ii; + pPos = pCsr->pIter->pData; + nPos = pCsr->pIter->nData; + if( pTab->eType==FTS5_VOCAB_ROW ){ + while( 0==sqlite3Fts5PoslistNext64(pPos, nPos, &iOff, &iPos) ){ + pCsr->aCnt[0]++; + } + pCsr->aDoc[0]++; + }else{ + int iCol = -1; + while( 0==sqlite3Fts5PoslistNext64(pPos, nPos, &iOff, &iPos) ){ + int ii = FTS5_POS2COLUMN(iPos); + pCsr->aCnt[ii]++; + if( iCol!=ii ){ + if( ii>=nCol ){ + rc = FTS5_CORRUPT; + break; } + pCsr->aDoc[ii]++; + iCol = ii; } } } @@ -443,19 +444,14 @@ static int fts5VocabNextMethod(sqlite3_vtab_cursor *pCursor){ if( pTab->eType==FTS5_VOCAB_ROW ){ pCsr->aDoc[0]++; }else{ - Fts5Buffer buf = {0, 0, 0}; - rc = sqlite3Fts5IterPoslistBuffer(pCsr->pIter, &buf); - if( rc==SQLITE_OK ){ - while( 0==sqlite3Fts5PoslistNext64(buf.p, buf.n, &iOff,&iPos) ){ - assert_nc( iPos>=0 && iPos=nCol ){ - rc = FTS5_CORRUPT; - break; - } - pCsr->aDoc[iPos]++; + while( 0==sqlite3Fts5PoslistNext64(pPos, nPos, &iOff,&iPos) ){ + assert_nc( iPos>=0 && iPos=nCol ){ + rc = FTS5_CORRUPT; + break; } + pCsr->aDoc[iPos]++; } - sqlite3Fts5BufferFree(&buf); } break; diff --git a/ext/fts5/test/fts5ac.test b/ext/fts5/test/fts5ac.test index 00b1328867..a5a522a466 100644 --- a/ext/fts5/test/fts5ac.test +++ b/ext/fts5/test/fts5ac.test @@ -250,7 +250,6 @@ foreach {tn2 sql} { FROM xx WHERE xx match $expr } $res - set res [fts5_query_data $expr xx DESC] do_execsql_test 1.$tn2.$tn.[llength $res].desc { SELECT rowid, fts5_test_poslist(xx), fts5_test_collist(xx) diff --git a/manifest b/manifest index 6c3814c3d9..99a9a8b139 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sthe\ssqlite3TokenInit()\sutility\sfunction. -D 2016-01-22T17:48:09.470 +C Experimental\sperformance\senhancements\sfor\sfts5. +D 2016-01-22T19:48:34.825 F Makefile.in 027c1603f255390c43a426671055a31c0a65fdb4 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc d2b93511a969c0c8fcf52aeb5e426571e8c610d2 @@ -97,13 +97,13 @@ F ext/fts3/unicode/mkunicode.tcl 95cf7ec186e48d4985e433ff8a1c89090a774252 F ext/fts3/unicode/parseunicode.tcl da577d1384810fb4e2b209bf3313074353193e95 F ext/fts5/extract_api_docs.tcl a36e54ec777172ddd3f9a88daf593b00848368e0 F ext/fts5/fts5.h ff9c2782e8ed890b0de2f697a8d63971939e70c7 -F ext/fts5/fts5Int.h 5599703af9c13512900a9f22fec39d48078d619d +F ext/fts5/fts5Int.h f93aed3d05d1b3686c4dccf70544bcfc7aa117f1 F ext/fts5/fts5_aux.c 2dafc3aee0c70d643140c77d8d70daffa51a9e9e F ext/fts5/fts5_buffer.c 7d3f6f01f8fdc45204e6a33925ef8478a67d28dd F ext/fts5/fts5_config.c 0c384ebdd23fd055e2e50a93277b8d59da538238 -F ext/fts5/fts5_expr.c 4ab4504c54bbe24689c83411d8588f4ec99136e9 +F ext/fts5/fts5_expr.c 48b9131b74c8d3b8c12ba0f7995e2d60eecce9f2 F ext/fts5/fts5_hash.c 1b113977296cf4212c6ec667d5e3f2bd18036955 -F ext/fts5/fts5_index.c 716c301835a122ba36910b4f821c87d26ae9a5d9 +F ext/fts5/fts5_index.c 19062d1f40ba6d88d786a986d1c20f9d741799d0 F ext/fts5/fts5_main.c 833db0a3df10ab26e0221a9baa40cf871c450df3 F ext/fts5/fts5_storage.c fb2eaec3aa954b680d43096dc539f8270bd6390e F ext/fts5/fts5_tcl.c f8731e0508299bd43f1a2eff7dbeaac870768966 @@ -112,13 +112,13 @@ F ext/fts5/fts5_test_tok.c db08af63673c3a7d39f053b36fd6e065017706be F ext/fts5/fts5_tokenize.c 504984ac6993323247221eebe3cd55bead01b5f8 F ext/fts5/fts5_unicode2.c 78273fbd588d1d9bd0a7e4e0ccc9207348bae33c F ext/fts5/fts5_varint.c 3f86ce09cab152e3d45490d7586b7ed2e40c13f1 -F ext/fts5/fts5_vocab.c ee6df1a3be103414d7b7af833ae1885c7b83a9d0 +F ext/fts5/fts5_vocab.c f1b4308b9b7ec8e659d0c9b39ddc8f1aeee47a1a F ext/fts5/fts5parse.y 1647eba089b9b3fc058b4dc989d9da87d15b9580 F ext/fts5/mkportersteps.tcl 5acf962d2e0074f701620bb5308155fa1e4a63ba F ext/fts5/test/fts5_common.tcl 6d0d74b695c4be055a8ba1dd807f22a2abc95b5e F ext/fts5/test/fts5aa.test 7e814df4a0e6c22a6fe2d84f210fdc0b5068a084 F ext/fts5/test/fts5ab.test 30325a89453280160106be411bba3acf138e6d1b -F ext/fts5/test/fts5ac.test d5073ca7bd2d9fe8aab0c82c6c75a7e4b0d70ced +F ext/fts5/test/fts5ac.test dec95549e007dd9be52aa435cdcd0f08e14e64d0 F ext/fts5/test/fts5ad.test 0ddaa5b692ff220100ee396228838f4331399eaa F ext/fts5/test/fts5ae.test 612dcb51f4069226791ff14c17dbfb3138c56f20 F ext/fts5/test/fts5af.test be858a96b1f5de66ba6d64f0021bd8b2408e126c @@ -1419,7 +1419,10 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P e60461e984b8df09256bb0d733dbfae52568a145 -R 03ab6310cefadc63b5c7c7da966c2348 -U drh -Z 0c42ba520d71deaa3e0a21b23ff67f9d +P 7323175337b7ba85ac932ca892b28860f6a5b688 +R bc65520844365f59e43048a22901b688 +T *branch * fts5-perf +T *sym-fts5-perf * +T -sym-trunk * +U dan +Z 20f25a74d681d80924173ee060583d9e diff --git a/manifest.uuid b/manifest.uuid index e9fd60917b..fc3a1227d6 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -7323175337b7ba85ac932ca892b28860f6a5b688 \ No newline at end of file +b5a57b812fd6a734cf2a342bf0b730ae18912d73 \ No newline at end of file From a8a18734857f3ad96403acecc201effaab473fb7 Mon Sep 17 00:00:00 2001 From: mistachkin Date: Fri, 22 Jan 2016 22:16:50 +0000 Subject: [PATCH 13/75] More MSVC makefile cleanup. FossilOrigin-Name: df22556fd75997111e52f96572da8379dfe948be --- Makefile.msc | 36 ++++++++++++++++++------------------ manifest | 14 +++++++------- manifest.uuid | 2 +- 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/Makefile.msc b/Makefile.msc index 3621d4f92b..504b2893ba 100644 --- a/Makefile.msc +++ b/Makefile.msc @@ -1326,12 +1326,29 @@ TESTOPTS = --verbose=file --output=test-out.txt # all: dll libsqlite3.lib shell libtclsqlite3.lib +# Dynamic link library section. +# +dll: $(SQLITE3DLL) + +# Shell executable. +# +shell: $(SQLITE3EXE) + libsqlite3.lib: $(LIBOBJ) $(LTLIB) $(LTLIBOPTS) /OUT:$@ $(LIBOBJ) $(TLIBS) libtclsqlite3.lib: tclsqlite.lo libsqlite3.lib $(LTLIB) $(LTLIBOPTS) $(LTLIBPATHS) /OUT:$@ tclsqlite.lo libsqlite3.lib $(LIBTCLSTUB) $(TLIBS) +$(SQLITE3DLL): $(LIBOBJ) $(LIBRESOBJS) $(CORE_LINK_DEP) + $(LD) $(LDFLAGS) $(LTLINKOPTS) $(LTLIBPATHS) /DLL $(CORE_LINK_OPTS) /OUT:$@ $(LIBOBJ) $(LIBRESOBJS) $(LTLIBS) $(TLIBS) + +sqlite3.def: libsqlite3.lib + echo EXPORTS > sqlite3.def + dumpbin /all libsqlite3.lib \ + | $(TCLSH_CMD) $(TOP)\tool\replace.tcl include "^\s+1 _?(sqlite3_.*)$$" \1 \ + | sort >> sqlite3.def + $(SQLITE3EXE): $(TOP)\src\shell.c $(SHELL_CORE_DEP) $(LIBRESOBJS) $(SHELL_CORE_SRC) $(SQLITE3H) $(LTLINK) $(SHELL_COMPILE_OPTS) $(READLINE_FLAGS) $(TOP)\src\shell.c $(SHELL_CORE_SRC) \ /link $(SQLITE3EXEPDB) $(LDFLAGS) $(LTLINKOPTS) $(SHELL_LINK_OPTS) $(LTLIBPATHS) $(LIBRESOBJS) $(LIBREADLINE) $(LTLIBS) $(TLIBS) @@ -1419,7 +1436,7 @@ opcodes.lo: opcodes.c # Rule to build the Win32 resources object file. # !IF $(USE_RC)!=0 -$(LIBRESOBJS): $(TOP)\src\sqlite3.rc $(HDR) +$(LIBRESOBJS): $(TOP)\src\sqlite3.rc $(SQLITE3H) echo #ifndef SQLITE_RESOURCE_VERSION > sqlite3rc.h for /F %%V in ('type "$(TOP)\VERSION"') do ( \ echo #define SQLITE_RESOURCE_VERSION %%V \ @@ -1957,20 +1974,3 @@ clean: del /Q sqlite-*-output.vsix 2>NUL del /Q fuzzershell.exe fuzzcheck.exe sqldiff.exe 2>NUL del /Q fts5.* fts5parse.* 2>NUL - -# Shell executable. -# -shell: $(SQLITE3EXE) - -# Dynamic link library section. -# -dll: $(SQLITE3DLL) - -sqlite3.def: libsqlite3.lib - echo EXPORTS > sqlite3.def - dumpbin /all libsqlite3.lib \ - | $(TCLSH_CMD) $(TOP)\tool\replace.tcl include "^\s+1 _?(sqlite3_.*)$$" \1 \ - | sort >> sqlite3.def - -$(SQLITE3DLL): $(LIBOBJ) $(LIBRESOBJS) $(CORE_LINK_DEP) - $(LD) $(LDFLAGS) $(LTLINKOPTS) $(LTLIBPATHS) /DLL $(CORE_LINK_OPTS) /OUT:$@ $(LIBOBJ) $(LIBRESOBJS) $(LTLIBS) $(TLIBS) diff --git a/manifest b/manifest index 566db8de82..2e197ef017 100644 --- a/manifest +++ b/manifest @@ -1,8 +1,8 @@ -C Reenable\sthe\sxCurrentTime\sand\sxGetLastError\smethods\son\sthe\sunix\sVFSes\sas\slong\nas\sSQLITE_OMIT_DEPRECATED\sis\snot\sdefined. -D 2016-01-22T19:44:03.065 +C More\sMSVC\smakefile\scleanup. +D 2016-01-22T22:16:50.346 F Makefile.in 027c1603f255390c43a426671055a31c0a65fdb4 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 -F Makefile.msc d2b93511a969c0c8fcf52aeb5e426571e8c610d2 +F Makefile.msc bf507c4168b28d0ba47ac29d53fd6244289f10b8 F README.md 8ecc12493ff9f820cdea6520a9016001cb2e59b7 F VERSION 866588d1edf0ccb5b0d33896974338f97564f719 F aclocal.m4 a5c22d164aff7ed549d53a90fa56d56955281f50 @@ -1419,7 +1419,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 7323175337b7ba85ac932ca892b28860f6a5b688 -R 4fcfc780a1da751b6f90e6d6f3ced841 -U drh -Z 703592c4495d8a71fd67fbd54e7f3927 +P c11c85fdb6514cae54bb44945cc197dcaba72307 +R 7e2bc2233b486c9642759e292a9803ed +U mistachkin +Z f537116bba79cbb015eb60c46b78af4d diff --git a/manifest.uuid b/manifest.uuid index a853332581..289f7591c2 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c11c85fdb6514cae54bb44945cc197dcaba72307 \ No newline at end of file +df22556fd75997111e52f96572da8379dfe948be \ No newline at end of file From 147ef3948622234303ef6d38c38e6ee9fe325928 Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 22 Jan 2016 23:17:51 +0000 Subject: [PATCH 14/75] In the TCL interface, if a database connection object was opened with the -uri 1 option, then also honor URI filenames for the "backup" and "restore" commands. FossilOrigin-Name: a1c8116ced62d81f3f5ca26bbe0877e829d4cc56 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/tclsqlite.c | 8 ++++++-- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index 2e197ef017..ffb98b2734 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C More\sMSVC\smakefile\scleanup. -D 2016-01-22T22:16:50.346 +C In\sthe\sTCL\sinterface,\sif\sa\sdatabase\sconnection\sobject\swas\sopened\swith\nthe\s-uri\s1\soption,\sthen\salso\shonor\sURI\sfilenames\sfor\sthe\s"backup"\sand\n"restore"\scommands. +D 2016-01-22T23:17:51.219 F Makefile.in 027c1603f255390c43a426671055a31c0a65fdb4 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc bf507c4168b28d0ba47ac29d53fd6244289f10b8 @@ -354,7 +354,7 @@ F src/sqliteInt.h 74e10a74116df0aec9d4a3e134f1a86cc34c2f14 F src/sqliteLimit.h 216557999cb45f2e3578ed53ebefe228d779cb46 F src/status.c 70912d7be68e9e2dbc4010c93d344af61d4c59ba F src/table.c 51b46b2a62d1b3a959633d593b89bab5e2c9155e -F src/tclsqlite.c 82979239a896992f9b78efec81cfda05d316a7d0 +F src/tclsqlite.c 94ef6e2794220c5b6064d4c78ec7169a8c5cc45d F src/test1.c 4f1b42699068b7806af3111786f5ad760c2c1ff7 F src/test2.c 5586f43fcd9a1be0830793cf9d354082c261b25b F src/test3.c a8887dabbbee3059af338f20d290084a63ed1b0f @@ -1419,7 +1419,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P c11c85fdb6514cae54bb44945cc197dcaba72307 -R 7e2bc2233b486c9642759e292a9803ed -U mistachkin -Z f537116bba79cbb015eb60c46b78af4d +P df22556fd75997111e52f96572da8379dfe948be +R 14f009751ec343de1132abf0a7bfa01f +U drh +Z 3618240e30f243f2df7ae3a3ace24b2d diff --git a/manifest.uuid b/manifest.uuid index 289f7591c2..5a178d2571 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -df22556fd75997111e52f96572da8379dfe948be \ No newline at end of file +a1c8116ced62d81f3f5ca26bbe0877e829d4cc56 \ No newline at end of file diff --git a/src/tclsqlite.c b/src/tclsqlite.c index 604e898265..aa913ca7c7 100644 --- a/src/tclsqlite.c +++ b/src/tclsqlite.c @@ -153,6 +153,7 @@ struct SqliteDb { IncrblobChannel *pIncrblob;/* Linked list of open incrblob channels */ int nStep, nSort, nIndex; /* Statistics for most recent operation */ int nTransaction; /* Number of nested [transaction] methods */ + int openFlags; /* Flags used to open. (SQLITE_OPEN_URI) */ #ifdef SQLITE_TEST int bLegacyPrepare; /* True to use sqlite3_prepare() */ #endif @@ -1750,7 +1751,8 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){ Tcl_WrongNumArgs(interp, 2, objv, "?DATABASE? FILENAME"); return TCL_ERROR; } - rc = sqlite3_open(zDestFile, &pDest); + rc = sqlite3_open_v2(zDestFile, &pDest, + SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE| pDb->openFlags, 0); if( rc!=SQLITE_OK ){ Tcl_AppendResult(interp, "cannot open target database: ", sqlite3_errmsg(pDest), (char*)0); @@ -2613,7 +2615,8 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){ Tcl_WrongNumArgs(interp, 2, objv, "?DATABASE? FILENAME"); return TCL_ERROR; } - rc = sqlite3_open_v2(zSrcFile, &pSrc, SQLITE_OPEN_READONLY, 0); + rc = sqlite3_open_v2(zSrcFile, &pSrc, + SQLITE_OPEN_READONLY | pDb->openFlags, 0); if( rc!=SQLITE_OK ){ Tcl_AppendResult(interp, "cannot open source database: ", sqlite3_errmsg(pSrc), (char*)0); @@ -3088,6 +3091,7 @@ static int DbMain(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){ return TCL_ERROR; } p->maxStmt = NUM_PREPARED_STMTS; + p->openFlags = flags & SQLITE_OPEN_URI; p->interp = interp; zArg = Tcl_GetStringFromObj(objv[1], 0); if( DbUseNre() ){ From 4cfea5c794983b03bc7fcf7b43b91b83d27b945c Mon Sep 17 00:00:00 2001 From: mistachkin Date: Sat, 23 Jan 2016 00:07:51 +0000 Subject: [PATCH 15/75] More work on the MSVC build. FossilOrigin-Name: a79c46bc61a35edbaf6112c26e8052314b0eb16a --- Makefile.msc | 2 +- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/sqlite3.rc | 2 ++ 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/Makefile.msc b/Makefile.msc index 504b2893ba..5921e9375a 100644 --- a/Makefile.msc +++ b/Makefile.msc @@ -1948,7 +1948,7 @@ rbu.exe: $(TOP)\ext\rbu\rbu.c $(TOP)\ext\rbu\sqlite3rbu.c $(SQLITE3C) $(SQLITE3H clean: del /Q *.exp *.lo *.ilk *.lib *.obj *.ncb *.pdb *.sdf *.suo 2>NUL - del /Q *.bsc *.cod *.da *.bb *.bbg gmon.out 2>NUL + del /Q *.bsc *.cod *.da *.bb *.bbg *.vc gmon.out 2>NUL del /Q $(SQLITE3C) $(SQLITE3H) opcodes.c opcodes.h 2>NUL del /Q lemon.* lempar.c parse.* 2>NUL del /Q mkkeywordhash.* keywordhash.h 2>NUL diff --git a/manifest b/manifest index ffb98b2734..61cf5d66ed 100644 --- a/manifest +++ b/manifest @@ -1,8 +1,8 @@ -C In\sthe\sTCL\sinterface,\sif\sa\sdatabase\sconnection\sobject\swas\sopened\swith\nthe\s-uri\s1\soption,\sthen\salso\shonor\sURI\sfilenames\sfor\sthe\s"backup"\sand\n"restore"\scommands. -D 2016-01-22T23:17:51.219 +C More\swork\son\sthe\sMSVC\sbuild. +D 2016-01-23T00:07:51.151 F Makefile.in 027c1603f255390c43a426671055a31c0a65fdb4 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 -F Makefile.msc bf507c4168b28d0ba47ac29d53fd6244289f10b8 +F Makefile.msc 1708a78eda223b6daa302b140037fcc214a779f9 F README.md 8ecc12493ff9f820cdea6520a9016001cb2e59b7 F VERSION 866588d1edf0ccb5b0d33896974338f97564f719 F aclocal.m4 a5c22d164aff7ed549d53a90fa56d56955281f50 @@ -348,7 +348,7 @@ F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e F src/select.c 1db9a902e89201a0ae3ff5243a7a3f37842a3937 F src/shell.c dcd7a83645ef2a58ee9c6d0ea4714d877d7835c4 F src/sqlite.h.in 214476a62012e578f42133a9a3b4f97a9aa421a3 -F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad +F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h dfbe62ffd95b99afe2140d8c35b180d11924072d F src/sqliteInt.h 74e10a74116df0aec9d4a3e134f1a86cc34c2f14 F src/sqliteLimit.h 216557999cb45f2e3578ed53ebefe228d779cb46 @@ -1419,7 +1419,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P df22556fd75997111e52f96572da8379dfe948be -R 14f009751ec343de1132abf0a7bfa01f -U drh -Z 3618240e30f243f2df7ae3a3ace24b2d +P a1c8116ced62d81f3f5ca26bbe0877e829d4cc56 +R b34246fa017fc0ae2e7bf7cb484e3eeb +U mistachkin +Z ba075ff448ff99fa520b3503324fe6e9 diff --git a/manifest.uuid b/manifest.uuid index 5a178d2571..d1ea2b33a4 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -a1c8116ced62d81f3f5ca26bbe0877e829d4cc56 \ No newline at end of file +a79c46bc61a35edbaf6112c26e8052314b0eb16a \ No newline at end of file diff --git a/src/sqlite3.rc b/src/sqlite3.rc index 04dd086488..5a856490d6 100644 --- a/src/sqlite3.rc +++ b/src/sqlite3.rc @@ -39,9 +39,11 @@ LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US * Icon */ +#if !defined(RC_VERONLY) #define IDI_SQLITE 101 IDI_SQLITE ICON "..\\art\\sqlite370.ico" +#endif /* !defined(RC_VERONLY) */ /* * Version From 3e7860938b58cae4388007a2bc6506679f13ddff Mon Sep 17 00:00:00 2001 From: mistachkin Date: Sat, 23 Jan 2016 07:53:04 +0000 Subject: [PATCH 16/75] Add tooling to create an MSVC Makefile capable of building the core library and shell only, using a pre-built amalgamation. FossilOrigin-Name: c46f1a13cb00264d1164399059250884c7be4ea0 --- Makefile.min.msc | 885 +++++++++++++++++++++++++++++++++++++++++++++ Makefile.msc | 38 ++ manifest | 17 +- manifest.uuid | 2 +- tool/mkmsvcmin.tcl | 88 +++++ 5 files changed, 1023 insertions(+), 7 deletions(-) create mode 100644 Makefile.min.msc create mode 100644 tool/mkmsvcmin.tcl diff --git a/Makefile.min.msc b/Makefile.min.msc new file mode 100644 index 0000000000..2ec986fa4b --- /dev/null +++ b/Makefile.min.msc @@ -0,0 +1,885 @@ +# +# nmake Makefile for SQLite +# +############################################################################### +############################## START OF OPTIONS ############################### +############################################################################### + +# The toplevel directory of the source tree. This is the directory +# that contains this "Makefile.msc". +# +TOP = . + + +# Set this non-0 to enable full warnings (-W4, etc) when compiling. +# +!IFNDEF USE_FULLWARN +USE_FULLWARN = 0 +!ENDIF + +# Set this non-0 to use "stdcall" calling convention for the core library +# and shell executable. +# +!IFNDEF USE_STDCALL +USE_STDCALL = 0 +!ENDIF + +# Set this non-0 to have the shell executable link against the core dynamic +# link library. +# +!IFNDEF DYNAMIC_SHELL +DYNAMIC_SHELL = 0 +!ENDIF + +# Set this non-0 to enable extra code that attempts to detect misuse of the +# SQLite API. +# +!IFNDEF API_ARMOR +API_ARMOR = 0 +!ENDIF + +# If necessary, create a list of harmless compiler warnings to disable when +# compiling the various tools. For the SQLite source code itself, warnings, +# if any, will be disabled from within it. +# +!IFNDEF NO_WARN +!IF $(USE_FULLWARN)!=0 +NO_WARN = -wd4054 -wd4055 -wd4100 -wd4127 -wd4130 -wd4152 -wd4189 -wd4206 +NO_WARN = $(NO_WARN) -wd4210 -wd4232 -wd4305 -wd4306 -wd4702 -wd4706 +!ENDIF +!ENDIF + +# Set this non-0 to use the library paths and other options necessary for +# Windows Phone 8.1. +# +!IFNDEF USE_WP81_OPTS +USE_WP81_OPTS = 0 +!ENDIF + +# Set this non-0 to split the SQLite amalgamation file into chunks to +# be used for debugging with Visual Studio. +# +!IFNDEF SPLIT_AMALGAMATION +SPLIT_AMALGAMATION = 0 +!ENDIF + + +# Set this non-0 to dynamically link to the MSVC runtime library. +# +!IFNDEF USE_CRT_DLL +USE_CRT_DLL = 0 +!ENDIF + +# Set this non-0 to link to the RPCRT4 library. +# +!IFNDEF USE_RPCRT4_LIB +USE_RPCRT4_LIB = 0 +!ENDIF + +# Set this non-0 to generate assembly code listings for the source code +# files. +# +!IFNDEF USE_LISTINGS +USE_LISTINGS = 0 +!ENDIF + +# Set this non-0 to attempt setting the native compiler automatically +# for cross-compiling the command line tools needed during the compilation +# process. +# +!IFNDEF XCOMPILE +XCOMPILE = 0 +!ENDIF + +# Set this non-0 to use the native libraries paths for cross-compiling +# the command line tools needed during the compilation process. +# +!IFNDEF USE_NATIVE_LIBPATHS +USE_NATIVE_LIBPATHS = 0 +!ENDIF + +# Set this 0 to skip the compiling and embedding of version resources. +# +!IFNDEF USE_RC +USE_RC = 1 +!ENDIF + +# Set this non-0 to compile binaries suitable for the WinRT environment. +# This setting does not apply to any binaries that require Tcl to operate +# properly (i.e. the text fixture, etc). +# +!IFNDEF FOR_WINRT +FOR_WINRT = 0 +!ENDIF + +# Set this non-0 to compile binaries suitable for the UAP environment. +# This setting does not apply to any binaries that require Tcl to operate +# properly (i.e. the text fixture, etc). +# +!IFNDEF FOR_UAP +FOR_UAP = 0 +!ENDIF + +# Set this non-0 to compile binaries suitable for the Windows 10 platform. +# +!IFNDEF FOR_WIN10 +FOR_WIN10 = 0 +!ENDIF + + +# Set this to non-0 to create and use PDBs. +# +!IFNDEF SYMBOLS +SYMBOLS = 1 +!ENDIF + +# Set this to non-0 to use the SQLite debugging heap subsystem. +# +!IFNDEF MEMDEBUG +MEMDEBUG = 0 +!ENDIF + +# Set this to non-0 to use the Win32 native heap subsystem. +# +!IFNDEF WIN32HEAP +WIN32HEAP = 0 +!ENDIF + +# Set this to non-0 to enable OSTRACE() macros, which can be useful when +# debugging. +# +!IFNDEF OSTRACE +OSTRACE = 0 +!ENDIF + +# Set this to one of the following values to enable various debugging +# features. Each level includes the debugging options from the previous +# levels. Currently, the recognized values for DEBUG are: +# +# 0 == NDEBUG: Disables assert() and other runtime diagnostics. +# 1 == SQLITE_ENABLE_API_ARMOR: extra attempts to detect misuse of the API. +# 2 == Disables NDEBUG and all optimizations and then enables PDBs. +# 3 == SQLITE_DEBUG: Enables various diagnostics messages and code. +# 4 == SQLITE_WIN32_MALLOC_VALIDATE: Validate the Win32 native heap per call. +# 5 == SQLITE_DEBUG_OS_TRACE: Enables output from the OSTRACE() macros. +# 6 == SQLITE_ENABLE_IOTRACE: Enables output from the IOTRACE() macros. +# +!IFNDEF DEBUG +DEBUG = 0 +!ENDIF + +# Enable use of available compiler optimizations? Normally, this should be +# non-zero. Setting this to zero, thus disabling all compiler optimizations, +# can be useful for testing. +# +!IFNDEF OPTIMIZATIONS +OPTIMIZATIONS = 2 +!ENDIF + +# Set the source code file to be used by executables and libraries when +# they need the amalgamation. +# +!IFNDEF SQLITE3C +!IF $(SPLIT_AMALGAMATION)!=0 +SQLITE3C = sqlite3-all.c +!ELSE +SQLITE3C = sqlite3.c +!ENDIF +!ENDIF + +# Set the include code file to be used by executables and libraries when +# they need SQLite. +# +!IFNDEF SQLITE3H +SQLITE3H = sqlite3.h +!ENDIF + +# This is the name to use for the SQLite dynamic link library (DLL). +# +!IFNDEF SQLITE3DLL +SQLITE3DLL = sqlite3.dll +!ENDIF + +# This is the name to use for the SQLite import library (LIB). +# +!IFNDEF SQLITE3LIB +SQLITE3LIB = sqlite3.lib +!ENDIF + +# This is the name to use for the SQLite shell executable (EXE). +# +!IFNDEF SQLITE3EXE +SQLITE3EXE = sqlite3.exe +!ENDIF + +# This is the argument used to set the program database (PDB) file for the +# SQLite shell executable (EXE). +# +!IFNDEF SQLITE3EXEPDB +SQLITE3EXEPDB = /pdb:sqlite3sh.pdb +!ENDIF + +# These are the "standard" SQLite compilation options used when compiling for +# the Windows platform. +# +!IFNDEF OPT_FEATURE_FLAGS +OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_FTS3=1 +OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_RTREE=1 +OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_COLUMN_METADATA=1 +!ENDIF + +# These are the "extended" SQLite compilation options used when compiling for +# the Windows 10 platform. +# +!IFNDEF EXT_FEATURE_FLAGS +!IF $(FOR_WIN10)!=0 +EXT_FEATURE_FLAGS = $(EXT_FEATURE_FLAGS) -DSQLITE_ENABLE_FTS4=1 +EXT_FEATURE_FLAGS = $(EXT_FEATURE_FLAGS) -DSQLITE_SYSTEM_MALLOC=1 +EXT_FEATURE_FLAGS = $(EXT_FEATURE_FLAGS) -DSQLITE_OMIT_LOCALTIME=1 +!ELSE +EXT_FEATURE_FLAGS = +!ENDIF +!ENDIF + +############################################################################### +############################### END OF OPTIONS ################################ +############################################################################### + +# This assumes that MSVC is always installed in 32-bit Program Files directory +# and sets the variable for use in locating other 32-bit installs accordingly. +# +PROGRAMFILES_X86 = $(VCINSTALLDIR)\..\.. +PROGRAMFILES_X86 = $(PROGRAMFILES_X86:\\=\) + +# Check for the predefined command macro CC. This should point to the compiler +# binary for the target platform. If it is not defined, simply define it to +# the legacy default value 'cl.exe'. +# +!IFNDEF CC +CC = cl.exe +!ENDIF + +# Check for the command macro LD. This should point to the linker binary for +# the target platform. If it is not defined, simply define it to the legacy +# default value 'link.exe'. +# +!IFNDEF LD +LD = link.exe +!ENDIF + +# Check for the predefined command macro RC. This should point to the resource +# compiler binary for the target platform. If it is not defined, simply define +# it to the legacy default value 'rc.exe'. +# +!IFNDEF RC +RC = rc.exe +!ENDIF + +# Check for the MSVC runtime library path macro. Othertise, this value will +# default to the 'lib' directory underneath the MSVC installation directory. +# +!IFNDEF CRTLIBPATH +CRTLIBPATH = $(VCINSTALLDIR)\lib +!ENDIF + +CRTLIBPATH = $(CRTLIBPATH:\\=\) + +# Check for the command macro NCC. This should point to the compiler binary +# for the platform the compilation process is taking place on. If it is not +# defined, simply define it to have the same value as the CC macro. When +# cross-compiling, it is suggested that this macro be modified via the command +# line (since nmake itself does not provide a built-in method to guess it). +# For example, to use the x86 compiler when cross-compiling for x64, a command +# line similar to the following could be used (all on one line): +# +# nmake /f Makefile.msc sqlite3.dll +# XCOMPILE=1 USE_NATIVE_LIBPATHS=1 +# +# Alternatively, the full path and file name to the compiler binary for the +# platform the compilation process is taking place may be specified (all on +# one line): +# +# nmake /f Makefile.msc sqlite3.dll +# "NCC=""%VCINSTALLDIR%\bin\cl.exe""" +# USE_NATIVE_LIBPATHS=1 +# +!IFDEF NCC +NCC = $(NCC:\\=\) +!ELSEIF $(XCOMPILE)!=0 +NCC = "$(VCINSTALLDIR)\bin\$(CC)" +NCC = $(NCC:\\=\) +!ELSE +NCC = $(CC) +!ENDIF + +# Check for the MSVC native runtime library path macro. Othertise, +# this value will default to the 'lib' directory underneath the MSVC +# installation directory. +# +!IFNDEF NCRTLIBPATH +NCRTLIBPATH = $(VCINSTALLDIR)\lib +!ENDIF + +NCRTLIBPATH = $(NCRTLIBPATH:\\=\) + +# Check for the Platform SDK library path macro. Othertise, this +# value will default to the 'lib' directory underneath the Windows +# SDK installation directory (the environment variable used appears +# to be available when using Visual C++ 2008 or later via the +# command line). +# +!IFNDEF NSDKLIBPATH +NSDKLIBPATH = $(WINDOWSSDKDIR)\lib +!ENDIF + +NSDKLIBPATH = $(NSDKLIBPATH:\\=\) + +# C compiler and options for use in building executables that +# will run on the platform that is doing the build. +# +!IF $(USE_FULLWARN)!=0 +BCC = $(NCC) -nologo -W4 $(CCOPTS) $(BCCOPTS) +!ELSE +BCC = $(NCC) -nologo -W3 $(CCOPTS) $(BCCOPTS) +!ENDIF + +# Check if assembly code listings should be generated for the source +# code files to be compiled. +# +!IF $(USE_LISTINGS)!=0 +BCC = $(BCC) -FAcs +!ENDIF + +# Check if the native library paths should be used when compiling +# the command line tools used during the compilation process. If +# so, set the necessary macro now. +# +!IF $(USE_NATIVE_LIBPATHS)!=0 +NLTLIBPATHS = "/LIBPATH:$(NCRTLIBPATH)" "/LIBPATH:$(NSDKLIBPATH)" + +!IFDEF NUCRTLIBPATH +NUCRTLIBPATH = $(NUCRTLIBPATH:\\=\) +NLTLIBPATHS = $(NLTLIBPATHS) "/LIBPATH:$(NUCRTLIBPATH)" +!ENDIF +!ENDIF + +# C compiler and options for use in building executables that +# will run on the target platform. (BCC and TCC are usually the +# same unless your are cross-compiling.) +# +!IF $(USE_FULLWARN)!=0 +TCC = $(CC) -nologo -W4 -DINCLUDE_MSVC_H=1 $(CCOPTS) $(TCCOPTS) +!ELSE +TCC = $(CC) -nologo -W3 $(CCOPTS) $(TCCOPTS) +!ENDIF + +TCC = $(TCC) -DSQLITE_OS_WIN=1 -I$(TOP) -fp:precise +RCC = $(RC) -DSQLITE_OS_WIN=1 -I$(TOP) $(RCOPTS) $(RCCOPTS) + +# Adjust the names of the primary targets for use with Windows 10. +# +!IF $(FOR_WIN10)!=0 +SQLITE3DLL = winsqlite3.dll +SQLITE3LIB = winsqlite3.lib +SQLITE3EXE = winsqlite3shell.exe +SQLITE3EXEPDB = +!ENDIF + +# Check if we want to use the "stdcall" calling convention when compiling. +# This is not supported by the compilers for non-x86 platforms. It should +# also be noted here that building any target with these "stdcall" options +# will most likely fail if the Tcl library is also required. This is due +# to how the Tcl library functions are declared and exported (i.e. without +# an explicit calling convention, which results in "cdecl"). +# +!IF $(USE_STDCALL)!=0 || $(FOR_WIN10)!=0 +!IF "$(PLATFORM)"=="x86" +CORE_CCONV_OPTS = -Gz -DSQLITE_CDECL=__cdecl -DSQLITE_STDCALL=__stdcall +SHELL_CCONV_OPTS = -Gz -DSQLITE_CDECL=__cdecl -DSQLITE_STDCALL=__stdcall +!ELSE +!IFNDEF PLATFORM +CORE_CCONV_OPTS = -Gz -DSQLITE_CDECL=__cdecl -DSQLITE_STDCALL=__stdcall +SHELL_CCONV_OPTS = -Gz -DSQLITE_CDECL=__cdecl -DSQLITE_STDCALL=__stdcall +!ELSE +CORE_CCONV_OPTS = +SHELL_CCONV_OPTS = +!ENDIF +!ENDIF +!ELSE +CORE_CCONV_OPTS = +SHELL_CCONV_OPTS = +!ENDIF + +# These are additional compiler options used for the core library. +# +!IFNDEF CORE_COMPILE_OPTS +!IF $(DYNAMIC_SHELL)!=0 || $(FOR_WIN10)!=0 +CORE_COMPILE_OPTS = $(CORE_CCONV_OPTS) -DSQLITE_API=__declspec(dllexport) +!ELSE +CORE_COMPILE_OPTS = $(CORE_CCONV_OPTS) +!ENDIF +!ENDIF + +# These are the additional targets that the core library should depend on +# when linking. +# +!IFNDEF CORE_LINK_DEP +!IF $(DYNAMIC_SHELL)!=0 || $(FOR_WIN10)!=0 +CORE_LINK_DEP = +!ELSE +CORE_LINK_DEP = +!ENDIF +!ENDIF + +# These are additional linker options used for the core library. +# +!IFNDEF CORE_LINK_OPTS +!IF $(DYNAMIC_SHELL)!=0 || $(FOR_WIN10)!=0 +CORE_LINK_OPTS = +!ELSE +CORE_LINK_OPTS = +!ENDIF +!ENDIF + +# These are additional compiler options used for the shell executable. +# +!IFNDEF SHELL_COMPILE_OPTS +!IF $(DYNAMIC_SHELL)!=0 || $(FOR_WIN10)!=0 +SHELL_COMPILE_OPTS = $(SHELL_CCONV_OPTS) -DSQLITE_API=__declspec(dllimport) +!ELSE +SHELL_COMPILE_OPTS = $(SHELL_CCONV_OPTS) +!ENDIF +!ENDIF + +# This is the source code that the shell executable should be compiled +# with. +# +!IFNDEF SHELL_CORE_SRC +!IF $(DYNAMIC_SHELL)!=0 || $(FOR_WIN10)!=0 +SHELL_CORE_SRC = +!ELSE +SHELL_CORE_SRC = $(SQLITE3C) +!ENDIF +!ENDIF + +# This is the core library that the shell executable should depend on. +# +!IFNDEF SHELL_CORE_DEP +!IF $(DYNAMIC_SHELL)!=0 || $(FOR_WIN10)!=0 +SHELL_CORE_DEP = $(SQLITE3DLL) +!ELSE +SHELL_CORE_DEP = +!ENDIF +!ENDIF + +# This is the core library that the shell executable should link with. +# +!IFNDEF SHELL_CORE_LIB +!IF $(DYNAMIC_SHELL)!=0 || $(FOR_WIN10)!=0 +SHELL_CORE_LIB = $(SQLITE3LIB) +!ELSE +SHELL_CORE_LIB = +!ENDIF +!ENDIF + +# These are additional linker options used for the shell executable. +# +!IFNDEF SHELL_LINK_OPTS +SHELL_LINK_OPTS = $(SHELL_CORE_LIB) +!ENDIF + +# Check if assembly code listings should be generated for the source +# code files to be compiled. +# +!IF $(USE_LISTINGS)!=0 +TCC = $(TCC) -FAcs +!ENDIF + +# When compiling the library for use in the WinRT environment, +# the following compile-time options must be used as well to +# disable use of Win32 APIs that are not available and to enable +# use of Win32 APIs that are specific to Windows 8 and/or WinRT. +# +!IF $(FOR_WINRT)!=0 +TCC = $(TCC) -DSQLITE_OS_WINRT=1 +RCC = $(RCC) -DSQLITE_OS_WINRT=1 +TCC = $(TCC) -DWINAPI_FAMILY=WINAPI_FAMILY_APP +RCC = $(RCC) -DWINAPI_FAMILY=WINAPI_FAMILY_APP +!ENDIF + +# C compiler options for the Windows 10 platform (needs MSVC 2015). +# +!IF $(FOR_WIN10)!=0 +TCC = $(TCC) /guard:cf -D_ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE +BCC = $(BCC) /guard:cf -D_ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE +!ENDIF + +# Also, we need to dynamically link to the correct MSVC runtime +# when compiling for WinRT (e.g. debug or release) OR if the +# USE_CRT_DLL option is set to force dynamically linking to the +# MSVC runtime library. +# +!IF $(FOR_WINRT)!=0 || $(FOR_WIN10)!=0 || $(USE_CRT_DLL)!=0 +!IF $(DEBUG)>1 +TCC = $(TCC) -MDd +BCC = $(BCC) -MDd +!ELSE +TCC = $(TCC) -MD +BCC = $(BCC) -MD +!ENDIF +!ELSE +!IF $(DEBUG)>1 +TCC = $(TCC) -MTd +BCC = $(BCC) -MTd +!ELSE +TCC = $(TCC) -MT +BCC = $(BCC) -MT +!ENDIF +!ENDIF + + +# Define -DNDEBUG to compile without debugging (i.e., for production usage) +# Omitting the define will cause extra debugging code to be inserted and +# includes extra comments when "EXPLAIN stmt" is used. +# +!IF $(DEBUG)==0 +TCC = $(TCC) -DNDEBUG +BCC = $(BCC) -DNDEBUG +RCC = $(RCC) -DNDEBUG +!ENDIF + +!IF $(DEBUG)>0 || $(API_ARMOR)!=0 || $(FOR_WIN10)!=0 +TCC = $(TCC) -DSQLITE_ENABLE_API_ARMOR=1 +RCC = $(RCC) -DSQLITE_ENABLE_API_ARMOR=1 +!ENDIF + +!IF $(DEBUG)>2 +TCC = $(TCC) -DSQLITE_DEBUG=1 +RCC = $(RCC) -DSQLITE_DEBUG=1 +!ENDIF + +!IF $(DEBUG)>4 || $(OSTRACE)!=0 +TCC = $(TCC) -DSQLITE_FORCE_OS_TRACE=1 -DSQLITE_DEBUG_OS_TRACE=1 +RCC = $(RCC) -DSQLITE_FORCE_OS_TRACE=1 -DSQLITE_DEBUG_OS_TRACE=1 +!ENDIF + +!IF $(DEBUG)>5 +TCC = $(TCC) -DSQLITE_ENABLE_IOTRACE=1 +RCC = $(RCC) -DSQLITE_ENABLE_IOTRACE=1 +!ENDIF + +# Prevent warnings about "insecure" MSVC runtime library functions +# being used. +# +TCC = $(TCC) -D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS +BCC = $(BCC) -D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS +RCC = $(RCC) -D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS + +# Prevent warnings about "deprecated" POSIX functions being used. +# +TCC = $(TCC) -D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_NONSTDC_NO_WARNINGS +BCC = $(BCC) -D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_NONSTDC_NO_WARNINGS +RCC = $(RCC) -D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_NONSTDC_NO_WARNINGS + +# Use the SQLite debugging heap subsystem? +# +!IF $(MEMDEBUG)!=0 +TCC = $(TCC) -DSQLITE_MEMDEBUG=1 +RCC = $(RCC) -DSQLITE_MEMDEBUG=1 + +# Use native Win32 heap subsystem instead of malloc/free? +# +!ELSEIF $(WIN32HEAP)!=0 +TCC = $(TCC) -DSQLITE_WIN32_MALLOC=1 +RCC = $(RCC) -DSQLITE_WIN32_MALLOC=1 + +# Validate the heap on every call into the native Win32 heap subsystem? +# +!IF $(DEBUG)>3 +TCC = $(TCC) -DSQLITE_WIN32_MALLOC_VALIDATE=1 +RCC = $(RCC) -DSQLITE_WIN32_MALLOC_VALIDATE=1 +!ENDIF +!ENDIF + + +# Compiler options needed for programs that use the readline() library. +# +!IFNDEF READLINE_FLAGS +READLINE_FLAGS = -DHAVE_READLINE=0 +!ENDIF + +# The library that programs using readline() must link against. +# +!IFNDEF LIBREADLINE +LIBREADLINE = +!ENDIF + +# Should the database engine be compiled threadsafe +# +TCC = $(TCC) -DSQLITE_THREADSAFE=1 +RCC = $(RCC) -DSQLITE_THREADSAFE=1 + +# Do threads override each others locks by default (1), or do we test (-1) +# +TCC = $(TCC) -DSQLITE_THREAD_OVERRIDE_LOCK=-1 +RCC = $(RCC) -DSQLITE_THREAD_OVERRIDE_LOCK=-1 + +# Any target libraries which libsqlite must be linked against +# +!IFNDEF TLIBS +TLIBS = +!ENDIF + +# Flags controlling use of the in memory btree implementation +# +# SQLITE_TEMP_STORE is 0 to force temporary tables to be in a file, 1 to +# default to file, 2 to default to memory, and 3 to force temporary +# tables to always be in memory. +# +TCC = $(TCC) -DSQLITE_TEMP_STORE=1 +RCC = $(RCC) -DSQLITE_TEMP_STORE=1 + +# Enable/disable loadable extensions, and other optional features +# based on configuration. (-DSQLITE_OMIT*, -DSQLITE_ENABLE*). +# The same set of OMIT and ENABLE flags should be passed to the +# LEMON parser generator and the mkkeywordhash tool as well. + +# These are the required SQLite compilation options used when compiling for +# the Windows platform. +# +REQ_FEATURE_FLAGS = $(REQ_FEATURE_FLAGS) -DSQLITE_MAX_TRIGGER_DEPTH=100 + +# If we are linking to the RPCRT4 library, enable features that need it. +# +!IF $(USE_RPCRT4_LIB)!=0 +REQ_FEATURE_FLAGS = $(REQ_FEATURE_FLAGS) -DSQLITE_WIN32_USE_UUID=1 +!ENDIF + +# Add the required and optional SQLite compilation options into the command +# lines used to invoke the MSVC code and resource compilers. +# +TCC = $(TCC) $(REQ_FEATURE_FLAGS) $(OPT_FEATURE_FLAGS) $(EXT_FEATURE_FLAGS) +RCC = $(RCC) $(REQ_FEATURE_FLAGS) $(OPT_FEATURE_FLAGS) $(EXT_FEATURE_FLAGS) + +# Add in any optional parameters specified on the commane line, e.g. +# nmake /f Makefile.msc all "OPTS=-DSQLITE_ENABLE_FOO=1 -DSQLITE_OMIT_FOO=1" +# +TCC = $(TCC) $(OPTS) +RCC = $(RCC) $(OPTS) + +# If compiling for debugging, add some defines. +# +!IF $(DEBUG)>1 +TCC = $(TCC) -D_DEBUG +BCC = $(BCC) -D_DEBUG +RCC = $(RCC) -D_DEBUG +!ENDIF + +# If optimizations are enabled or disabled (either implicitly or +# explicitly), add the necessary flags. +# +!IF $(DEBUG)>1 || $(OPTIMIZATIONS)==0 +TCC = $(TCC) -Od +BCC = $(BCC) -Od +!ELSEIF $(OPTIMIZATIONS)>=3 +TCC = $(TCC) -Ox +BCC = $(BCC) -Ox +!ELSEIF $(OPTIMIZATIONS)==2 +TCC = $(TCC) -O2 +BCC = $(BCC) -O2 +!ELSEIF $(OPTIMIZATIONS)==1 +TCC = $(TCC) -O1 +BCC = $(BCC) -O1 +!ENDIF + +# If symbols are enabled (or compiling for debugging), enable PDBs. +# +!IF $(DEBUG)>1 || $(SYMBOLS)!=0 +TCC = $(TCC) -Zi +BCC = $(BCC) -Zi +!ENDIF + + +# Command line prefixes for compiling code, compiling resources, +# linking, etc. +# +LTCOMPILE = $(TCC) -Fo$@ +LTRCOMPILE = $(RCC) -r +LTLIB = lib.exe +LTLINK = $(TCC) -Fe$@ + +# If requested, link to the RPCRT4 library. +# +!IF $(USE_RPCRT4_LIB)!=0 +LTLINK = $(LTLINK) rpcrt4.lib +!ENDIF + +# If a platform was set, force the linker to target that. +# Note that the vcvars*.bat family of batch files typically +# set this for you. Otherwise, the linker will attempt +# to deduce the binary type based on the object files. +!IFDEF PLATFORM +LTLINKOPTS = /NOLOGO /MACHINE:$(PLATFORM) +LTLIBOPTS = /NOLOGO /MACHINE:$(PLATFORM) +!ELSE +LTLINKOPTS = /NOLOGO +LTLIBOPTS = /NOLOGO +!ENDIF + +# When compiling for use in the WinRT environment, the following +# linker option must be used to mark the executable as runnable +# only in the context of an application container. +# +!IF $(FOR_WINRT)!=0 +LTLINKOPTS = $(LTLINKOPTS) /APPCONTAINER +!IF "$(VISUALSTUDIOVERSION)"=="12.0" || "$(VISUALSTUDIOVERSION)"=="14.0" +!IFNDEF STORELIBPATH +!IF "$(PLATFORM)"=="x86" +STORELIBPATH = $(CRTLIBPATH)\store +!ELSEIF "$(PLATFORM)"=="x64" +STORELIBPATH = $(CRTLIBPATH)\store\amd64 +!ELSEIF "$(PLATFORM)"=="ARM" +STORELIBPATH = $(CRTLIBPATH)\store\arm +!ELSE +STORELIBPATH = $(CRTLIBPATH)\store +!ENDIF +!ENDIF +STORELIBPATH = $(STORELIBPATH:\\=\) +LTLINKOPTS = $(LTLINKOPTS) "/LIBPATH:$(STORELIBPATH)" +!ENDIF +!ENDIF + +# When compiling for Windows Phone 8.1, an extra library path is +# required. +# +!IF $(USE_WP81_OPTS)!=0 +!IFNDEF WP81LIBPATH +!IF "$(PLATFORM)"=="x86" +WP81LIBPATH = $(PROGRAMFILES_X86)\Windows Phone Kits\8.1\lib\x86 +!ELSEIF "$(PLATFORM)"=="ARM" +WP81LIBPATH = $(PROGRAMFILES_X86)\Windows Phone Kits\8.1\lib\ARM +!ELSE +WP81LIBPATH = $(PROGRAMFILES_X86)\Windows Phone Kits\8.1\lib\x86 +!ENDIF +!ENDIF +!ENDIF + +# When compiling for Windows Phone 8.1, some extra linker options +# are also required. +# +!IF $(USE_WP81_OPTS)!=0 +!IFDEF WP81LIBPATH +LTLINKOPTS = $(LTLINKOPTS) "/LIBPATH:$(WP81LIBPATH)" +!ENDIF +LTLINKOPTS = $(LTLINKOPTS) /DYNAMICBASE +LTLINKOPTS = $(LTLINKOPTS) WindowsPhoneCore.lib RuntimeObject.lib PhoneAppModelHost.lib +LTLINKOPTS = $(LTLINKOPTS) /NODEFAULTLIB:kernel32.lib /NODEFAULTLIB:ole32.lib +!ENDIF + +# When compiling for UAP, some extra linker options are also required. +# +!IF $(FOR_UAP)!=0 +LTLINKOPTS = $(LTLINKOPTS) /DYNAMICBASE /NODEFAULTLIB:kernel32.lib +LTLINKOPTS = $(LTLINKOPTS) mincore.lib +!IFDEF PSDKLIBPATH +LTLINKOPTS = $(LTLINKOPTS) "/LIBPATH:$(PSDKLIBPATH)" +!ENDIF +!ENDIF + +# If either debugging or symbols are enabled, enable PDBs. +# +!IF $(DEBUG)>1 || $(SYMBOLS)!=0 +LDFLAGS = /DEBUG $(LDOPTS) +!ELSE +LDFLAGS = $(LDOPTS) +!ENDIF + + +# You should not have to change anything below this line +############################################################################### + + +# Object files for the amalgamation. +# +LIBOBJS1 = sqlite3.lo + +# Determine the real value of LIBOBJ based on the 'configure' script +# +LIBOBJ = $(LIBOBJS1) + +# Determine if embedded resource compilation and usage are enabled. +# +!IF $(USE_RC)!=0 +LIBRESOBJS = sqlite3res.lo +!ELSE +LIBRESOBJS = +!ENDIF + + +# Additional compiler options for the shell. These are only effective +# when the shell is not being dynamically linked. +# +!IF $(DYNAMIC_SHELL)==0 && $(FOR_WIN10)==0 +SHELL_COMPILE_OPTS = $(SHELL_COMPILE_OPTS) -DSQLITE_SHELL_JSON1 -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS5 +!ENDIF + + +# This is the default Makefile target. The objects listed here +# are what get build when you type just "make" with no arguments. +# +all: dll libsqlite3.lib shell + +# Dynamic link library section. +# +dll: $(SQLITE3DLL) + +# Shell executable. +# +shell: $(SQLITE3EXE) + +libsqlite3.lib: $(LIBOBJ) + $(LTLIB) $(LTLIBOPTS) /OUT:$@ $(LIBOBJ) $(TLIBS) + + +$(SQLITE3DLL): $(LIBOBJ) $(LIBRESOBJS) $(CORE_LINK_DEP) + $(LD) $(LDFLAGS) $(LTLINKOPTS) $(LTLIBPATHS) /DLL $(CORE_LINK_OPTS) /OUT:$@ $(LIBOBJ) $(LIBRESOBJS) $(LTLIBS) $(TLIBS) + + +$(SQLITE3EXE): $(TOP)\shell.c $(SHELL_CORE_DEP) $(LIBRESOBJS) $(SHELL_CORE_SRC) $(SQLITE3H) + $(LTLINK) $(SHELL_COMPILE_OPTS) $(READLINE_FLAGS) $(TOP)\shell.c $(SHELL_CORE_SRC) \ + /link $(SQLITE3EXEPDB) $(LDFLAGS) $(LTLINKOPTS) $(SHELL_LINK_OPTS) $(LTLIBPATHS) $(LIBRESOBJS) $(LIBREADLINE) $(LTLIBS) $(TLIBS) + + +# Rule to build the amalgamation +# +sqlite3.lo: $(SQLITE3C) + $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(SQLITE3C) + + +# Rule to build the Win32 resources object file. +# +!IF $(USE_RC)!=0 +_HASHCHAR=^# +!IF ![echo !IFNDEF VERSION > rcver.vc] && \ + ![for /F "delims=" %V in ('type "$(SQLITE3H)" ^| find "$(_HASHCHAR)define SQLITE_VERSION "') do (echo VERSION = ^^%V >> rcver.vc)] && \ + ![echo !ENDIF >> rcver.vc] +!INCLUDE rcver.vc +!ENDIF + +RESOURCE_VERSION = $(VERSION:^#=) +RESOURCE_VERSION = $(RESOURCE_VERSION:define=) +RESOURCE_VERSION = $(RESOURCE_VERSION:SQLITE_VERSION=) +RESOURCE_VERSION = $(RESOURCE_VERSION:"=) +RESOURCE_VERSION = $(RESOURCE_VERSION:.=,) + +$(LIBRESOBJS): $(TOP)\sqlite3.rc rcver.vc $(SQLITE3H) + echo #ifndef SQLITE_RESOURCE_VERSION > sqlite3rc.h + echo #define SQLITE_RESOURCE_VERSION $(RESOURCE_VERSION) >> sqlite3rc.h + echo #endif >> sqlite3rc.h + $(LTRCOMPILE) -fo $(LIBRESOBJS) -DRC_VERONLY $(TOP)\sqlite3.rc +!ENDIF + + +clean: + del /Q *.exp *.lo *.ilk *.lib *.obj *.ncb *.pdb *.sdf *.suo 2>NUL + del /Q *.bsc *.cod *.da *.bb *.bbg *.vc gmon.out 2>NUL diff --git a/Makefile.msc b/Makefile.msc index 5921e9375a..ab0ba95d53 100644 --- a/Makefile.msc +++ b/Makefile.msc @@ -10,11 +10,13 @@ # TOP = . +# <> # Set this non-0 to create and use the SQLite amalgamation file. # !IFNDEF USE_AMALGAMATION USE_AMALGAMATION = 1 !ENDIF +# <> # Set this non-0 to enable full warnings (-W4, etc) when compiling. # @@ -68,11 +70,13 @@ USE_WP81_OPTS = 0 SPLIT_AMALGAMATION = 0 !ENDIF +# <> # Set this non-0 to use the International Components for Unicode (ICU). # !IFNDEF USE_ICU USE_ICU = 0 !ENDIF +# <> # Set this non-0 to dynamically link to the MSVC runtime library. # @@ -136,12 +140,14 @@ FOR_UAP = 0 FOR_WIN10 = 0 !ENDIF +# <> # Set this non-0 to skip attempting to look for and/or link with the Tcl # runtime library. # !IFNDEF NO_TCL NO_TCL = 0 !ENDIF +# <> # Set this to non-0 to create and use PDBs. # @@ -553,6 +559,7 @@ BCC = $(BCC) -MT !ENDIF !ENDIF +# <> # The mksqlite3c.tcl and mksqlite3h.tcl scripts will pull in # any extension header files by default. For non-amalgamation # builds, we need to make sure the compiler can find these. @@ -576,6 +583,7 @@ MKSQLITE3C_ARGS = --linemacros MKSQLITE3C_ARGS = !ENDIF !ENDIF +# <> # Define -DNDEBUG to compile without debugging (i.e., for production usage) # Omitting the define will cause extra debugging code to be inserted and @@ -640,6 +648,7 @@ RCC = $(RCC) -DSQLITE_WIN32_MALLOC_VALIDATE=1 !ENDIF !ENDIF +# <> # The locations of the Tcl header and library files. Also, the library that # non-stubs enabled programs using Tcl must link against. These variables # (TCLINCDIR, TCLLIBDIR, and LIBTCL) may be overridden via the environment @@ -691,6 +700,7 @@ LIBICU = icuuc.lib icuin.lib !IFNDEF TCLSH_CMD TCLSH_CMD = tclsh85 !ENDIF +# <> # Compiler options needed for programs that use the readline() library. # @@ -789,6 +799,7 @@ TCC = $(TCC) -Zi BCC = $(BCC) -Zi !ENDIF +# <> # If ICU support is enabled, add the compiler options for it. # !IF $(USE_ICU)!=0 @@ -799,6 +810,7 @@ RCC = $(RCC) -I$(TOP)\ext\icu TCC = $(TCC) -I$(ICUINCDIR) RCC = $(RCC) -I$(ICUINCDIR) !ENDIF +# <> # Command line prefixes for compiling code, compiling resources, # linking, etc. @@ -894,6 +906,7 @@ LDFLAGS = /DEBUG $(LDOPTS) LDFLAGS = $(LDOPTS) !ENDIF +# <> # Start with the Tcl related linker options. # !IF $(NO_TCL)==0 @@ -907,10 +920,12 @@ LTLIBS = $(LIBTCL) LTLIBPATHS = $(LTLIBPATHS) /LIBPATH:$(ICULIBDIR) LTLIBS = $(LTLIBS) $(LIBICU) !ENDIF +# <> # You should not have to change anything below this line ############################################################################### +# <> # Object files for the SQLite library (non-amalgamation). # LIBOBJS0 = vdbe.lo parse.lo alter.lo analyze.lo attach.lo auth.lo \ @@ -934,6 +949,7 @@ LIBOBJS0 = vdbe.lo parse.lo alter.lo analyze.lo attach.lo auth.lo \ vdbeapi.lo vdbeaux.lo vdbeblob.lo vdbemem.lo vdbesort.lo \ vdbetrace.lo wal.lo walker.lo where.lo wherecode.lo whereexpr.lo \ utf.lo vtab.lo +# <> # Object files for the amalgamation. # @@ -941,11 +957,15 @@ LIBOBJS1 = sqlite3.lo # Determine the real value of LIBOBJ based on the 'configure' script # +# <> !IF $(USE_AMALGAMATION)==0 LIBOBJ = $(LIBOBJS0) !ELSE +# <> LIBOBJ = $(LIBOBJS1) +# <> !ENDIF +# <> # Determine if embedded resource compilation and usage are enabled. # @@ -955,6 +975,7 @@ LIBRESOBJS = sqlite3res.lo LIBRESOBJS = !ENDIF +# <> # All of the source code files. # SRC1 = \ @@ -1303,6 +1324,7 @@ FUZZDATA = \ $(TOP)\test\fuzzdata2.db \ $(TOP)\test\fuzzdata3.db \ $(TOP)\test\fuzzdata4.db +# <> # Additional compiler options for the shell. These are only effective # when the shell is not being dynamically linked. @@ -1311,6 +1333,7 @@ FUZZDATA = \ SHELL_COMPILE_OPTS = $(SHELL_COMPILE_OPTS) -DSQLITE_SHELL_JSON1 -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS5 !ENDIF +# <> # Extra compiler options for various test tools. # MPTESTER_COMPILE_OPTS = -DSQLITE_SHELL_JSON1 -DSQLITE_ENABLE_FTS5 @@ -1320,6 +1343,7 @@ FUZZCHECK_COMPILE_OPTS = -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_MEMSYS5 # Standard options to testfixture. # TESTOPTS = --verbose=file --output=test-out.txt +# <> # This is the default Makefile target. The objects listed here # are what get build when you type just "make" with no arguments. @@ -1337,22 +1361,27 @@ shell: $(SQLITE3EXE) libsqlite3.lib: $(LIBOBJ) $(LTLIB) $(LTLIBOPTS) /OUT:$@ $(LIBOBJ) $(TLIBS) +# <> libtclsqlite3.lib: tclsqlite.lo libsqlite3.lib $(LTLIB) $(LTLIBOPTS) $(LTLIBPATHS) /OUT:$@ tclsqlite.lo libsqlite3.lib $(LIBTCLSTUB) $(TLIBS) +# <> $(SQLITE3DLL): $(LIBOBJ) $(LIBRESOBJS) $(CORE_LINK_DEP) $(LD) $(LDFLAGS) $(LTLINKOPTS) $(LTLIBPATHS) /DLL $(CORE_LINK_OPTS) /OUT:$@ $(LIBOBJ) $(LIBRESOBJS) $(LTLIBS) $(TLIBS) +# <> sqlite3.def: libsqlite3.lib echo EXPORTS > sqlite3.def dumpbin /all libsqlite3.lib \ | $(TCLSH_CMD) $(TOP)\tool\replace.tcl include "^\s+1 _?(sqlite3_.*)$$" \1 \ | sort >> sqlite3.def +# <> $(SQLITE3EXE): $(TOP)\src\shell.c $(SHELL_CORE_DEP) $(LIBRESOBJS) $(SHELL_CORE_SRC) $(SQLITE3H) $(LTLINK) $(SHELL_COMPILE_OPTS) $(READLINE_FLAGS) $(TOP)\src\shell.c $(SHELL_CORE_SRC) \ /link $(SQLITE3EXEPDB) $(LDFLAGS) $(LTLINKOPTS) $(SHELL_LINK_OPTS) $(LTLIBPATHS) $(LIBRESOBJS) $(LIBREADLINE) $(LTLIBS) $(TLIBS) +# <> sqldiff.exe: $(TOP)\tool\sqldiff.c $(SQLITE3C) $(SQLITE3H) $(LTLINK) $(NO_WARN) $(TOP)\tool\sqldiff.c $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS) @@ -1406,12 +1435,14 @@ sqlite3.c: .target_source sqlite3ext.h $(TOP)\tool\mksqlite3c.tcl sqlite3-all.c: sqlite3.c $(TOP)\tool\split-sqlite3c.tcl $(TCLSH_CMD) $(TOP)\tool\split-sqlite3c.tcl +# <> # Rule to build the amalgamation # sqlite3.lo: $(SQLITE3C) $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(SQLITE3C) +# <> # Rules to build the LEMON compiler generator # lempar.c: $(TOP)\tool\lempar.c @@ -1432,10 +1463,12 @@ parse.lo: parse.c $(HDR) opcodes.lo: opcodes.c $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c opcodes.c +# <> # Rule to build the Win32 resources object file. # !IF $(USE_RC)!=0 +# <> $(LIBRESOBJS): $(TOP)\src\sqlite3.rc $(SQLITE3H) echo #ifndef SQLITE_RESOURCE_VERSION > sqlite3rc.h for /F %%V in ('type "$(TOP)\VERSION"') do ( \ @@ -1444,8 +1477,10 @@ $(LIBRESOBJS): $(TOP)\src\sqlite3.rc $(SQLITE3H) ) echo #endif >> sqlite3rc.h $(LTRCOMPILE) -fo $(LIBRESOBJS) $(TOP)\src\sqlite3.rc +# <> !ENDIF +# <> # Rules to build individual *.lo files from files in the src directory. # alter.lo: $(TOP)\src\alter.c $(HDR) @@ -1945,10 +1980,12 @@ speedtest1.exe: $(TOP)\test\speedtest1.c $(SQLITE3C) $(SQLITE3H) rbu.exe: $(TOP)\ext\rbu\rbu.c $(TOP)\ext\rbu\sqlite3rbu.c $(SQLITE3C) $(SQLITE3H) $(LTLINK) $(NO_WARN) -DSQLITE_ENABLE_RBU -Fe$@ \ $(TOP)\ext\rbu\rbu.c $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS) +# <> clean: del /Q *.exp *.lo *.ilk *.lib *.obj *.ncb *.pdb *.sdf *.suo 2>NUL del /Q *.bsc *.cod *.da *.bb *.bbg *.vc gmon.out 2>NUL +# <> del /Q $(SQLITE3C) $(SQLITE3H) opcodes.c opcodes.h 2>NUL del /Q lemon.* lempar.c parse.* 2>NUL del /Q mkkeywordhash.* keywordhash.h 2>NUL @@ -1974,3 +2011,4 @@ clean: del /Q sqlite-*-output.vsix 2>NUL del /Q fuzzershell.exe fuzzcheck.exe sqldiff.exe 2>NUL del /Q fts5.* fts5parse.* 2>NUL +# <> diff --git a/manifest b/manifest index 61cf5d66ed..12db615b93 100644 --- a/manifest +++ b/manifest @@ -1,8 +1,9 @@ -C More\swork\son\sthe\sMSVC\sbuild. -D 2016-01-23T00:07:51.151 +C Add\stooling\sto\screate\san\sMSVC\sMakefile\scapable\sof\sbuilding\sthe\score\slibrary\sand\sshell\sonly,\susing\sa\spre-built\samalgamation. +D 2016-01-23T07:53:04.796 F Makefile.in 027c1603f255390c43a426671055a31c0a65fdb4 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 -F Makefile.msc 1708a78eda223b6daa302b140037fcc214a779f9 +F Makefile.min.msc c805e4a474fc7610d4f0cd0b6a9f56334a14c6ad +F Makefile.msc 6fca5455aaecbd14479f33f091aa19df2d3d2969 F README.md 8ecc12493ff9f820cdea6520a9016001cb2e59b7 F VERSION 866588d1edf0ccb5b0d33896974338f97564f719 F aclocal.m4 a5c22d164aff7ed549d53a90fa56d56955281f50 @@ -1378,6 +1379,7 @@ F tool/loadfts.c c3c64e4d5e90e8ba41159232c2189dba4be7b862 F tool/logest.c eef612f8adf4d0993dafed0416064cf50d5d33c6 F tool/mkautoconfamal.sh 5a5441280b509d2bb3bdc71bfb63781b0d570373 F tool/mkkeywordhash.c 06ec0b78bd4fa68c12d90ef2bdfe76b039133ff8 +F tool/mkmsvcmin.tcl 859737ff14668827738a3f7ca17ba643a88bcecc F tool/mkopcodec.tcl edde8adc42621b5e598127f8cdc6d52cfe21f52b F tool/mkopcodeh.tcl e04177031532b7aa9379ded50e820231ac4abd6e F tool/mkopts.tcl 66ac10d240cc6e86abd37dc908d50382f84ff46e @@ -1419,7 +1421,10 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P a1c8116ced62d81f3f5ca26bbe0877e829d4cc56 -R b34246fa017fc0ae2e7bf7cb484e3eeb +P a79c46bc61a35edbaf6112c26e8052314b0eb16a +R bd00cfb25453f633191b5f1755909575 +T *branch * msvcMakeMin +T *sym-msvcMakeMin * +T -sym-trunk * U mistachkin -Z ba075ff448ff99fa520b3503324fe6e9 +Z 18f99743dd26f3a3f31830457ad1b4ef diff --git a/manifest.uuid b/manifest.uuid index d1ea2b33a4..06bbe8845c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -a79c46bc61a35edbaf6112c26e8052314b0eb16a \ No newline at end of file +c46f1a13cb00264d1164399059250884c7be4ea0 \ No newline at end of file diff --git a/tool/mkmsvcmin.tcl b/tool/mkmsvcmin.tcl new file mode 100644 index 0000000000..56c9d52811 --- /dev/null +++ b/tool/mkmsvcmin.tcl @@ -0,0 +1,88 @@ +#!/usr/bin/tcl +# +# Removes and/or replaces specially marked sections from the Makefile +# for MSVC, writing the resulting output to another (different) file. +# In addition, some other strings are also removed and/or replaced if +# they are present in the Makefile. +# +set fromFileName [lindex $argv 0] + +if {![file exists $fromFileName]} then { + error "input file \"$fromFileName\" does not exist" +} + +set toFileName [lindex $argv 1] + +if {[file exists $toFileName]} then { + error "output file \"$toFileName\" already exists" +} + +proc readFile { fileName } { + set file_id [open $fileName RDONLY] + fconfigure $file_id -encoding binary -translation binary + set result [read $file_id] + close $file_id + return $result +} + +proc writeFile { fileName data } { + set file_id [open $fileName {WRONLY CREAT TRUNC}] + fconfigure $file_id -encoding binary -translation binary + puts -nonewline $file_id $data + close $file_id + return "" +} + +proc escapeSubSpec { data } { + regsub -all -- {&} $data {\\\&} data + regsub -all -- {\\(\d+)} $data {\\\\\1} data + return $data +} + +proc substVars { data } { + return [uplevel 1 [list subst -nocommands -nobackslashes $data]] +} + +# +# NOTE: This block is used to replace the section marked <> in +# the Makefile, if it exists. +# +set blocks(1) [string trimleft [string map [list \\\\ \\] { +_HASHCHAR=^# +!IF ![echo !IFNDEF VERSION > rcver.vc] && \\ + ![for /F "delims=" %V in ('type "$(SQLITE3H)" ^| find "$(_HASHCHAR)define SQLITE_VERSION "') do (echo VERSION = ^^%V >> rcver.vc)] && \\ + ![echo !ENDIF >> rcver.vc] +!INCLUDE rcver.vc +!ENDIF + +RESOURCE_VERSION = $(VERSION:^#=) +RESOURCE_VERSION = $(RESOURCE_VERSION:define=) +RESOURCE_VERSION = $(RESOURCE_VERSION:SQLITE_VERSION=) +RESOURCE_VERSION = $(RESOURCE_VERSION:"=) +RESOURCE_VERSION = $(RESOURCE_VERSION:.=,) + +$(LIBRESOBJS): $(TOP)\sqlite3.rc rcver.vc $(SQLITE3H) + echo #ifndef SQLITE_RESOURCE_VERSION > sqlite3rc.h + echo #define SQLITE_RESOURCE_VERSION $(RESOURCE_VERSION) >> sqlite3rc.h + echo #endif >> sqlite3rc.h + $(LTRCOMPILE) -fo $(LIBRESOBJS) -DRC_VERONLY $(TOP)\sqlite3.rc +}]] + +set data [readFile $fromFileName] + +regsub -all -- {# <>\n.*?# <>\n} \ + $data "" data + +foreach i [lsort [array names blocks]] { + regsub -all -- [substVars \ + {# <>\n.*?# <>\n}] \ + $data [escapeSubSpec $blocks($i)] data +} + +set data [string map [list " -I\$(TOP)\\src" ""] $data] +set data [string map [list " /DEF:sqlite3.def" ""] $data] +set data [string map [list " sqlite3.def" ""] $data] +set data [string map [list " libtclsqlite3.lib" ""] $data] +set data [string map [list "\$(TOP)\\src\\" "\$(TOP)\\"] $data] + +writeFile $toFileName $data From c615097d3d9140f9ea2d23faf2dd4ed58475a6ad Mon Sep 17 00:00:00 2001 From: drh Date: Sat, 23 Jan 2016 14:05:27 +0000 Subject: [PATCH 17/75] Remove an assert() that can be false if compiled with SQLITE_USE_ALLOCA. FossilOrigin-Name: f0a551edf87ef061deae34d88b02c3b484ae9adc --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/prepare.c | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 61cf5d66ed..7b54ea0ab0 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C More\swork\son\sthe\sMSVC\sbuild. -D 2016-01-23T00:07:51.151 +C Remove\san\sassert()\sthat\scan\sbe\sfalse\sif\scompiled\swith\sSQLITE_USE_ALLOCA. +D 2016-01-23T14:05:27.109 F Makefile.in 027c1603f255390c43a426671055a31c0a65fdb4 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 1708a78eda223b6daa302b140037fcc214a779f9 @@ -340,7 +340,7 @@ F src/pcache.h 4d0ccaad264d360981ec5e6a2b596d6e85242545 F src/pcache1.c 72f644dc9e1468c72922eff5904048427b817051 F src/pragma.c ea290193369faa0a26ae2f924e7b86289b4a7987 F src/pragma.h 64c78a648751b9f4f297276c4eb7507b14b4628c -F src/prepare.c 74855ddbdfad6a1c4a4d5c4b0913ebb01174ba19 +F src/prepare.c 8ca7237428f372a04717d558555ea67ee1c5df93 F src/printf.c af589a27b7d40f6f4f704e9eea99f02f18ad6d32 F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c 9f7ce3a3c087afb7597b7c916c99126ff3f12f0c @@ -1419,7 +1419,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P a1c8116ced62d81f3f5ca26bbe0877e829d4cc56 -R b34246fa017fc0ae2e7bf7cb484e3eeb -U mistachkin -Z ba075ff448ff99fa520b3503324fe6e9 +P a79c46bc61a35edbaf6112c26e8052314b0eb16a +R 78c84a447f1adb3672b2aa032cc33ea6 +U drh +Z 2d3baf83036e6553ecd28fa4c13c4bc2 diff --git a/manifest.uuid b/manifest.uuid index d1ea2b33a4..d11f7b73ef 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -a79c46bc61a35edbaf6112c26e8052314b0eb16a \ No newline at end of file +f0a551edf87ef061deae34d88b02c3b484ae9adc \ No newline at end of file diff --git a/src/prepare.c b/src/prepare.c index acc70dd2d5..acd50fcaf7 100644 --- a/src/prepare.c +++ b/src/prepare.c @@ -525,7 +525,7 @@ static int sqlite3Prepare( } pParse->pReprepare = pReprepare; assert( ppStmt && *ppStmt==0 ); - assert( !db->mallocFailed ); + /* assert( !db->mallocFailed ); // not true with SQLITE_USE_ALLOCA */ assert( sqlite3_mutex_held(db->mutex) ); /* Check to verify that it is possible to get a read lock on all From 8498f387be1e02e4053c4bf5dcf4ded8a7103484 Mon Sep 17 00:00:00 2001 From: dan Date: Sat, 23 Jan 2016 14:45:36 +0000 Subject: [PATCH 18/75] Fix a problem involving detail=col and column filters. FossilOrigin-Name: 7558a0ad2276e91f2faced8ea405d9fdb4fa0c6e --- ext/fts5/fts5_index.c | 14 ++++++++++---- manifest | 15 ++++++--------- manifest.uuid | 2 +- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/ext/fts5/fts5_index.c b/ext/fts5/fts5_index.c index 2ea57b04f9..8323842dc6 100644 --- a/ext/fts5/fts5_index.c +++ b/ext/fts5/fts5_index.c @@ -5013,21 +5013,26 @@ static void fts5IterSetOutputs_Col(Fts5Iter *pIter, Fts5SegIter *pSeg){ assert( pIter->pIndex->pConfig->eDetail==FTS5_DETAIL_COLUMNS ); assert( pColset ); - if( pSeg->iLeafOffset+pSeg->nPos<=pSeg->pLeaf->szLeaf && 0 ){ + if( pSeg->iLeafOffset+pSeg->nPos<=pSeg->pLeaf->szLeaf ){ /* All data is stored on the current page. Populate the output ** variables to point into the body of the page object. */ Fts5PoslistWriter writer = {0}; const u8 *a = &pSeg->pLeaf->p[pSeg->iLeafOffset]; int n = pSeg->nPos; int iCol = 0; + int iCVal = pColset->aiCol[0]; i64 iPos = 0; int iOff = 0; fts5BufferZero(&pIter->poslist); while( 0==sqlite3Fts5PoslistNext64(a, n, &iOff, &iPos) ){ - if( iPos==pColset->aiCol[iCol] ){ - sqlite3Fts5PoslistWriterAppend(&pIter->poslist, &writer, iPos); - if( ++iCol>=pColset->nCol ) break; + while( iPos>=iCVal ){ + if( iPos==iCVal ){ + sqlite3Fts5PoslistWriterAppend(&pIter->poslist, &writer, iPos); + } + if( ++iCol>=pColset->nCol ) goto setoutputs_col_out; + assert( pColset->aiCol[iCol]>iCVal ); + iCVal = pColset->aiCol[iCol]; } } @@ -5039,6 +5044,7 @@ static void fts5IterSetOutputs_Col(Fts5Iter *pIter, Fts5SegIter *pSeg){ fts5SegiterPoslist(pIter->pIndex, pSeg, pColset, &pIter->poslist); } +setoutputs_col_out: pIter->base.pData = pIter->poslist.p; pIter->base.nData = pIter->poslist.n; } diff --git a/manifest b/manifest index 99a9a8b139..0168850d28 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Experimental\sperformance\senhancements\sfor\sfts5. -D 2016-01-22T19:48:34.825 +C Fix\sa\sproblem\sinvolving\sdetail=col\sand\scolumn\sfilters. +D 2016-01-23T14:45:36.706 F Makefile.in 027c1603f255390c43a426671055a31c0a65fdb4 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc d2b93511a969c0c8fcf52aeb5e426571e8c610d2 @@ -103,7 +103,7 @@ F ext/fts5/fts5_buffer.c 7d3f6f01f8fdc45204e6a33925ef8478a67d28dd F ext/fts5/fts5_config.c 0c384ebdd23fd055e2e50a93277b8d59da538238 F ext/fts5/fts5_expr.c 48b9131b74c8d3b8c12ba0f7995e2d60eecce9f2 F ext/fts5/fts5_hash.c 1b113977296cf4212c6ec667d5e3f2bd18036955 -F ext/fts5/fts5_index.c 19062d1f40ba6d88d786a986d1c20f9d741799d0 +F ext/fts5/fts5_index.c bd5476edd4d6ef37fc389794a78f47f29f521634 F ext/fts5/fts5_main.c 833db0a3df10ab26e0221a9baa40cf871c450df3 F ext/fts5/fts5_storage.c fb2eaec3aa954b680d43096dc539f8270bd6390e F ext/fts5/fts5_tcl.c f8731e0508299bd43f1a2eff7dbeaac870768966 @@ -1419,10 +1419,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 7323175337b7ba85ac932ca892b28860f6a5b688 -R bc65520844365f59e43048a22901b688 -T *branch * fts5-perf -T *sym-fts5-perf * -T -sym-trunk * +P b5a57b812fd6a734cf2a342bf0b730ae18912d73 +R 20bdd3799e5ba562672d44f9df7f8c2a U dan -Z 20f25a74d681d80924173ee060583d9e +Z fc938fd5a5718db0c9c10bacac344b80 diff --git a/manifest.uuid b/manifest.uuid index fc3a1227d6..7a9fdf27eb 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -b5a57b812fd6a734cf2a342bf0b730ae18912d73 \ No newline at end of file +7558a0ad2276e91f2faced8ea405d9fdb4fa0c6e \ No newline at end of file From c66d03f1e13e8f1746e063d642480cd951d4ca44 Mon Sep 17 00:00:00 2001 From: dan Date: Sat, 23 Jan 2016 15:57:06 +0000 Subject: [PATCH 19/75] Fix some signed/unsigned comparison compiler warnings in fts5. FossilOrigin-Name: 3be336aa893f9eb0837d7d66c83bab1489792b9a --- ext/fts5/fts5Int.h | 6 +++--- ext/fts5/fts5_buffer.c | 2 +- manifest | 16 ++++++++-------- manifest.uuid | 2 +- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/ext/fts5/fts5Int.h b/ext/fts5/fts5Int.h index b2f0d6c34e..5d7facc948 100644 --- a/ext/fts5/fts5Int.h +++ b/ext/fts5/fts5Int.h @@ -225,8 +225,8 @@ int sqlite3Fts5ConfigParseRank(const char*, char**, char**); typedef struct Fts5Buffer Fts5Buffer; struct Fts5Buffer { u8 *p; - u32 n; - u32 nSpace; + int n; + int nSpace; }; int sqlite3Fts5BufferSize(int*, Fts5Buffer*, u32); @@ -247,7 +247,7 @@ char *sqlite3Fts5Mprintf(int *pRc, const char *zFmt, ...); #define fts5BufferSet(a,b,c,d) sqlite3Fts5BufferSet(a,b,c,d) #define fts5BufferGrow(pRc,pBuf,nn) ( \ - (pBuf)->n + (nn) <= (pBuf)->nSpace ? 0 : \ + (u32)((pBuf)->n) + (u32)(nn) <= (u32)((pBuf)->nSpace) ? 0 : \ sqlite3Fts5BufferSize((pRc),(pBuf),(nn)+(pBuf)->n) \ ) diff --git a/ext/fts5/fts5_buffer.c b/ext/fts5/fts5_buffer.c index 94591188d3..9bd4fddb82 100644 --- a/ext/fts5/fts5_buffer.c +++ b/ext/fts5/fts5_buffer.c @@ -363,7 +363,7 @@ int sqlite3Fts5TermsetAdd( void sqlite3Fts5TermsetFree(Fts5Termset *p){ if( p ){ - int i; + u32 i; for(i=0; iapHash); i++){ Fts5TermsetEntry *pEntry = p->apHash[i]; while( pEntry ){ diff --git a/manifest b/manifest index 7b54ea0ab0..9f8ab447a0 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Remove\san\sassert()\sthat\scan\sbe\sfalse\sif\scompiled\swith\sSQLITE_USE_ALLOCA. -D 2016-01-23T14:05:27.109 +C Fix\ssome\ssigned/unsigned\scomparison\scompiler\swarnings\sin\sfts5. +D 2016-01-23T15:57:06.186 F Makefile.in 027c1603f255390c43a426671055a31c0a65fdb4 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 1708a78eda223b6daa302b140037fcc214a779f9 @@ -97,9 +97,9 @@ F ext/fts3/unicode/mkunicode.tcl 95cf7ec186e48d4985e433ff8a1c89090a774252 F ext/fts3/unicode/parseunicode.tcl da577d1384810fb4e2b209bf3313074353193e95 F ext/fts5/extract_api_docs.tcl a36e54ec777172ddd3f9a88daf593b00848368e0 F ext/fts5/fts5.h ff9c2782e8ed890b0de2f697a8d63971939e70c7 -F ext/fts5/fts5Int.h 5599703af9c13512900a9f22fec39d48078d619d +F ext/fts5/fts5Int.h e4c7ca41a7841f180d78a24850757e0ffcb20f27 F ext/fts5/fts5_aux.c 2dafc3aee0c70d643140c77d8d70daffa51a9e9e -F ext/fts5/fts5_buffer.c 7d3f6f01f8fdc45204e6a33925ef8478a67d28dd +F ext/fts5/fts5_buffer.c 0b8e1f84fec3ec01f7e17f8d4f17c46856b31e10 F ext/fts5/fts5_config.c 0c384ebdd23fd055e2e50a93277b8d59da538238 F ext/fts5/fts5_expr.c 4ab4504c54bbe24689c83411d8588f4ec99136e9 F ext/fts5/fts5_hash.c 1b113977296cf4212c6ec667d5e3f2bd18036955 @@ -1419,7 +1419,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P a79c46bc61a35edbaf6112c26e8052314b0eb16a -R 78c84a447f1adb3672b2aa032cc33ea6 -U drh -Z 2d3baf83036e6553ecd28fa4c13c4bc2 +P f0a551edf87ef061deae34d88b02c3b484ae9adc +R 962289f1674397e1ac71fafb409f527f +U dan +Z 5f630552e065d9e5a5f7f6919a0222d3 diff --git a/manifest.uuid b/manifest.uuid index d11f7b73ef..e3c087f5fd 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -f0a551edf87ef061deae34d88b02c3b484ae9adc \ No newline at end of file +3be336aa893f9eb0837d7d66c83bab1489792b9a \ No newline at end of file From c6aab321441e0ce3eefa2a2ace0864cbca116231 Mon Sep 17 00:00:00 2001 From: drh Date: Sat, 23 Jan 2016 18:24:52 +0000 Subject: [PATCH 20/75] Changes to spellfix to try to get it to use stack space instead of heap space in cases where that makes sense. FossilOrigin-Name: dfcebc7393a3a780ee9c4f257723c303bb633064 --- ext/misc/spellfix.c | 17 +++++++++++++---- manifest | 14 +++++++------- manifest.uuid | 2 +- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/ext/misc/spellfix.c b/ext/misc/spellfix.c index c0da6b339b..d17a05a3cd 100644 --- a/ext/misc/spellfix.c +++ b/ext/misc/spellfix.c @@ -365,8 +365,8 @@ static int editdist1(const char *zA, const char *zB, int *pnMatch){ int *m; /* The cost matrix */ char *cx; /* Corresponding character values */ int *toFree = 0; /* Malloced space */ - int mStack[60+15]; /* Stack space to use if not too much is needed */ int nMatch = 0; + int mStack[60+15]; /* Stack space to use if not too much is needed */ /* Early out if either input is NULL */ if( zA==0 || zB==0 ) return -1; @@ -899,15 +899,24 @@ static int editDist3Core( EditDist3FromString f = *pFrom; EditDist3To *a2; unsigned int *m; + unsigned int *pToFree; int szRow; EditDist3Cost *p; int res; + sqlite3_uint64 nByte; + unsigned int stackSpace[16*1024]; /* allocate the Wagner matrix and the aTo[] array for the TO string */ n = (f.n+1)*(n2+1); n = (n+1)&~1; - m = sqlite3_malloc( n*sizeof(m[0]) + sizeof(a2[0])*n2 ); - if( m==0 ) return -1; /* Out of memory */ + nByte = n*sizeof(m[0]) + sizeof(a2[0])*n2; + if( nByte<=sizeof(stackSpace) ){ + m = stackSpace; + pToFree = 0; + }else{ + m = pToFree = sqlite3_malloc( nByte ); + if( m==0 ) return -1; /* Out of memory */ + } a2 = (EditDist3To*)&m[n]; memset(a2, 0, sizeof(a2[0])*n2); @@ -1029,7 +1038,7 @@ static int editDist3Core( editDist3Abort: for(i2=0; i2 Date: Sat, 23 Jan 2016 18:51:59 +0000 Subject: [PATCH 21/75] Fix an fts5 problem with using both xPhraseFirst() and xPhraseFirstColumn() within a single statement in detail=col mode. FossilOrigin-Name: 72d53699bf0dcdb9d2a22e229989d7435f061399 --- ext/fts5/fts5Int.h | 6 +-- ext/fts5/fts5_aux.c | 2 +- ext/fts5/fts5_buffer.c | 4 +- ext/fts5/fts5_expr.c | 79 +++++++++++---------------------- ext/fts5/fts5_index.c | 79 --------------------------------- ext/fts5/fts5_main.c | 4 +- ext/fts5/fts5_storage.c | 2 +- ext/fts5/fts5_tokenize.c | 2 +- ext/fts5/fts5_vocab.c | 3 +- ext/fts5/test/fts5_common.tcl | 3 +- ext/fts5/test/fts5synonym2.test | 37 ++++++++++++++- manifest | 32 ++++++------- manifest.uuid | 2 +- 13 files changed, 90 insertions(+), 165 deletions(-) diff --git a/ext/fts5/fts5Int.h b/ext/fts5/fts5Int.h index b8486dfdfb..48ab980921 100644 --- a/ext/fts5/fts5Int.h +++ b/ext/fts5/fts5Int.h @@ -29,7 +29,7 @@ typedef unsigned short u16; typedef sqlite3_int64 i64; typedef sqlite3_uint64 u64; -#define ArraySize(x) (sizeof(x) / sizeof(x[0])) +#define ArraySize(x) ((int)(sizeof(x) / sizeof(x[0]))) #define testcase(x) #define ALWAYS(x) 1 @@ -388,8 +388,6 @@ int sqlite3Fts5IterEof(Fts5IndexIter*); int sqlite3Fts5IterNext(Fts5IndexIter*); int sqlite3Fts5IterNextFrom(Fts5IndexIter*, i64 iMatch); i64 sqlite3Fts5IterRowid(Fts5IndexIter*); -int sqlite3Fts5IterPoslist(Fts5IndexIter*,Fts5Colset*, const u8**, int*, i64*); -int sqlite3Fts5IterPoslistBuffer(Fts5IndexIter *pIter, Fts5Buffer *pBuf); /* ** Close an iterator opened by sqlite3Fts5IndexQuery(). @@ -402,8 +400,6 @@ void sqlite3Fts5IterClose(Fts5IndexIter*); const char *sqlite3Fts5IterTerm(Fts5IndexIter*, int*); int sqlite3Fts5IterNextScan(Fts5IndexIter*); -int sqlite3Fts5IterCollist(Fts5IndexIter*, const u8 **, int*); - /* ** Insert or remove data to or from the index. Each time a document is diff --git a/ext/fts5/fts5_aux.c b/ext/fts5/fts5_aux.c index 011064d405..79bed1c8f7 100644 --- a/ext/fts5/fts5_aux.c +++ b/ext/fts5/fts5_aux.c @@ -544,7 +544,7 @@ int sqlite3Fts5AuxInit(fts5_api *pApi){ int rc = SQLITE_OK; /* Return code */ int i; /* To iterate through builtin functions */ - for(i=0; rc==SQLITE_OK && i<(int)ArraySize(aBuiltin); i++){ + for(i=0; rc==SQLITE_OK && ixCreateFunction(pApi, aBuiltin[i].zFunc, aBuiltin[i].pUserData, diff --git a/ext/fts5/fts5_buffer.c b/ext/fts5/fts5_buffer.c index 9bd4fddb82..d69adf7d24 100644 --- a/ext/fts5/fts5_buffer.c +++ b/ext/fts5/fts5_buffer.c @@ -322,7 +322,7 @@ int sqlite3Fts5TermsetAdd( *pbPresent = 0; if( p ){ int i; - int hash = 13; + u32 hash = 13; Fts5TermsetEntry *pEntry; /* Calculate a hash value for this term. This is the same hash checksum @@ -339,7 +339,7 @@ int sqlite3Fts5TermsetAdd( if( pEntry->iIdx==iIdx && pEntry->nTerm==nTerm && memcmp(pEntry->pTerm, pTerm, nTerm)==0 - ){ + ){ *pbPresent = 1; break; } diff --git a/ext/fts5/fts5_expr.c b/ext/fts5/fts5_expr.c index 290baf4e2c..3a1497f05d 100644 --- a/ext/fts5/fts5_expr.c +++ b/ext/fts5/fts5_expr.c @@ -306,7 +306,7 @@ static int fts5ExprSynonymList( int bCollist, Fts5Colset *pColset, i64 iRowid, - int *pbDel, /* OUT: Caller should sqlite3_free(*pa) */ + Fts5Buffer *pBuf, /* Use this buffer for space if required */ u8 **pa, int *pn ){ Fts5PoslistReader aStatic[4]; @@ -320,22 +320,7 @@ static int fts5ExprSynonymList( for(p=pTerm; p; p=p->pSynonym){ Fts5IndexIter *pIter = p->pIter; if( sqlite3Fts5IterEof(pIter)==0 && sqlite3Fts5IterRowid(pIter)==iRowid ){ - const u8 *a; - int n; - - if( 0 && bCollist ){ - rc = sqlite3Fts5IterCollist(pIter, &a, &n); - }else{ - i64 dummy; -#if 0 - rc = sqlite3Fts5IterPoslist(pIter, pColset, &a, &n, &dummy); -#endif - a = pIter->pData; - n = pIter->nData; - } - - if( rc!=SQLITE_OK ) goto synonym_poslist_out; - if( n==0 ) continue; + if( pIter->nData==0 ) continue; if( nIter==nAlloc ){ int nByte = sizeof(Fts5PoslistReader) * nAlloc * 2; Fts5PoslistReader *aNew = (Fts5PoslistReader*)sqlite3_malloc(nByte); @@ -348,20 +333,19 @@ static int fts5ExprSynonymList( if( aIter!=aStatic ) sqlite3_free(aIter); aIter = aNew; } - sqlite3Fts5PoslistReaderInit(a, n, &aIter[nIter]); + sqlite3Fts5PoslistReaderInit(pIter->pData, pIter->nData, &aIter[nIter]); assert( aIter[nIter].bEof==0 ); nIter++; } } - assert( *pbDel==0 ); if( nIter==1 ){ *pa = (u8*)aIter[0].a; *pn = aIter[0].n; }else{ Fts5PoslistWriter writer = {0}; - Fts5Buffer buf = {0,0,0}; i64 iPrev = -1; + fts5BufferZero(pBuf); while( 1 ){ int i; i64 iMin = FTS5_LARGEST_INT64; @@ -376,15 +360,12 @@ static int fts5ExprSynonymList( } } if( iMin==FTS5_LARGEST_INT64 || rc!=SQLITE_OK ) break; - rc = sqlite3Fts5PoslistWriterAppend(&buf, &writer, iMin); + rc = sqlite3Fts5PoslistWriterAppend(pBuf, &writer, iMin); iPrev = iMin; } - if( rc ){ - sqlite3_free(buf.p); - }else{ - *pa = buf.p; - *pn = buf.n; - *pbDel = 1; + if( rc==SQLITE_OK ){ + *pa = pBuf->p; + *pn = pBuf->n; } } @@ -421,7 +402,7 @@ static int fts5ExprPhraseIsMatch( /* If the aStatic[] array is not large enough, allocate a large array ** using sqlite3_malloc(). This approach could be improved upon. */ - if( pPhrase->nTerm>(int)ArraySize(aStatic) ){ + if( pPhrase->nTerm>ArraySize(aStatic) ){ int nByte = sizeof(Fts5PoslistReader) * pPhrase->nTerm; aIter = (Fts5PoslistReader*)sqlite3_malloc(nByte); if( !aIter ) return SQLITE_NOMEM; @@ -431,23 +412,23 @@ static int fts5ExprPhraseIsMatch( /* Initialize a term iterator for each term in the phrase */ for(i=0; inTerm; i++){ Fts5ExprTerm *pTerm = &pPhrase->aTerm[i]; - i64 dummy; int n = 0; int bFlag = 0; - const u8 *a = 0; + u8 *a = 0; if( pTerm->pSynonym ){ + Fts5Buffer buf = {0, 0, 0}; rc = fts5ExprSynonymList( - pTerm, 0, pColset, pNode->iRowid, &bFlag, (u8**)&a, &n + pTerm, 0, pColset, pNode->iRowid, &buf, &a, &n ); + if( rc ){ + sqlite3_free(a); + goto ismatch_out; + } + if( a==buf.p ) bFlag = 1; }else{ - Fts5IndexIter *pIter = pTerm->pIter; -#if 0 - rc = sqlite3Fts5IterPoslist(pTerm->pIter, pColset, &a, &n, &dummy); -#endif - a = pIter->pData; - n = pIter->nData; + a = (u8*)pTerm->pIter->pData; + n = pTerm->pIter->nData; } - if( rc!=SQLITE_OK ) goto ismatch_out; sqlite3Fts5PoslistReaderInit(a, n, &aIter[i]); aIter[i].bFlag = (u8)bFlag; if( aIter[i].bEof ) goto ismatch_out; @@ -562,7 +543,7 @@ static int fts5ExprNearIsMatch(int *pRc, Fts5ExprNearset *pNear){ /* If the aStatic[] array is not large enough, allocate a large array ** using sqlite3_malloc(). This approach could be improved upon. */ - if( pNear->nPhrase>(int)ArraySize(aStatic) ){ + if( pNear->nPhrase>ArraySize(aStatic) ){ int nByte = sizeof(Fts5NearTrimmer) * pNear->nPhrase; a = (Fts5NearTrimmer*)sqlite3Fts5MallocZero(&rc, nByte); }else{ @@ -1387,10 +1368,10 @@ static void fts5ExprPhraseFree(Fts5ExprPhrase *pPhrase){ Fts5ExprTerm *pTerm = &pPhrase->aTerm[i]; sqlite3_free(pTerm->zTerm); sqlite3Fts5IterClose(pTerm->pIter); - for(pSyn=pTerm->pSynonym; pSyn; pSyn=pNext){ pNext = pSyn->pSynonym; sqlite3Fts5IterClose(pSyn->pIter); + fts5BufferFree((Fts5Buffer*)&pSyn[1]); sqlite3_free(pSyn); } } @@ -1478,13 +1459,13 @@ static int fts5ParseTokenize( assert( pPhrase==0 || pPhrase->nTerm>0 ); if( pPhrase && (tflags & FTS5_TOKEN_COLOCATED) ){ Fts5ExprTerm *pSyn; - int nByte = sizeof(Fts5ExprTerm) + nToken+1; + int nByte = sizeof(Fts5ExprTerm) + sizeof(Fts5Buffer) + nToken+1; pSyn = (Fts5ExprTerm*)sqlite3_malloc(nByte); if( pSyn==0 ){ rc = SQLITE_NOMEM; }else{ memset(pSyn, 0, nByte); - pSyn->zTerm = (char*)&pSyn[1]; + pSyn->zTerm = ((char*)pSyn) + sizeof(Fts5ExprTerm) + sizeof(Fts5Buffer); memcpy(pSyn->zTerm, pToken, nToken); pSyn->pSynonym = pPhrase->aTerm[pPhrase->nTerm-1].pSynonym; pPhrase->aTerm[pPhrase->nTerm-1].pSynonym = pSyn; @@ -2263,7 +2244,7 @@ int sqlite3Fts5ExprInit(Fts5Global *pGlobal, sqlite3 *db){ int rc = SQLITE_OK; void *pCtx = (void*)pGlobal; - for(i=0; rc==SQLITE_OK && i<(int)ArraySize(aFunc); i++){ + for(i=0; rc==SQLITE_OK && iz, -1, SQLITE_UTF8, pCtx, p->x, 0, 0); } @@ -2509,18 +2490,10 @@ int sqlite3Fts5ExprPhraseCollist( ){ Fts5ExprTerm *pTerm = &pPhrase->aTerm[0]; if( pTerm->pSynonym ){ - int bDel = 0; - u8 *a; + Fts5Buffer *pBuf = (Fts5Buffer*)&pTerm->pSynonym[1]; rc = fts5ExprSynonymList( - pTerm, 1, 0, pNode->iRowid, &bDel, &a, pnCollist + pTerm, 1, 0, pNode->iRowid, pBuf, (u8**)ppCollist, pnCollist ); - if( bDel ){ - sqlite3Fts5BufferSet(&rc, &pPhrase->poslist, *pnCollist, a); - *ppCollist = pPhrase->poslist.p; - sqlite3_free(a); - }else{ - *ppCollist = a; - } }else{ *ppCollist = pPhrase->aTerm[0].pIter->pData; *pnCollist = pPhrase->aTerm[0].pIter->nData; diff --git a/ext/fts5/fts5_index.c b/ext/fts5/fts5_index.c index 8323842dc6..e147199ef8 100644 --- a/ext/fts5/fts5_index.c +++ b/ext/fts5/fts5_index.c @@ -5249,85 +5249,6 @@ const char *sqlite3Fts5IterTerm(Fts5IndexIter *pIndexIter, int *pn){ return &z[1]; } - -/* -** Return a pointer to a buffer containing a copy of the position list for -** the current entry. Output variable *pn is set to the size of the buffer -** in bytes before returning. -** -** The returned position list does not include the "number of bytes" varint -** field that starts the position list on disk. -*/ -int sqlite3Fts5IterPoslist( - Fts5IndexIter *pIndexIter, - Fts5Colset *pColset, /* Column filter (or NULL) */ - const u8 **pp, /* OUT: Pointer to position-list data */ - int *pn, /* OUT: Size of position-list in bytes */ - i64 *piRowid /* OUT: Current rowid */ -){ - Fts5Iter *pIter = (Fts5Iter*)pIndexIter; - Fts5SegIter *pSeg = &pIter->aSeg[ pIter->aFirst[1].iFirst ]; - int eDetail = pIter->pIndex->pConfig->eDetail; - - assert( pIter->pIndex->rc==SQLITE_OK ); - *piRowid = pSeg->iRowid; - if( eDetail==FTS5_DETAIL_NONE ){ - *pn = pSeg->nPos; - }else - if( eDetail==FTS5_DETAIL_FULL - && pSeg->iLeafOffset+pSeg->nPos<=pSeg->pLeaf->szLeaf - ){ - u8 *pPos = &pSeg->pLeaf->p[pSeg->iLeafOffset]; - if( pColset==0 || pIter->bFiltered ){ - *pn = pSeg->nPos; - *pp = pPos; - }else if( pColset->nCol==1 ){ - *pp = pPos; - *pn = fts5IndexExtractCol(pp, pSeg->nPos, pColset->aiCol[0]); - }else{ - fts5BufferZero(&pIter->poslist); - fts5IndexExtractColset(pColset, pPos, pSeg->nPos, &pIter->poslist); - *pp = pIter->poslist.p; - *pn = pIter->poslist.n; - } - }else{ - fts5BufferZero(&pIter->poslist); - fts5SegiterPoslist(pIter->pIndex, pSeg, pColset, &pIter->poslist); - if( eDetail==FTS5_DETAIL_FULL ){ - *pp = pIter->poslist.p; - } - *pn = pIter->poslist.n; - } - return fts5IndexReturn(pIter->pIndex); -} - -int sqlite3Fts5IterCollist( - Fts5IndexIter *pIndexIter, - const u8 **pp, /* OUT: Pointer to position-list data */ - int *pn /* OUT: Size of position-list in bytes */ -){ - Fts5Iter *pIter = (Fts5Iter*)pIndexIter; - assert( pIter->pIndex->pConfig->eDetail==FTS5_DETAIL_COLUMNS ); - *pp = pIter->poslist.p; - *pn = pIter->poslist.n; - return SQLITE_OK; -} - -/* -** This function is similar to sqlite3Fts5IterPoslist(), except that it -** copies the position list into the buffer supplied as the second -** argument. -*/ -int sqlite3Fts5IterPoslistBuffer(Fts5IndexIter *pIndexIter, Fts5Buffer *pBuf){ - Fts5Iter *pIter = (Fts5Iter*)pIndexIter; - Fts5Index *p = pIter->pIndex; - Fts5SegIter *pSeg = &pIter->aSeg[ pIter->aFirst[1].iFirst ]; - assert( p->rc==SQLITE_OK ); - fts5BufferZero(pBuf); - fts5SegiterPoslist(p, pSeg, 0, pBuf); - return fts5IndexReturn(p); -} - /* ** Close an iterator opened by an earlier call to sqlite3Fts5IndexQuery(). */ diff --git a/ext/fts5/fts5_main.c b/ext/fts5/fts5_main.c index 7447f9b5e1..ec045da6bf 100644 --- a/ext/fts5/fts5_main.c +++ b/ext/fts5/fts5_main.c @@ -538,7 +538,7 @@ static int fts5BestIndexMethod(sqlite3_vtab *pVTab, sqlite3_index_info *pInfo){ for(i=0; inConstraint; i++){ struct sqlite3_index_constraint *p = &pInfo->aConstraint[i]; int j; - for(j=0; j<(int)ArraySize(aConstraint); j++){ + for(j=0; jiColumn==aColMap[pC->iCol] && p->op & pC->op ){ if( p->usable ){ @@ -585,7 +585,7 @@ static int fts5BestIndexMethod(sqlite3_vtab *pVTab, sqlite3_index_info *pInfo){ /* Assign argvIndex values to each constraint in use. */ iNext = 1; - for(i=0; i<(int)ArraySize(aConstraint); i++){ + for(i=0; iiConsIndex>=0 ){ pInfo->aConstraintUsage[pC->iConsIndex].argvIndex = iNext++; diff --git a/ext/fts5/fts5_storage.c b/ext/fts5/fts5_storage.c index 56383619d1..da9524dea3 100644 --- a/ext/fts5/fts5_storage.c +++ b/ext/fts5/fts5_storage.c @@ -338,7 +338,7 @@ int sqlite3Fts5StorageClose(Fts5Storage *p){ int i; /* Finalize all SQL statements */ - for(i=0; i<(int)ArraySize(p->aStmt); i++){ + for(i=0; iaStmt); i++){ sqlite3_finalize(p->aStmt[i]); } diff --git a/ext/fts5/fts5_tokenize.c b/ext/fts5/fts5_tokenize.c index e60183c095..790adaae47 100644 --- a/ext/fts5/fts5_tokenize.c +++ b/ext/fts5/fts5_tokenize.c @@ -1220,7 +1220,7 @@ int sqlite3Fts5TokenizerInit(fts5_api *pApi){ int rc = SQLITE_OK; /* Return code */ int i; /* To iterate through builtin functions */ - for(i=0; rc==SQLITE_OK && i<(int)ArraySize(aBuiltin); i++){ + for(i=0; rc==SQLITE_OK && ixCreateTokenizer(pApi, aBuiltin[i].zName, (void*)pApi, diff --git a/ext/fts5/fts5_vocab.c b/ext/fts5/fts5_vocab.c index 17aa5816c4..b17e8974fb 100644 --- a/ext/fts5/fts5_vocab.c +++ b/ext/fts5/fts5_vocab.c @@ -184,7 +184,7 @@ static int fts5VocabInitVtab( rc = fts5VocabTableType(zType, pzErr, &eType); if( rc==SQLITE_OK ){ - assert( eType>=0 && eType=0 && eTypeeType==FTS5_VOCAB_COL || pTab->eType==FTS5_VOCAB_ROW ); while( rc==SQLITE_OK ){ - i64 dummy; const u8 *pPos; int nPos; /* Position list */ i64 iPos = 0; /* 64-bit position read from poslist */ int iOff = 0; /* Current offset within position list */ diff --git a/ext/fts5/test/fts5_common.tcl b/ext/fts5/test/fts5_common.tcl index e7c61af00c..cf688dcc0d 100644 --- a/ext/fts5/test/fts5_common.tcl +++ b/ext/fts5/test/fts5_common.tcl @@ -48,7 +48,8 @@ proc fts5_test_poslist2 {cmd} { } } - set res + #set res + sort_poslist $res } proc fts5_test_collist {cmd} { diff --git a/ext/fts5/test/fts5synonym2.test b/ext/fts5/test/fts5synonym2.test index dddaa17af8..7e92822c33 100644 --- a/ext/fts5/test/fts5synonym2.test +++ b/ext/fts5/test/fts5synonym2.test @@ -27,6 +27,21 @@ foreach_detail_mode $testprefix { fts5_tclnum_register db fts5_aux_test_functions db +proc fts5_test_bothlist {cmd} { + + for {set i 0} {$i < [$cmd xPhraseCount]} {incr i} { + set bFirst 1 + $cmd xPhraseColumnForeach $i c { + lappend CL $i.$c + if {$bFirst} { $cmd xPhraseForeach $i c o { lappend PL $i.$c.$o } } + set bFirst 0 + } + } + + list [sort_poslist $PL] $CL +} +sqlite3_fts5_create_function db fts5_test_bothlist fts5_test_bothlist + proc fts5_rowid {cmd} { expr [$cmd xColumnText -1] } sqlite3_fts5_create_function db fts5_rowid fts5_rowid @@ -89,6 +104,8 @@ do_execsql_test 1.$tok.0.2 { } foreach {tn expr} { + 2.1 "one OR two OR three OR four" + 1.1 "one" 1.2 "two" 1.3 "three" 1.4 "four" 1.5 "v" 1.6 "vi" 1.7 "vii" 1.8 "viii" 1.9 "9" 1.10 "0" 1.11 "1" 1.12 "2" @@ -113,13 +130,31 @@ foreach {tn expr} { set res [fts5_query_data $expr ss ASC ::tclnum_syn] do_execsql_test 1.$tok.$tn.[llength $res].asc.1 { - SELECT rowid, fts5_test_poslist(ss), fts5_test_collist(ss) FROM ss($expr) + SELECT rowid, fts5_test_poslist2(ss), fts5_test_collist(ss) FROM ss($expr) } $res do_execsql_test 1.$tok.$tn.[llength $res].asc.2 { SELECT rowid, fts5_test_poslist(ss), fts5_test_collist(ss) FROM ss($expr) + } $res + + do_execsql_test 1.$tok.$tn.[llength $res].asc.2 { + SELECT rowid, fts5_test_poslist2(ss), fts5_test_collist(ss) FROM ss($expr) ORDER BY rank ASC } $res + + set res2 [list] + foreach {a b c} $res { lappend res2 $a $c $b } + do_execsql_test 1.$tok.$tn.[llength $res].asc.3 { + SELECT rowid, fts5_test_collist(ss), fts5_test_poslist2(ss) FROM ss($expr) + } $res2 + + set res3 [list] + foreach {a b c} $res { lappend res3 $a [list $b $c] } + do_execsql_test 1.$tok.$tn.[llength $res].asc.3 { + SELECT rowid, fts5_test_bothlist(ss) FROM ss($expr) + } $res3 + + } } diff --git a/manifest b/manifest index e3a6b78f3f..fbcb4d2d1b 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Merge\strunk\schanges\s(including\sfixes\sfor\swarnings\sin\sfts5)\swith\sthis\sbranch. -D 2016-01-23T16:20:16.389 +C Fix\san\sfts5\sproblem\swith\susing\sboth\sxPhraseFirst()\sand\sxPhraseFirstColumn()\swithin\sa\ssingle\sstatement\sin\sdetail=col\smode. +D 2016-01-23T18:51:59.865 F Makefile.in 027c1603f255390c43a426671055a31c0a65fdb4 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 1708a78eda223b6daa302b140037fcc214a779f9 @@ -97,25 +97,25 @@ F ext/fts3/unicode/mkunicode.tcl 95cf7ec186e48d4985e433ff8a1c89090a774252 F ext/fts3/unicode/parseunicode.tcl da577d1384810fb4e2b209bf3313074353193e95 F ext/fts5/extract_api_docs.tcl a36e54ec777172ddd3f9a88daf593b00848368e0 F ext/fts5/fts5.h ff9c2782e8ed890b0de2f697a8d63971939e70c7 -F ext/fts5/fts5Int.h a810589cf2fedd7dcfc9ba7871d2a5a09e850ace -F ext/fts5/fts5_aux.c 2dafc3aee0c70d643140c77d8d70daffa51a9e9e -F ext/fts5/fts5_buffer.c 0b8e1f84fec3ec01f7e17f8d4f17c46856b31e10 +F ext/fts5/fts5Int.h 6e0f90eb4872654a5b98130dec16965716525c9a +F ext/fts5/fts5_aux.c b9bcce753ef5b451267b2232f0ca153ddeb3951d +F ext/fts5/fts5_buffer.c f6e0c6018ffc8e39fc0b333b5daa8b8d528ae6e4 F ext/fts5/fts5_config.c 0c384ebdd23fd055e2e50a93277b8d59da538238 -F ext/fts5/fts5_expr.c 48b9131b74c8d3b8c12ba0f7995e2d60eecce9f2 +F ext/fts5/fts5_expr.c a66b9694519d9c336d9bdbd46ea22e7e14aef412 F ext/fts5/fts5_hash.c 1b113977296cf4212c6ec667d5e3f2bd18036955 -F ext/fts5/fts5_index.c bd5476edd4d6ef37fc389794a78f47f29f521634 -F ext/fts5/fts5_main.c 833db0a3df10ab26e0221a9baa40cf871c450df3 -F ext/fts5/fts5_storage.c fb2eaec3aa954b680d43096dc539f8270bd6390e +F ext/fts5/fts5_index.c 722d8717e3167dd05fa48af970352932052da318 +F ext/fts5/fts5_main.c 3886bbfc5ac1d9df29979823ddf2b68241e1127e +F ext/fts5/fts5_storage.c 2a1f44deae090cd711f02cec0c2af8e660360d24 F ext/fts5/fts5_tcl.c f8731e0508299bd43f1a2eff7dbeaac870768966 F ext/fts5/fts5_test_mi.c 1ec66ffdf7632077fbd773b7a6df5153272ec070 F ext/fts5/fts5_test_tok.c db08af63673c3a7d39f053b36fd6e065017706be -F ext/fts5/fts5_tokenize.c 504984ac6993323247221eebe3cd55bead01b5f8 +F ext/fts5/fts5_tokenize.c 4d5c4f183c7d07d144bc219b92da1ea0e962fae3 F ext/fts5/fts5_unicode2.c 78273fbd588d1d9bd0a7e4e0ccc9207348bae33c F ext/fts5/fts5_varint.c 3f86ce09cab152e3d45490d7586b7ed2e40c13f1 -F ext/fts5/fts5_vocab.c f1b4308b9b7ec8e659d0c9b39ddc8f1aeee47a1a +F ext/fts5/fts5_vocab.c 3ef401a8d6932db56368de32f446eb9fe73aa623 F ext/fts5/fts5parse.y 1647eba089b9b3fc058b4dc989d9da87d15b9580 F ext/fts5/mkportersteps.tcl 5acf962d2e0074f701620bb5308155fa1e4a63ba -F ext/fts5/test/fts5_common.tcl 6d0d74b695c4be055a8ba1dd807f22a2abc95b5e +F ext/fts5/test/fts5_common.tcl 61ff0d1a29d98a91c4553b20b3f410d858834ee9 F ext/fts5/test/fts5aa.test 7e814df4a0e6c22a6fe2d84f210fdc0b5068a084 F ext/fts5/test/fts5ab.test 30325a89453280160106be411bba3acf138e6d1b F ext/fts5/test/fts5ac.test dec95549e007dd9be52aa435cdcd0f08e14e64d0 @@ -177,7 +177,7 @@ F ext/fts5/test/fts5rowid.test 16908a99d6efc9ba21081b4f2b86b3fc699839a6 F ext/fts5/test/fts5simple.test 2bc6451cbe887a9215f5b14ae307c70d850344c9 F ext/fts5/test/fts5simple2.test 98377ae1ff7749a42c21fe1a139c1ed312522c46 F ext/fts5/test/fts5synonym.test 6475d189c2e20d60795808f83e36bf9318708d48 -F ext/fts5/test/fts5synonym2.test eadb00c73ef0653258873e756b7e9102e0687539 +F ext/fts5/test/fts5synonym2.test aa4c43bd3b691ff80f658cb064f5ab40690e834e F ext/fts5/test/fts5tok1.test beb894c6f3468f10a574302f69ebe4436b0287c7 F ext/fts5/test/fts5tok2.test dcacb32d4a2a3f0dd3215d4a3987f78ae4be21a2 F ext/fts5/test/fts5tokenizer.test ea4df698b35cc427ebf2ba22829d0e28386d8c89 @@ -1419,7 +1419,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 7558a0ad2276e91f2faced8ea405d9fdb4fa0c6e 3be336aa893f9eb0837d7d66c83bab1489792b9a -R 27b07c29574081bf2a6f1649bb5e2393 +P ceccc9ad788fb4da9120915741995b9f088f85ff +R e7d7753020b6f70b109a92a8ac037ba7 U dan -Z 165b70c16fc218fdaf7b93acd8863bd2 +Z 648645363fb131dd10e5d7321a173b9d diff --git a/manifest.uuid b/manifest.uuid index 3e212691ce..1891619c18 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ceccc9ad788fb4da9120915741995b9f088f85ff \ No newline at end of file +72d53699bf0dcdb9d2a22e229989d7435f061399 \ No newline at end of file From 408273e722fbff04e6f02960060529cd85ba772e Mon Sep 17 00:00:00 2001 From: mistachkin Date: Sat, 23 Jan 2016 19:24:19 +0000 Subject: [PATCH 22/75] Use the -integer option when sorting list elements. FossilOrigin-Name: 949aa614e1401f6ab61cbb2e0469c60d764e6880 --- manifest | 15 ++++++--------- manifest.uuid | 2 +- tool/mkmsvcmin.tcl | 2 +- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index 12db615b93..d24047ded1 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\stooling\sto\screate\san\sMSVC\sMakefile\scapable\sof\sbuilding\sthe\score\slibrary\sand\sshell\sonly,\susing\sa\spre-built\samalgamation. -D 2016-01-23T07:53:04.796 +C Use\sthe\s-integer\soption\swhen\ssorting\slist\selements. +D 2016-01-23T19:24:19.182 F Makefile.in 027c1603f255390c43a426671055a31c0a65fdb4 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.min.msc c805e4a474fc7610d4f0cd0b6a9f56334a14c6ad @@ -1379,7 +1379,7 @@ F tool/loadfts.c c3c64e4d5e90e8ba41159232c2189dba4be7b862 F tool/logest.c eef612f8adf4d0993dafed0416064cf50d5d33c6 F tool/mkautoconfamal.sh 5a5441280b509d2bb3bdc71bfb63781b0d570373 F tool/mkkeywordhash.c 06ec0b78bd4fa68c12d90ef2bdfe76b039133ff8 -F tool/mkmsvcmin.tcl 859737ff14668827738a3f7ca17ba643a88bcecc +F tool/mkmsvcmin.tcl a0217f49042ec8160ff8665db638e9b5edc17964 F tool/mkopcodec.tcl edde8adc42621b5e598127f8cdc6d52cfe21f52b F tool/mkopcodeh.tcl e04177031532b7aa9379ded50e820231ac4abd6e F tool/mkopts.tcl 66ac10d240cc6e86abd37dc908d50382f84ff46e @@ -1421,10 +1421,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P a79c46bc61a35edbaf6112c26e8052314b0eb16a -R bd00cfb25453f633191b5f1755909575 -T *branch * msvcMakeMin -T *sym-msvcMakeMin * -T -sym-trunk * +P c46f1a13cb00264d1164399059250884c7be4ea0 +R ce47a7131ea57ef586dba1d328c21253 U mistachkin -Z 18f99743dd26f3a3f31830457ad1b4ef +Z c9f6cfce5ff80db91258ef2b40e34be6 diff --git a/manifest.uuid b/manifest.uuid index 06bbe8845c..0c60eb81fc 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c46f1a13cb00264d1164399059250884c7be4ea0 \ No newline at end of file +949aa614e1401f6ab61cbb2e0469c60d764e6880 \ No newline at end of file diff --git a/tool/mkmsvcmin.tcl b/tool/mkmsvcmin.tcl index 56c9d52811..188b73a18e 100644 --- a/tool/mkmsvcmin.tcl +++ b/tool/mkmsvcmin.tcl @@ -73,7 +73,7 @@ set data [readFile $fromFileName] regsub -all -- {# <>\n.*?# <>\n} \ $data "" data -foreach i [lsort [array names blocks]] { +foreach i [lsort -integer [array names blocks]] { regsub -all -- [substVars \ {# <>\n.*?# <>\n}] \ $data [escapeSubSpec $blocks($i)] data From 06cee48728424701260e2f3215ad75c257bace44 Mon Sep 17 00:00:00 2001 From: drh Date: Sat, 23 Jan 2016 19:47:00 +0000 Subject: [PATCH 23/75] Improved comments on the transformation script and on the generated Makefile. FossilOrigin-Name: c6e633ab73812fe38f3e969f1652f1b5759096e4 --- Makefile.min.msc | 6 ++++++ manifest | 16 +++++++-------- manifest.uuid | 2 +- tool/mkmsvcmin.tcl | 51 +++++++++++++++++++++++++++------------------- 4 files changed, 45 insertions(+), 30 deletions(-) diff --git a/Makefile.min.msc b/Makefile.min.msc index 2ec986fa4b..e2187efad3 100644 --- a/Makefile.min.msc +++ b/Makefile.min.msc @@ -1,3 +1,9 @@ +#### DO NOT EDIT #### +# This makefile is automatically generated from the Makefile.msc at +# the root of the canonical SQLite source tree using the +# tool/mkmsvcmin.tcl script. +# + # # nmake Makefile for SQLite # diff --git a/manifest b/manifest index d24047ded1..504f2ebbaf 100644 --- a/manifest +++ b/manifest @@ -1,8 +1,8 @@ -C Use\sthe\s-integer\soption\swhen\ssorting\slist\selements. -D 2016-01-23T19:24:19.182 +C Improved\scomments\son\sthe\stransformation\sscript\sand\son\sthe\sgenerated\sMakefile. +D 2016-01-23T19:47:00.459 F Makefile.in 027c1603f255390c43a426671055a31c0a65fdb4 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 -F Makefile.min.msc c805e4a474fc7610d4f0cd0b6a9f56334a14c6ad +F Makefile.min.msc cbbc5e37bfe74583cce7c2585319620b7516e6ed F Makefile.msc 6fca5455aaecbd14479f33f091aa19df2d3d2969 F README.md 8ecc12493ff9f820cdea6520a9016001cb2e59b7 F VERSION 866588d1edf0ccb5b0d33896974338f97564f719 @@ -1379,7 +1379,7 @@ F tool/loadfts.c c3c64e4d5e90e8ba41159232c2189dba4be7b862 F tool/logest.c eef612f8adf4d0993dafed0416064cf50d5d33c6 F tool/mkautoconfamal.sh 5a5441280b509d2bb3bdc71bfb63781b0d570373 F tool/mkkeywordhash.c 06ec0b78bd4fa68c12d90ef2bdfe76b039133ff8 -F tool/mkmsvcmin.tcl a0217f49042ec8160ff8665db638e9b5edc17964 +F tool/mkmsvcmin.tcl a62d398d1304b36dd41b69e655d875728fd9d509 F tool/mkopcodec.tcl edde8adc42621b5e598127f8cdc6d52cfe21f52b F tool/mkopcodeh.tcl e04177031532b7aa9379ded50e820231ac4abd6e F tool/mkopts.tcl 66ac10d240cc6e86abd37dc908d50382f84ff46e @@ -1421,7 +1421,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P c46f1a13cb00264d1164399059250884c7be4ea0 -R ce47a7131ea57ef586dba1d328c21253 -U mistachkin -Z c9f6cfce5ff80db91258ef2b40e34be6 +P 949aa614e1401f6ab61cbb2e0469c60d764e6880 +R 52e20c37d886e0ca572199fede1eb984 +U drh +Z 5f79d302a18d7c201b23ed73e75ff6ef diff --git a/manifest.uuid b/manifest.uuid index 0c60eb81fc..876d304c70 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -949aa614e1401f6ab61cbb2e0469c60d764e6880 \ No newline at end of file +c6e633ab73812fe38f3e969f1652f1b5759096e4 \ No newline at end of file diff --git a/tool/mkmsvcmin.tcl b/tool/mkmsvcmin.tcl index 188b73a18e..7414f53000 100644 --- a/tool/mkmsvcmin.tcl +++ b/tool/mkmsvcmin.tcl @@ -1,22 +1,26 @@ #!/usr/bin/tcl # -# Removes and/or replaces specially marked sections from the Makefile -# for MSVC, writing the resulting output to another (different) file. -# In addition, some other strings are also removed and/or replaced if -# they are present in the Makefile. -# -set fromFileName [lindex $argv 0] - -if {![file exists $fromFileName]} then { - error "input file \"$fromFileName\" does not exist" +# This script reads the regular MSVC makefile (../Makefile.msc) and outputs +# a revised version of that Makefile that is "minimal" in the sense that +# it uses the sqlite3.c amalgamation as input and does not require tclsh. +# The resulting "../Makefile.min.msc" is suitable for use in the amalgamation +# tarballs. +# +if {$argc==0} { + set basedir [file dir [file dir [file normalize $argv0]]] + set fromFileName [file join $basedir Makefile.msc] + set toFileName [file join $basedir Makefile.min.msc] +} else { + set fromFileName [lindex $argv 0] + if {![file exists $fromFileName]} then { + error "input file \"$fromFileName\" does not exist" + } + set toFileName [lindex $argv 1] + if {[file exists $toFileName]} then { + error "output file \"$toFileName\" already exists" + } } - -set toFileName [lindex $argv 1] -if {[file exists $toFileName]} then { - error "output file \"$toFileName\" already exists" -} - proc readFile { fileName } { set file_id [open $fileName RDONLY] fconfigure $file_id -encoding binary -translation binary @@ -24,7 +28,7 @@ proc readFile { fileName } { close $file_id return $result } - + proc writeFile { fileName data } { set file_id [open $fileName {WRONLY CREAT TRUNC}] fconfigure $file_id -encoding binary -translation binary @@ -32,17 +36,17 @@ proc writeFile { fileName data } { close $file_id return "" } - + proc escapeSubSpec { data } { regsub -all -- {&} $data {\\\&} data regsub -all -- {\\(\d+)} $data {\\\\\1} data return $data } - + proc substVars { data } { return [uplevel 1 [list subst -nocommands -nobackslashes $data]] } - + # # NOTE: This block is used to replace the section marked <> in # the Makefile, if it exists. @@ -67,8 +71,13 @@ $(LIBRESOBJS): $(TOP)\sqlite3.rc rcver.vc $(SQLITE3H) echo #endif >> sqlite3rc.h $(LTRCOMPILE) -fo $(LIBRESOBJS) -DRC_VERONLY $(TOP)\sqlite3.rc }]] - -set data [readFile $fromFileName] + +set data "#### DO NOT EDIT ####\n" +append data "# This makefile is automatically " +append data "generated from the [file tail $fromFileName] at\n" +append data "# the root of the canonical SQLite source tree using the\n" +append data "# tool/[file tail $argv0] script.\n#\n\n" +append data [readFile $fromFileName] regsub -all -- {# <>\n.*?# <>\n} \ $data "" data From ac779bcbe964611322cc9ad4e056e8220784b84a Mon Sep 17 00:00:00 2001 From: drh Date: Sat, 23 Jan 2016 20:09:30 +0000 Subject: [PATCH 24/75] Adjust the amalgamation-tarball build process so that it includes the MSVC makefile and the sqlite3.rc resource file. FossilOrigin-Name: e420f3dc93a0e3364f0773950b7a125f5221a109 --- autoconf/Makefile.am | 2 +- autoconf/{README => README.txt} | 5 ++++- manifest | 16 ++++++++-------- manifest.uuid | 2 +- tool/mkautoconfamal.sh | 17 +++++++++-------- 5 files changed, 23 insertions(+), 19 deletions(-) rename autoconf/{README => README.txt} (88%) diff --git a/autoconf/Makefile.am b/autoconf/Makefile.am index eed3ba41cb..03424a606b 100644 --- a/autoconf/Makefile.am +++ b/autoconf/Makefile.am @@ -14,7 +14,7 @@ sqlite3_CFLAGS = $(AM_CFLAGS) include_HEADERS = sqlite3.h sqlite3ext.h -EXTRA_DIST = sqlite3.1 tea +EXTRA_DIST = sqlite3.1 tea Makefile.msc sqlite3.rc README.txt pkgconfigdir = ${libdir}/pkgconfig pkgconfig_DATA = sqlite3.pc diff --git a/autoconf/README b/autoconf/README.txt similarity index 88% rename from autoconf/README rename to autoconf/README.txt index dd8cca24bd..731158a883 100644 --- a/autoconf/README +++ b/autoconf/README.txt @@ -1,4 +1,3 @@ - This package contains: * the SQLite library amalgamation (single file) source code distribution, @@ -6,6 +5,7 @@ This package contains: * the sqlite3.h and sqlite3ext.h header files required to link programs and sqlite extensions against the installed libary. * autoconf/automake installation infrastucture. + * a Makefile.msc and sqlite3.rc for Microsoft Visual C++ The generic installation instructions for autoconf/automake are found in the INSTALL file. @@ -30,3 +30,6 @@ example: $ CFLAGS="-Os -DSQLITE_OMIT_TRIGGERS" ./configure +To compile for Windows using Microsoft Visual C++: + + $ nmake /f Makefile.msc FOR_WIN10=1 diff --git a/manifest b/manifest index 504f2ebbaf..a6797b77e5 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Improved\scomments\son\sthe\stransformation\sscript\sand\son\sthe\sgenerated\sMakefile. -D 2016-01-23T19:47:00.459 +C Adjust\sthe\samalgamation-tarball\sbuild\sprocess\sso\sthat\sit\sincludes\sthe\nMSVC\smakefile\sand\sthe\ssqlite3.rc\sresource\sfile. +D 2016-01-23T20:09:30.205 F Makefile.in 027c1603f255390c43a426671055a31c0a65fdb4 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.min.msc cbbc5e37bfe74583cce7c2585319620b7516e6ed @@ -11,9 +11,9 @@ F art/sqlite370.eps aa97a671332b432a54e1d74ff5e8775be34200c2 F art/sqlite370.ico af56c1d00fee7cd4753e8631ed60703ed0fc6e90 F art/sqlite370.jpg d512473dae7e378a67e28ff96a34da7cb331def2 F autoconf/INSTALL 83e4a25da9fd053c7b3665eaaaf7919707915903 -F autoconf/Makefile.am 089e5ecdb5761e64ea1013ded02feb4d8b29927d -F autoconf/README 14458f1046c118efa721aadec5f227e876d3cd38 +F autoconf/Makefile.am 1c1657650775960804945dc392e14d9e43c5ed84 F autoconf/README.first 6c4f34fe115ff55d4e8dbfa3cecf04a0188292f7 +F autoconf/README.txt c9265657b6ca8c4de1e148e8c0c4c29d60ec860c w autoconf/README F autoconf/configure.ac 7b1ea0dcaf49fafba262ce4b0ee8cb3281b555d1 F autoconf/tea/Makefile.in b438a7020446c8a8156e8d97c8914a04833da6fd F autoconf/tea/README 3e9a3c060f29a44344ab50aec506f4db903fb873 @@ -1377,7 +1377,7 @@ F tool/lemon.c 799e73e19a33b8dd7767a7fa34618ed2a9c2397d F tool/lempar.c 3ec1463a034b37d87d782be5f6b8b10a3b1ecbe7 F tool/loadfts.c c3c64e4d5e90e8ba41159232c2189dba4be7b862 F tool/logest.c eef612f8adf4d0993dafed0416064cf50d5d33c6 -F tool/mkautoconfamal.sh 5a5441280b509d2bb3bdc71bfb63781b0d570373 +F tool/mkautoconfamal.sh add1d703074e7edb2d8423441c7e245271c5c8cb F tool/mkkeywordhash.c 06ec0b78bd4fa68c12d90ef2bdfe76b039133ff8 F tool/mkmsvcmin.tcl a62d398d1304b36dd41b69e655d875728fd9d509 F tool/mkopcodec.tcl edde8adc42621b5e598127f8cdc6d52cfe21f52b @@ -1421,7 +1421,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 949aa614e1401f6ab61cbb2e0469c60d764e6880 -R 52e20c37d886e0ca572199fede1eb984 +P c6e633ab73812fe38f3e969f1652f1b5759096e4 +R d5543de9eede26dd90664aa004eef406 U drh -Z 5f79d302a18d7c201b23ed73e75ff6ef +Z 98c1051b769380596fbf89ccef90cc39 diff --git a/manifest.uuid b/manifest.uuid index 876d304c70..c32f479829 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c6e633ab73812fe38f3e969f1652f1b5759096e4 \ No newline at end of file +e420f3dc93a0e3364f0773950b7a125f5221a109 \ No newline at end of file diff --git a/tool/mkautoconfamal.sh b/tool/mkautoconfamal.sh index 9f44152e36..d368cd226b 100644 --- a/tool/mkautoconfamal.sh +++ b/tool/mkautoconfamal.sh @@ -34,14 +34,15 @@ set -e ARTIFACT=`printf "3%.2d%.2d%.2d" $xx $yy $zz` rm -rf $TMPSPACE -cp -R $TOP/autoconf $TMPSPACE - -cp sqlite3.c $TMPSPACE -cp sqlite3.h $TMPSPACE -cp sqlite3ext.h $TMPSPACE -cp $TOP/sqlite3.1 $TMPSPACE -cp $TOP/sqlite3.pc.in $TMPSPACE -cp $TOP/src/shell.c $TMPSPACE +cp -R $TOP/autoconf $TMPSPACE +cp sqlite3.c $TMPSPACE +cp sqlite3.h $TMPSPACE +cp sqlite3ext.h $TMPSPACE +cp $TOP/sqlite3.1 $TMPSPACE +cp $TOP/sqlite3.pc.in $TMPSPACE +cp $TOP/src/shell.c $TMPSPACE +cp $TOP/Makefile.min.msc $TMPSPACE/Makefile.msc +cp $TOP/src/sqlite3.rc $TMPSPACE cat $TMPSPACE/configure.ac | sed "s/--SQLITE-VERSION--/$VERSION/" > $TMPSPACE/tmp From 4a25549b087bd576ac413f88f5e2d654cd59e0b4 Mon Sep 17 00:00:00 2001 From: mistachkin Date: Sat, 23 Jan 2016 20:16:40 +0000 Subject: [PATCH 25/75] Minor coding style tweaks for the mkmsvcmin tool. FossilOrigin-Name: c15e0fc4be08b92547bea1f1cac65581ef497409 --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- tool/mkmsvcmin.tcl | 6 +++--- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/manifest b/manifest index a6797b77e5..2076ff35e1 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Adjust\sthe\samalgamation-tarball\sbuild\sprocess\sso\sthat\sit\sincludes\sthe\nMSVC\smakefile\sand\sthe\ssqlite3.rc\sresource\sfile. -D 2016-01-23T20:09:30.205 +C Minor\scoding\sstyle\stweaks\sfor\sthe\smkmsvcmin\stool. +D 2016-01-23T20:16:40.624 F Makefile.in 027c1603f255390c43a426671055a31c0a65fdb4 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.min.msc cbbc5e37bfe74583cce7c2585319620b7516e6ed @@ -13,7 +13,7 @@ F art/sqlite370.jpg d512473dae7e378a67e28ff96a34da7cb331def2 F autoconf/INSTALL 83e4a25da9fd053c7b3665eaaaf7919707915903 F autoconf/Makefile.am 1c1657650775960804945dc392e14d9e43c5ed84 F autoconf/README.first 6c4f34fe115ff55d4e8dbfa3cecf04a0188292f7 -F autoconf/README.txt c9265657b6ca8c4de1e148e8c0c4c29d60ec860c w autoconf/README +F autoconf/README.txt c9265657b6ca8c4de1e148e8c0c4c29d60ec860c F autoconf/configure.ac 7b1ea0dcaf49fafba262ce4b0ee8cb3281b555d1 F autoconf/tea/Makefile.in b438a7020446c8a8156e8d97c8914a04833da6fd F autoconf/tea/README 3e9a3c060f29a44344ab50aec506f4db903fb873 @@ -1379,7 +1379,7 @@ F tool/loadfts.c c3c64e4d5e90e8ba41159232c2189dba4be7b862 F tool/logest.c eef612f8adf4d0993dafed0416064cf50d5d33c6 F tool/mkautoconfamal.sh add1d703074e7edb2d8423441c7e245271c5c8cb F tool/mkkeywordhash.c 06ec0b78bd4fa68c12d90ef2bdfe76b039133ff8 -F tool/mkmsvcmin.tcl a62d398d1304b36dd41b69e655d875728fd9d509 +F tool/mkmsvcmin.tcl c1f92b52505fe4a026e7b57fffe49b439b11b71b F tool/mkopcodec.tcl edde8adc42621b5e598127f8cdc6d52cfe21f52b F tool/mkopcodeh.tcl e04177031532b7aa9379ded50e820231ac4abd6e F tool/mkopts.tcl 66ac10d240cc6e86abd37dc908d50382f84ff46e @@ -1421,7 +1421,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P c6e633ab73812fe38f3e969f1652f1b5759096e4 -R d5543de9eede26dd90664aa004eef406 -U drh -Z 98c1051b769380596fbf89ccef90cc39 +P e420f3dc93a0e3364f0773950b7a125f5221a109 +R 0e64448b1af0ccd7100284f6f222657e +U mistachkin +Z 38e3fbc9582e760d49d364916a96f186 diff --git a/manifest.uuid b/manifest.uuid index c32f479829..6bcba645b0 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -e420f3dc93a0e3364f0773950b7a125f5221a109 \ No newline at end of file +c15e0fc4be08b92547bea1f1cac65581ef497409 \ No newline at end of file diff --git a/tool/mkmsvcmin.tcl b/tool/mkmsvcmin.tcl index 7414f53000..d0143ddd86 100644 --- a/tool/mkmsvcmin.tcl +++ b/tool/mkmsvcmin.tcl @@ -5,18 +5,18 @@ # it uses the sqlite3.c amalgamation as input and does not require tclsh. # The resulting "../Makefile.min.msc" is suitable for use in the amalgamation # tarballs. -# +# if {$argc==0} { set basedir [file dir [file dir [file normalize $argv0]]] set fromFileName [file join $basedir Makefile.msc] set toFileName [file join $basedir Makefile.min.msc] } else { set fromFileName [lindex $argv 0] - if {![file exists $fromFileName]} then { + if {![file exists $fromFileName]} { error "input file \"$fromFileName\" does not exist" } set toFileName [lindex $argv 1] - if {[file exists $toFileName]} then { + if {[file exists $toFileName]} { error "output file \"$toFileName\" already exists" } } From 021f9a6605c2c1af96db9fd144c64749c5224751 Mon Sep 17 00:00:00 2001 From: drh Date: Sat, 23 Jan 2016 20:34:27 +0000 Subject: [PATCH 26/75] Move Makefile.min.msc into the autoconf subdir where it belongs and change its name to Makefile.msc. Adjust build scripts accordingly. FossilOrigin-Name: 12eb8db79697ef55228c78011d275f36f58271e1 --- Makefile.min.msc => autoconf/Makefile.msc | 5 +++-- manifest | 18 +++++++++--------- manifest.uuid | 2 +- tool/mkautoconfamal.sh | 1 - tool/mkmsvcmin.tcl | 7 ++++--- 5 files changed, 17 insertions(+), 16 deletions(-) rename Makefile.min.msc => autoconf/Makefile.msc (99%) diff --git a/Makefile.min.msc b/autoconf/Makefile.msc similarity index 99% rename from Makefile.min.msc rename to autoconf/Makefile.msc index e2187efad3..fce62b2b8a 100644 --- a/Makefile.min.msc +++ b/autoconf/Makefile.msc @@ -1,7 +1,8 @@ #### DO NOT EDIT #### # This makefile is automatically generated from the Makefile.msc at -# the root of the canonical SQLite source tree using the -# tool/mkmsvcmin.tcl script. +# the root of the canonical SQLite source tree (not the +# amalgamation tarball) using the tool/mkmsvcmin.tcl +# script. # # diff --git a/manifest b/manifest index 2076ff35e1..9a914fa3d3 100644 --- a/manifest +++ b/manifest @@ -1,8 +1,7 @@ -C Minor\scoding\sstyle\stweaks\sfor\sthe\smkmsvcmin\stool. -D 2016-01-23T20:16:40.624 +C Move\sMakefile.min.msc\sinto\sthe\sautoconf\ssubdir\swhere\sit\sbelongs\sand\schange\nits\sname\sto\sMakefile.msc.\s\sAdjust\sbuild\sscripts\saccordingly. +D 2016-01-23T20:34:27.088 F Makefile.in 027c1603f255390c43a426671055a31c0a65fdb4 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 -F Makefile.min.msc cbbc5e37bfe74583cce7c2585319620b7516e6ed F Makefile.msc 6fca5455aaecbd14479f33f091aa19df2d3d2969 F README.md 8ecc12493ff9f820cdea6520a9016001cb2e59b7 F VERSION 866588d1edf0ccb5b0d33896974338f97564f719 @@ -12,6 +11,7 @@ F art/sqlite370.ico af56c1d00fee7cd4753e8631ed60703ed0fc6e90 F art/sqlite370.jpg d512473dae7e378a67e28ff96a34da7cb331def2 F autoconf/INSTALL 83e4a25da9fd053c7b3665eaaaf7919707915903 F autoconf/Makefile.am 1c1657650775960804945dc392e14d9e43c5ed84 +F autoconf/Makefile.msc 68ed752a809b611d97b95d8572a34fe6fd1196f1 w Makefile.min.msc F autoconf/README.first 6c4f34fe115ff55d4e8dbfa3cecf04a0188292f7 F autoconf/README.txt c9265657b6ca8c4de1e148e8c0c4c29d60ec860c F autoconf/configure.ac 7b1ea0dcaf49fafba262ce4b0ee8cb3281b555d1 @@ -1377,9 +1377,9 @@ F tool/lemon.c 799e73e19a33b8dd7767a7fa34618ed2a9c2397d F tool/lempar.c 3ec1463a034b37d87d782be5f6b8b10a3b1ecbe7 F tool/loadfts.c c3c64e4d5e90e8ba41159232c2189dba4be7b862 F tool/logest.c eef612f8adf4d0993dafed0416064cf50d5d33c6 -F tool/mkautoconfamal.sh add1d703074e7edb2d8423441c7e245271c5c8cb +F tool/mkautoconfamal.sh a29b14d54302b33fd892958f6895582ea90e4a45 F tool/mkkeywordhash.c 06ec0b78bd4fa68c12d90ef2bdfe76b039133ff8 -F tool/mkmsvcmin.tcl c1f92b52505fe4a026e7b57fffe49b439b11b71b +F tool/mkmsvcmin.tcl 93167a9e73383465b5716aa8dfa407409fccef1d F tool/mkopcodec.tcl edde8adc42621b5e598127f8cdc6d52cfe21f52b F tool/mkopcodeh.tcl e04177031532b7aa9379ded50e820231ac4abd6e F tool/mkopts.tcl 66ac10d240cc6e86abd37dc908d50382f84ff46e @@ -1421,7 +1421,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P e420f3dc93a0e3364f0773950b7a125f5221a109 -R 0e64448b1af0ccd7100284f6f222657e -U mistachkin -Z 38e3fbc9582e760d49d364916a96f186 +P c15e0fc4be08b92547bea1f1cac65581ef497409 +R ffa1a98b2b7806021300568489ac1126 +U drh +Z ba6195ff75ad05f3ae39571f4a1714e5 diff --git a/manifest.uuid b/manifest.uuid index 6bcba645b0..e3e08e4e7c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c15e0fc4be08b92547bea1f1cac65581ef497409 \ No newline at end of file +12eb8db79697ef55228c78011d275f36f58271e1 \ No newline at end of file diff --git a/tool/mkautoconfamal.sh b/tool/mkautoconfamal.sh index d368cd226b..6081a7b0ec 100644 --- a/tool/mkautoconfamal.sh +++ b/tool/mkautoconfamal.sh @@ -41,7 +41,6 @@ cp sqlite3ext.h $TMPSPACE cp $TOP/sqlite3.1 $TMPSPACE cp $TOP/sqlite3.pc.in $TMPSPACE cp $TOP/src/shell.c $TMPSPACE -cp $TOP/Makefile.min.msc $TMPSPACE/Makefile.msc cp $TOP/src/sqlite3.rc $TMPSPACE cat $TMPSPACE/configure.ac | diff --git a/tool/mkmsvcmin.tcl b/tool/mkmsvcmin.tcl index d0143ddd86..de01490c97 100644 --- a/tool/mkmsvcmin.tcl +++ b/tool/mkmsvcmin.tcl @@ -9,7 +9,7 @@ if {$argc==0} { set basedir [file dir [file dir [file normalize $argv0]]] set fromFileName [file join $basedir Makefile.msc] - set toFileName [file join $basedir Makefile.min.msc] + set toFileName [file join $basedir autoconf Makefile.msc] } else { set fromFileName [lindex $argv 0] if {![file exists $fromFileName]} { @@ -75,8 +75,9 @@ $(LIBRESOBJS): $(TOP)\sqlite3.rc rcver.vc $(SQLITE3H) set data "#### DO NOT EDIT ####\n" append data "# This makefile is automatically " append data "generated from the [file tail $fromFileName] at\n" -append data "# the root of the canonical SQLite source tree using the\n" -append data "# tool/[file tail $argv0] script.\n#\n\n" +append data "# the root of the canonical SQLite source tree (not the\n" +append data "# amalgamation tarball) using the tool/[file tail $argv0]\n" +append data "# script.\n#\n\n" append data [readFile $fromFileName] regsub -all -- {# <>\n.*?# <>\n} \ From 74f6e6ccf877fd3154eff2fabaa0c55e188bb019 Mon Sep 17 00:00:00 2001 From: drh Date: Sat, 23 Jan 2016 20:43:48 +0000 Subject: [PATCH 27/75] Updates to the autoconf README file. FossilOrigin-Name: 4ce60fa42d8486d219d40d25d785d7f2cabe5e06 --- autoconf/README.txt | 11 +++++++++-- manifest | 14 +++++++------- manifest.uuid | 2 +- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/autoconf/README.txt b/autoconf/README.txt index 731158a883..575e0a8dd8 100644 --- a/autoconf/README.txt +++ b/autoconf/README.txt @@ -4,8 +4,11 @@ This package contains: * the shell.c file used to build the sqlite3 shell too, and * the sqlite3.h and sqlite3ext.h header files required to link programs and sqlite extensions against the installed libary. - * autoconf/automake installation infrastucture. - * a Makefile.msc and sqlite3.rc for Microsoft Visual C++ + * autoconf/automake installation infrastucture for building on posix systems. + * a Makefile.msc and sqlite3.rc for building with Microsoft Visual C++ + +BUILDING ON POSIX +================= The generic installation instructions for autoconf/automake are found in the INSTALL file. @@ -30,6 +33,10 @@ example: $ CFLAGS="-Os -DSQLITE_OMIT_TRIGGERS" ./configure + +BUILDING WITH MICROSOFT VISUAL C++: +=================================== + To compile for Windows using Microsoft Visual C++: $ nmake /f Makefile.msc FOR_WIN10=1 diff --git a/manifest b/manifest index 9a914fa3d3..e41fae053e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Move\sMakefile.min.msc\sinto\sthe\sautoconf\ssubdir\swhere\sit\sbelongs\sand\schange\nits\sname\sto\sMakefile.msc.\s\sAdjust\sbuild\sscripts\saccordingly. -D 2016-01-23T20:34:27.088 +C Updates\sto\sthe\sautoconf\sREADME\sfile. +D 2016-01-23T20:43:48.995 F Makefile.in 027c1603f255390c43a426671055a31c0a65fdb4 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 6fca5455aaecbd14479f33f091aa19df2d3d2969 @@ -11,9 +11,9 @@ F art/sqlite370.ico af56c1d00fee7cd4753e8631ed60703ed0fc6e90 F art/sqlite370.jpg d512473dae7e378a67e28ff96a34da7cb331def2 F autoconf/INSTALL 83e4a25da9fd053c7b3665eaaaf7919707915903 F autoconf/Makefile.am 1c1657650775960804945dc392e14d9e43c5ed84 -F autoconf/Makefile.msc 68ed752a809b611d97b95d8572a34fe6fd1196f1 w Makefile.min.msc +F autoconf/Makefile.msc 68ed752a809b611d97b95d8572a34fe6fd1196f1 F autoconf/README.first 6c4f34fe115ff55d4e8dbfa3cecf04a0188292f7 -F autoconf/README.txt c9265657b6ca8c4de1e148e8c0c4c29d60ec860c +F autoconf/README.txt ebf930270b2d6258f4d2c62c8c5a5dcc7cff5293 F autoconf/configure.ac 7b1ea0dcaf49fafba262ce4b0ee8cb3281b555d1 F autoconf/tea/Makefile.in b438a7020446c8a8156e8d97c8914a04833da6fd F autoconf/tea/README 3e9a3c060f29a44344ab50aec506f4db903fb873 @@ -1421,7 +1421,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P c15e0fc4be08b92547bea1f1cac65581ef497409 -R ffa1a98b2b7806021300568489ac1126 +P 12eb8db79697ef55228c78011d275f36f58271e1 +R f077ea8ac49bb767871086d72cc4aac2 U drh -Z ba6195ff75ad05f3ae39571f4a1714e5 +Z 47e598e0236f733ea03c00ba7b81ee9b diff --git a/manifest.uuid b/manifest.uuid index e3e08e4e7c..ea84af834d 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -12eb8db79697ef55228c78011d275f36f58271e1 \ No newline at end of file +4ce60fa42d8486d219d40d25d785d7f2cabe5e06 \ No newline at end of file From 76d4b1b835be68f6164042e34efb4c31e3dc11c3 Mon Sep 17 00:00:00 2001 From: mistachkin Date: Sat, 23 Jan 2016 21:57:46 +0000 Subject: [PATCH 28/75] More updates to the README. FossilOrigin-Name: 9f02868df71d902a2b9118d0b06df18ee92b666b --- autoconf/README.txt | 77 +++++++++++++++++++++++++++++++++++++++++---- manifest | 14 ++++----- manifest.uuid | 2 +- 3 files changed, 79 insertions(+), 14 deletions(-) diff --git a/autoconf/README.txt b/autoconf/README.txt index 575e0a8dd8..a581c39dea 100644 --- a/autoconf/README.txt +++ b/autoconf/README.txt @@ -4,8 +4,10 @@ This package contains: * the shell.c file used to build the sqlite3 shell too, and * the sqlite3.h and sqlite3ext.h header files required to link programs and sqlite extensions against the installed libary. - * autoconf/automake installation infrastucture for building on posix systems. - * a Makefile.msc and sqlite3.rc for building with Microsoft Visual C++ + * autoconf/automake installation infrastucture for building on POSIX + compliant systems. + * a Makefile.msc and sqlite3.rc for building with Microsoft Visual C++ on + Windows. BUILDING ON POSIX ================= @@ -19,7 +21,7 @@ The following SQLite specific boolean options are supported: --enable-threadsafe build a thread-safe library [default=yes] --enable-dynamic-extensions support loadable extensions [default=yes] -The default value for the CFLAGS variable (options passed to the C +The default value for the CFLAGS variable (options passed to the C compiler) includes debugging symbols in the build, resulting in larger binaries than are necessary. Override it on the configure command line like this: @@ -34,9 +36,72 @@ example: $ CFLAGS="-Os -DSQLITE_OMIT_TRIGGERS" ./configure -BUILDING WITH MICROSOFT VISUAL C++: -=================================== +BUILDING WITH MICROSOFT VISUAL C++ +================================== To compile for Windows using Microsoft Visual C++: - $ nmake /f Makefile.msc FOR_WIN10=1 + $ nmake /f Makefile.msc + +Using Microsoft Visual C++ 2005 (or later) is recommended. Several Windows +platform variants may be built by adding additional macros to the NMAKE +command line. + +BUILDING FOR WINRT 8.0 +---------------------- + + FOR_WINRT=1 + +Using Microsoft Visual C++ 2012 (or later) is required. When using the +above, something like the following macro will need to be added to the +NMAKE command line as well: + + "NSDKLIBPATH=%WindowsSdkDir%\..\8.0\lib\win8\um\x86" + +BUILDING FOR WINRT 8.1 +---------------------- + + FOR_WINRT=1 + +Using Microsoft Visual C++ 2013 (or later) is required. When using the +above, something like the following macro will need to be added to the +NMAKE command line as well: + + "NSDKLIBPATH=%WindowsSdkDir%\..\8.1\lib\winv6.3\um\x86" + +BUILDING FOR UAP 10.0 +--------------------- + + FOR_WINRT=1 FOR_UAP=1 + +Using Microsoft Visual C++ 2015 (or later) is required. When using the +above, something like the following macros will need to be added to the +NMAKE command line as well: + + "NSDKLIBPATH=%WindowsSdkDir%\..\10\lib\10.0.10586.0\um\x86" + "PSDKLIBPATH=%WindowsSdkDir%\..\10\lib\10.0.10586.0\um\x86" + "NUCRTLIBPATH=%UniversalCRTSdkDir%\..\10\lib\10.0.10586.0\ucrt\x86" + +BUILDING FOR THE WINDOWS 10 SDK +------------------------------- + + FOR_WIN10=1 + +Using Microsoft Visual C++ 2015 (or later) is required. When using the +above, no other macros should be needed on the NMAKE command line. + +USING PREPROCESSOR DEFINES +-------------------------- + +Additionally, preprocessor defines may be specified by using the OPTS macro +on the NMAKE command line. However, not all possible preprocessor defines +may be specified in this manner as some require the amalgamation to be built +with them enabled (see http://www.sqlite.org/compile.html). For example, the +following will work: + + "OPTS=-DSQLITE_ENABLE_STAT4=1 -DSQLITE_ENABLE_JSON1=1" + +However, the following will not compile unless the amalgamation was built +with it enabled: + + "OPTS=-DSQLITE_ENABLE_UPDATE_DELETE_LIMIT=1" diff --git a/manifest b/manifest index e41fae053e..0f3e8b7b8d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Updates\sto\sthe\sautoconf\sREADME\sfile. -D 2016-01-23T20:43:48.995 +C More\supdates\sto\sthe\sREADME. +D 2016-01-23T21:57:46.170 F Makefile.in 027c1603f255390c43a426671055a31c0a65fdb4 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 6fca5455aaecbd14479f33f091aa19df2d3d2969 @@ -13,7 +13,7 @@ F autoconf/INSTALL 83e4a25da9fd053c7b3665eaaaf7919707915903 F autoconf/Makefile.am 1c1657650775960804945dc392e14d9e43c5ed84 F autoconf/Makefile.msc 68ed752a809b611d97b95d8572a34fe6fd1196f1 F autoconf/README.first 6c4f34fe115ff55d4e8dbfa3cecf04a0188292f7 -F autoconf/README.txt ebf930270b2d6258f4d2c62c8c5a5dcc7cff5293 +F autoconf/README.txt fc86867528c500dfd691620e623bfe6799c98d14 F autoconf/configure.ac 7b1ea0dcaf49fafba262ce4b0ee8cb3281b555d1 F autoconf/tea/Makefile.in b438a7020446c8a8156e8d97c8914a04833da6fd F autoconf/tea/README 3e9a3c060f29a44344ab50aec506f4db903fb873 @@ -1421,7 +1421,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 12eb8db79697ef55228c78011d275f36f58271e1 -R f077ea8ac49bb767871086d72cc4aac2 -U drh -Z 47e598e0236f733ea03c00ba7b81ee9b +P 4ce60fa42d8486d219d40d25d785d7f2cabe5e06 +R 9ddb76e24748b77caceaf34a8b255b23 +U mistachkin +Z 8a8dd4db0d2ee1de0599573a5cb1355c diff --git a/manifest.uuid b/manifest.uuid index ea84af834d..c53057578b 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -4ce60fa42d8486d219d40d25d785d7f2cabe5e06 \ No newline at end of file +9f02868df71d902a2b9118d0b06df18ee92b666b \ No newline at end of file From 9084ec1d962388a219d32fbed684f15e44de11d8 Mon Sep 17 00:00:00 2001 From: drh Date: Sat, 23 Jan 2016 22:55:53 +0000 Subject: [PATCH 29/75] Add the SQLITE_SPELLFIX_STACKALLOC_SZ compile-time option to control how much stack space is available for use as the Wagner matrix in editDest3 of the spellfix extension. FossilOrigin-Name: dd0100dd87e2c7c70fabb2d3188f0906e605583d --- ext/misc/spellfix.c | 13 ++++++++++++- manifest | 12 ++++++------ manifest.uuid | 2 +- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/ext/misc/spellfix.c b/ext/misc/spellfix.c index d17a05a3cd..68bd2afbb2 100644 --- a/ext/misc/spellfix.c +++ b/ext/misc/spellfix.c @@ -875,6 +875,17 @@ static void updateCost( } } +/* +** How much stack space (int bytes) to use for Wagner matrix in +** editDist3Core(). If more space than this is required, the entire +** matrix is taken from the heap. To reduce the load on the memory +** allocator, make this value as large as practical for the +** architecture in use. +*/ +#ifndef SQLITE_SPELLFIX_STACKALLOC_SZ +# define SQLITE_SPELLFIX_STACKALLOC_SZ (1024) +#endif + /* Compute the edit distance between two strings. ** ** If an error occurs, return a negative number which is the error code. @@ -904,7 +915,7 @@ static int editDist3Core( EditDist3Cost *p; int res; sqlite3_uint64 nByte; - unsigned int stackSpace[16*1024]; + unsigned int stackSpace[SQLITE_SPELLFIX_STACKALLOC_SZ/sizeof(unsigned int)]; /* allocate the Wagner matrix and the aTo[] array for the TO string */ n = (f.n+1)*(n2+1); diff --git a/manifest b/manifest index 8a5302c683..d6adb98190 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Changes\sto\sspellfix\sto\stry\sto\sget\sit\sto\suse\sstack\sspace\sinstead\sof\sheap\sspace\nin\scases\swhere\sthat\smakes\ssense. -D 2016-01-23T18:24:52.238 +C Add\sthe\sSQLITE_SPELLFIX_STACKALLOC_SZ\scompile-time\soption\sto\scontrol\show\smuch\nstack\sspace\sis\savailable\sfor\suse\sas\sthe\sWagner\smatrix\sin\seditDest3\sof\sthe\nspellfix\sextension. +D 2016-01-23T22:55:53.451 F Makefile.in 027c1603f255390c43a426671055a31c0a65fdb4 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 1708a78eda223b6daa302b140037fcc214a779f9 @@ -210,7 +210,7 @@ F ext/misc/regexp.c af92cdaa5058fcec1451e49becc7ba44dba023dc F ext/misc/rot13.c 1ac6f95f99b575907b9b09c81a349114cf9be45a F ext/misc/series.c b8fb7befd85b3a9b4a10e701b30b2b79ca92b6d4 F ext/misc/showauth.c 732578f0fe4ce42d577e1c86dc89dd14a006ab52 -F ext/misc/spellfix.c 5850a0e05ae1eacd48a3d80991c63b58d41e2d27 +F ext/misc/spellfix.c db4cc4b7aa12384e6c19a289a39cd232d355413d F ext/misc/totype.c 4a167594e791abeed95e0a8db028822b5e8fe512 F ext/misc/vfslog.c fe40fab5c077a40477f7e5eba994309ecac6cc95 F ext/misc/vtshim.c babb0dc2bf116029e3e7c9a618b8a1377045303e @@ -1419,7 +1419,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 3be336aa893f9eb0837d7d66c83bab1489792b9a -R e0cc5654cf9d372268674d3acd0d1178 +P dfcebc7393a3a780ee9c4f257723c303bb633064 +R f2b384711e45db4261b5ef34d3e09d67 U drh -Z 5f4045218ee81aac454594c9cbaf4e94 +Z 57efa8447e9c944d8afed12c4b4dd5da diff --git a/manifest.uuid b/manifest.uuid index ff35bf94f1..dfbb1735b4 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -dfcebc7393a3a780ee9c4f257723c303bb633064 \ No newline at end of file +dd0100dd87e2c7c70fabb2d3188f0906e605583d \ No newline at end of file From d0d0f8dc67725287d31be219314e839594a4278f Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 25 Jan 2016 01:07:59 +0000 Subject: [PATCH 30/75] Small simplification and performance improvement in memsys5Free(). FossilOrigin-Name: 0a9cff5c4822874b74e90bfca3963bc7e5c753a5 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/mem5.c | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index d6adb98190..1cbb37b406 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sthe\sSQLITE_SPELLFIX_STACKALLOC_SZ\scompile-time\soption\sto\scontrol\show\smuch\nstack\sspace\sis\savailable\sfor\suse\sas\sthe\sWagner\smatrix\sin\seditDest3\sof\sthe\nspellfix\sextension. -D 2016-01-23T22:55:53.451 +C Small\ssimplification\sand\sperformance\simprovement\sin\smemsys5Free(). +D 2016-01-25T01:07:59.493 F Makefile.in 027c1603f255390c43a426671055a31c0a65fdb4 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 1708a78eda223b6daa302b140037fcc214a779f9 @@ -316,7 +316,7 @@ F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645 F src/mem1.c 6919bcf12f221868ea066eec27e579fed95ce98b F src/mem2.c f1940d9e91948dd6a908fbb9ce3835c36b5d83c3 F src/mem3.c 8768ac94694f31ffaf8b4d0ea5dc08af7010a35a -F src/mem5.c 71f81a11fc5e29a57428761ab38a7bf2ef4ee19d +F src/mem5.c 9bf955937b07f8c32541c8a9991f33ce3173d944 F src/memjournal.c 3eb2c0b51adbd869cb6a44780323f05fa904dc85 F src/msvc.h d9ba56c6851227ab44b3f228a35f3f5772296495 F src/mutex.c 8e45800ee78e0cd1f1f3fe8e398853307f4a085c @@ -1419,7 +1419,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P dfcebc7393a3a780ee9c4f257723c303bb633064 -R f2b384711e45db4261b5ef34d3e09d67 +P dd0100dd87e2c7c70fabb2d3188f0906e605583d +R a179bcf25d5e17fae98e7434f7b5c754 U drh -Z 57efa8447e9c944d8afed12c4b4dd5da +Z 6a3ae2a8bc97ab052cdf4e5d8140159f diff --git a/manifest.uuid b/manifest.uuid index dfbb1735b4..fed0f2a557 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -dd0100dd87e2c7c70fabb2d3188f0906e605583d \ No newline at end of file +0a9cff5c4822874b74e90bfca3963bc7e5c753a5 \ No newline at end of file diff --git a/src/mem5.c b/src/mem5.c index 7316a630a6..c194a6b778 100644 --- a/src/mem5.c +++ b/src/mem5.c @@ -322,11 +322,11 @@ static void memsys5FreeUnsafe(void *pOld){ int iBuddy; if( (iBlock>>iLogsize) & 1 ){ iBuddy = iBlock - size; + assert( iBuddy>=0 ); }else{ iBuddy = iBlock + size; + if( iBuddy>=mem5.nBlock ) break; } - assert( iBuddy>=0 ); - if( (iBuddy+(1<mem5.nBlock ) break; if( mem5.aCtrl[iBuddy]!=(CTRL_FREE | iLogsize) ) break; memsys5Unlink(iBuddy, iLogsize); iLogsize++; From a7dc4a321d8f537d9257b20634f93dccfabd03cd Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 25 Jan 2016 02:15:02 +0000 Subject: [PATCH 31/75] Small simplification to the prepare statement opcode memory reuse logic. Easier to read, and slightly smaller and faster. FossilOrigin-Name: 8a1deae497edf3fa43fa96152d140405398c5ed6 --- manifest | 12 ++--- manifest.uuid | 2 +- src/vdbeaux.c | 119 ++++++++++++++++++++++++-------------------------- 3 files changed, 64 insertions(+), 69 deletions(-) diff --git a/manifest b/manifest index 1cbb37b406..e1fe265cc4 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Small\ssimplification\sand\sperformance\simprovement\sin\smemsys5Free(). -D 2016-01-25T01:07:59.493 +C Small\ssimplification\sto\sthe\sprepare\sstatement\sopcode\smemory\sreuse\slogic.\nEasier\sto\sread,\sand\sslightly\ssmaller\sand\sfaster. +D 2016-01-25T02:15:02.255 F Makefile.in 027c1603f255390c43a426671055a31c0a65fdb4 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 1708a78eda223b6daa302b140037fcc214a779f9 @@ -414,7 +414,7 @@ F src/vdbe.c b90d9d38e5e0260c2eafa3cb4c2274d8ea94da27 F src/vdbe.h 7a733ea8aac1b77305a67698e784fa3484ee3337 F src/vdbeInt.h 42eefa4f9e7432b9968d321b44e48821ec13b189 F src/vdbeapi.c ffae8f5af4570fbd548504e815e9fb7227f0822e -F src/vdbeaux.c 07f8f485a6cbc0a62da660f14e303061d45d5cb6 +F src/vdbeaux.c 757f86e6fef8efb3dd4226cb31e2e82b9c44c883 F src/vdbeblob.c 37c3d11a753e403698c69e17383d282e1ae73e75 F src/vdbemem.c b9181e77eca2a095929d46250daf85c8d2621fc0 F src/vdbesort.c 0971557e5d3c289e46f56a52aed2197c13251de7 @@ -1419,7 +1419,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P dd0100dd87e2c7c70fabb2d3188f0906e605583d -R a179bcf25d5e17fae98e7434f7b5c754 +P 0a9cff5c4822874b74e90bfca3963bc7e5c753a5 +R 5ad29c29cc49b0c7f9cd0947deba5a80 U drh -Z 6a3ae2a8bc97ab052cdf4e5d8140159f +Z 5c673e5ee459b55b04084dc37cebc110 diff --git a/manifest.uuid b/manifest.uuid index fed0f2a557..f04ce16d0b 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -0a9cff5c4822874b74e90bfca3963bc7e5c753a5 \ No newline at end of file +8a1deae497edf3fa43fa96152d140405398c5ed6 \ No newline at end of file diff --git a/src/vdbeaux.c b/src/vdbeaux.c index 17f1cb7dc4..e9be081a20 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -1721,41 +1721,43 @@ void sqlite3VdbeIOTraceSql(Vdbe *p){ } #endif /* !SQLITE_OMIT_TRACE && SQLITE_ENABLE_IOTRACE */ -/* -** Allocate space from a fixed size buffer and return a pointer to -** that space. If insufficient space is available, return NULL. +/* An instance of this object describes bulk memory available for use +** by subcomponents of a prepared statement. Space is allocated out +** of a ReusableSpace object by the allocSpace() routine below. +*/ +struct ReusableSpace { + u8 *pSpace; /* Available memory */ + int nFree; /* Bytes of available memory */ + int nNeeded; /* Total bytes that could not be allocated */ +}; + +/* Try to allocate nByte bytes of 8-byte aligned bulk memory for pBuf +** from the ReusableSpace object. Return a pointer to the allocated +** memory on success. If insufficient memory is available in the +** ReusableSpace object, increase the ReusableSpace.nNeeded +** value by the amount needed and return NULL. ** -** The pBuf parameter is the initial value of a pointer which will -** receive the new memory. pBuf is normally NULL. If pBuf is not -** NULL, it means that memory space has already been allocated and that -** this routine should not allocate any new memory. When pBuf is not -** NULL simply return pBuf. Only allocate new memory space when pBuf -** is NULL. +** If pBuf is not initially NULL, that means that the memory has already +** been allocated by a prior call to this routine, so just return a copy +** of pBuf and leave ReusableSpace unchanged. ** -** nByte is the number of bytes of space needed. -** -** pFrom points to *pnFrom bytes of available space. New space is allocated -** from the end of the pFrom buffer and *pnFrom is decremented. -** -** *pnNeeded is a counter of the number of bytes of space that have failed -** to allocate. If there is insufficient space in pFrom to satisfy the -** request, then increment *pnNeeded by the amount of the request. +** This allocator is employed to repurpose unused slots at the end of the +** opcode array of prepared state for other memory needs of the prepared +** statement. */ static void *allocSpace( - void *pBuf, /* Where return pointer will be stored */ - int nByte, /* Number of bytes to allocate */ - u8 *pFrom, /* Memory available for allocation */ - int *pnFrom, /* IN/OUT: Space available at pFrom */ - int *pnNeeded /* If allocation cannot be made, increment *pnByte */ + struct ReusableSpace *p, /* Bulk memory available for allocation */ + void *pBuf, /* Pointer to a prior allocation */ + int nByte /* Bytes of memory needed */ ){ - assert( EIGHT_BYTE_ALIGNMENT(pFrom) ); + assert( EIGHT_BYTE_ALIGNMENT(p->pSpace) ); if( pBuf==0 ){ nByte = ROUND8(nByte); - if( nByte <= *pnFrom ){ - *pnFrom -= nByte; - pBuf = &pFrom[*pnFrom]; + if( nByte <= p->nFree ){ + p->nFree -= nByte; + pBuf = &p->pSpace[p->nFree]; }else{ - *pnNeeded += nByte; + p->nNeeded += nByte; } } assert( EIGHT_BYTE_ALIGNMENT(pBuf) ); @@ -1831,9 +1833,7 @@ void sqlite3VdbeMakeReady( int nArg; /* Number of arguments in subprograms */ int nOnce; /* Number of OP_Once instructions */ int n; /* Loop counter */ - int nFree; /* Available free space */ - u8 *zCsr; /* Memory available for allocation */ - int nByte; /* How much extra memory is needed */ + struct ReusableSpace x; /* Reusable bulk memory */ assert( p!=0 ); assert( p->nOp>0 ); @@ -1851,7 +1851,7 @@ void sqlite3VdbeMakeReady( /* For each cursor required, also allocate a memory cell. Memory ** cells (nMem+1-nCursor)..nMem, inclusive, will never be used by - ** the vdbe program. Instead they are used to allocate space for + ** the vdbe program. Instead they are used to allocate memory for ** VdbeCursor/BtCursor structures. The blob of memory associated with ** cursor 0 is stored in memory cell nMem. Memory cell (nMem-1) ** stores the blob of memory associated with cursor 1, etc. @@ -1860,20 +1860,18 @@ void sqlite3VdbeMakeReady( */ nMem += nCursor; - /* zCsr will initially point to nFree bytes of unused space at the - ** end of the opcode array, p->aOp. The computation of nFree is - ** conservative - it might be smaller than the true number of free - ** bytes, but never larger. nFree must be a multiple of 8 - it is - ** rounded down if is not. + /* Figure out how much reusable memory is available at the end of the + ** opcode array. This extra memory will be reallocated for other elements + ** of the prepared statement. */ - n = ROUND8(sizeof(Op)*p->nOp); /* Bytes of opcode space used */ - zCsr = &((u8*)p->aOp)[n]; /* Unused opcode space */ - assert( EIGHT_BYTE_ALIGNMENT(zCsr) ); - nFree = ROUNDDOWN8(pParse->szOpAlloc - n); /* Bytes of unused space */ - assert( nFree>=0 ); - if( nFree>0 ){ - memset(zCsr, 0, nFree); - assert( EIGHT_BYTE_ALIGNMENT(&zCsr[nFree]) ); + n = ROUND8(sizeof(Op)*p->nOp); /* Bytes of opcode memory used */ + x.pSpace = &((u8*)p->aOp)[n]; /* Unused opcode memory */ + assert( EIGHT_BYTE_ALIGNMENT(x.pSpace) ); + x.nFree = ROUNDDOWN8(pParse->szOpAlloc - n); /* Bytes of unused memory */ + assert( x.nFree>=0 ); + if( x.nFree>0 ){ + memset(x.pSpace, 0, x.nFree); + assert( EIGHT_BYTE_ALIGNMENT(&x.pSpace[x.nFree]) ); } resolveP2Values(p, &nArg); @@ -1883,33 +1881,30 @@ void sqlite3VdbeMakeReady( } p->expired = 0; - /* Memory for registers, parameters, cursor, etc, is allocated in two - ** passes. On the first pass, we try to reuse unused space at the + /* Memory for registers, parameters, cursor, etc, is allocated in one or two + ** passes. On the first pass, we try to reuse unused memory at the ** end of the opcode array. If we are unable to satisfy all memory ** requirements by reusing the opcode array tail, then the second - ** pass will fill in the rest using a fresh allocation. + ** pass will fill in the remainder using a fresh memory allocation. ** ** This two-pass approach that reuses as much memory as possible from - ** the leftover space at the end of the opcode array can significantly + ** the leftover memory at the end of the opcode array. This can significantly ** reduce the amount of memory held by a prepared statement. */ do { - nByte = 0; - p->aMem = allocSpace(p->aMem, nMem*sizeof(Mem), zCsr, &nFree, &nByte); - p->aVar = allocSpace(p->aVar, nVar*sizeof(Mem), zCsr, &nFree, &nByte); - p->apArg = allocSpace(p->apArg, nArg*sizeof(Mem*), zCsr, &nFree, &nByte); - p->apCsr = allocSpace(p->apCsr, nCursor*sizeof(VdbeCursor*), - zCsr, &nFree, &nByte); - p->aOnceFlag = allocSpace(p->aOnceFlag, nOnce, zCsr, &nFree, &nByte); + x.nNeeded = 0; + p->aMem = allocSpace(&x, p->aMem, nMem*sizeof(Mem)); + p->aVar = allocSpace(&x, p->aVar, nVar*sizeof(Mem)); + p->apArg = allocSpace(&x, p->apArg, nArg*sizeof(Mem*)); + p->apCsr = allocSpace(&x, p->apCsr, nCursor*sizeof(VdbeCursor*)); + p->aOnceFlag = allocSpace(&x, p->aOnceFlag, nOnce); #ifdef SQLITE_ENABLE_STMT_SCANSTATUS - p->anExec = allocSpace(p->anExec, p->nOp*sizeof(i64), zCsr, &nFree, &nByte); + p->anExec = allocSpace(&x, p->anExec, p->nOp*sizeof(i64)); #endif - if( nByte ){ - p->pFree = sqlite3DbMallocZero(db, nByte); - } - zCsr = p->pFree; - nFree = nByte; - }while( nByte && !db->mallocFailed ); + if( x.nNeeded==0 ) break; + x.pSpace = p->pFree = sqlite3DbMallocZero(db, x.nNeeded); + x.nFree = x.nNeeded; + }while( !db->mallocFailed ); p->nCursor = nCursor; p->nOnceFlag = nOnce; From 164c957b091ed8fb0b875481556e9e7d882d11a2 Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 25 Jan 2016 13:55:47 +0000 Subject: [PATCH 32/75] Add the SQLITE_EXTRA_DURABLE compile-time option. FossilOrigin-Name: 30671345b1c1ee55a2d1aa17273213f1849efd81 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/pager.c | 17 ++++++++++++++++- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index e1fe265cc4..69e58459fa 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Small\ssimplification\sto\sthe\sprepare\sstatement\sopcode\smemory\sreuse\slogic.\nEasier\sto\sread,\sand\sslightly\ssmaller\sand\sfaster. -D 2016-01-25T02:15:02.255 +C Add\sthe\sSQLITE_EXTRA_DURABLE\scompile-time\soption. +D 2016-01-25T13:55:47.049 F Makefile.in 027c1603f255390c43a426671055a31c0a65fdb4 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 1708a78eda223b6daa302b140037fcc214a779f9 @@ -332,7 +332,7 @@ F src/os_setup.h c9d4553b5aaa6f73391448b265b89bed0b890faa F src/os_unix.c 0eb7f469fcd4e1fbedf30060438e26b839ec5486 F src/os_win.c 386fba30419e8458b13209781c2af5590eab2811 F src/os_win.h eb7a47aa17b26b77eb97e4823f20a00b8bda12ca -F src/pager.c f4e9ac39fbb1e0fde97af85c0f4e00eb90764b67 +F src/pager.c 2916c66aee50f69d9ec56a7619b62d9c6a3bee61 F src/pager.h 1c2a49143dfba9e69cc8159ef019f472ed8d260b F src/parse.y caad1e98edeca6960493d0c60d31b76820dd7776 F src/pcache.c 73895411fa6b7bd6f0091212feabbe833b358d23 @@ -1419,7 +1419,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 0a9cff5c4822874b74e90bfca3963bc7e5c753a5 -R 5ad29c29cc49b0c7f9cd0947deba5a80 +P 8a1deae497edf3fa43fa96152d140405398c5ed6 +R ae4ccddaf3c593cdf1ed2beb484cfd15 U drh -Z 5c673e5ee459b55b04084dc37cebc110 +Z 297086babbdf85e61ae58e42a437c1ec diff --git a/manifest.uuid b/manifest.uuid index f04ce16d0b..439be2e5fa 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -8a1deae497edf3fa43fa96152d140405398c5ed6 \ No newline at end of file +30671345b1c1ee55a2d1aa17273213f1849efd81 \ No newline at end of file diff --git a/src/pager.c b/src/pager.c index 2c904d2df1..0afbe215c6 100644 --- a/src/pager.c +++ b/src/pager.c @@ -428,6 +428,20 @@ int sqlite3PagerTrace=1; /* True to enable tracing */ */ #define MAX_SECTOR_SIZE 0x10000 +/* +** If the option SQLITE_EXTRA_DURABLE option is set at compile-time, then +** SQLite will do extra fsync() operations when synchronous==FULL to help +** ensure that transactions are durable across a power failure. Most +** applications are happy as long as transactions are consistent across +** a power failure, and are perfectly willing to lose the last transaction +** in exchange for the extra performance of avoiding directory syncs. +** And so the default SQLITE_EXTRA_DURABLE setting is off. +*/ +#ifndef SQLITE_EXTRA_DURABLE +# define SQLITE_EXTRA_DURABLE 0 +#endif + + /* ** An instance of the following structure is allocated for each active ** savepoint and statement transaction in the system. All such structures @@ -1983,7 +1997,8 @@ static int pager_end_transaction(Pager *pPager, int hasMaster, int bCommit){ ); sqlite3OsClose(pPager->jfd); if( bDelete ){ - rc = sqlite3OsDelete(pPager->pVfs, pPager->zJournal, 0); + rc = sqlite3OsDelete(pPager->pVfs, pPager->zJournal, + pPager->fullSync && SQLITE_EXTRA_DURABLE); } } } From cc2fa4cf5599637bdb8f5a2cc64f0805243e04e4 Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 25 Jan 2016 15:57:29 +0000 Subject: [PATCH 33/75] Replace the OP_SetIfNotPos operator with OP_OffsetLimit in the VDBE, for simpler and smaller code. FossilOrigin-Name: 7ac017a498b6fb28343eef2d24e400c7800660d6 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/select.c | 9 +++------ src/vdbe.c | 33 ++++++++++++++++++++++----------- 4 files changed, 33 insertions(+), 25 deletions(-) diff --git a/manifest b/manifest index 69e58459fa..827a3d5126 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sthe\sSQLITE_EXTRA_DURABLE\scompile-time\soption. -D 2016-01-25T13:55:47.049 +C Replace\sthe\sOP_SetIfNotPos\soperator\swith\sOP_OffsetLimit\sin\sthe\sVDBE,\sfor\nsimpler\sand\ssmaller\scode. +D 2016-01-25T15:57:29.060 F Makefile.in 027c1603f255390c43a426671055a31c0a65fdb4 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 1708a78eda223b6daa302b140037fcc214a779f9 @@ -345,7 +345,7 @@ F src/printf.c af589a27b7d40f6f4f704e9eea99f02f18ad6d32 F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c 9f7ce3a3c087afb7597b7c916c99126ff3f12f0c F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e -F src/select.c 1db9a902e89201a0ae3ff5243a7a3f37842a3937 +F src/select.c c34292c8ce7fe69c7cf890d933834a22572bd301 F src/shell.c dcd7a83645ef2a58ee9c6d0ea4714d877d7835c4 F src/sqlite.h.in 214476a62012e578f42133a9a3b4f97a9aa421a3 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 @@ -410,7 +410,7 @@ F src/update.c 17332f9fe818cbc0444c36a811800af8498af4c3 F src/utf.c 32d7f82aa921322f3e1c956f4b58f019ebd2c6b3 F src/util.c 72d40df0a52d3f30b462a15f0e094fcbade6dc82 F src/vacuum.c 2ddd5cad2a7b9cef7f9e431b8c7771634c6b1701 -F src/vdbe.c b90d9d38e5e0260c2eafa3cb4c2274d8ea94da27 +F src/vdbe.c 3ffbcc413bf793e3f0b95b79ef2f4bd449a5b5a3 F src/vdbe.h 7a733ea8aac1b77305a67698e784fa3484ee3337 F src/vdbeInt.h 42eefa4f9e7432b9968d321b44e48821ec13b189 F src/vdbeapi.c ffae8f5af4570fbd548504e815e9fb7227f0822e @@ -1419,7 +1419,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 8a1deae497edf3fa43fa96152d140405398c5ed6 -R ae4ccddaf3c593cdf1ed2beb484cfd15 +P 30671345b1c1ee55a2d1aa17273213f1849efd81 +R f342889ba3409bd63b1cf54d88bfe0e2 U drh -Z 297086babbdf85e61ae58e42a437c1ec +Z e7c5fc86067d4269675714897cec0b51 diff --git a/manifest.uuid b/manifest.uuid index 439be2e5fa..276ef7a03f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -30671345b1c1ee55a2d1aa17273213f1849efd81 \ No newline at end of file +7ac017a498b6fb28343eef2d24e400c7800660d6 \ No newline at end of file diff --git a/src/select.c b/src/select.c index ffc0ec2415..ea4298e677 100644 --- a/src/select.c +++ b/src/select.c @@ -1860,10 +1860,8 @@ static void computeLimitRegisters(Parse *pParse, Select *p, int iBreak){ sqlite3ExprCode(pParse, p->pOffset, iOffset); sqlite3VdbeAddOp1(v, OP_MustBeInt, iOffset); VdbeCoverage(v); VdbeComment((v, "OFFSET counter")); - sqlite3VdbeAddOp3(v, OP_SetIfNotPos, iOffset, iOffset, 0); - sqlite3VdbeAddOp3(v, OP_Add, iLimit, iOffset, iOffset+1); + sqlite3VdbeAddOp3(v, OP_OffsetLimit, iLimit, iOffset+1, iOffset); VdbeComment((v, "LIMIT+OFFSET")); - sqlite3VdbeAddOp3(v, OP_SetIfNotPos, iLimit, iOffset+1, -1); } } } @@ -2280,9 +2278,8 @@ static int multiSelect( addr = sqlite3VdbeAddOp1(v, OP_IfNot, p->iLimit); VdbeCoverage(v); VdbeComment((v, "Jump ahead if LIMIT reached")); if( p->iOffset ){ - sqlite3VdbeAddOp3(v, OP_SetIfNotPos, p->iOffset, p->iOffset, 0); - sqlite3VdbeAddOp3(v, OP_Add, p->iLimit, p->iOffset, p->iOffset+1); - sqlite3VdbeAddOp3(v, OP_SetIfNotPos, p->iLimit, p->iOffset+1, -1); + sqlite3VdbeAddOp3(v, OP_OffsetLimit, + p->iLimit, p->iOffset+1, p->iOffset); } } explainSetInteger(iSub2, pParse->iNextSelectId); diff --git a/src/vdbe.c b/src/vdbe.c index c6d5f7b0cc..cfff895c30 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -5757,20 +5757,31 @@ case OP_IfPos: { /* jump, in1 */ break; } -/* Opcode: SetIfNotPos P1 P2 P3 * * -** Synopsis: if r[P1]<=0 then r[P2]=P3 +/* Opcode: OffsetLimit P1 P2 P3 * * +** Synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) ** -** Register P1 must contain an integer. -** If the value of register P1 is not positive (if it is less than 1) then -** set the value of register P2 to be the integer P3. +** This opcode performs a commonly used computation associated with +** LIMIT and OFFSET process. r[P1] holds the limit counter. r[P3] +** holds the offset counter. The opcode computes the combined value +** of the LIMIT and OFFSET and stores that value in r[P2]. The r[P2] +** value computed is the total number of rows that will need to be +** visited in order to complete the query. +** +** If r[P3] is zero or negative, that means there is no OFFSET +** and r[P2] is set to be the value of the LIMIT, r[P1]. +** +** if r[P1] is zero or negative, that means there is no LIMIT +** and r[P2] is set to -1. +** +** Otherwise, r[P2] is set to the sum of r[P1] and r[P3]. */ -case OP_SetIfNotPos: { /* in1, in2 */ +case OP_OffsetLimit: { /* in1, out2, in3 */ pIn1 = &aMem[pOp->p1]; - assert( pIn1->flags&MEM_Int ); - if( pIn1->u.i<=0 ){ - pOut = out2Prerelease(p, pOp); - pOut->u.i = pOp->p3; - } + pIn3 = &aMem[pOp->p3]; + pOut = out2Prerelease(p, pOp); + assert( pIn1->flags & MEM_Int ); + assert( pIn3->flags & MEM_Int ); + pOut->u.i = pIn1->u.i<=0 ? -1 : pIn1->u.i+(pIn3->u.i>0?pIn3->u.i:0); break; } From e88ec187cdd590f7b9155cef3ee276c268a4a522 Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 25 Jan 2016 17:04:48 +0000 Subject: [PATCH 34/75] Fix issues on unix with opening database files via symlinks that are not in the current working directory. And with nested symlinks. FossilOrigin-Name: 80398fd44fb232193450103808e1854e0eba5652 --- manifest | 19 +++--- manifest.uuid | 2 +- src/os_unix.c | 154 +++++++++++++++++++++++++++++++++------------- test/symlink.test | 119 ++++++++++++++++++++++++++--------- 4 files changed, 215 insertions(+), 79 deletions(-) diff --git a/manifest b/manifest index 827a3d5126..0b395a1661 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Replace\sthe\sOP_SetIfNotPos\soperator\swith\sOP_OffsetLimit\sin\sthe\sVDBE,\sfor\nsimpler\sand\ssmaller\scode. -D 2016-01-25T15:57:29.060 +C Fix\sissues\son\sunix\swith\sopening\sdatabase\sfiles\svia\ssymlinks\sthat\sare\snot\sin\sthe\scurrent\sworking\sdirectory.\sAnd\swith\snested\ssymlinks. +D 2016-01-25T17:04:48.546 F Makefile.in 027c1603f255390c43a426671055a31c0a65fdb4 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 1708a78eda223b6daa302b140037fcc214a779f9 @@ -329,7 +329,7 @@ F src/os.c 8fd25588eeba74068d41102d26810e216999b6c8 F src/os.h 3e57a24e2794a94d3cf2342c6d9a884888cd96bf F src/os_common.h abdb9a191a367793268fe553d25bab894e986a0e F src/os_setup.h c9d4553b5aaa6f73391448b265b89bed0b890faa -F src/os_unix.c 0eb7f469fcd4e1fbedf30060438e26b839ec5486 +F src/os_unix.c cf524029242b4f878d6b97bad25cc2c0b66c2b31 F src/os_win.c 386fba30419e8458b13209781c2af5590eab2811 F src/os_win.h eb7a47aa17b26b77eb97e4823f20a00b8bda12ca F src/pager.c 2916c66aee50f69d9ec56a7619b62d9c6a3bee61 @@ -1061,7 +1061,7 @@ F test/subselect.test d24fd8757daf97dafd2e889c73ea4c4272dcf4e4 F test/substr.test 18f57c4ca8a598805c4d64e304c418734d843c1a F test/subtype1.test 7fe09496352f97053af1437150751be2d0a0cae8 F test/superlock.test 1cde669f68d2dd37d6c9bd35eee1d95491ae3fc2 -F test/symlink.test cbf6cb8c6c4b63a39e9f0f6b0d5c99e249dbc102 +F test/symlink.test 511db82662446bb0d3619002422760ef8e4b1122 F test/sync.test a34cd43e98b7fb84eabbf38f7ed8f7349b3f3d85 F test/syscall.test 2aa9e111b79fb385681ff8940124def6f8faab87 F test/sysfault.test c9f2b0d8d677558f74de750c75e12a5454719d04 @@ -1419,7 +1419,10 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 30671345b1c1ee55a2d1aa17273213f1849efd81 -R f342889ba3409bd63b1cf54d88bfe0e2 -U drh -Z e7c5fc86067d4269675714897cec0b51 +P 7ac017a498b6fb28343eef2d24e400c7800660d6 +R 0289127606d03bb3b649ecbd39bb14a5 +T *branch * follow-symlinks +T *sym-follow-symlinks * +T -sym-trunk * +U dan +Z 3e18b3d01ba737d3635110839e378935 diff --git a/manifest.uuid b/manifest.uuid index 276ef7a03f..6dda1af216 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -7ac017a498b6fb28343eef2d24e400c7800660d6 \ No newline at end of file +80398fd44fb232193450103808e1854e0eba5652 \ No newline at end of file diff --git a/src/os_unix.c b/src/os_unix.c index ee9b55674b..9cd1fa19ad 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -149,6 +149,11 @@ */ #define MAX_PATHNAME 512 +/* +** Maximum supported symbolic links +*/ +#define SQLITE_MAX_SYMLINKS 100 + /* Always cast the getpid() return type for compatibility with ** kernel modules in VxWorks. */ #define osGetpid(X) (pid_t)getpid() @@ -5927,52 +5932,22 @@ static int unixAccess( return SQLITE_OK; } - /* -** Turn a relative pathname into a full pathname. The relative path -** is stored as a nul-terminated string in the buffer pointed to by -** zPath. +** Buffer zOut contains a (possibly) relative pathname. Overwrite it with +** the corresponding full pathname. ** -** zOut points to a buffer of at least sqlite3_vfs.mxPathname bytes -** (in this case, MAX_PATHNAME bytes). The full-path is written to -** this buffer before returning. +** Parameter nOut is the allocated size of buffer zOut. nByte is the number +** of bytes in the nul-terminated string that it contains (not including +** the nul-terminator itself). +** +** Return SQLITE_OK if successful, or an SQLite error code otherwise. */ -static int unixFullPathname( - sqlite3_vfs *pVfs, /* Pointer to vfs object */ - const char *zPath, /* Possibly relative input path */ - int nOut, /* Size of output buffer in bytes */ - char *zOut /* Output buffer */ +static int mkFullPathname( + const char *zPath, /* Use this path to log any errors */ + char *zOut, /* IN/OUT: Buffer to modify */ + int nByte, /* size of nul-terminated zOut in bytes */ + int nOut /* Allocated size of buffer zOut */ ){ - int nByte; - - /* It's odd to simulate an io-error here, but really this is just - ** using the io-error infrastructure to test that SQLite handles this - ** function failing. This function could fail if, for example, the - ** current working directory has been unlinked. - */ - SimulateIOError( return SQLITE_ERROR ); - - assert( pVfs->mxPathname==MAX_PATHNAME ); - UNUSED_PARAMETER(pVfs); - -#if defined(HAVE_READLINK) - /* Attempt to resolve the path as if it were a symbolic link. If it is - ** a symbolic link, the resolved path is stored in buffer zOut[]. Or, if - ** the identified file is not a symbolic link or does not exist, then - ** zPath is copied directly into zOut. Either way, nByte is left set to - ** the size of the string copied into zOut[] in bytes. */ - nByte = osReadlink(zPath, zOut, nOut-1); - if( nByte<0 ){ - if( errno!=EINVAL && errno!=ENOENT ){ - return unixLogError(SQLITE_CANTOPEN_BKPT, "readlink", zPath); - } - sqlite3_snprintf(nOut, zOut, "%s", zPath); - nByte = sqlite3Strlen30(zOut); - }else{ - zOut[nByte] = '\0'; - } -#endif - /* If buffer zOut[] now contains an absolute path there is nothing more ** to do. If it contains a relative path, do the following: ** @@ -5989,6 +5964,7 @@ static int unixFullPathname( ** truncated to make it fit. This is Ok, as SQLite refuses to open any ** file for which this function returns a full path larger than (nOut-8) ** bytes in size. */ + assert( nBytemxPathname==MAX_PATHNAME ); + UNUSED_PARAMETER(pVfs); + + /* It's odd to simulate an io-error here, but really this is just + ** using the io-error infrastructure to test that SQLite handles this + ** function failing. This function could fail if, for example, the + ** current working directory has been unlinked. + */ + SimulateIOError( return SQLITE_ERROR ); + + do { + + /* Attempt to resolve the path as if it were a symbolic link. If it is + ** a symbolic link, the resolved path is stored in buffer zOut[]. Or, if + ** the identified file is not a symbolic link or does not exist, then + ** zPath is copied directly into zOut. Either way, nByte is left set to + ** the size of the string copied into zOut[] in bytes. */ + assert( (zDel==0 && zIn==zPath) || (zDel!=0 && zIn==zDel) ); + if( zDel ){ + assert( zIn==zDel ); + sqlite3_snprintf(nOut, zDel, "%s", zOut); + } + nByte = osReadlink(zIn, zOut, nOut-1); + if( nByte<0 ){ + if( errno!=EINVAL && errno!=ENOENT ){ + rc = unixLogError(SQLITE_CANTOPEN_BKPT, "readlink", zPath); + }else{ + sqlite3_snprintf(nOut, zOut, "%s", zIn); + nByte = sqlite3Strlen30(zOut); + } + bLink = 0; + }else if( ++nLink>SQLITE_MAX_SYMLINKS ){ + sqlite3_log(SQLITE_CANTOPEN, + "too many symbolic links (max=%d)", SQLITE_MAX_SYMLINKS + ); + rc = SQLITE_CANTOPEN_BKPT; + }else{ + zOut[nByte] = '\0'; + if( zOut[0]!='/' ){ + int n; + for(n = sqlite3Strlen30(zIn); n>0 && zIn[n-1]!='/'; n--); + if( nByte+n+1>nOut ){ + rc = SQLITE_CANTOPEN_BKPT; + }else{ + memmove(&zOut[n], zOut, nByte+1); + memcpy(zOut, zIn, n); + nByte += n; + } + } + if( zDel==0 ){ + zDel = sqlite3_malloc(nOut); + if( zDel==0 ) rc = SQLITE_NOMEM; + zIn = (const char*)zDel; + } + bLink = 1; + } + + if( rc==SQLITE_OK ){ + rc = mkFullPathname(zPath, zOut, nByte, nOut); + } + }while( bLink && rc==SQLITE_OK ); + + sqlite3_free(zDel); + return rc; +#endif /* HAVE_READLINK */ +} + #ifndef SQLITE_OMIT_LOAD_EXTENSION /* diff --git a/test/symlink.test b/test/symlink.test index 790624161f..e9e5f3c305 100644 --- a/test/symlink.test +++ b/test/symlink.test @@ -83,38 +83,49 @@ do_test 1.5 { do_test 2.0 { catch { db close } catch { db2 close } - forcedelete test.db test.db2 + forcedelete test.db test.db2 test.db3 sqlite3 db test.db execsql { CREATE TABLE t1(x) } file link test.db2 test.db - sqlite3 db2 test.db2 - file exists test.db-journal -} 0 + file link test.db3 test.db2 + set {} {} +} {} -do_test 2.1 { - execsql { - BEGIN; - INSERT INTO t1 VALUES(1); - } db2 - file exists test.db-journal -} 1 -do_test 2.2 { - file exists test.db2-journal -} 0 -do_test 2.3 { - execsql { - COMMIT; - PRAGMA journal_mode = wal; - INSERT INTO t1 VALUES(2); - } db2 - file exists test.db-wal -} 1 -do_test 2.4 { - file exists test.db2-wal -} 0 -do_execsql_test 2.5 { - SELECT * FROM t1; -} {1 2} +foreach {tn f} {1 test.db2 2 test.db3} { + do_test 2.$tn.1 { + sqlite3 db2 $f + file exists test.db-journal + } 0 + do_test 2.$tn.2 { + execsql { + BEGIN; + INSERT INTO t1 VALUES(1); + } db2 + file exists test.db-journal + } 1 + do_test 2.$tn.3 { + list [file exists test2.db-journal] [file exists test3.db-journal] + } {0 0} + do_test 2.$tn.4 { + execsql { + COMMIT; + PRAGMA journal_mode = wal; + INSERT INTO t1 VALUES(2); + } db2 + file exists test.db-wal + } 1 + do_test 2.$tn.5 { + list [file exists test2.db-wal] [file exists test3.db-wal] + } {0 0} + do_execsql_test 2.$tn.6 { + SELECT * FROM t1; + } {1 2} + db2 close + do_execsql_test 2.$tn.7 { + DELETE FROM t1; + PRAGMA journal_mode = delete; + } delete +} # Try to open a ridiculously long pathname. Bug found by # Kostya Serebryany using libFuzzer on 2015-11-30. @@ -125,5 +136,57 @@ do_test 3.1 { set res } {unable to open database file} +#------------------------------------------------------------------------- +# Test that relative symlinks that are not located in the cwd work. +# +do_test 4.1 { + forcedelete x y z + file mkdir x + file mkdir y + file mkdir z + sqlite3 db x/test.db + file link y/test.db ../x/test.db + file link z/test.db ../y/test.db + execsql { + PRAGMA journal_mode = wal; + CREATE TABLE t1(x, y); + INSERT INTO t1 VALUES('hello', 'world'); + } +} {wal} + +do_test 4.2.1 { + db close + sqlite3 db y/test.db + db eval { SELECT * FROM t1 } +} {hello world} +do_test 4.2.2 { + list [file exists x/test.db-wal] [file exists y/test.db-wal] +} {1 0} + +do_test 4.3.1 { + db close + sqlite3 db z/test.db + db eval { SELECT * FROM t1 } +} {hello world} +do_test 4.3.2 { + list [file exists x/test.db-wal] [file exists y/test.db-wal] \ + [file exists z/test.db-wal] +} {1 0 0} + +do_test 4.4.0 { + forcedelete w + file mkdir w + file link w/test.db [file join [pwd] x/test.db] + set {} {} +} {} +do_test 4.4.1 { + db close + breakpoint + sqlite3 db w/test.db + db eval { SELECT * FROM t1 } +} {hello world} +do_test 4.4.2 { + list [file exists x/test.db-wal] [file exists w/test.db-wal] +} {1 0} finish_test From caf6b150a1077f2d4293b4091247c7e932da3927 Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 25 Jan 2016 18:05:49 +0000 Subject: [PATCH 35/75] Simplify the unixFullpathname() function. This adds a dependency on lstat(). FossilOrigin-Name: f71249d3db9242b8f38955db51a7a5789d002803 --- manifest | 15 +++--- manifest.uuid | 2 +- src/os_unix.c | 137 +++++++++++++++++++------------------------------- 3 files changed, 60 insertions(+), 94 deletions(-) diff --git a/manifest b/manifest index 0b395a1661..27188d419f 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sissues\son\sunix\swith\sopening\sdatabase\sfiles\svia\ssymlinks\sthat\sare\snot\sin\sthe\scurrent\sworking\sdirectory.\sAnd\swith\snested\ssymlinks. -D 2016-01-25T17:04:48.546 +C Simplify\sthe\sunixFullpathname()\sfunction.\sThis\sadds\sa\sdependency\son\slstat(). +D 2016-01-25T18:05:49.964 F Makefile.in 027c1603f255390c43a426671055a31c0a65fdb4 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 1708a78eda223b6daa302b140037fcc214a779f9 @@ -329,7 +329,7 @@ F src/os.c 8fd25588eeba74068d41102d26810e216999b6c8 F src/os.h 3e57a24e2794a94d3cf2342c6d9a884888cd96bf F src/os_common.h abdb9a191a367793268fe553d25bab894e986a0e F src/os_setup.h c9d4553b5aaa6f73391448b265b89bed0b890faa -F src/os_unix.c cf524029242b4f878d6b97bad25cc2c0b66c2b31 +F src/os_unix.c 6604e7f9e5298b615f729b6bb3c22bd3545cdca6 F src/os_win.c 386fba30419e8458b13209781c2af5590eab2811 F src/os_win.h eb7a47aa17b26b77eb97e4823f20a00b8bda12ca F src/pager.c 2916c66aee50f69d9ec56a7619b62d9c6a3bee61 @@ -1419,10 +1419,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 7ac017a498b6fb28343eef2d24e400c7800660d6 -R 0289127606d03bb3b649ecbd39bb14a5 -T *branch * follow-symlinks -T *sym-follow-symlinks * -T -sym-trunk * +P 80398fd44fb232193450103808e1854e0eba5652 +R 084dee05e1353887f6af0d88670b22d0 U dan -Z 3e18b3d01ba737d3635110839e378935 +Z 72572e009a3ce3b7747f3257ebf7dfc7 diff --git a/manifest.uuid b/manifest.uuid index 6dda1af216..b66c39a6ae 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -80398fd44fb232193450103808e1854e0eba5652 \ No newline at end of file +f71249d3db9242b8f38955db51a7a5789d002803 \ No newline at end of file diff --git a/src/os_unix.c b/src/os_unix.c index 9cd1fa19ad..3d113301b8 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -480,6 +480,8 @@ static struct unix_syscall { #endif #define osReadlink ((ssize_t(*)(const char*,char*,size_t))aSyscall[26].pCurrent) + { "lstat", (sqlite3_syscall_ptr)lstat, 0 }, +#define osLstat ((int(*)(const char*,struct stat*))aSyscall[27].pCurrent) }; /* End of the overrideable system calls */ @@ -5933,54 +5935,24 @@ static int unixAccess( } /* -** Buffer zOut contains a (possibly) relative pathname. Overwrite it with -** the corresponding full pathname. ** -** Parameter nOut is the allocated size of buffer zOut. nByte is the number -** of bytes in the nul-terminated string that it contains (not including -** the nul-terminator itself). -** -** Return SQLITE_OK if successful, or an SQLite error code otherwise. */ static int mkFullPathname( - const char *zPath, /* Use this path to log any errors */ - char *zOut, /* IN/OUT: Buffer to modify */ - int nByte, /* size of nul-terminated zOut in bytes */ + const char *zPath, /* Input path */ + char *zOut, /* Output buffer */ int nOut /* Allocated size of buffer zOut */ ){ - /* If buffer zOut[] now contains an absolute path there is nothing more - ** to do. If it contains a relative path, do the following: - ** - ** * move the relative path string so that it is at the end of th - ** zOut[] buffer. - ** * Call getcwd() to read the path of the current working directory - ** into the start of the zOut[] buffer. - ** * Append a '/' character to the cwd string and move the - ** relative path back within the buffer so that it immediately - ** follows the '/'. - ** - ** This code is written so that if the combination of the CWD and relative - ** path are larger than the allocated size of zOut[] the CWD is silently - ** truncated to make it fit. This is Ok, as SQLite refuses to open any - ** file for which this function returns a full path larger than (nOut-8) - ** bytes in size. */ - assert( nBytenOut ) return SQLITE_CANTOPEN_BKPT; + sqlite3_snprintf(nOut-iOff, &zOut[iOff], "%s", zPath); return SQLITE_OK; } @@ -6000,13 +5972,11 @@ static int unixFullPathname( char *zOut /* Output buffer */ ){ #if !defined(HAVE_READLINK) - sqlite3_snprintf(nOut, zOut, "%s", zIn); - nByte = sqlite3Strlen30(zOut); - return mkFullPathname(zPath, zOut, sqlite3Strlen30(zOut), nOut); + return mkFullPathname(zPath, zOut, nOut); #else int rc = SQLITE_OK; int nByte; - int nLink = 0; /* Number of symbolic links followed so far */ + int nLink = 1; /* Number of symbolic links followed so far */ int bLink; /* True for a symbolic link */ const char *zIn = zPath; /* Input path for each iteration of loop */ char *zDel = 0; @@ -6023,55 +5993,54 @@ static int unixFullPathname( do { - /* Attempt to resolve the path as if it were a symbolic link. If it is - ** a symbolic link, the resolved path is stored in buffer zOut[]. Or, if - ** the identified file is not a symbolic link or does not exist, then - ** zPath is copied directly into zOut. Either way, nByte is left set to - ** the size of the string copied into zOut[] in bytes. */ - assert( (zDel==0 && zIn==zPath) || (zDel!=0 && zIn==zDel) ); - if( zDel ){ - assert( zIn==zDel ); - sqlite3_snprintf(nOut, zDel, "%s", zOut); - } - nByte = osReadlink(zIn, zOut, nOut-1); - if( nByte<0 ){ - if( errno!=EINVAL && errno!=ENOENT ){ - rc = unixLogError(SQLITE_CANTOPEN_BKPT, "readlink", zPath); - }else{ - sqlite3_snprintf(nOut, zOut, "%s", zIn); - nByte = sqlite3Strlen30(zOut); + /* Call stat() on path zIn. Set bLink to true if the path is a symbolic + ** link, or false otherwise. */ + int bLink = 0; + struct stat buf; + if( osLstat(zIn, &buf)!=0 ){ + if( errno!=ENOENT ){ + rc = unixLogError(SQLITE_CANTOPEN_BKPT, "stat", zIn); } - bLink = 0; - }else if( ++nLink>SQLITE_MAX_SYMLINKS ){ - sqlite3_log(SQLITE_CANTOPEN, - "too many symbolic links (max=%d)", SQLITE_MAX_SYMLINKS - ); - rc = SQLITE_CANTOPEN_BKPT; }else{ - zOut[nByte] = '\0'; - if( zOut[0]!='/' ){ - int n; - for(n = sqlite3Strlen30(zIn); n>0 && zIn[n-1]!='/'; n--); - if( nByte+n+1>nOut ){ - rc = SQLITE_CANTOPEN_BKPT; - }else{ - memmove(&zOut[n], zOut, nByte+1); - memcpy(zOut, zIn, n); - nByte += n; - } - } + bLink = S_ISLNK(buf.st_mode); + } + + if( bLink ){ if( zDel==0 ){ zDel = sqlite3_malloc(nOut); if( zDel==0 ) rc = SQLITE_NOMEM; - zIn = (const char*)zDel; + }else if( ++nLink>SQLITE_MAX_SYMLINKS ){ + rc = SQLITE_CANTOPEN_BKPT; } - bLink = 1; + + if( rc==SQLITE_OK ){ + nByte = osReadlink(zIn, zDel, nOut-1); + if( nByte<0 ){ + rc = unixLogError(SQLITE_CANTOPEN_BKPT, "readlink", zIn); + }else if( zDel[0]!='/' ){ + int n; + for(n = sqlite3Strlen30(zIn); n>0 && zIn[n-1]!='/'; n--); + if( nByte+n+1>nOut ){ + rc = SQLITE_CANTOPEN_BKPT; + }else{ + memmove(&zDel[n], zDel, nByte+1); + memcpy(zDel, zIn, n); + nByte += n; + } + zDel[nByte] = '\0'; + } + } + + zIn = zDel; } if( rc==SQLITE_OK ){ - rc = mkFullPathname(zPath, zOut, nByte, nOut); + assert( zIn!=zOut || zIn[0]=='/' ); + rc = mkFullPathname(zIn, zOut, nOut); } - }while( bLink && rc==SQLITE_OK ); + if( bLink==0 ) break; + zIn = zOut; + }while( rc==SQLITE_OK ); sqlite3_free(zDel); return rc; @@ -7574,7 +7543,7 @@ int sqlite3_os_init(void){ /* Double-check that the aSyscall[] array has been constructed ** correctly. See ticket [bb3a86e890c8e96ab] */ - assert( ArraySize(aSyscall)==27 ); + assert( ArraySize(aSyscall)==28 ); /* Register all VFSes defined in the aVfs[] array */ for(i=0; i<(sizeof(aVfs)/sizeof(sqlite3_vfs)); i++){ From af1b36b1df592aa8ecf1fd8799db7e415688ed6e Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 25 Jan 2016 18:43:05 +0000 Subject: [PATCH 36/75] Only use lstat() if the HAVE_LSTAT macro is defined. Fix some test file issues. FossilOrigin-Name: 8a6e4147a680ad6c5fdd588468b6daac82349d2c --- manifest | 18 +++++++++--------- manifest.uuid | 2 +- src/os_unix.c | 12 ++++++++---- src/vxworks.h | 1 + test/oserror.test | 2 +- test/syscall.test | 2 +- 6 files changed, 21 insertions(+), 16 deletions(-) diff --git a/manifest b/manifest index 27188d419f..33b8dc8b5c 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Simplify\sthe\sunixFullpathname()\sfunction.\sThis\sadds\sa\sdependency\son\slstat(). -D 2016-01-25T18:05:49.964 +C Only\suse\slstat()\sif\sthe\sHAVE_LSTAT\smacro\sis\sdefined.\sFix\ssome\stest\sfile\sissues. +D 2016-01-25T18:43:05.007 F Makefile.in 027c1603f255390c43a426671055a31c0a65fdb4 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 1708a78eda223b6daa302b140037fcc214a779f9 @@ -329,7 +329,7 @@ F src/os.c 8fd25588eeba74068d41102d26810e216999b6c8 F src/os.h 3e57a24e2794a94d3cf2342c6d9a884888cd96bf F src/os_common.h abdb9a191a367793268fe553d25bab894e986a0e F src/os_setup.h c9d4553b5aaa6f73391448b265b89bed0b890faa -F src/os_unix.c 6604e7f9e5298b615f729b6bb3c22bd3545cdca6 +F src/os_unix.c 4c217111d7bdebbd7a9b47cf11f434420da432e7 F src/os_win.c 386fba30419e8458b13209781c2af5590eab2811 F src/os_win.h eb7a47aa17b26b77eb97e4823f20a00b8bda12ca F src/pager.c 2916c66aee50f69d9ec56a7619b62d9c6a3bee61 @@ -420,7 +420,7 @@ F src/vdbemem.c b9181e77eca2a095929d46250daf85c8d2621fc0 F src/vdbesort.c 0971557e5d3c289e46f56a52aed2197c13251de7 F src/vdbetrace.c 8befe829faff6d9e6f6e4dee5a7d3f85cc85f1a0 F src/vtab.c 320682cca733115b4cbe71320b5c5eeb1074ebde -F src/vxworks.h 974e7d9a98f602d6310d563e1dc4e08f9fc48e47 +F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9 F src/wal.c d21b99fd1458159d0b1ecdccc8ee6ada4fdc4c54 F src/wal.h 2f7c831cf3b071fa548bf2d5cac640846a7ff19c F src/walker.c 0f142b5bd3ed2041fc52d773880748b212e63354 @@ -924,7 +924,7 @@ F test/orderby6.test 8b38138ab0972588240b3fca0985d2e400432859 F test/orderby7.test 3d1383d52ade5b9eb3a173b3147fdd296f0202da F test/orderby8.test 23ef1a5d72bd3adcc2f65561c654295d1b8047bd F test/orderby9.test 87fb9548debcc2cd141c5299002dd94672fa76a3 -F test/oserror.test 361346396ae18462c7393c1ac5c3f17237bd89b2 +F test/oserror.test b32dc34f2363ef18532e3a0a7358e3e7e321974f F test/ovfl.test 4f7ca651cba5c059a12d8c67dddd49bec5747799 F test/pager1.test 1acbdb14c5952a72dd43129cabdbf69aaa3ed1fa F test/pager2.test 67b8f40ae98112bcdba1f2b2d03ea83266418c71 @@ -1063,7 +1063,7 @@ F test/subtype1.test 7fe09496352f97053af1437150751be2d0a0cae8 F test/superlock.test 1cde669f68d2dd37d6c9bd35eee1d95491ae3fc2 F test/symlink.test 511db82662446bb0d3619002422760ef8e4b1122 F test/sync.test a34cd43e98b7fb84eabbf38f7ed8f7349b3f3d85 -F test/syscall.test 2aa9e111b79fb385681ff8940124def6f8faab87 +F test/syscall.test f59ba4e25f7ba4a4c031026cc2ef8b6e4b4c639c F test/sysfault.test c9f2b0d8d677558f74de750c75e12a5454719d04 F test/tabfunc01.test cc33684f9480fcf1fd5ce287ac28d22971cad1cc F test/table.test b708f3e5fa2542fa51dfab21fc07b36ea445cb2f @@ -1419,7 +1419,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 80398fd44fb232193450103808e1854e0eba5652 -R 084dee05e1353887f6af0d88670b22d0 +P f71249d3db9242b8f38955db51a7a5789d002803 +R 31817b68212f6684c4e9fbfebdae658d U dan -Z 72572e009a3ce3b7747f3257ebf7dfc7 +Z 17d90a7cade21886dca3e4bdfc08ed4c diff --git a/manifest.uuid b/manifest.uuid index b66c39a6ae..35202dd686 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -f71249d3db9242b8f38955db51a7a5789d002803 \ No newline at end of file +8a6e4147a680ad6c5fdd588468b6daac82349d2c \ No newline at end of file diff --git a/src/os_unix.c b/src/os_unix.c index 3d113301b8..a3bb45bdb9 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -480,7 +480,11 @@ static struct unix_syscall { #endif #define osReadlink ((ssize_t(*)(const char*,char*,size_t))aSyscall[26].pCurrent) - { "lstat", (sqlite3_syscall_ptr)lstat, 0 }, +#if defined(HAVE_LSTAT) + { "lstat", (sqlite3_syscall_ptr)lstat, 0 }, +#else + { "lstat", (sqlite3_syscall_ptr)0, 0 }, +#endif #define osLstat ((int(*)(const char*,struct stat*))aSyscall[27].pCurrent) }; /* End of the overrideable system calls */ @@ -5971,7 +5975,7 @@ static int unixFullPathname( int nOut, /* Size of output buffer in bytes */ char *zOut /* Output buffer */ ){ -#if !defined(HAVE_READLINK) +#if !defined(HAVE_READLINK) || !defined(HAVE_LSTAT) return mkFullPathname(zPath, zOut, nOut); #else int rc = SQLITE_OK; @@ -5999,7 +6003,7 @@ static int unixFullPathname( struct stat buf; if( osLstat(zIn, &buf)!=0 ){ if( errno!=ENOENT ){ - rc = unixLogError(SQLITE_CANTOPEN_BKPT, "stat", zIn); + rc = unixLogError(SQLITE_CANTOPEN_BKPT, "lstat", zIn); } }else{ bLink = S_ISLNK(buf.st_mode); @@ -6044,7 +6048,7 @@ static int unixFullPathname( sqlite3_free(zDel); return rc; -#endif /* HAVE_READLINK */ +#endif /* HAVE_READLINK && HAVE_LSTAT */ } diff --git a/src/vxworks.h b/src/vxworks.h index 60c41a19b8..e7013c3f66 100644 --- a/src/vxworks.h +++ b/src/vxworks.h @@ -28,4 +28,5 @@ #define OS_VXWORKS 0 #define HAVE_FCHOWN 1 #define HAVE_READLINK 1 +#define HAVE_LSTAT 1 #endif /* defined(_WRS_KERNEL) */ diff --git a/test/oserror.test b/test/oserror.test index 5fa7f98eb5..246a9d4023 100644 --- a/test/oserror.test +++ b/test/oserror.test @@ -95,7 +95,7 @@ do_test 1.4.1 { do_re_test 1.4.2 { lindex $::log 0 -} {^os_unix.c:\d*: \(\d+\) (open|readlink)\(.*test.db\) - } +} {^os_unix.c:\d*: \(\d+\) (open|readlink|lstat)\(.*test.db\) - } #-------------------------------------------------------------------------- # Tests oserror-1.* test failures in the unlink() system call. diff --git a/test/syscall.test b/test/syscall.test index a935957d39..5716b35a6e 100644 --- a/test/syscall.test +++ b/test/syscall.test @@ -61,7 +61,7 @@ foreach s { fcntl read pread write pwrite fchmod fallocate pread64 pwrite64 unlink openDirectory mkdir rmdir statvfs fchown geteuid umask mmap munmap mremap - getpagesize readlink + getpagesize readlink lstat } { if {[test_syscall exists $s]} {lappend syscall_list $s} } From 2aac8c7ba1e84a90b36906926336a4558360a02e Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 25 Jan 2016 22:08:11 +0000 Subject: [PATCH 37/75] Fix a compiler warning about doing pointer arithmetic involving a NULL pointer even though the result of computation is never used. FossilOrigin-Name: 7c49a9478bd36564e81d33458ca1f4063ddaca83 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/vdbesort.c | 4 +++- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 827a3d5126..5a7fe0a637 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Replace\sthe\sOP_SetIfNotPos\soperator\swith\sOP_OffsetLimit\sin\sthe\sVDBE,\sfor\nsimpler\sand\ssmaller\scode. -D 2016-01-25T15:57:29.060 +C Fix\sa\scompiler\swarning\sabout\sdoing\spointer\sarithmetic\sinvolving\sa\sNULL\spointer\neven\sthough\sthe\sresult\sof\scomputation\sis\snever\sused. +D 2016-01-25T22:08:11.961 F Makefile.in 027c1603f255390c43a426671055a31c0a65fdb4 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 1708a78eda223b6daa302b140037fcc214a779f9 @@ -417,7 +417,7 @@ F src/vdbeapi.c ffae8f5af4570fbd548504e815e9fb7227f0822e F src/vdbeaux.c 757f86e6fef8efb3dd4226cb31e2e82b9c44c883 F src/vdbeblob.c 37c3d11a753e403698c69e17383d282e1ae73e75 F src/vdbemem.c b9181e77eca2a095929d46250daf85c8d2621fc0 -F src/vdbesort.c 0971557e5d3c289e46f56a52aed2197c13251de7 +F src/vdbesort.c 3bb1f1f03162e6d223da623714d8e93fcaeac658 F src/vdbetrace.c 8befe829faff6d9e6f6e4dee5a7d3f85cc85f1a0 F src/vtab.c 320682cca733115b4cbe71320b5c5eeb1074ebde F src/vxworks.h 974e7d9a98f602d6310d563e1dc4e08f9fc48e47 @@ -1419,7 +1419,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 30671345b1c1ee55a2d1aa17273213f1849efd81 -R f342889ba3409bd63b1cf54d88bfe0e2 +P 7ac017a498b6fb28343eef2d24e400c7800660d6 +R aa5d51a793ca6d0a7613986a1affa54a U drh -Z e7c5fc86067d4269675714897cec0b51 +Z 142832d114ade2d8f5ff5fab3faed40b diff --git a/manifest.uuid b/manifest.uuid index 276ef7a03f..d34f9b48c8 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -7ac017a498b6fb28343eef2d24e400c7800660d6 \ No newline at end of file +7c49a9478bd36564e81d33458ca1f4063ddaca83 \ No newline at end of file diff --git a/src/vdbesort.c b/src/vdbesort.c index e095f80912..22029aa6bf 100644 --- a/src/vdbesort.c +++ b/src/vdbesort.c @@ -1837,7 +1837,9 @@ int sqlite3VdbeSorterWrite( pNew = (SorterRecord*)&pSorter->list.aMemory[pSorter->iMemory]; pSorter->iMemory += ROUND8(nReq); - pNew->u.iNext = (int)((u8*)(pSorter->list.pList) - pSorter->list.aMemory); + if( pSorter->list.pList ){ + pNew->u.iNext = (int)((u8*)(pSorter->list.pList) - pSorter->list.aMemory); + } }else{ pNew = (SorterRecord *)sqlite3Malloc(nReq); if( pNew==0 ){ From a72d15b5f0bbc0d67eb117624df7f005ad89c443 Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 25 Jan 2016 23:19:58 +0000 Subject: [PATCH 38/75] Minor changes to the autoconf/README.txt file. FossilOrigin-Name: 6df8a9c00a9d067f67d492da7a4617908070c6c0 --- autoconf/README.txt | 16 +++++++++++----- manifest | 14 +++++++------- manifest.uuid | 2 +- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/autoconf/README.txt b/autoconf/README.txt index a581c39dea..114831ec5e 100644 --- a/autoconf/README.txt +++ b/autoconf/README.txt @@ -9,6 +9,12 @@ This package contains: * a Makefile.msc and sqlite3.rc for building with Microsoft Visual C++ on Windows. +SUMMARY OF HOW TO BUILD +======================= + + unix: ./configure; make + windows: nmake /f Makefile.msc + BUILDING ON POSIX ================= @@ -47,7 +53,7 @@ Using Microsoft Visual C++ 2005 (or later) is recommended. Several Windows platform variants may be built by adding additional macros to the NMAKE command line. -BUILDING FOR WINRT 8.0 +Building for WinRT 8.0 ---------------------- FOR_WINRT=1 @@ -58,7 +64,7 @@ NMAKE command line as well: "NSDKLIBPATH=%WindowsSdkDir%\..\8.0\lib\win8\um\x86" -BUILDING FOR WINRT 8.1 +Building for WinRT 8.1 ---------------------- FOR_WINRT=1 @@ -69,7 +75,7 @@ NMAKE command line as well: "NSDKLIBPATH=%WindowsSdkDir%\..\8.1\lib\winv6.3\um\x86" -BUILDING FOR UAP 10.0 +Building for UAP 10.0 --------------------- FOR_WINRT=1 FOR_UAP=1 @@ -82,7 +88,7 @@ NMAKE command line as well: "PSDKLIBPATH=%WindowsSdkDir%\..\10\lib\10.0.10586.0\um\x86" "NUCRTLIBPATH=%UniversalCRTSdkDir%\..\10\lib\10.0.10586.0\ucrt\x86" -BUILDING FOR THE WINDOWS 10 SDK +Building for the Windows 10 SDK ------------------------------- FOR_WIN10=1 @@ -90,7 +96,7 @@ BUILDING FOR THE WINDOWS 10 SDK Using Microsoft Visual C++ 2015 (or later) is required. When using the above, no other macros should be needed on the NMAKE command line. -USING PREPROCESSOR DEFINES +Other preprocessor defines -------------------------- Additionally, preprocessor defines may be specified by using the OPTS macro diff --git a/manifest b/manifest index 0f3e8b7b8d..48622ea281 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C More\supdates\sto\sthe\sREADME. -D 2016-01-23T21:57:46.170 +C Minor\schanges\sto\sthe\sautoconf/README.txt\sfile. +D 2016-01-25T23:19:58.651 F Makefile.in 027c1603f255390c43a426671055a31c0a65fdb4 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 6fca5455aaecbd14479f33f091aa19df2d3d2969 @@ -13,7 +13,7 @@ F autoconf/INSTALL 83e4a25da9fd053c7b3665eaaaf7919707915903 F autoconf/Makefile.am 1c1657650775960804945dc392e14d9e43c5ed84 F autoconf/Makefile.msc 68ed752a809b611d97b95d8572a34fe6fd1196f1 F autoconf/README.first 6c4f34fe115ff55d4e8dbfa3cecf04a0188292f7 -F autoconf/README.txt fc86867528c500dfd691620e623bfe6799c98d14 +F autoconf/README.txt e3a5cf0ba2d8944c71ca1eb7c06c15f52bfca131 F autoconf/configure.ac 7b1ea0dcaf49fafba262ce4b0ee8cb3281b555d1 F autoconf/tea/Makefile.in b438a7020446c8a8156e8d97c8914a04833da6fd F autoconf/tea/README 3e9a3c060f29a44344ab50aec506f4db903fb873 @@ -1421,7 +1421,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 4ce60fa42d8486d219d40d25d785d7f2cabe5e06 -R 9ddb76e24748b77caceaf34a8b255b23 -U mistachkin -Z 8a8dd4db0d2ee1de0599573a5cb1355c +P 9f02868df71d902a2b9118d0b06df18ee92b666b +R 9aeab9bcdca09d2b8e9198ca7dec65cb +U drh +Z 1be43b84d3a6e7c2425c5f0806c1fce0 diff --git a/manifest.uuid b/manifest.uuid index c53057578b..4cab521d6d 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -9f02868df71d902a2b9118d0b06df18ee92b666b \ No newline at end of file +6df8a9c00a9d067f67d492da7a4617908070c6c0 \ No newline at end of file From f0fc9929369cda0c7416174d43a299188b8beabf Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 26 Jan 2016 00:12:42 +0000 Subject: [PATCH 39/75] Remove an unused variable. FossilOrigin-Name: 1c2656c1d37906230edc142d3a4253b16b6e925f --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/os_unix.c | 1 - 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 33b8dc8b5c..ea40dd333f 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Only\suse\slstat()\sif\sthe\sHAVE_LSTAT\smacro\sis\sdefined.\sFix\ssome\stest\sfile\sissues. -D 2016-01-25T18:43:05.007 +C Remove\san\sunused\svariable. +D 2016-01-26T00:12:42.634 F Makefile.in 027c1603f255390c43a426671055a31c0a65fdb4 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 1708a78eda223b6daa302b140037fcc214a779f9 @@ -329,7 +329,7 @@ F src/os.c 8fd25588eeba74068d41102d26810e216999b6c8 F src/os.h 3e57a24e2794a94d3cf2342c6d9a884888cd96bf F src/os_common.h abdb9a191a367793268fe553d25bab894e986a0e F src/os_setup.h c9d4553b5aaa6f73391448b265b89bed0b890faa -F src/os_unix.c 4c217111d7bdebbd7a9b47cf11f434420da432e7 +F src/os_unix.c e9e1e6a49892a76fe1fd167b1d475eeddaf1ccb3 F src/os_win.c 386fba30419e8458b13209781c2af5590eab2811 F src/os_win.h eb7a47aa17b26b77eb97e4823f20a00b8bda12ca F src/pager.c 2916c66aee50f69d9ec56a7619b62d9c6a3bee61 @@ -1419,7 +1419,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P f71249d3db9242b8f38955db51a7a5789d002803 -R 31817b68212f6684c4e9fbfebdae658d -U dan -Z 17d90a7cade21886dca3e4bdfc08ed4c +P 8a6e4147a680ad6c5fdd588468b6daac82349d2c +R d2cf53f7b50c768b631d5f18bba143b9 +U drh +Z 592370e14c792642f017f87ac074cb77 diff --git a/manifest.uuid b/manifest.uuid index 35202dd686..78b51cd18f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -8a6e4147a680ad6c5fdd588468b6daac82349d2c \ No newline at end of file +1c2656c1d37906230edc142d3a4253b16b6e925f \ No newline at end of file diff --git a/src/os_unix.c b/src/os_unix.c index a3bb45bdb9..cdbcd2c8e0 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -5981,7 +5981,6 @@ static int unixFullPathname( int rc = SQLITE_OK; int nByte; int nLink = 1; /* Number of symbolic links followed so far */ - int bLink; /* True for a symbolic link */ const char *zIn = zPath; /* Input path for each iteration of loop */ char *zDel = 0; From 23496702622549d23f22639b7e2f5c47cfeba9a6 Mon Sep 17 00:00:00 2001 From: dan Date: Tue, 26 Jan 2016 13:56:42 +0000 Subject: [PATCH 40/75] Ensure that unixFullpathname() always nul-terminates its output buffer, even when returning an error. FossilOrigin-Name: 4a4385564dd3887a7953820b60c99d6ce289f96a --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/os_unix.c | 31 +++++++++++++++++++------------ test/symlink.test | 1 - 4 files changed, 28 insertions(+), 22 deletions(-) diff --git a/manifest b/manifest index ea40dd333f..2765e104fb 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Remove\san\sunused\svariable. -D 2016-01-26T00:12:42.634 +C Ensure\sthat\sunixFullpathname()\salways\snul-terminates\sits\soutput\sbuffer,\seven\swhen\sreturning\san\serror. +D 2016-01-26T13:56:42.494 F Makefile.in 027c1603f255390c43a426671055a31c0a65fdb4 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 1708a78eda223b6daa302b140037fcc214a779f9 @@ -329,7 +329,7 @@ F src/os.c 8fd25588eeba74068d41102d26810e216999b6c8 F src/os.h 3e57a24e2794a94d3cf2342c6d9a884888cd96bf F src/os_common.h abdb9a191a367793268fe553d25bab894e986a0e F src/os_setup.h c9d4553b5aaa6f73391448b265b89bed0b890faa -F src/os_unix.c e9e1e6a49892a76fe1fd167b1d475eeddaf1ccb3 +F src/os_unix.c 5bb20172d0c9a6afcfa829a88c406970593c848d F src/os_win.c 386fba30419e8458b13209781c2af5590eab2811 F src/os_win.h eb7a47aa17b26b77eb97e4823f20a00b8bda12ca F src/pager.c 2916c66aee50f69d9ec56a7619b62d9c6a3bee61 @@ -1061,7 +1061,7 @@ F test/subselect.test d24fd8757daf97dafd2e889c73ea4c4272dcf4e4 F test/substr.test 18f57c4ca8a598805c4d64e304c418734d843c1a F test/subtype1.test 7fe09496352f97053af1437150751be2d0a0cae8 F test/superlock.test 1cde669f68d2dd37d6c9bd35eee1d95491ae3fc2 -F test/symlink.test 511db82662446bb0d3619002422760ef8e4b1122 +F test/symlink.test c9ebe7330d228249e447038276bfc8a7b22f4849 F test/sync.test a34cd43e98b7fb84eabbf38f7ed8f7349b3f3d85 F test/syscall.test f59ba4e25f7ba4a4c031026cc2ef8b6e4b4c639c F test/sysfault.test c9f2b0d8d677558f74de750c75e12a5454719d04 @@ -1419,7 +1419,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 8a6e4147a680ad6c5fdd588468b6daac82349d2c -R d2cf53f7b50c768b631d5f18bba143b9 -U drh -Z 592370e14c792642f017f87ac074cb77 +P 1c2656c1d37906230edc142d3a4253b16b6e925f +R 6c0824142ba46339a29c32338146479b +U dan +Z e95289d1bfc22539e02b85ec76fd69c7 diff --git a/manifest.uuid b/manifest.uuid index 78b51cd18f..72144560be 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -1c2656c1d37906230edc142d3a4253b16b6e925f \ No newline at end of file +4a4385564dd3887a7953820b60c99d6ce289f96a \ No newline at end of file diff --git a/src/os_unix.c b/src/os_unix.c index cdbcd2c8e0..81422f215d 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -5955,7 +5955,12 @@ static int mkFullPathname( iOff = sqlite3Strlen30(zOut); zOut[iOff++] = '/'; } - if( (iOff+nPath+1)>nOut ) return SQLITE_CANTOPEN_BKPT; + if( (iOff+nPath+1)>nOut ){ + /* SQLite assumes that xFullPathname() nul-terminates the output buffer + ** even if it returns an error. */ + zOut[iOff] = '\0'; + return SQLITE_CANTOPEN_BKPT; + } sqlite3_snprintf(nOut-iOff, &zOut[iOff], "%s", zPath); return SQLITE_OK; } @@ -6020,15 +6025,17 @@ static int unixFullPathname( nByte = osReadlink(zIn, zDel, nOut-1); if( nByte<0 ){ rc = unixLogError(SQLITE_CANTOPEN_BKPT, "readlink", zIn); - }else if( zDel[0]!='/' ){ - int n; - for(n = sqlite3Strlen30(zIn); n>0 && zIn[n-1]!='/'; n--); - if( nByte+n+1>nOut ){ - rc = SQLITE_CANTOPEN_BKPT; - }else{ - memmove(&zDel[n], zDel, nByte+1); - memcpy(zDel, zIn, n); - nByte += n; + }else{ + if( zDel[0]!='/' ){ + int n; + for(n = sqlite3Strlen30(zIn); n>0 && zIn[n-1]!='/'; n--); + if( nByte+n+1>nOut ){ + rc = SQLITE_CANTOPEN_BKPT; + }else{ + memmove(&zDel[n], zDel, nByte+1); + memcpy(zDel, zIn, n); + nByte += n; + } } zDel[nByte] = '\0'; } @@ -6037,8 +6044,8 @@ static int unixFullPathname( zIn = zDel; } - if( rc==SQLITE_OK ){ - assert( zIn!=zOut || zIn[0]=='/' ); + assert( rc!=SQLITE_OK || zIn!=zOut || zIn[0]=='/' ); + if( rc==SQLITE_OK && zIn!=zOut ){ rc = mkFullPathname(zIn, zOut, nOut); } if( bLink==0 ) break; diff --git a/test/symlink.test b/test/symlink.test index e9e5f3c305..949102cf8a 100644 --- a/test/symlink.test +++ b/test/symlink.test @@ -181,7 +181,6 @@ do_test 4.4.0 { } {} do_test 4.4.1 { db close - breakpoint sqlite3 db w/test.db db eval { SELECT * FROM t1 } } {hello world} From fee981e5b97a79b26308c2dc3f946264e4ee8028 Mon Sep 17 00:00:00 2001 From: dan Date: Tue, 26 Jan 2016 17:08:22 +0000 Subject: [PATCH 41/75] Enhance fts5txt2db.tcl, a script used to generate fts5/fts4 databases for performance testing. FossilOrigin-Name: c646e40350e5aa91abcf52de61fb31275bad38f9 --- ext/fts5/tool/fts5txt2db.tcl | 200 +++++++++++++++++++++++++---------- manifest | 12 +-- manifest.uuid | 2 +- 3 files changed, 152 insertions(+), 62 deletions(-) diff --git a/ext/fts5/tool/fts5txt2db.tcl b/ext/fts5/tool/fts5txt2db.tcl index c22c5dae72..c6a58e6edd 100644 --- a/ext/fts5/tool/fts5txt2db.tcl +++ b/ext/fts5/tool/fts5txt2db.tcl @@ -1,13 +1,127 @@ -proc usage {} { - puts stderr "$::argv0 ?OPTIONS? DATABASE FILE1..." +#------------------------------------------------------------------------- +# Command line options processor. +# +proc command_line_error {O E {msg ""}} { + if {$msg != ""} { + puts stderr "Error: $msg" + puts stderr "" + } + + set L [list] + foreach o $O { + if {[llength $o]==1} { + lappend L [string toupper $o] + } + } + + puts stderr "Usage: $::argv0 ?SWITCHES? $L" puts stderr "" - puts stderr "Options are" - puts stderr " -fts5" - puts stderr " -fts4" - puts stderr " -colsize " - puts stderr { + puts stderr "Switches are:" + foreach o $O { + if {[llength $o]==3} { + foreach {a b c} $o {} + puts stderr [format " -%-15s %s (default \"%s\")" "$a VAL" $c $b] + } elseif {[llength $o]==2} { + foreach {a b} $o {} + puts stderr [format " -%-15s %s" $a $b] + } + } + puts stderr "" + puts stderr $E + exit -1 +} + +proc process_command_line {avar lArgs O E} { + + upvar $avar A + set zTrailing "" ;# True if ... is present in $O + set lPosargs [list] + + # Populate A() with default values. Also, for each switch in the command + # line spec, set an entry in the idx() array as follows: + # + # {tblname t1 "table name to use"} + # -> [set idx(-tblname) {tblname t1 "table name to use"} + # + # For each position parameter, append its name to $lPosargs. If the ... + # specifier is present, set $zTrailing to the name of the prefix. + # + foreach o $O { + set nm [lindex $o 0] + set nArg [llength $o] + switch -- $nArg { + 1 { + if {[string range $nm end-2 end]=="..."} { + set zTrailing [string range $nm 0 end-3] + } else { + lappend lPosargs $nm + } + } + 2 { + set A($nm) 0 + set idx(-$nm) $o + } + 3 { + set A($nm) [lindex $o 1] + set idx(-$nm) $o + } + default { + error "Error in command line specification" + } + } + } + + # Set explicitly specified option values + # + set nArg [llength $lArgs] + for {set i 0} {$i < $nArg} {incr i} { + set opt [lindex $lArgs $i] + if {[string range $opt 0 0]!="-" || $opt=="--"} break + set c [array names idx "${opt}*"] + if {[llength $c]==0} { command_line_error $O $E "Unrecognized option: $opt"} + if {[llength $c]>1} { command_line_error $O $E "Ambiguous option: $opt"} + + if {[llength $idx($c)]==3} { + if {$i==[llength $lArgs]-1} { + command_line_error $O $E "Option requires argument: $c" + } + incr i + set A([lindex $idx($c) 0]) [lindex $lArgs $i] + } else { + set A([lindex $idx($c) 0]) 1 + } + } + + # Deal with position arguments. + # + set nPosarg [llength $lPosargs] + set nRem [expr $nArg - $i] + if {$nRem < $nPosarg || ($zTrailing=="" && $nRem > $nPosarg)} { + command_line_error $O $E + } + for {set j 0} {$j < $nPosarg} {incr j} { + set A([lindex $lPosargs $j]) [lindex $lArgs [expr $j+$i]] + } + if {$zTrailing!=""} { + set A($zTrailing) [lrange $lArgs [expr $j+$i] end] + } +} +# End of command line options processor. +#------------------------------------------------------------------------- + + +process_command_line A $argv { + {fts5 "use fts5"} + {fts4 "use fts4"} + {colsize "10 10 10" "list of column sizes"} + {tblname "t1" "table name to create"} + {detail "full" "Fts5 detail mode to use"} + {repeat 1 "Load each file this many times"} + database + file... +} { This script is designed to create fts4/5 tables with more than one column. The -colsize option should be set to a Tcl list of integer values, one for each column in the table. Each value is the number of tokens that will be @@ -22,59 +136,27 @@ of the -colsize list. The next N2 are used for the second column of the first row, and so on. Rows are added to the table until the entire list of tokens is exhausted. } - exit -1 + +if {$A(fts4)} { + set A(fts) fts4 +} else { + set A(fts) fts5 } -set O(aColSize) [list 10 10 10] -set O(tblname) t1 -set O(fts) fts5 - - -set options_with_values {-colsize} - -for {set i 0} {$i < [llength $argv]} {incr i} { - set opt [lindex $argv $i] - if {[string range $opt 0 0]!="-"} break - - if {[lsearch $options_with_values $opt]>=0} { - incr i - if {$i==[llength $argv]} usage - set val [lindex $argv $i] - } - - switch -- $opt { - -colsize { - set O(aColSize) $val - } - - -fts4 { - set O(fts) fts4 - } - - -fts5 { - set O(fts) fts5 - } - } -} - -if {$i > [llength $argv]-2} usage -set O(db) [lindex $argv $i] -set O(files) [lrange $argv [expr $i+1] end] - -sqlite3 db $O(db) +sqlite3 db $A(database) # Create the FTS table in the db. Return a list of the table columns. # proc create_table {} { - global O + global A set cols [list a b c d e f g h i j k l m n o p q r s t u v w x y z] - set nCol [llength $O(aColSize)] + set nCol [llength $A(colsize)] set cols [lrange $cols 0 [expr $nCol-1]] - set sql "CREATE VIRTUAL TABLE IF NOT EXISTS $O(tblname) USING $O(fts) (" + set sql "CREATE VIRTUAL TABLE IF NOT EXISTS $A(tblname) USING $A(fts) (" append sql [join $cols ,] - append sql ");" + if {$A(fts)=="fts5"} { append sql ",detail=$A(detail));" } db eval $sql return $cols @@ -89,27 +171,35 @@ proc readfile {file} { split $data } +proc repeat {L n} { + set res [list] + for {set i 0} {$i < $n} {incr i} { + set res [concat $res $L] + } + set res +} + # Load all the data into a big list of tokens. # set tokens [list] -foreach f $O(files) { - set tokens [concat $tokens [readfile $f]] +foreach f $A(file) { + set tokens [concat $tokens [repeat [readfile $f] $A(repeat)]] } set N [llength $tokens] set i 0 set cols [create_table] -set sql "INSERT INTO $O(tblname) VALUES(\$[lindex $cols 0]" +set sql "INSERT INTO $A(tblname) VALUES(\$R([lindex $cols 0])" foreach c [lrange $cols 1 end] { - append sql ", \$A($c)" + append sql ", \$R($c)" } append sql ")" db eval BEGIN while {$i < $N} { - foreach c $cols s $O(aColSize) { - set A($c) [lrange $tokens $i [expr $i+$s-1]] + foreach c $cols s $A(colsize) { + set R($c) [lrange $tokens $i [expr $i+$s-1]] incr i $s } db eval $sql diff --git a/manifest b/manifest index fbcb4d2d1b..32c610bbaf 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\san\sfts5\sproblem\swith\susing\sboth\sxPhraseFirst()\sand\sxPhraseFirstColumn()\swithin\sa\ssingle\sstatement\sin\sdetail=col\smode. -D 2016-01-23T18:51:59.865 +C Enhance\sfts5txt2db.tcl,\sa\sscript\sused\sto\sgenerate\sfts5/fts4\sdatabases\sfor\sperformance\stesting. +D 2016-01-26T17:08:22.193 F Makefile.in 027c1603f255390c43a426671055a31c0a65fdb4 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 1708a78eda223b6daa302b140037fcc214a779f9 @@ -189,7 +189,7 @@ F ext/fts5/test/fts5update.test 57c7012a7919889048947addae10e0613df45529 F ext/fts5/test/fts5version.test 978f59541d8cef7e8591f8be2115ec5ccb863e2e F ext/fts5/test/fts5vocab.test 480d780aa6b699816c5066225fbd86f3a0239477 F ext/fts5/tool/fts5speed.tcl aaee41894b552df8fbf8616aad003b2ea9ba3221 -F ext/fts5/tool/fts5txt2db.tcl c374c4c4797e8cdfadabdfaeeb5412dcd6686e84 +F ext/fts5/tool/fts5txt2db.tcl ae308338b2da1646dea456ab66706acdde8c714e F ext/fts5/tool/loadfts5.tcl 95b03429ee6b138645703c6ca192c3ac96eaf093 F ext/fts5/tool/mkfts5c.tcl d1c2a9ab8e0ec690a52316f33dd9b1d379942f45 F ext/fts5/tool/showfts5.tcl d54da0e067306663e2d5d523965ca487698e722c @@ -1419,7 +1419,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P ceccc9ad788fb4da9120915741995b9f088f85ff -R e7d7753020b6f70b109a92a8ac037ba7 +P 72d53699bf0dcdb9d2a22e229989d7435f061399 +R e572f7330a1bdca73a606e620f2735b9 U dan -Z 648645363fb131dd10e5d7321a173b9d +Z 9f71d918f9bd09bf4fa550347b1ed369 diff --git a/manifest.uuid b/manifest.uuid index 1891619c18..0db14bcc12 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -72d53699bf0dcdb9d2a22e229989d7435f061399 \ No newline at end of file +c646e40350e5aa91abcf52de61fb31275bad38f9 \ No newline at end of file From 1c16bccb79888f775b4e1fbdca00d8f272afed17 Mon Sep 17 00:00:00 2001 From: dan Date: Tue, 26 Jan 2016 19:30:49 +0000 Subject: [PATCH 42/75] Improve the performance of fts5 column filters on detail=col tables. FossilOrigin-Name: 249a2d070c34bf884a04cb248b9691e239f2871c --- ext/fts5/fts5_index.c | 68 ++++++++++++++++++++++++++++++---- ext/fts5/test/fts5ac.test | 2 +- ext/fts5/test/fts5simple3.test | 44 ++++++++++++++++++++++ ext/fts5/tool/fts5speed.tcl | 2 + manifest | 17 +++++---- manifest.uuid | 2 +- 6 files changed, 117 insertions(+), 18 deletions(-) create mode 100644 ext/fts5/test/fts5simple3.test diff --git a/ext/fts5/fts5_index.c b/ext/fts5/fts5_index.c index e147199ef8..6d442de799 100644 --- a/ext/fts5/fts5_index.c +++ b/ext/fts5/fts5_index.c @@ -5003,6 +5003,53 @@ static void fts5IterSetOutputs_Nocolset(Fts5Iter *pIter, Fts5SegIter *pSeg){ } } +/* +** xSetOutputs callback used when: detail=col when there is a column filter. +** +** * detail=col, +** * there is a column filter, and +** * the table contains 32 or fewer columns. +*/ +static void fts5IterSetOutputs_Col32(Fts5Iter *pIter, Fts5SegIter *pSeg){ + Fts5Colset *pColset = pIter->pColset; + pIter->base.iRowid = pSeg->iRowid; + + assert( pIter->pIndex->pConfig->eDetail==FTS5_DETAIL_COLUMNS ); + assert( pColset ); + + fts5BufferZero(&pIter->poslist); + if( pSeg->iLeafOffset+pSeg->nPos<=pSeg->pLeaf->szLeaf ){ + int i; + int iPrev = 0; + u32 m = 0; + u8 *a = (u8*)&pSeg->pLeaf->p[pSeg->iLeafOffset]; + u8 *pEnd = (u8*)&a[pSeg->nPos]; + + while( aposlist.p; + for(i=0; inCol; i++){ + int iCol = pColset->aiCol[i]; + if( m & (1 << iCol) ){ + *a++ = (iCol - iPrev) + 2; + iPrev = iCol; + } + } + pIter->poslist.n = a - pIter->poslist.p; + + }else{ + fts5SegiterPoslist(pIter->pIndex, pSeg, pColset, &pIter->poslist); + } + + pIter->base.pData = pIter->poslist.p; + pIter->base.nData = pIter->poslist.n; +} + /* ** xSetOutputs callback used by detail=col when there is a column filter. */ @@ -5083,9 +5130,9 @@ static void fts5IterSetOutputs_Full(Fts5Iter *pIter, Fts5SegIter *pSeg){ } } -static void fts5IterSetOutputCb(Fts5Iter *pIter){ - int eDetail = pIter->pIndex->pConfig->eDetail; - if( eDetail==FTS5_DETAIL_NONE ){ +static void fts5IterSetOutputCb(int *pRc, Fts5Iter *pIter){ + Fts5Config *pConfig = pIter->pIndex->pConfig; + if( pConfig->eDetail==FTS5_DETAIL_NONE ){ pIter->xSetOutputs = fts5IterSetOutputs_None; } @@ -5093,13 +5140,18 @@ static void fts5IterSetOutputCb(Fts5Iter *pIter){ pIter->xSetOutputs = fts5IterSetOutputs_Nocolset; } - else if( eDetail==FTS5_DETAIL_FULL ){ + else if( pConfig->eDetail==FTS5_DETAIL_FULL ){ pIter->xSetOutputs = fts5IterSetOutputs_Full; } else{ - assert( eDetail==FTS5_DETAIL_COLUMNS ); - pIter->xSetOutputs = fts5IterSetOutputs_Col; + assert( pConfig->eDetail==FTS5_DETAIL_COLUMNS ); + if( pConfig->nCol<=32 ){ + pIter->xSetOutputs = fts5IterSetOutputs_Col32; + sqlite3Fts5BufferSize(pRc, &pIter->poslist, pConfig->nCol); + }else{ + pIter->xSetOutputs = fts5IterSetOutputs_Col; + } } } @@ -5166,8 +5218,8 @@ int sqlite3Fts5IndexQuery( if( p->rc==SQLITE_OK ){ Fts5SegIter *pSeg = &pRet->aSeg[pRet->aFirst[1].iFirst]; pRet->pColset = pColset; - fts5IterSetOutputCb(pRet); - if( pSeg->pLeaf ) pRet->xSetOutputs(pRet, pSeg); + fts5IterSetOutputCb(&p->rc, pRet); + if( p->rc==SQLITE_OK && pSeg->pLeaf ) pRet->xSetOutputs(pRet, pSeg); } if( p->rc ){ sqlite3Fts5IterClose(&pRet->base); diff --git a/ext/fts5/test/fts5ac.test b/ext/fts5/test/fts5ac.test index a5a522a466..61b3230772 100644 --- a/ext/fts5/test/fts5ac.test +++ b/ext/fts5/test/fts5ac.test @@ -158,8 +158,8 @@ foreach {tn2 sql} { #------------------------------------------------------------------------- # foreach {tn expr} { - 1.2 "a OR b" 1.1 "a AND b" + 1.2 "a OR b" 1.3 "o" 1.4 "b q" 1.5 "e a e" diff --git a/ext/fts5/test/fts5simple3.test b/ext/fts5/test/fts5simple3.test new file mode 100644 index 0000000000..b84a3e56dd --- /dev/null +++ b/ext/fts5/test/fts5simple3.test @@ -0,0 +1,44 @@ +# 2015 September 05 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# + +source [file join [file dirname [info script]] fts5_common.tcl] +set testprefix fts5simple3 + +# If SQLITE_ENABLE_FTS5 is defined, omit this file. +ifcapable !fts5 { + finish_test + return +} + +fts5_aux_test_functions db + +do_execsql_test 1.0 { + CREATE VIRTUAL TABLE t1 USING fts5(a, b, c, detail=col); + INSERT INTO t1 VALUES('a', 'b', 'c'); + INSERT INTO t1 VALUES('x', 'x', 'x'); +} + +do_execsql_test 1.1 { + SELECT rowid, fts5_test_collist(t1) FROM t1('a:a'); +} {1 0.0} + +do_execsql_test 1.2 { + SELECT rowid, fts5_test_collist(t1) FROM t1('b:x'); +} {2 0.1} + +do_execsql_test 1.3 { + SELECT rowid, fts5_test_collist(t1) FROM t1('b:a'); +} {} + + +finish_test + diff --git a/ext/fts5/tool/fts5speed.tcl b/ext/fts5/tool/fts5speed.tcl index 1b060ea759..8e1c7f3899 100644 --- a/ext/fts5/tool/fts5speed.tcl +++ b/ext/fts5/tool/fts5speed.tcl @@ -11,6 +11,8 @@ set Q { {1 "SELECT count(*) FROM t1 WHERE t1 MATCH 'c:t*'"} {1 "SELECT count(*) FROM t1 WHERE t1 MATCH 'a:t* OR b:t* OR c:t* OR d:t* OR e:t* OR f:t* OR g:t*'"} {1 "SELECT count(*) FROM t1 WHERE t1 MATCH 'a:t*'"} + + {2 "SELECT count(*) FROM t1 WHERE t1 MATCH 'c:the'"} } proc usage {} { diff --git a/manifest b/manifest index 32c610bbaf..2e90cb8536 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Enhance\sfts5txt2db.tcl,\sa\sscript\sused\sto\sgenerate\sfts5/fts4\sdatabases\sfor\sperformance\stesting. -D 2016-01-26T17:08:22.193 +C Improve\sthe\sperformance\sof\sfts5\scolumn\sfilters\son\sdetail=col\stables. +D 2016-01-26T19:30:49.768 F Makefile.in 027c1603f255390c43a426671055a31c0a65fdb4 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 1708a78eda223b6daa302b140037fcc214a779f9 @@ -103,7 +103,7 @@ F ext/fts5/fts5_buffer.c f6e0c6018ffc8e39fc0b333b5daa8b8d528ae6e4 F ext/fts5/fts5_config.c 0c384ebdd23fd055e2e50a93277b8d59da538238 F ext/fts5/fts5_expr.c a66b9694519d9c336d9bdbd46ea22e7e14aef412 F ext/fts5/fts5_hash.c 1b113977296cf4212c6ec667d5e3f2bd18036955 -F ext/fts5/fts5_index.c 722d8717e3167dd05fa48af970352932052da318 +F ext/fts5/fts5_index.c b34b7257f73929dc1b25c420aad2453dcbe36128 F ext/fts5/fts5_main.c 3886bbfc5ac1d9df29979823ddf2b68241e1127e F ext/fts5/fts5_storage.c 2a1f44deae090cd711f02cec0c2af8e660360d24 F ext/fts5/fts5_tcl.c f8731e0508299bd43f1a2eff7dbeaac870768966 @@ -118,7 +118,7 @@ F ext/fts5/mkportersteps.tcl 5acf962d2e0074f701620bb5308155fa1e4a63ba F ext/fts5/test/fts5_common.tcl 61ff0d1a29d98a91c4553b20b3f410d858834ee9 F ext/fts5/test/fts5aa.test 7e814df4a0e6c22a6fe2d84f210fdc0b5068a084 F ext/fts5/test/fts5ab.test 30325a89453280160106be411bba3acf138e6d1b -F ext/fts5/test/fts5ac.test dec95549e007dd9be52aa435cdcd0f08e14e64d0 +F ext/fts5/test/fts5ac.test 55cad4275a1f5acabfe14d8442a8046b47e49e5f F ext/fts5/test/fts5ad.test 0ddaa5b692ff220100ee396228838f4331399eaa F ext/fts5/test/fts5ae.test 612dcb51f4069226791ff14c17dbfb3138c56f20 F ext/fts5/test/fts5af.test be858a96b1f5de66ba6d64f0021bd8b2408e126c @@ -176,6 +176,7 @@ F ext/fts5/test/fts5restart.test c17728fdea26e7d0f617d22ad5b4b2862b994c17 F ext/fts5/test/fts5rowid.test 16908a99d6efc9ba21081b4f2b86b3fc699839a6 F ext/fts5/test/fts5simple.test 2bc6451cbe887a9215f5b14ae307c70d850344c9 F ext/fts5/test/fts5simple2.test 98377ae1ff7749a42c21fe1a139c1ed312522c46 +F ext/fts5/test/fts5simple3.test e671b36bc4dbd4f5095e66cb04473cba9f680f53 F ext/fts5/test/fts5synonym.test 6475d189c2e20d60795808f83e36bf9318708d48 F ext/fts5/test/fts5synonym2.test aa4c43bd3b691ff80f658cb064f5ab40690e834e F ext/fts5/test/fts5tok1.test beb894c6f3468f10a574302f69ebe4436b0287c7 @@ -188,7 +189,7 @@ F ext/fts5/test/fts5unindexed.test e9539d5b78c677315e7ed8ea911d4fd25437c680 F ext/fts5/test/fts5update.test 57c7012a7919889048947addae10e0613df45529 F ext/fts5/test/fts5version.test 978f59541d8cef7e8591f8be2115ec5ccb863e2e F ext/fts5/test/fts5vocab.test 480d780aa6b699816c5066225fbd86f3a0239477 -F ext/fts5/tool/fts5speed.tcl aaee41894b552df8fbf8616aad003b2ea9ba3221 +F ext/fts5/tool/fts5speed.tcl 47f0031e6ac564964f4f4805e439ea665e848df2 F ext/fts5/tool/fts5txt2db.tcl ae308338b2da1646dea456ab66706acdde8c714e F ext/fts5/tool/loadfts5.tcl 95b03429ee6b138645703c6ca192c3ac96eaf093 F ext/fts5/tool/mkfts5c.tcl d1c2a9ab8e0ec690a52316f33dd9b1d379942f45 @@ -1419,7 +1420,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 72d53699bf0dcdb9d2a22e229989d7435f061399 -R e572f7330a1bdca73a606e620f2735b9 +P c646e40350e5aa91abcf52de61fb31275bad38f9 +R a44979856d96ea38951595ad6e15598a U dan -Z 9f71d918f9bd09bf4fa550347b1ed369 +Z a6d46df0ea079f8f36131bee8e2cf5b7 diff --git a/manifest.uuid b/manifest.uuid index 0db14bcc12..54ccb7acb1 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c646e40350e5aa91abcf52de61fb31275bad38f9 \ No newline at end of file +249a2d070c34bf884a04cb248b9691e239f2871c \ No newline at end of file From 18205c781d4bb15d5a26801844212f231a4aed9d Mon Sep 17 00:00:00 2001 From: dan Date: Tue, 26 Jan 2016 20:08:50 +0000 Subject: [PATCH 43/75] Further minor performance improvements and code-size reductions related to fts5 column filters on detail=col tables. FossilOrigin-Name: b4ac61aeee976296e7719949cd4fb496147a29e8 --- ext/fts5/fts5_index.c | 119 +++++++++++++++--------------------------- manifest | 12 ++--- manifest.uuid | 2 +- 3 files changed, 50 insertions(+), 83 deletions(-) diff --git a/ext/fts5/fts5_index.c b/ext/fts5/fts5_index.c index 6d442de799..ca3feb86f7 100644 --- a/ext/fts5/fts5_index.c +++ b/ext/fts5/fts5_index.c @@ -5004,96 +5004,63 @@ static void fts5IterSetOutputs_Nocolset(Fts5Iter *pIter, Fts5SegIter *pSeg){ } /* -** xSetOutputs callback used when: detail=col when there is a column filter. -** -** * detail=col, -** * there is a column filter, and -** * the table contains 32 or fewer columns. +** xSetOutputs callback used by detail=col when there is a column filter +** and there are 100 or more columns. Also called as a fallback from +** fts5IterSetOutputs_Col100 if the column-list spans more than one page. */ -static void fts5IterSetOutputs_Col32(Fts5Iter *pIter, Fts5SegIter *pSeg){ - Fts5Colset *pColset = pIter->pColset; - pIter->base.iRowid = pSeg->iRowid; - - assert( pIter->pIndex->pConfig->eDetail==FTS5_DETAIL_COLUMNS ); - assert( pColset ); - +static void fts5IterSetOutputs_Col(Fts5Iter *pIter, Fts5SegIter *pSeg){ fts5BufferZero(&pIter->poslist); - if( pSeg->iLeafOffset+pSeg->nPos<=pSeg->pLeaf->szLeaf ){ - int i; - int iPrev = 0; - u32 m = 0; - u8 *a = (u8*)&pSeg->pLeaf->p[pSeg->iLeafOffset]; - u8 *pEnd = (u8*)&a[pSeg->nPos]; - - while( aposlist.p; - for(i=0; inCol; i++){ - int iCol = pColset->aiCol[i]; - if( m & (1 << iCol) ){ - *a++ = (iCol - iPrev) + 2; - iPrev = iCol; - } - } - pIter->poslist.n = a - pIter->poslist.p; - - }else{ - fts5SegiterPoslist(pIter->pIndex, pSeg, pColset, &pIter->poslist); - } - + fts5SegiterPoslist(pIter->pIndex, pSeg, pIter->pColset, &pIter->poslist); + pIter->base.iRowid = pSeg->iRowid; pIter->base.pData = pIter->poslist.p; pIter->base.nData = pIter->poslist.n; } /* -** xSetOutputs callback used by detail=col when there is a column filter. +** xSetOutputs callback used when: +** +** * detail=col, +** * there is a column filter, and +** * the table contains 100 or fewer columns. +** +** The last point is to ensure all column numbers are stored as +** single-byte varints. */ -static void fts5IterSetOutputs_Col(Fts5Iter *pIter, Fts5SegIter *pSeg){ - Fts5Colset *pColset = pIter->pColset; - pIter->base.iRowid = pSeg->iRowid; +static void fts5IterSetOutputs_Col100(Fts5Iter *pIter, Fts5SegIter *pSeg){ assert( pIter->pIndex->pConfig->eDetail==FTS5_DETAIL_COLUMNS ); - assert( pColset ); + assert( pIter->pColset ); - if( pSeg->iLeafOffset+pSeg->nPos<=pSeg->pLeaf->szLeaf ){ - /* All data is stored on the current page. Populate the output - ** variables to point into the body of the page object. */ - Fts5PoslistWriter writer = {0}; - const u8 *a = &pSeg->pLeaf->p[pSeg->iLeafOffset]; - int n = pSeg->nPos; - int iCol = 0; - int iCVal = pColset->aiCol[0]; - i64 iPos = 0; - int iOff = 0; + if( pSeg->iLeafOffset+pSeg->nPos>pSeg->pLeaf->szLeaf ){ + fts5IterSetOutputs_Col(pIter, pSeg); + }else{ + u8 *a = (u8*)&pSeg->pLeaf->p[pSeg->iLeafOffset]; + u8 *pEnd = (u8*)&a[pSeg->nPos]; + int iPrev = 0; + int *aiCol = pIter->pColset->aiCol; + int *aiColEnd = &aiCol[pIter->pColset->nCol]; - fts5BufferZero(&pIter->poslist); - while( 0==sqlite3Fts5PoslistNext64(a, n, &iOff, &iPos) ){ - while( iPos>=iCVal ){ - if( iPos==iCVal ){ - sqlite3Fts5PoslistWriterAppend(&pIter->poslist, &writer, iPos); - } - if( ++iCol>=pColset->nCol ) goto setoutputs_col_out; - assert( pColset->aiCol[iCol]>iCVal ); - iCVal = pColset->aiCol[iCol]; + u8 *aOut = pIter->poslist.p; + int iPrevOut = 0; + + pIter->base.iRowid = pSeg->iRowid; + + while( aposlist); - fts5SegiterPoslist(pIter->pIndex, pSeg, pColset, &pIter->poslist); - } - setoutputs_col_out: - pIter->base.pData = pIter->poslist.p; - pIter->base.nData = pIter->poslist.n; + pIter->base.pData = pIter->poslist.p; + pIter->base.nData = aOut - pIter->poslist.p; + } } /* @@ -5146,8 +5113,8 @@ static void fts5IterSetOutputCb(int *pRc, Fts5Iter *pIter){ else{ assert( pConfig->eDetail==FTS5_DETAIL_COLUMNS ); - if( pConfig->nCol<=32 ){ - pIter->xSetOutputs = fts5IterSetOutputs_Col32; + if( pConfig->nCol<=100 ){ + pIter->xSetOutputs = fts5IterSetOutputs_Col100; sqlite3Fts5BufferSize(pRc, &pIter->poslist, pConfig->nCol); }else{ pIter->xSetOutputs = fts5IterSetOutputs_Col; diff --git a/manifest b/manifest index 2e90cb8536..173bd3a03a 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Improve\sthe\sperformance\sof\sfts5\scolumn\sfilters\son\sdetail=col\stables. -D 2016-01-26T19:30:49.768 +C Further\sminor\sperformance\simprovements\sand\scode-size\sreductions\srelated\sto\sfts5\scolumn\sfilters\son\sdetail=col\stables. +D 2016-01-26T20:08:50.348 F Makefile.in 027c1603f255390c43a426671055a31c0a65fdb4 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 1708a78eda223b6daa302b140037fcc214a779f9 @@ -103,7 +103,7 @@ F ext/fts5/fts5_buffer.c f6e0c6018ffc8e39fc0b333b5daa8b8d528ae6e4 F ext/fts5/fts5_config.c 0c384ebdd23fd055e2e50a93277b8d59da538238 F ext/fts5/fts5_expr.c a66b9694519d9c336d9bdbd46ea22e7e14aef412 F ext/fts5/fts5_hash.c 1b113977296cf4212c6ec667d5e3f2bd18036955 -F ext/fts5/fts5_index.c b34b7257f73929dc1b25c420aad2453dcbe36128 +F ext/fts5/fts5_index.c 5558bfbeaf364cc67f937e25753ceed8757cb6d1 F ext/fts5/fts5_main.c 3886bbfc5ac1d9df29979823ddf2b68241e1127e F ext/fts5/fts5_storage.c 2a1f44deae090cd711f02cec0c2af8e660360d24 F ext/fts5/fts5_tcl.c f8731e0508299bd43f1a2eff7dbeaac870768966 @@ -1420,7 +1420,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P c646e40350e5aa91abcf52de61fb31275bad38f9 -R a44979856d96ea38951595ad6e15598a +P 249a2d070c34bf884a04cb248b9691e239f2871c +R a28f5f4bedd812396ab85ff0aefd35c4 U dan -Z a6d46df0ea079f8f36131bee8e2cf5b7 +Z 56fb7a3fddaab518f0c4eb551a124662 diff --git a/manifest.uuid b/manifest.uuid index 54ccb7acb1..708359e9ec 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -249a2d070c34bf884a04cb248b9691e239f2871c \ No newline at end of file +b4ac61aeee976296e7719949cd4fb496147a29e8 \ No newline at end of file From d5be6f01cd7aa0aaa10334c6df01fd8118126d42 Mon Sep 17 00:00:00 2001 From: mistachkin Date: Wed, 27 Jan 2016 07:28:33 +0000 Subject: [PATCH 44/75] Support building for Windows 10 desktop using 'MinCore.lib'. FossilOrigin-Name: 4bf89891fbb076364dc45a6bf3246efa6bc33d5d --- Makefile.msc | 12 ++++++++++-- autoconf/Makefile.msc | 2 +- manifest | 20 ++++++++++---------- manifest.uuid | 2 +- src/os_win.c | 35 ++++++++++++++++++++++++++--------- tool/mkmsvcmin.tcl | 2 +- 6 files changed, 49 insertions(+), 24 deletions(-) diff --git a/Makefile.msc b/Makefile.msc index ab0ba95d53..3427b8177a 100644 --- a/Makefile.msc +++ b/Makefile.msc @@ -890,7 +890,7 @@ LTLINKOPTS = $(LTLINKOPTS) /NODEFAULTLIB:kernel32.lib /NODEFAULTLIB:ole32.lib # When compiling for UAP, some extra linker options are also required. # -!IF $(FOR_UAP)!=0 +!IF $(FOR_UAP)!=0 || $(FOR_WIN10)!=0 LTLINKOPTS = $(LTLINKOPTS) /DYNAMICBASE /NODEFAULTLIB:kernel32.lib LTLINKOPTS = $(LTLINKOPTS) mincore.lib !IFDEF PSDKLIBPATH @@ -1343,12 +1343,20 @@ FUZZCHECK_COMPILE_OPTS = -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_MEMSYS5 # Standard options to testfixture. # TESTOPTS = --verbose=file --output=test-out.txt + +# Extra targets for the "all" target that require Tcl. +# +!IF $(NO_TCL)==0 +ALL_TCL_TARGETS = libtclsqlite3.lib +!ELSE +ALL_TCL_TARGETS = +!ENDIF # <> # This is the default Makefile target. The objects listed here # are what get build when you type just "make" with no arguments. # -all: dll libsqlite3.lib shell libtclsqlite3.lib +all: dll libsqlite3.lib shell $(ALL_TCL_TARGETS) # Dynamic link library section. # diff --git a/autoconf/Makefile.msc b/autoconf/Makefile.msc index fce62b2b8a..598e6517ae 100644 --- a/autoconf/Makefile.msc +++ b/autoconf/Makefile.msc @@ -785,7 +785,7 @@ LTLINKOPTS = $(LTLINKOPTS) /NODEFAULTLIB:kernel32.lib /NODEFAULTLIB:ole32.lib # When compiling for UAP, some extra linker options are also required. # -!IF $(FOR_UAP)!=0 +!IF $(FOR_UAP)!=0 || $(FOR_WIN10)!=0 LTLINKOPTS = $(LTLINKOPTS) /DYNAMICBASE /NODEFAULTLIB:kernel32.lib LTLINKOPTS = $(LTLINKOPTS) mincore.lib !IFDEF PSDKLIBPATH diff --git a/manifest b/manifest index a5a0c52194..07acca6779 100644 --- a/manifest +++ b/manifest @@ -1,8 +1,8 @@ -C Performance\simprovements\sfor\sfts5,\sparticularly\sdetail=col\smode. -D 2016-01-26T20:19:55.225 +C Support\sbuilding\sfor\sWindows\s10\sdesktop\susing\s'MinCore.lib'. +D 2016-01-27T07:28:33.525 F Makefile.in 027c1603f255390c43a426671055a31c0a65fdb4 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 -F Makefile.msc 6fca5455aaecbd14479f33f091aa19df2d3d2969 +F Makefile.msc 72b7858f02017611c3ac1ddc965251017fed0845 F README.md 8ecc12493ff9f820cdea6520a9016001cb2e59b7 F VERSION 866588d1edf0ccb5b0d33896974338f97564f719 F aclocal.m4 a5c22d164aff7ed549d53a90fa56d56955281f50 @@ -11,7 +11,7 @@ F art/sqlite370.ico af56c1d00fee7cd4753e8631ed60703ed0fc6e90 F art/sqlite370.jpg d512473dae7e378a67e28ff96a34da7cb331def2 F autoconf/INSTALL 83e4a25da9fd053c7b3665eaaaf7919707915903 F autoconf/Makefile.am 1c1657650775960804945dc392e14d9e43c5ed84 -F autoconf/Makefile.msc 68ed752a809b611d97b95d8572a34fe6fd1196f1 +F autoconf/Makefile.msc 2ce3b1565a52d7083a1dbf57a1706fd14cc1ee0c F autoconf/README.first 6c4f34fe115ff55d4e8dbfa3cecf04a0188292f7 F autoconf/README.txt e9757a381e5ce2553dbaa6247bb8ad00eb8d87aa F autoconf/configure.ac 7b1ea0dcaf49fafba262ce4b0ee8cb3281b555d1 @@ -332,7 +332,7 @@ F src/os.h 3e57a24e2794a94d3cf2342c6d9a884888cd96bf F src/os_common.h abdb9a191a367793268fe553d25bab894e986a0e F src/os_setup.h c9d4553b5aaa6f73391448b265b89bed0b890faa F src/os_unix.c 5bb20172d0c9a6afcfa829a88c406970593c848d -F src/os_win.c 386fba30419e8458b13209781c2af5590eab2811 +F src/os_win.c ccf29ddded3e41e506b6bd98c1171aa0963b23f2 F src/os_win.h eb7a47aa17b26b77eb97e4823f20a00b8bda12ca F src/pager.c 2916c66aee50f69d9ec56a7619b62d9c6a3bee61 F src/pager.h 1c2a49143dfba9e69cc8159ef019f472ed8d260b @@ -1380,7 +1380,7 @@ F tool/loadfts.c c3c64e4d5e90e8ba41159232c2189dba4be7b862 F tool/logest.c eef612f8adf4d0993dafed0416064cf50d5d33c6 F tool/mkautoconfamal.sh a29b14d54302b33fd892958f6895582ea90e4a45 F tool/mkkeywordhash.c 06ec0b78bd4fa68c12d90ef2bdfe76b039133ff8 -F tool/mkmsvcmin.tcl 93167a9e73383465b5716aa8dfa407409fccef1d +F tool/mkmsvcmin.tcl d57e6efc9428605f5418d0b235721ddf7b5d9c0b F tool/mkopcodec.tcl edde8adc42621b5e598127f8cdc6d52cfe21f52b F tool/mkopcodeh.tcl e04177031532b7aa9379ded50e820231ac4abd6e F tool/mkopts.tcl 66ac10d240cc6e86abd37dc908d50382f84ff46e @@ -1422,7 +1422,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 4003db4a49c6b623750e56f626fa492c8402067f b4ac61aeee976296e7719949cd4fb496147a29e8 -R 3b6b6d60ef77e3cea10b7a0c2c39f1b3 -U dan -Z 0416f9e7e1e3c46e17637bea5d350927 +P a3d7b8ac53f94d29a11362f193fd1967f30583df +R 626d84a8bdebb7b947f7c1e376ac97c5 +U mistachkin +Z 136b0599f548728406750a73608ec6f4 diff --git a/manifest.uuid b/manifest.uuid index 915fae58ae..20f348c1ae 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -a3d7b8ac53f94d29a11362f193fd1967f30583df \ No newline at end of file +4bf89891fbb076364dc45a6bf3246efa6bc33d5d \ No newline at end of file diff --git a/src/os_win.c b/src/os_win.c index c54bfd6a90..eda6cf59fb 100644 --- a/src/os_win.c +++ b/src/os_win.c @@ -76,6 +76,10 @@ # define NTDDI_WINBLUE 0x06030000 #endif +#ifndef NTDDI_WINTHRESHOLD +# define NTDDI_WINTHRESHOLD 0x06040000 +#endif + /* ** Check to see if the GetVersionEx[AW] functions are deprecated on the ** target system. GetVersionEx was first deprecated in Win8.1. @@ -88,6 +92,19 @@ # endif #endif +/* +** Check to see if the CreateFileMappingA function is supported on the +** target system. It is unavailable when using "mincore.lib" on Win10. +** When compiling for Windows 10, always assume "mincore.lib" is in use. +*/ +#ifndef SQLITE_WIN32_CREATEFILEMAPPINGA +# if defined(NTDDI_VERSION) && NTDDI_VERSION >= NTDDI_WINTHRESHOLD +# define SQLITE_WIN32_CREATEFILEMAPPINGA 0 +# else +# define SQLITE_WIN32_CREATEFILEMAPPINGA 1 +# endif +#endif + /* ** This constant should already be defined (in the "WinDef.h" SDK file). */ @@ -494,8 +511,9 @@ static struct win_syscall { #define osCreateFileW ((HANDLE(WINAPI*)(LPCWSTR,DWORD,DWORD, \ LPSECURITY_ATTRIBUTES,DWORD,DWORD,HANDLE))aSyscall[5].pCurrent) -#if (!SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_ANSI) && \ - (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0)) +#if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_ANSI) && \ + (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0) && \ + SQLITE_WIN32_CREATEFILEMAPPINGA { "CreateFileMappingA", (SYSCALL)CreateFileMappingA, 0 }, #else { "CreateFileMappingA", (SYSCALL)0, 0 }, @@ -725,8 +743,7 @@ static struct win_syscall { #define osGetTickCount ((DWORD(WINAPI*)(VOID))aSyscall[33].pCurrent) -#if defined(SQLITE_WIN32_HAS_ANSI) && defined(SQLITE_WIN32_GETVERSIONEX) && \ - SQLITE_WIN32_GETVERSIONEX +#if defined(SQLITE_WIN32_HAS_ANSI) && SQLITE_WIN32_GETVERSIONEX { "GetVersionExA", (SYSCALL)GetVersionExA, 0 }, #else { "GetVersionExA", (SYSCALL)0, 0 }, @@ -736,7 +753,7 @@ static struct win_syscall { LPOSVERSIONINFOA))aSyscall[34].pCurrent) #if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE) && \ - defined(SQLITE_WIN32_GETVERSIONEX) && SQLITE_WIN32_GETVERSIONEX + SQLITE_WIN32_GETVERSIONEX { "GetVersionExW", (SYSCALL)GetVersionExW, 0 }, #else { "GetVersionExW", (SYSCALL)0, 0 }, @@ -1347,7 +1364,7 @@ DWORD sqlite3Win32Wait(HANDLE hObject){ ** the LockFileEx() API. */ -#if !defined(SQLITE_WIN32_GETVERSIONEX) || !SQLITE_WIN32_GETVERSIONEX +#if !SQLITE_WIN32_GETVERSIONEX # define osIsNT() (1) #elif SQLITE_OS_WINCE || SQLITE_OS_WINRT || !defined(SQLITE_WIN32_HAS_ANSI) # define osIsNT() (1) @@ -1368,7 +1385,7 @@ int sqlite3_win32_is_nt(void){ ** kernel. */ return 1; -#elif defined(SQLITE_WIN32_GETVERSIONEX) && SQLITE_WIN32_GETVERSIONEX +#elif SQLITE_WIN32_GETVERSIONEX if( osInterlockedCompareExchange(&sqlite3_os_type, 0, 0)==0 ){ #if defined(SQLITE_WIN32_HAS_ANSI) OSVERSIONINFOA sInfo; @@ -3952,7 +3969,7 @@ static int winShmMap( hMap = osCreateFileMappingW(pShmNode->hFile.h, NULL, PAGE_READWRITE, 0, nByte, NULL ); -#elif defined(SQLITE_WIN32_HAS_ANSI) +#elif defined(SQLITE_WIN32_HAS_ANSI) && SQLITE_WIN32_CREATEFILEMAPPINGA hMap = osCreateFileMappingA(pShmNode->hFile.h, NULL, PAGE_READWRITE, 0, nByte, NULL ); @@ -4108,7 +4125,7 @@ static int winMapfile(winFile *pFd, sqlite3_int64 nByte){ pFd->hMap = osCreateFileMappingW(pFd->h, NULL, protect, (DWORD)((nMap>>32) & 0xffffffff), (DWORD)(nMap & 0xffffffff), NULL); -#elif defined(SQLITE_WIN32_HAS_ANSI) +#elif defined(SQLITE_WIN32_HAS_ANSI) && SQLITE_WIN32_CREATEFILEMAPPINGA pFd->hMap = osCreateFileMappingA(pFd->h, NULL, protect, (DWORD)((nMap>>32) & 0xffffffff), (DWORD)(nMap & 0xffffffff), NULL); diff --git a/tool/mkmsvcmin.tcl b/tool/mkmsvcmin.tcl index de01490c97..da0cd6283c 100644 --- a/tool/mkmsvcmin.tcl +++ b/tool/mkmsvcmin.tcl @@ -92,7 +92,7 @@ foreach i [lsort -integer [array names blocks]] { set data [string map [list " -I\$(TOP)\\src" ""] $data] set data [string map [list " /DEF:sqlite3.def" ""] $data] set data [string map [list " sqlite3.def" ""] $data] -set data [string map [list " libtclsqlite3.lib" ""] $data] +set data [string map [list " \$(ALL_TCL_TARGETS)" ""] $data] set data [string map [list "\$(TOP)\\src\\" "\$(TOP)\\"] $data] writeFile $toFileName $data From b89aeb6aa2cacdb57ef4bd73f980eb4f16ec52e4 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 27 Jan 2016 15:49:32 +0000 Subject: [PATCH 45/75] Add assert() statements on the nExtraDelete variable in vdbe.c to try to verify that the FORDELETE and IDXDELETE flags are being generated correctly. Those flags are not currently generated correctly, and so the assert()s trip on this check-in. FossilOrigin-Name: dde1db0dd2e2cf04706117629756c352b178ebb8 --- manifest | 25 ++++++++++++++----------- manifest.uuid | 2 +- src/delete.c | 11 +++++++---- src/insert.c | 11 ++++++----- src/vdbe.c | 34 ++++++++++++++++++++++++++++++++-- src/vdbeInt.h | 1 + test/e_changes.test | 1 + 7 files changed, 62 insertions(+), 23 deletions(-) diff --git a/manifest b/manifest index 101db20db8..bf4b14906c 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Merge\sall\srecent\strunk\senhancements. -D 2016-01-26T23:32:55.750 +C Add\sassert()\sstatements\son\sthe\snExtraDelete\svariable\sin\svdbe.c\sto\stry\sto\sverify\nthat\sthe\sFORDELETE\sand\sIDXDELETE\sflags\sare\sbeing\sgenerated\scorrectly.\s\sThose\nflags\sare\snot\scurrently\sgenerated\scorrectly,\sand\sso\sthe\sassert()s\strip\son\sthis\ncheck-in. +D 2016-01-27T15:49:32.327 F Makefile.in 027c1603f255390c43a426671055a31c0a65fdb4 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 6fca5455aaecbd14479f33f091aa19df2d3d2969 @@ -13,7 +13,7 @@ F autoconf/INSTALL 83e4a25da9fd053c7b3665eaaaf7919707915903 F autoconf/Makefile.am 1c1657650775960804945dc392e14d9e43c5ed84 F autoconf/Makefile.msc 68ed752a809b611d97b95d8572a34fe6fd1196f1 F autoconf/README.first 6c4f34fe115ff55d4e8dbfa3cecf04a0188292f7 -F autoconf/README.txt e9757a381e5ce2553dbaa6247bb8ad00eb8d87aa w autoconf/README +F autoconf/README.txt e9757a381e5ce2553dbaa6247bb8ad00eb8d87aa F autoconf/configure.ac 7b1ea0dcaf49fafba262ce4b0ee8cb3281b555d1 F autoconf/tea/Makefile.in b438a7020446c8a8156e8d97c8914a04833da6fd F autoconf/tea/README 3e9a3c060f29a44344ab50aec506f4db903fb873 @@ -299,7 +299,7 @@ F src/complete.c addcd8160b081131005d5bc2d34adf20c1c5c92f F src/ctime.c 60e135af364d777a9ab41c97e5e89cd224da6198 F src/date.c 997651e3ee6c2818fbf7fcdb7156cef9eb3ece20 F src/dbstat.c b2ec6793eef97aebb4d171d490a4ffdfa9f2475c -F src/delete.c f02e46234c5fc86f6c03ae34dc0ba48e93cd5029 +F src/delete.c db231a9895681efed007c0887e38b49f4d1291a5 F src/expr.c d10c1cdef5810cdbf73adc9f9b383684230b360a F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb F src/fkey.c c66d3e5b35d4d95b5c1e2ee6c12f5df13a7f9ad6 @@ -308,7 +308,7 @@ F src/global.c bd5a0af3f30b0c01be6db756c626cd3c33a3d260 F src/hash.c 4263fbc955f26c2e8cdc0cf214bc42435aa4e4f5 F src/hash.h c8f3c31722cf3277d03713909761e152a5b81094 F src/hwtime.h d32741c8f4df852c7d959236615444e2b1063b08 -F src/insert.c a00e6d8a843dc22e2c136df04e6300c4528d9b9f +F src/insert.c 410f52b9ef4603dc0aebb169b7cb6b3c60eda07e F src/journal.c b4124532212b6952f42eb2c12fa3c25701d8ba8d F src/legacy.c ba1863ea58c4c840335a84ec276fc2b25e22bc4e F src/loadext.c 84996d7d70a605597d79c1f1d7b2012a5fd34f2b @@ -412,9 +412,9 @@ F src/update.c 17332f9fe818cbc0444c36a811800af8498af4c3 F src/utf.c 32d7f82aa921322f3e1c956f4b58f019ebd2c6b3 F src/util.c 72d40df0a52d3f30b462a15f0e094fcbade6dc82 F src/vacuum.c 2ddd5cad2a7b9cef7f9e431b8c7771634c6b1701 -F src/vdbe.c 6039096edea4ed25f7b1e28aa5d46b0ee3ba73ef +F src/vdbe.c a27a3fdc65f5728c6e9bff49b6753fbf9d73c8c0 F src/vdbe.h 7a733ea8aac1b77305a67698e784fa3484ee3337 -F src/vdbeInt.h 42eefa4f9e7432b9968d321b44e48821ec13b189 +F src/vdbeInt.h 40c728712a2975855a2ac6aac44bf02dfd4a4c30 F src/vdbeapi.c ffae8f5af4570fbd548504e815e9fb7227f0822e F src/vdbeaux.c 757f86e6fef8efb3dd4226cb31e2e82b9c44c883 F src/vdbeblob.c 37c3d11a753e403698c69e17383d282e1ae73e75 @@ -595,7 +595,7 @@ F test/e_blobbytes.test 9bea1d3e2b20f3010b04abba58f6ba172301f49f F test/e_blobclose.test df756753f571bc30e42e3a6cba2807576e49e716 F test/e_blobopen.test 234f960d90235a9b51ec3ca1e062e8541dd558d8 F test/e_blobwrite.test 615b405f29feb2cfb5a1f03dab7933258294fa26 -F test/e_changes.test fd66105385153dbf21fdb35eb8ef6c3e1eade579 +F test/e_changes.test d66e8c1e33f5ec61af32eda729c8a2475404e49b F test/e_createtable.test d4c6059d44dcd4b636de9aae322766062b471844 F test/e_delete.test ab39084f26ae1f033c940b70ebdbbd523dc4962e F test/e_droptrigger.test 3cd080807622c13e5bbb61fc9a57bd7754da2412 @@ -1422,7 +1422,10 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P ac2cbadd8000947c097da5b00c00090fe58fdcff a3d7b8ac53f94d29a11362f193fd1967f30583df -R 7855243eb7d1aae3e5a98345ca05c333 +P 9a71d56dcea953cb965f1fdda9a8b8f158cdeff6 +R 3af2d64e2a860c6e0d1b5193b911b983 +T *branch * fordelete-assert +T *sym-fordelete-assert * +T -sym-btree-fordelete-flag * U drh -Z 6eda54656ca87ef44dc31ff7472a92ee +Z f5e1f3160ce620e13f32c1dda67a1107 diff --git a/manifest.uuid b/manifest.uuid index 7255a707a7..beafd3f9d6 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -9a71d56dcea953cb965f1fdda9a8b8f158cdeff6 \ No newline at end of file +dde1db0dd2e2cf04706117629756c352b178ebb8 \ No newline at end of file diff --git a/src/delete.c b/src/delete.c index 98c49c9930..b3143c5f72 100644 --- a/src/delete.c +++ b/src/delete.c @@ -479,13 +479,12 @@ void sqlite3DeleteFrom( */ if( !isView ){ int iAddrOnce = 0; - u8 p5 = (eOnePass==ONEPASS_OFF ? 0 : OPFLAG_FORDELETE); if( eOnePass==ONEPASS_MULTI ){ iAddrOnce = sqlite3CodeOnce(pParse); VdbeCoverage(v); } testcase( IsVirtual(pTab) ); - sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenWrite, p5, iTabCur, - aToOpen, &iDataCur, &iIdxCur); + sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenWrite, OPFLAG_FORDELETE, + iTabCur, aToOpen, &iDataCur, &iIdxCur); assert( pPk || IsVirtual(pTab) || iDataCur==iTabCur ); assert( pPk || IsVirtual(pTab) || iIdxCur==iDataCur+1 ); if( eOnePass==ONEPASS_MULTI ) sqlite3VdbeJumpHere(v, iAddrOnce); @@ -724,9 +723,13 @@ void sqlite3GenerateRowDelete( if( count ){ sqlite3VdbeChangeP4(v, -1, pTab->zName, P4_TRANSIENT); } + if( eMode!=ONEPASS_OFF ){ + sqlite3VdbeChangeP5(v, OPFLAG_IDXDELETE); + p5 = OPFLAG_IDXDELETE; + } if( iIdxNoSeek>=0 ){ sqlite3VdbeAddOp1(v, OP_Delete, iIdxNoSeek); - if( eMode!=ONEPASS_OFF ) p5 = OPFLAG_IDXDELETE; + p5 = 0; } if( eMode==ONEPASS_MULTI ) p5 |= OPFLAG_SAVEPOSITION; sqlite3VdbeChangeP5(v, p5); diff --git a/src/insert.c b/src/insert.c index 8082bcb459..cbe933c221 100644 --- a/src/insert.c +++ b/src/insert.c @@ -1647,7 +1647,7 @@ int sqlite3OpenTableAndIndices( Parse *pParse, /* Parsing context */ Table *pTab, /* Table to be opened */ int op, /* OP_OpenRead or OP_OpenWrite */ - u8 p5, /* P5 value for OP_Open* instructions */ + u8 p5, /* P5 value for OP_Open* opcodes (except on WITHOUT ROWID) */ int iBase, /* Use this for the table cursor, if there is one */ u8 *aToOpen, /* If not NULL: boolean for each table and index */ int *piDataCur, /* Write the database source cursor number here */ @@ -1682,15 +1682,16 @@ int sqlite3OpenTableAndIndices( for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){ int iIdxCur = iBase++; assert( pIdx->pSchema==pTab->pSchema ); - if( IsPrimaryKeyIndex(pIdx) && !HasRowid(pTab) && piDataCur ){ - *piDataCur = iIdxCur; - } if( aToOpen==0 || aToOpen[i+1] ){ sqlite3VdbeAddOp3(v, op, iIdxCur, pIdx->tnum, iDb); sqlite3VdbeSetP4KeyInfo(pParse, pIdx); - sqlite3VdbeChangeP5(v, p5); VdbeComment((v, "%s", pIdx->zName)); } + if( IsPrimaryKeyIndex(pIdx) && !HasRowid(pTab) ){ + if( piDataCur ) *piDataCur = iIdxCur; + }else{ + sqlite3VdbeChangeP5(v, p5); + } } if( iBase>pParse->nTab ) pParse->nTab = iBase; return i; diff --git a/src/vdbe.c b/src/vdbe.c index adbdab0652..8583bcd4ba 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -551,6 +551,9 @@ int sqlite3VdbeExec( Op *pOp = aOp; /* Current operation */ #if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE) Op *pOrigOp; /* Value of pOp at the top of the loop */ +#endif +#ifdef SQLITE_DEBUG + int nExtraDelete = 0; /* Verifies FORDELETE and IDXDELETE flags */ #endif int rc = SQLITE_OK; /* Value to return */ sqlite3 *db = p->db; /* The database */ @@ -3392,6 +3395,9 @@ case OP_OpenWrite: pCur->nullRow = 1; pCur->isOrdered = 1; pCur->pgnoRoot = p2; +#ifdef SQLITE_DEBUG + pCur->wrFlag = wrFlag; +#endif rc = sqlite3BtreeCursor(pX, p2, wrFlag, pKeyInfo, pCur->uc.pCursor); pCur->pKeyInfo = pKeyInfo; /* Set the VdbeCursor.isTable variable. Previous versions of @@ -4390,10 +4396,24 @@ case OP_Delete: { assert( pC->movetoTarget==iKey ); } #endif - + + /* Only flags that can be set are SAVEPOISTION and IDXDELETE */ assert( (pOp->p5 & ~(OPFLAG_SAVEPOSITION|OPFLAG_IDXDELETE))==0 ); assert( OPFLAG_SAVEPOSITION==BTREE_SAVEPOSITION ); assert( OPFLAG_IDXDELETE==BTREE_IDXDELETE ); + +#ifdef SQLITE_DEBUG + if( pC->isEphemeral==0 + && (pOp->p5 & OPFLAG_IDXDELETE)==0 + && (pC->wrFlag & OPFLAG_FORDELETE)==0 + ){ + nExtraDelete++; + } + if( pOp->p2 & OPFLAG_NCHANGE ){ + nExtraDelete--; + } +#endif + rc = sqlite3BtreeDelete(pC->uc.pCursor, pOp->p5); pC->cacheStatus = CACHE_STALE; @@ -4939,7 +4959,16 @@ case OP_IdxDelete: { r.default_rc = 0; r.aMem = &aMem[pOp->p2]; #ifdef SQLITE_DEBUG - { int i; for(i=0; iisEphemeral==0 + && (pOp->p5 & OPFLAG_IDXDELETE)==0 + && (pC->wrFlag & OPFLAG_FORDELETE)==0 + ){ + nExtraDelete++; + } + } #endif rc = sqlite3BtreeMovetoUnpacked(pCrsr, &r, 0, 0, &res); if( rc==SQLITE_OK && res==0 ){ @@ -6762,6 +6791,7 @@ vdbe_return: testcase( nVmStep>0 ); p->aCounter[SQLITE_STMTSTATUS_VM_STEP] += (int)nVmStep; sqlite3VdbeLeave(p); + assert( nExtraDelete==0 || sqlite3_strlike("DELETE%",p->zSql,0)!=0 ); return rc; /* Jump to here if a string or blob larger than SQLITE_MAX_LENGTH diff --git a/src/vdbeInt.h b/src/vdbeInt.h index b231cf908e..646cf31fed 100644 --- a/src/vdbeInt.h +++ b/src/vdbeInt.h @@ -82,6 +82,7 @@ struct VdbeCursor { u8 isTable; /* True for rowid tables. False for indexes */ #ifdef SQLITE_DEBUG u8 seekOp; /* Most recent seek operation on this cursor */ + u8 wrFlag; /* The wrFlag argument to sqlite3BtreeCursor() */ #endif Bool isEphemeral:1; /* True for an ephemeral table */ Bool useRandomRowid:1;/* Generate new record numbers semi-randomly */ diff --git a/test/e_changes.test b/test/e_changes.test index a77e22a2ee..c4b4406f7b 100644 --- a/test/e_changes.test +++ b/test/e_changes.test @@ -65,6 +65,7 @@ foreach {tn schema} { UPDATE t1 SET b=b+1 WHERE a<5; } 5 +exit # Delete 4 rows do_changes_test 1.$tn.4 { DELETE FROM t1 WHERE a>6 From 127f720240d07433276e0ce98cb8426a23266467 Mon Sep 17 00:00:00 2001 From: dan Date: Wed, 27 Jan 2016 16:17:41 +0000 Subject: [PATCH 46/75] Fix tests in fordelete.test to test for the BTREE_AUXDELETE flag. FossilOrigin-Name: bbd25cf179df5bda1fe729928d6746248f06e46f --- manifest | 17 ++++++------- manifest.uuid | 2 +- test/fordelete.test | 58 +++++++++++++++++++++++++++++++++++---------- 3 files changed, 53 insertions(+), 24 deletions(-) diff --git a/manifest b/manifest index bf4b14906c..dfebd3f6ae 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sassert()\sstatements\son\sthe\snExtraDelete\svariable\sin\svdbe.c\sto\stry\sto\sverify\nthat\sthe\sFORDELETE\sand\sIDXDELETE\sflags\sare\sbeing\sgenerated\scorrectly.\s\sThose\nflags\sare\snot\scurrently\sgenerated\scorrectly,\sand\sso\sthe\sassert()s\strip\son\sthis\ncheck-in. -D 2016-01-27T15:49:32.327 +C Fix\stests\sin\sfordelete.test\sto\stest\sfor\sthe\sBTREE_AUXDELETE\sflag. +D 2016-01-27T16:17:41.726 F Makefile.in 027c1603f255390c43a426671055a31c0a65fdb4 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 6fca5455aaecbd14479f33f091aa19df2d3d2969 @@ -642,7 +642,7 @@ F test/fkey6.test abb59f866c1b44926fd02d1fdd217d831fe04f48 F test/fkey7.test 72e915890ee4a005daaf3002cb208e8fe973ac13 F test/fkey8.test 8f08203458321e6c19a263829de4cfc936274ab0 F test/fkey_malloc.test 594a7ea1fbab553c036c70813cd8bd9407d63749 -F test/fordelete.test ba12ec1d27cc34a4c23db4446029126d773f3849 +F test/fordelete.test f794392f1768584609fa439f7528484dc04d3a03 F test/format4.test 1f0cac8ff3895e9359ed87e41aaabee982a812eb F test/fts-9fd058691.test 78b887e30ae6816df0e1fed6259de4b5a64ad33c F test/fts1a.test 46090311f85da51bb33bd5ce84f7948359c6d8d7 @@ -1422,10 +1422,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 9a71d56dcea953cb965f1fdda9a8b8f158cdeff6 -R 3af2d64e2a860c6e0d1b5193b911b983 -T *branch * fordelete-assert -T *sym-fordelete-assert * -T -sym-btree-fordelete-flag * -U drh -Z f5e1f3160ce620e13f32c1dda67a1107 +P dde1db0dd2e2cf04706117629756c352b178ebb8 +R 112344660260002964aa8c335bb07305 +U dan +Z e0043c886092534757bb67db359c02f9 diff --git a/manifest.uuid b/manifest.uuid index beafd3f9d6..2b4460a277 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -dde1db0dd2e2cf04706117629756c352b178ebb8 \ No newline at end of file +bbd25cf179df5bda1fe729928d6746248f06e46f \ No newline at end of file diff --git a/test/fordelete.test b/test/fordelete.test index 1e860e8867..7a49b5cbfd 100644 --- a/test/fordelete.test +++ b/test/fordelete.test @@ -30,17 +30,49 @@ proc analyze_delete_program {sql} { } { set T($rootpage) $name } - - # Calculate the results. - set res [list] + + # For each OpenWrite instruction generated for the proposed DELETE + # statement, add the following array entries: + # + # $M() -> + # $O() -> "*" | "" + # + # The O() entry is set to "*" if the BTREE_FORDELETE flag is specified, + # or "" otherwise. + # db eval "EXPLAIN $sql" R { - if {$R(opcode) == "OpenWrite"} { - set obj $T($R(p2)) - if {"0x$R(p5)" & 0x08} { append obj *} - lappend res $obj + if {$R(opcode)=="OpenWrite"} { + set root $R(p2) + set csr $R(p1) + if {[info exists T($root)]} { set M($csr) $T($root) } + + set obj $T($root) + set O($obj) "" + if {"0x$R(p5)" & 0x08} { + set O($obj) * + } else { + set O($obj) "" + } } } + db eval "EXPLAIN $sql" R { + if {$R(opcode) == "Delete"} { + set csr $R(p1) + if {[info exists M($csr)]} { + set idxdelete [expr {("0x$R(p5)" & 0x04) ? 1 : 0}] + if {$idxdelete} { + append O($M($csr)) "+" + } + } + } + } + + set res [list] + foreach {k v} [array get O] { + lappend res "${k}${v}" + } + lsort $res } @@ -53,10 +85,10 @@ do_execsql_test 1.0 { } foreach {tn sql res} { - 1 { DELETE FROM t1 WHERE a=?} { sqlite_autoindex_t1_1 t1* } - 2 { DELETE FROM t1 WHERE a=? AND b=? } { sqlite_autoindex_t1_1 t1 } - 3 { DELETE FROM t1 WHERE a>? } { sqlite_autoindex_t1_1 t1* } - 4 { DELETE FROM t1 WHERE rowid=? } { sqlite_autoindex_t1_1* t1 } + 1 { DELETE FROM t1 WHERE a=?} { sqlite_autoindex_t1_1 t1*+ } + 2 { DELETE FROM t1 WHERE a=? AND b=? } { sqlite_autoindex_t1_1 t1+ } + 3 { DELETE FROM t1 WHERE a>? } { sqlite_autoindex_t1_1 t1*+ } + 4 { DELETE FROM t1 WHERE rowid=? } { sqlite_autoindex_t1_1* t1 } } { do_adp_test 1.$tn $sql $res } @@ -68,8 +100,8 @@ do_execsql_test 2.0 { CREATE INDEX t2c ON t2(c); } foreach {tn sql res} { - 1 { DELETE FROM t2 WHERE a=?} { t2* t2a t2b* t2c* } - 2 { DELETE FROM t2 WHERE a=? AND +b=?} { t2 t2a t2b* t2c* } + 1 { DELETE FROM t2 WHERE a=?} { t2*+ t2a t2b* t2c* } + 2 { DELETE FROM t2 WHERE a=? AND +b=?} { t2+ t2a t2b* t2c* } 3 { DELETE FROM t2 WHERE a=? OR b=?} { t2 t2a* t2b* t2c* } 4 { DELETE FROM t2 WHERE +a=? } { t2 t2a* t2b* t2c* } 5 { DELETE FROM t2 WHERE rowid=? } { t2 t2a* t2b* t2c* } From def19e3b48c4064f38e6c701469f5365962f1481 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 27 Jan 2016 16:26:25 +0000 Subject: [PATCH 47/75] Change the name of the BTREE_IDXDELETE flag to BTREE_AUXDELETE, to better reflect its purpose. FossilOrigin-Name: 1d3bf6bebdda9f96734bc139601e9b05344ea0b4 --- manifest | 22 +++++++++++----------- manifest.uuid | 2 +- src/btree.c | 11 +++++++---- src/btree.h | 2 +- src/delete.c | 4 +--- src/sqliteInt.h | 2 +- src/vdbe.c | 20 +++++++++++--------- 7 files changed, 33 insertions(+), 30 deletions(-) diff --git a/manifest b/manifest index dfebd3f6ae..9790c25453 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\stests\sin\sfordelete.test\sto\stest\sfor\sthe\sBTREE_AUXDELETE\sflag. -D 2016-01-27T16:17:41.726 +C Change\sthe\sname\sof\sthe\sBTREE_IDXDELETE\sflag\sto\sBTREE_AUXDELETE,\sto\sbetter\nreflect\sits\spurpose. +D 2016-01-27T16:26:25.226 F Makefile.in 027c1603f255390c43a426671055a31c0a65fdb4 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 6fca5455aaecbd14479f33f091aa19df2d3d2969 @@ -290,8 +290,8 @@ F src/auth.c b56c78ebe40a2110fd361379f7e8162d23f92240 F src/backup.c 2869a76c03eb393ee795416e2387005553df72bc F src/bitvec.c 1a78d450a17c5016710eec900bedfc5729bf9bdf F src/btmutex.c bc87dd3b062cc26edfe79918de2200ccb8d41e73 -F src/btree.c 97cf881292e085ee71faf44f7167b6312965b562 -F src/btree.h c5dfbbc59226fa5fcc2b03befa85fe10ef23c1b5 +F src/btree.c 16edaf415a54a2fc9058e3bc47d0c894cd59635e +F src/btree.h 368ceeb4bd9312dc8df2ffd64b4b7dbcf4db5f8e F src/btreeInt.h c18b7d2a3494695133e4e60ee36061d37f45d9a5 F src/build.c b4eba1e84752ec9cae7ff3dacd5a8b6d1ab8deb9 F src/callback.c 29ae4faba226c7ebb9aee93016b5ce8a8f071261 @@ -299,7 +299,7 @@ F src/complete.c addcd8160b081131005d5bc2d34adf20c1c5c92f F src/ctime.c 60e135af364d777a9ab41c97e5e89cd224da6198 F src/date.c 997651e3ee6c2818fbf7fcdb7156cef9eb3ece20 F src/dbstat.c b2ec6793eef97aebb4d171d490a4ffdfa9f2475c -F src/delete.c db231a9895681efed007c0887e38b49f4d1291a5 +F src/delete.c 33ed87dc0746b1f8ce186f62b608bf40801af9c0 F src/expr.c d10c1cdef5810cdbf73adc9f9b383684230b360a F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb F src/fkey.c c66d3e5b35d4d95b5c1e2ee6c12f5df13a7f9ad6 @@ -352,7 +352,7 @@ F src/shell.c dcd7a83645ef2a58ee9c6d0ea4714d877d7835c4 F src/sqlite.h.in 214476a62012e578f42133a9a3b4f97a9aa421a3 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h dfbe62ffd95b99afe2140d8c35b180d11924072d -F src/sqliteInt.h 0faffdeed20201bedb202cf6ec07f14b29158c66 +F src/sqliteInt.h 12ec54454fc0f1c25f5c7057423ada1a363b6db0 F src/sqliteLimit.h 216557999cb45f2e3578ed53ebefe228d779cb46 F src/status.c 70912d7be68e9e2dbc4010c93d344af61d4c59ba F src/table.c 51b46b2a62d1b3a959633d593b89bab5e2c9155e @@ -412,7 +412,7 @@ F src/update.c 17332f9fe818cbc0444c36a811800af8498af4c3 F src/utf.c 32d7f82aa921322f3e1c956f4b58f019ebd2c6b3 F src/util.c 72d40df0a52d3f30b462a15f0e094fcbade6dc82 F src/vacuum.c 2ddd5cad2a7b9cef7f9e431b8c7771634c6b1701 -F src/vdbe.c a27a3fdc65f5728c6e9bff49b6753fbf9d73c8c0 +F src/vdbe.c c367615fecb5fae8a39113ee2b6ecbab94e4bcd3 F src/vdbe.h 7a733ea8aac1b77305a67698e784fa3484ee3337 F src/vdbeInt.h 40c728712a2975855a2ac6aac44bf02dfd4a4c30 F src/vdbeapi.c ffae8f5af4570fbd548504e815e9fb7227f0822e @@ -1422,7 +1422,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P dde1db0dd2e2cf04706117629756c352b178ebb8 -R 112344660260002964aa8c335bb07305 -U dan -Z e0043c886092534757bb67db359c02f9 +P bbd25cf179df5bda1fe729928d6746248f06e46f +R 21474325914b9893f106ce3a1694990c +U drh +Z 6ce2f1bf15f4f84bace517d6cc10a5ac diff --git a/manifest.uuid b/manifest.uuid index 2b4460a277..d16254398c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -bbd25cf179df5bda1fe729928d6746248f06e46f \ No newline at end of file +1d3bf6bebdda9f96734bc139601e9b05344ea0b4 \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index 89144e7a84..04748e1b37 100644 --- a/src/btree.c +++ b/src/btree.c @@ -8098,9 +8098,12 @@ end_insert: ** the next call to BtreeNext() or BtreePrev() moves it to the same row ** as it would have been on if the call to BtreeDelete() had been omitted. ** -** The BTREE_IDXDELETE bit of flags indicates that this is a delete of -** an index entry where the corresponding table row has already been deleted. -** The BTREE_IDXDELETE bit is a hint that is not used by this implementation, +** The BTREE_AUXDELETE bit of flags indicates that is one of several deletes +** associated with a single table entry and its indexes. Only one of those +** deletes is considered the "primary" delete. The primary delete occurs +** on a cursor that is not a BTREE_FORDELETE cursor. All but one delete +** operation on non-FORDELETE cursors is tagged with the AUXDELETE flag. +** The BTREE_AUXDELETE bit is a hint that is not used by this implementation, ** but which might be used by alternative storage engines. */ int sqlite3BtreeDelete(BtCursor *pCur, u8 flags){ @@ -8123,7 +8126,7 @@ int sqlite3BtreeDelete(BtCursor *pCur, u8 flags){ assert( !hasReadConflicts(p, pCur->pgnoRoot) ); assert( pCur->aiIdx[pCur->iPage]apPage[pCur->iPage]->nCell ); assert( pCur->eState==CURSOR_VALID ); - assert( (flags & ~(BTREE_SAVEPOSITION | BTREE_IDXDELETE))==0 ); + assert( (flags & ~(BTREE_SAVEPOSITION | BTREE_AUXDELETE))==0 ); iCellDepth = pCur->iPage; iCellIdx = pCur->aiIdx[iCellDepth]; diff --git a/src/btree.h b/src/btree.h index 416faca651..30522e99e1 100644 --- a/src/btree.h +++ b/src/btree.h @@ -249,7 +249,7 @@ int sqlite3BtreeDelete(BtCursor*, u8 flags); /* Allowed flags for the 2nd argument to sqlite3BtreeDelete() */ #define BTREE_SAVEPOSITION 0x02 /* Leave cursor pointing at NEXT or PREV */ -#define BTREE_IDXDELETE 0x04 /* this is index, table row already deleted */ +#define BTREE_AUXDELETE 0x04 /* not the primary delete operation */ int sqlite3BtreeInsert(BtCursor*, const void *pKey, i64 nKey, const void *pData, int nData, diff --git a/src/delete.c b/src/delete.c index b3143c5f72..5b5a5e3cb1 100644 --- a/src/delete.c +++ b/src/delete.c @@ -724,12 +724,10 @@ void sqlite3GenerateRowDelete( sqlite3VdbeChangeP4(v, -1, pTab->zName, P4_TRANSIENT); } if( eMode!=ONEPASS_OFF ){ - sqlite3VdbeChangeP5(v, OPFLAG_IDXDELETE); - p5 = OPFLAG_IDXDELETE; + sqlite3VdbeChangeP5(v, OPFLAG_AUXDELETE); } if( iIdxNoSeek>=0 ){ sqlite3VdbeAddOp1(v, OP_Delete, iIdxNoSeek); - p5 = 0; } if( eMode==ONEPASS_MULTI ) p5 |= OPFLAG_SAVEPOSITION; sqlite3VdbeChangeP5(v, p5); diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 9aeffe216c..364b7a352e 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -2862,7 +2862,7 @@ struct AuthContext { #define OPFLAG_P2ISREG 0x10 /* P2 to OP_Open** is a register number */ #define OPFLAG_PERMUTE 0x01 /* OP_Compare: use the permutation */ #define OPFLAG_SAVEPOSITION 0x02 /* OP_Delete: keep cursor position */ -#define OPFLAG_IDXDELETE 0x04 /* OP_Delete: index in a DELETE op */ +#define OPFLAG_AUXDELETE 0x04 /* OP_Delete: index in a DELETE op */ /* * Each trigger present in the database schema is stored as an instance of diff --git a/src/vdbe.c b/src/vdbe.c index 8583bcd4ba..f6a7946e6f 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -553,7 +553,7 @@ int sqlite3VdbeExec( Op *pOrigOp; /* Value of pOp at the top of the loop */ #endif #ifdef SQLITE_DEBUG - int nExtraDelete = 0; /* Verifies FORDELETE and IDXDELETE flags */ + int nExtraDelete = 0; /* Verifies FORDELETE and AUXDELETE flags */ #endif int rc = SQLITE_OK; /* Value to return */ sqlite3 *db = p->db; /* The database */ @@ -4355,9 +4355,11 @@ case OP_InsertInt: { ** OPFLAG_SAVEPOSITION bit of P5 is clear, then the cursor will be ** left in an undefined state. ** -** If the OPFLAG_IDXDELETE bit is set on P5, that indicates that this -** delete is on an index cursor where the corresponding table row has -** already been deleted. +** If the OPFLAG_AUXDELETE bit is set on P5, that indicates that this +** delete one of several associated with deleting a table row and all its +** associated index entries. Exactly one of those deletes is the "primary" +** delete. The others are all on OPFLAG_FORDELETE cursors or else are +** marked with the AUXDELETE flag. ** ** If the OPFLAG_NCHANGE flag of P2 (NB: P2 not P5) is set, then the row ** change count is incremented (otherwise not). @@ -4397,14 +4399,14 @@ case OP_Delete: { } #endif - /* Only flags that can be set are SAVEPOISTION and IDXDELETE */ - assert( (pOp->p5 & ~(OPFLAG_SAVEPOSITION|OPFLAG_IDXDELETE))==0 ); + /* Only flags that can be set are SAVEPOISTION and AUXDELETE */ + assert( (pOp->p5 & ~(OPFLAG_SAVEPOSITION|OPFLAG_AUXDELETE))==0 ); assert( OPFLAG_SAVEPOSITION==BTREE_SAVEPOSITION ); - assert( OPFLAG_IDXDELETE==BTREE_IDXDELETE ); + assert( OPFLAG_AUXDELETE==BTREE_AUXDELETE ); #ifdef SQLITE_DEBUG if( pC->isEphemeral==0 - && (pOp->p5 & OPFLAG_IDXDELETE)==0 + && (pOp->p5 & OPFLAG_AUXDELETE)==0 && (pC->wrFlag & OPFLAG_FORDELETE)==0 ){ nExtraDelete++; @@ -4963,7 +4965,7 @@ case OP_IdxDelete: { int i; for(i=0; iisEphemeral==0 - && (pOp->p5 & OPFLAG_IDXDELETE)==0 + && (pOp->p5 & OPFLAG_AUXDELETE)==0 && (pC->wrFlag & OPFLAG_FORDELETE)==0 ){ nExtraDelete++; From 5a2412f418bf96767fb5bc9979ca678811f8d94d Mon Sep 17 00:00:00 2001 From: mistachkin Date: Wed, 27 Jan 2016 23:50:14 +0000 Subject: [PATCH 48/75] Match the MSVC batch build tool sub-routine 'fn_UnsetVariable' a bit more robust. FossilOrigin-Name: 1edd5f31b9e6f91bb5434055a539428c000f1084 --- manifest | 12 ++++++------ manifest.uuid | 2 +- tool/build-all-msvc.bat | 5 +++-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 07acca6779..7bd8b070a6 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Support\sbuilding\sfor\sWindows\s10\sdesktop\susing\s'MinCore.lib'. -D 2016-01-27T07:28:33.525 +C Match\sthe\sMSVC\sbatch\sbuild\stool\ssub-routine\s'fn_UnsetVariable'\sa\sbit\smore\srobust. +D 2016-01-27T23:50:14.931 F Makefile.in 027c1603f255390c43a426671055a31c0a65fdb4 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 72b7858f02017611c3ac1ddc965251017fed0845 @@ -1363,7 +1363,7 @@ F test/zerodamage.test cf6748bad89553cc1632be51a6f54e487e4039ac F tool/GetFile.cs a15e08acb5dd7539b75ba23501581d7c2b462cb5 F tool/GetTclKit.bat 629d87562e0487c386db630033931d12d62e6372 F tool/addopcodes.tcl 4ca9c3ef196f08da30add5d07ce0c9458dc8c633 -F tool/build-all-msvc.bat 204a039f985d5a4f4f9df3a3aa594fd17848c37e x +F tool/build-all-msvc.bat 6def0b5cebba36db69da8a92a9a31daf92714b4f x F tool/build-shell.sh 950f47c6174f1eea171319438b93ba67ff5bf367 F tool/cg_anno.tcl 692ce4b8693d59e3a3de77ca97f4139ecfa641b0 x F tool/checkSpacing.c 810e51703529a204fc4e1eb060e9ab663e3c06d2 @@ -1422,7 +1422,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P a3d7b8ac53f94d29a11362f193fd1967f30583df -R 626d84a8bdebb7b947f7c1e376ac97c5 +P 4bf89891fbb076364dc45a6bf3246efa6bc33d5d +R 9e8aa43303c9d43f019b8eceec782e78 U mistachkin -Z 136b0599f548728406750a73608ec6f4 +Z 8662626dcb0cb6b59115e089abf15292 diff --git a/manifest.uuid b/manifest.uuid index 20f348c1ae..60bd1f672e 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -4bf89891fbb076364dc45a6bf3246efa6bc33d5d \ No newline at end of file +1edd5f31b9e6f91bb5434055a539428c000f1084 \ No newline at end of file diff --git a/tool/build-all-msvc.bat b/tool/build-all-msvc.bat index 87794132b6..30371177db 100755 --- a/tool/build-all-msvc.bat +++ b/tool/build-all-msvc.bat @@ -729,8 +729,9 @@ GOTO no_errors GOTO :EOF :fn_UnsetVariable - IF NOT "%1" == "" ( - SET %1= + SET VALUE=%1 + IF DEFINED VALUE ( + SET %VALUE%= CALL :fn_ResetErrorLevel ) GOTO :EOF From 00029a1add0f6e19b134b585bade4cbfefe1afa4 Mon Sep 17 00:00:00 2001 From: mistachkin Date: Thu, 28 Jan 2016 00:04:32 +0000 Subject: [PATCH 49/75] Minor correction to the batch tool changes in the previous check-in. FossilOrigin-Name: 7c89d75de1e8d44d7ebd8eac1320b50dd6c221a8 --- manifest | 12 ++++++------ manifest.uuid | 2 +- tool/build-all-msvc.bat | 1 + 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/manifest b/manifest index 7bd8b070a6..8dd79dc815 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Match\sthe\sMSVC\sbatch\sbuild\stool\ssub-routine\s'fn_UnsetVariable'\sa\sbit\smore\srobust. -D 2016-01-27T23:50:14.931 +C Minor\scorrection\sto\sthe\sbatch\stool\schanges\sin\sthe\sprevious\scheck-in. +D 2016-01-28T00:04:32.165 F Makefile.in 027c1603f255390c43a426671055a31c0a65fdb4 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 72b7858f02017611c3ac1ddc965251017fed0845 @@ -1363,7 +1363,7 @@ F test/zerodamage.test cf6748bad89553cc1632be51a6f54e487e4039ac F tool/GetFile.cs a15e08acb5dd7539b75ba23501581d7c2b462cb5 F tool/GetTclKit.bat 629d87562e0487c386db630033931d12d62e6372 F tool/addopcodes.tcl 4ca9c3ef196f08da30add5d07ce0c9458dc8c633 -F tool/build-all-msvc.bat 6def0b5cebba36db69da8a92a9a31daf92714b4f x +F tool/build-all-msvc.bat 77f85f4268c2711d637c629610d0cf3df5338638 x F tool/build-shell.sh 950f47c6174f1eea171319438b93ba67ff5bf367 F tool/cg_anno.tcl 692ce4b8693d59e3a3de77ca97f4139ecfa641b0 x F tool/checkSpacing.c 810e51703529a204fc4e1eb060e9ab663e3c06d2 @@ -1422,7 +1422,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 4bf89891fbb076364dc45a6bf3246efa6bc33d5d -R 9e8aa43303c9d43f019b8eceec782e78 +P 1edd5f31b9e6f91bb5434055a539428c000f1084 +R dd88757d0a47522dcabe5cdbe4d1c234 U mistachkin -Z 8662626dcb0cb6b59115e089abf15292 +Z b852cd61a6ae9681850058c67e7066b1 diff --git a/manifest.uuid b/manifest.uuid index 60bd1f672e..3c05b7f8a9 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -1edd5f31b9e6f91bb5434055a539428c000f1084 \ No newline at end of file +7c89d75de1e8d44d7ebd8eac1320b50dd6c221a8 \ No newline at end of file diff --git a/tool/build-all-msvc.bat b/tool/build-all-msvc.bat index 30371177db..2dd01004d5 100755 --- a/tool/build-all-msvc.bat +++ b/tool/build-all-msvc.bat @@ -732,6 +732,7 @@ GOTO no_errors SET VALUE=%1 IF DEFINED VALUE ( SET %VALUE%= + SET VALUE= CALL :fn_ResetErrorLevel ) GOTO :EOF From ba60fbb6216f1b0dd5625429b8c8d12de965c65a Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 28 Jan 2016 02:47:32 +0000 Subject: [PATCH 50/75] Fix for pthread detection in the configure scripts. FossilOrigin-Name: 47633ffdbfead3ce7b1f6560660df99f950d24f8 --- autoconf/configure.ac | 1 + configure | 56 +++++++++++++++++++++++++++++++++++++++++++ configure.ac | 1 + manifest | 18 +++++++------- manifest.uuid | 2 +- 5 files changed, 68 insertions(+), 10 deletions(-) diff --git a/autoconf/configure.ac b/autoconf/configure.ac index fcca148aea..9492530680 100644 --- a/autoconf/configure.ac +++ b/autoconf/configure.ac @@ -75,6 +75,7 @@ AC_ARG_ENABLE(threadsafe, [AS_HELP_STRING( THREADSAFE_FLAGS=-DSQLITE_THREADSAFE=0 if test x"$enable_threadsafe" != "xno"; then THREADSAFE_FLAGS="-D_REENTRANT=1 -DSQLITE_THREADSAFE=1" + AC_SEARCH_LIBS(pthread_create, pthread) AC_SEARCH_LIBS(pthread_mutexattr_init, pthread) fi AC_SUBST(THREADSAFE_FLAGS) diff --git a/configure b/configure index 951b719ed5..b2cb4d1308 100755 --- a/configure +++ b/configure @@ -10464,6 +10464,62 @@ fi if test "$SQLITE_THREADSAFE" = "1"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing pthread_create" >&5 +$as_echo_n "checking for library containing pthread_create... " >&6; } +if ${ac_cv_search_pthread_create+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_func_search_save_LIBS=$LIBS +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char pthread_create (); +int +main () +{ +return pthread_create (); + ; + return 0; +} +_ACEOF +for ac_lib in '' pthread; do + if test -z "$ac_lib"; then + ac_res="none required" + else + ac_res=-l$ac_lib + LIBS="-l$ac_lib $ac_func_search_save_LIBS" + fi + if ac_fn_c_try_link "$LINENO"; then : + ac_cv_search_pthread_create=$ac_res +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext + if ${ac_cv_search_pthread_create+:} false; then : + break +fi +done +if ${ac_cv_search_pthread_create+:} false; then : + +else + ac_cv_search_pthread_create=no +fi +rm conftest.$ac_ext +LIBS=$ac_func_search_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_pthread_create" >&5 +$as_echo "$ac_cv_search_pthread_create" >&6; } +ac_res=$ac_cv_search_pthread_create +if test "$ac_res" != no; then : + test "$ac_res" = "none required" || LIBS="$ac_res $LIBS" + +fi + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing pthread_mutexattr_init" >&5 $as_echo_n "checking for library containing pthread_mutexattr_init... " >&6; } if ${ac_cv_search_pthread_mutexattr_init+:} false; then : diff --git a/configure.ac b/configure.ac index 26a60147dd..19f85dc875 100644 --- a/configure.ac +++ b/configure.ac @@ -194,6 +194,7 @@ fi AC_SUBST(SQLITE_THREADSAFE) if test "$SQLITE_THREADSAFE" = "1"; then + AC_SEARCH_LIBS(pthread_create, pthread) AC_SEARCH_LIBS(pthread_mutexattr_init, pthread) fi diff --git a/manifest b/manifest index 8dd79dc815..c2a27c575e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Minor\scorrection\sto\sthe\sbatch\stool\schanges\sin\sthe\sprevious\scheck-in. -D 2016-01-28T00:04:32.165 +C Fix\sfor\spthread\sdetection\sin\sthe\sconfigure\sscripts. +D 2016-01-28T02:47:32.836 F Makefile.in 027c1603f255390c43a426671055a31c0a65fdb4 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 72b7858f02017611c3ac1ddc965251017fed0845 @@ -14,7 +14,7 @@ F autoconf/Makefile.am 1c1657650775960804945dc392e14d9e43c5ed84 F autoconf/Makefile.msc 2ce3b1565a52d7083a1dbf57a1706fd14cc1ee0c F autoconf/README.first 6c4f34fe115ff55d4e8dbfa3cecf04a0188292f7 F autoconf/README.txt e9757a381e5ce2553dbaa6247bb8ad00eb8d87aa -F autoconf/configure.ac 7b1ea0dcaf49fafba262ce4b0ee8cb3281b555d1 +F autoconf/configure.ac 72a5e42beb090b32bca580285dc0ab3c4670adb8 F autoconf/tea/Makefile.in b438a7020446c8a8156e8d97c8914a04833da6fd F autoconf/tea/README 3e9a3c060f29a44344ab50aec506f4db903fb873 F autoconf/tea/aclocal.m4 52c47aac44ce0ddb1f918b6993e8beb8eee88f43 @@ -30,8 +30,8 @@ F autoconf/tea/win/rules.vc c511f222b80064096b705dbeb97060ee1d6b6d63 F config.guess 226d9a188c6196f3033ffc651cbc9dcee1a42977 F config.h.in 42b71ad3fe21c9e88fa59e8458ca1a6bc72eb0c0 F config.sub 9ebe4c3b3dab6431ece34f16828b594fb420da55 -F configure d57d3b9d5c66549e54a4a2960de9813142d30a5a x -F configure.ac c59513d560b3107995c73b9cc1e55bfd086c4764 +F configure 12d96e3798e612e0ffa53a7a8c4d7fb1090df80e x +F configure.ac a2224b1162f79848982d3618ac1deffcd94e88ec F contrib/sqlitecon.tcl 210a913ad63f9f991070821e599d600bd913e0ad F doc/lemon.html 334dbf6621b8fb8790297ec1abf3cfa4621709d1 F doc/pager-invariants.txt 27fed9a70ddad2088750c4a2b493b63853da2710 @@ -1422,7 +1422,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 1edd5f31b9e6f91bb5434055a539428c000f1084 -R dd88757d0a47522dcabe5cdbe4d1c234 -U mistachkin -Z b852cd61a6ae9681850058c67e7066b1 +P 7c89d75de1e8d44d7ebd8eac1320b50dd6c221a8 +R aa8b5eab35ce807961f68c0e84ef93a7 +U drh +Z c7a8f0aff80d4c386e53fd4da40e1b68 diff --git a/manifest.uuid b/manifest.uuid index 3c05b7f8a9..a8cb6444e4 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -7c89d75de1e8d44d7ebd8eac1320b50dd6c221a8 \ No newline at end of file +47633ffdbfead3ce7b1f6560660df99f950d24f8 \ No newline at end of file From d5cafb380e588ac0b2f18bfaa2008c9a90fb5996 Mon Sep 17 00:00:00 2001 From: dan Date: Thu, 28 Jan 2016 08:58:45 +0000 Subject: [PATCH 51/75] Remove a duplicate "p->magic = VDBE_MAGIC_RUN;" line from vdbeaux.c. FossilOrigin-Name: 688eb3b400a3f2f8005c341e8259f4c1485cb0ed --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/vdbeaux.c | 1 - 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index c2a27c575e..2864c79773 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sfor\spthread\sdetection\sin\sthe\sconfigure\sscripts. -D 2016-01-28T02:47:32.836 +C Remove\sa\sduplicate\s"p->magic\s=\sVDBE_MAGIC_RUN;"\sline\sfrom\svdbeaux.c. +D 2016-01-28T08:58:45.702 F Makefile.in 027c1603f255390c43a426671055a31c0a65fdb4 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 72b7858f02017611c3ac1ddc965251017fed0845 @@ -416,7 +416,7 @@ F src/vdbe.c 3ffbcc413bf793e3f0b95b79ef2f4bd449a5b5a3 F src/vdbe.h 7a733ea8aac1b77305a67698e784fa3484ee3337 F src/vdbeInt.h 42eefa4f9e7432b9968d321b44e48821ec13b189 F src/vdbeapi.c ffae8f5af4570fbd548504e815e9fb7227f0822e -F src/vdbeaux.c 757f86e6fef8efb3dd4226cb31e2e82b9c44c883 +F src/vdbeaux.c fc8926c4232cd5c982f36197b1443212f265d927 F src/vdbeblob.c 37c3d11a753e403698c69e17383d282e1ae73e75 F src/vdbemem.c b9181e77eca2a095929d46250daf85c8d2621fc0 F src/vdbesort.c 3bb1f1f03162e6d223da623714d8e93fcaeac658 @@ -1422,7 +1422,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 7c89d75de1e8d44d7ebd8eac1320b50dd6c221a8 -R aa8b5eab35ce807961f68c0e84ef93a7 -U drh -Z c7a8f0aff80d4c386e53fd4da40e1b68 +P 47633ffdbfead3ce7b1f6560660df99f950d24f8 +R cfc22f0fb66c12a8ff66ff6486e44028 +U dan +Z 6ad2591078bc40cf96572d242da40773 diff --git a/manifest.uuid b/manifest.uuid index a8cb6444e4..a99478065f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -47633ffdbfead3ce7b1f6560660df99f950d24f8 \ No newline at end of file +688eb3b400a3f2f8005c341e8259f4c1485cb0ed \ No newline at end of file diff --git a/src/vdbeaux.c b/src/vdbeaux.c index e9be081a20..3bbc5aad53 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -1790,7 +1790,6 @@ void sqlite3VdbeRewind(Vdbe *p){ p->pc = -1; p->rc = SQLITE_OK; p->errorAction = OE_Abort; - p->magic = VDBE_MAGIC_RUN; p->nChange = 0; p->cacheCtr = 1; p->minWriteFileFormat = 255; From e61bbf441746d6129c9bfb09ab70ccdd6bfc421f Mon Sep 17 00:00:00 2001 From: dan Date: Thu, 28 Jan 2016 17:06:17 +0000 Subject: [PATCH 52/75] Modifications to ensure the nExtraDelete-related assert() statement does not fail. FossilOrigin-Name: f43ff8f82d6c1239e6f9a32e7716421c1180ac74 --- manifest | 16 +++++++-------- manifest.uuid | 2 +- src/vdbe.c | 32 +++++++++++------------------- test/fordelete.test | 48 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 68 insertions(+), 30 deletions(-) diff --git a/manifest b/manifest index 9790c25453..dc719b86ce 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Change\sthe\sname\sof\sthe\sBTREE_IDXDELETE\sflag\sto\sBTREE_AUXDELETE,\sto\sbetter\nreflect\sits\spurpose. -D 2016-01-27T16:26:25.226 +C Modifications\sto\sensure\sthe\snExtraDelete-related\sassert()\sstatement\sdoes\snot\sfail. +D 2016-01-28T17:06:17.501 F Makefile.in 027c1603f255390c43a426671055a31c0a65fdb4 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 6fca5455aaecbd14479f33f091aa19df2d3d2969 @@ -412,7 +412,7 @@ F src/update.c 17332f9fe818cbc0444c36a811800af8498af4c3 F src/utf.c 32d7f82aa921322f3e1c956f4b58f019ebd2c6b3 F src/util.c 72d40df0a52d3f30b462a15f0e094fcbade6dc82 F src/vacuum.c 2ddd5cad2a7b9cef7f9e431b8c7771634c6b1701 -F src/vdbe.c c367615fecb5fae8a39113ee2b6ecbab94e4bcd3 +F src/vdbe.c 66c429896ce44ebcbe199f1c7a592c12095158f0 F src/vdbe.h 7a733ea8aac1b77305a67698e784fa3484ee3337 F src/vdbeInt.h 40c728712a2975855a2ac6aac44bf02dfd4a4c30 F src/vdbeapi.c ffae8f5af4570fbd548504e815e9fb7227f0822e @@ -642,7 +642,7 @@ F test/fkey6.test abb59f866c1b44926fd02d1fdd217d831fe04f48 F test/fkey7.test 72e915890ee4a005daaf3002cb208e8fe973ac13 F test/fkey8.test 8f08203458321e6c19a263829de4cfc936274ab0 F test/fkey_malloc.test 594a7ea1fbab553c036c70813cd8bd9407d63749 -F test/fordelete.test f794392f1768584609fa439f7528484dc04d3a03 +F test/fordelete.test 57ed9b953eeace09dd2eac3251b40bf9d6990aec F test/format4.test 1f0cac8ff3895e9359ed87e41aaabee982a812eb F test/fts-9fd058691.test 78b887e30ae6816df0e1fed6259de4b5a64ad33c F test/fts1a.test 46090311f85da51bb33bd5ce84f7948359c6d8d7 @@ -1422,7 +1422,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P bbd25cf179df5bda1fe729928d6746248f06e46f -R 21474325914b9893f106ce3a1694990c -U drh -Z 6ce2f1bf15f4f84bace517d6cc10a5ac +P 1d3bf6bebdda9f96734bc139601e9b05344ea0b4 +R 8c4c31e27c8a082a17d0a49af9f3ce1b +U dan +Z 9dc5d2517a8a4fb456754e0a3cfe77cf diff --git a/manifest.uuid b/manifest.uuid index d16254398c..b83d35e772 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -1d3bf6bebdda9f96734bc139601e9b05344ea0b4 \ No newline at end of file +f43ff8f82d6c1239e6f9a32e7716421c1180ac74 \ No newline at end of file diff --git a/src/vdbe.c b/src/vdbe.c index f6a7946e6f..c2e70ea8b2 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -4405,14 +4405,16 @@ case OP_Delete: { assert( OPFLAG_AUXDELETE==BTREE_AUXDELETE ); #ifdef SQLITE_DEBUG - if( pC->isEphemeral==0 - && (pOp->p5 & OPFLAG_AUXDELETE)==0 - && (pC->wrFlag & OPFLAG_FORDELETE)==0 - ){ - nExtraDelete++; - } - if( pOp->p2 & OPFLAG_NCHANGE ){ - nExtraDelete--; + if( p->pFrame==0 ){ + if( pC->isEphemeral==0 + && (pOp->p5 & OPFLAG_AUXDELETE)==0 + && (pC->wrFlag & OPFLAG_FORDELETE)==0 + ){ + nExtraDelete++; + } + if( pOp->p2 & OPFLAG_NCHANGE ){ + nExtraDelete--; + } } #endif @@ -4960,21 +4962,9 @@ case OP_IdxDelete: { r.nField = (u16)pOp->p3; r.default_rc = 0; r.aMem = &aMem[pOp->p2]; -#ifdef SQLITE_DEBUG - { - int i; - for(i=0; iisEphemeral==0 - && (pOp->p5 & OPFLAG_AUXDELETE)==0 - && (pC->wrFlag & OPFLAG_FORDELETE)==0 - ){ - nExtraDelete++; - } - } -#endif rc = sqlite3BtreeMovetoUnpacked(pCrsr, &r, 0, 0, &res); if( rc==SQLITE_OK && res==0 ){ - rc = sqlite3BtreeDelete(pCrsr, 0); + rc = sqlite3BtreeDelete(pCrsr, BTREE_AUXDELETE); } assert( pC->deferredMoveto==0 ); pC->cacheStatus = CACHE_STALE; diff --git a/test/fordelete.test b/test/fordelete.test index 7a49b5cbfd..bc38a4c5e3 100644 --- a/test/fordelete.test +++ b/test/fordelete.test @@ -158,5 +158,53 @@ do_test 3.2 { } } {6 {} {} {}} + +#------------------------------------------------------------------------- +# +reset_db +do_execsql_test 4.0 { + CREATE TABLE log(x); + CREATE TABLE p1(one PRIMARY KEY, two); + + CREATE TRIGGER tr_bd BEFORE DELETE ON p1 BEGIN + INSERT INTO log VALUES('delete'); + END; + INSERT INTO p1 VALUES('a', 'A'), ('b', 'B'), ('c', 'C'); + DELETE FROM p1 WHERE one = 'a'; +} + +reset_db +do_execsql_test 4.1 { + BEGIN TRANSACTION; + CREATE TABLE tbl(a PRIMARY KEY, b, c); + CREATE TABLE log(a, b, c); + INSERT INTO "tbl" VALUES(1,2,3); + CREATE TRIGGER the_trigger BEFORE DELETE ON tbl BEGIN + INSERT INTO log VALUES(1, 2,3); + END; + COMMIT; + DELETE FROM tbl WHERE a=1; +} + +reset_db +do_execsql_test 5.1 { + PRAGMA foreign_keys = 1; + CREATE TABLE t1(a INTEGER PRIMARY KEY, b); + CREATE TABLE t2( + c INTEGER PRIMARY KEY, + d INTEGER DEFAULT 1 REFERENCES t1 ON DELETE SET DEFAULT + ); +} {} +do_execsql_test 5.2 { + INSERT INTO t1 VALUES(1, 'one'); + INSERT INTO t1 VALUES(2, 'two'); + INSERT INTO t2 VALUES(1, 2); + SELECT * FROM t2; +} {1 2} +do_execsql_test 5.3 { + DELETE FROM t1 WHERE a = 2; +} {} + + finish_test From 895c00e16a0308b0e0fc9fb49c1c6fdc8713af46 Mon Sep 17 00:00:00 2001 From: dan Date: Thu, 28 Jan 2016 18:22:46 +0000 Subject: [PATCH 53/75] Modify the order of terms in an "if" condition to avoid implicitly comparing a dangling pointer to NULL following an OOM error. FossilOrigin-Name: 5372f800835da61736a64dcee8b476bbe7ee2e46 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/parse.y | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 2864c79773..771dba7fa8 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Remove\sa\sduplicate\s"p->magic\s=\sVDBE_MAGIC_RUN;"\sline\sfrom\svdbeaux.c. -D 2016-01-28T08:58:45.702 +C Modify\sthe\sorder\sof\sterms\sin\san\s"if"\scondition\sto\savoid\simplicitly\scomparing\sa\sdangling\spointer\sto\sNULL\sfollowing\san\sOOM\serror. +D 2016-01-28T18:22:46.091 F Makefile.in 027c1603f255390c43a426671055a31c0a65fdb4 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 72b7858f02017611c3ac1ddc965251017fed0845 @@ -336,7 +336,7 @@ F src/os_win.c ccf29ddded3e41e506b6bd98c1171aa0963b23f2 F src/os_win.h eb7a47aa17b26b77eb97e4823f20a00b8bda12ca F src/pager.c 2916c66aee50f69d9ec56a7619b62d9c6a3bee61 F src/pager.h 1c2a49143dfba9e69cc8159ef019f472ed8d260b -F src/parse.y caad1e98edeca6960493d0c60d31b76820dd7776 +F src/parse.y 426a91fbbbf7cdde3fd4b8798de7317a8782bec5 F src/pcache.c 73895411fa6b7bd6f0091212feabbe833b358d23 F src/pcache.h 4d0ccaad264d360981ec5e6a2b596d6e85242545 F src/pcache1.c 72f644dc9e1468c72922eff5904048427b817051 @@ -1422,7 +1422,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 47633ffdbfead3ce7b1f6560660df99f950d24f8 -R cfc22f0fb66c12a8ff66ff6486e44028 +P 688eb3b400a3f2f8005c341e8259f4c1485cb0ed +R e0b38fbf138d8fe5067019d9b4797980 U dan -Z 6ad2591078bc40cf96572d242da40773 +Z 338551eead62c92e7c871564cd38e428 diff --git a/manifest.uuid b/manifest.uuid index a99478065f..9de4b4f3bf 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -688eb3b400a3f2f8005c341e8259f4c1485cb0ed \ No newline at end of file +5372f800835da61736a64dcee8b476bbe7ee2e46 \ No newline at end of file diff --git a/src/parse.y b/src/parse.y index d6a587a2c8..846c2504b7 100644 --- a/src/parse.y +++ b/src/parse.y @@ -1010,7 +1010,7 @@ expr(A) ::= expr(X) NOT NULL(E). {spanUnaryPostfix(&A,pParse,TK_NOTNULL,&X,&E);} ** unary TK_ISNULL or TK_NOTNULL expression. */ static void binaryToUnaryIfNull(Parse *pParse, Expr *pY, Expr *pA, int op){ sqlite3 *db = pParse->db; - if( pY && pA && pY->op==TK_NULL ){ + if( pA && pY && pY->op==TK_NULL ){ pA->op = (u8)op; sqlite3ExprDelete(db, pA->pRight); pA->pRight = 0; From 98a4d5a7fa997ddabe04c1352acedfb080d0b506 Mon Sep 17 00:00:00 2001 From: dan Date: Fri, 29 Jan 2016 08:38:35 +0000 Subject: [PATCH 54/75] Avoid two more instances of pointer arithmetic on freed pointers. FossilOrigin-Name: 2910ef64097b890c9f8929bf609ea2827db7ac97 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/prepare.c | 2 +- src/vdbesort.c | 5 ++--- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/manifest b/manifest index 771dba7fa8..04ba39cdd8 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Modify\sthe\sorder\sof\sterms\sin\san\s"if"\scondition\sto\savoid\simplicitly\scomparing\sa\sdangling\spointer\sto\sNULL\sfollowing\san\sOOM\serror. -D 2016-01-28T18:22:46.091 +C Avoid\stwo\smore\sinstances\sof\spointer\sarithmetic\son\sfreed\spointers. +D 2016-01-29T08:38:35.193 F Makefile.in 027c1603f255390c43a426671055a31c0a65fdb4 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 72b7858f02017611c3ac1ddc965251017fed0845 @@ -342,7 +342,7 @@ F src/pcache.h 4d0ccaad264d360981ec5e6a2b596d6e85242545 F src/pcache1.c 72f644dc9e1468c72922eff5904048427b817051 F src/pragma.c ea290193369faa0a26ae2f924e7b86289b4a7987 F src/pragma.h 64c78a648751b9f4f297276c4eb7507b14b4628c -F src/prepare.c 8ca7237428f372a04717d558555ea67ee1c5df93 +F src/prepare.c db85f0451ba93ecb3c1e497c279abece5cb5aead F src/printf.c af589a27b7d40f6f4f704e9eea99f02f18ad6d32 F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c 9f7ce3a3c087afb7597b7c916c99126ff3f12f0c @@ -419,7 +419,7 @@ F src/vdbeapi.c ffae8f5af4570fbd548504e815e9fb7227f0822e F src/vdbeaux.c fc8926c4232cd5c982f36197b1443212f265d927 F src/vdbeblob.c 37c3d11a753e403698c69e17383d282e1ae73e75 F src/vdbemem.c b9181e77eca2a095929d46250daf85c8d2621fc0 -F src/vdbesort.c 3bb1f1f03162e6d223da623714d8e93fcaeac658 +F src/vdbesort.c ef3c6d1f1a7d44cf67bb2bee59ea3d1fe5bad174 F src/vdbetrace.c 8befe829faff6d9e6f6e4dee5a7d3f85cc85f1a0 F src/vtab.c 320682cca733115b4cbe71320b5c5eeb1074ebde F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9 @@ -1422,7 +1422,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 688eb3b400a3f2f8005c341e8259f4c1485cb0ed -R e0b38fbf138d8fe5067019d9b4797980 +P 5372f800835da61736a64dcee8b476bbe7ee2e46 +R 3b0a4b2b0654f088a973292429d2f71d U dan -Z 338551eead62c92e7c871564cd38e428 +Z daf578eb367bf673fc68218c1dc6fe42 diff --git a/manifest.uuid b/manifest.uuid index 9de4b4f3bf..32fa4e2607 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -5372f800835da61736a64dcee8b476bbe7ee2e46 \ No newline at end of file +2910ef64097b890c9f8929bf609ea2827db7ac97 \ No newline at end of file diff --git a/src/prepare.c b/src/prepare.c index acd50fcaf7..f8ad54665a 100644 --- a/src/prepare.c +++ b/src/prepare.c @@ -582,8 +582,8 @@ static int sqlite3Prepare( zSqlCopy = sqlite3DbStrNDup(db, zSql, nBytes); if( zSqlCopy ){ sqlite3RunParser(pParse, zSqlCopy, &zErrMsg); - sqlite3DbFree(db, zSqlCopy); pParse->zTail = &zSql[pParse->zTail-zSqlCopy]; + sqlite3DbFree(db, zSqlCopy); }else{ pParse->zTail = &zSql[nBytes]; } diff --git a/src/vdbesort.c b/src/vdbesort.c index 22029aa6bf..380772ee16 100644 --- a/src/vdbesort.c +++ b/src/vdbesort.c @@ -1821,6 +1821,7 @@ int sqlite3VdbeSorterWrite( if( nMin>pSorter->nMemory ){ u8 *aNew; + int iListOff = (u8*)pSorter->list.pList - pSorter->list.aMemory; int nNew = pSorter->nMemory * 2; while( nNew < nMin ) nNew = nNew*2; if( nNew > pSorter->mxPmaSize ) nNew = pSorter->mxPmaSize; @@ -1828,9 +1829,7 @@ int sqlite3VdbeSorterWrite( aNew = sqlite3Realloc(pSorter->list.aMemory, nNew); if( !aNew ) return SQLITE_NOMEM; - pSorter->list.pList = (SorterRecord*)( - aNew + ((u8*)pSorter->list.pList - pSorter->list.aMemory) - ); + pSorter->list.pList = (SorterRecord*)&aNew[iListOff]; pSorter->list.aMemory = aNew; pSorter->nMemory = nNew; } From 3b83f0cd8f8525672a2631c57cea897f95a13a10 Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 29 Jan 2016 16:57:06 +0000 Subject: [PATCH 55/75] Avoid unnecessary WHERE clause term tests when coding a join where one of the tables contains a OR constraint. FossilOrigin-Name: ab94603974a0ad5342e5aee27603162652e70492 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/wherecode.c | 4 +++- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 04ba39cdd8..4caab7f68f 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Avoid\stwo\smore\sinstances\sof\spointer\sarithmetic\son\sfreed\spointers. -D 2016-01-29T08:38:35.193 +C Avoid\sunnecessary\sWHERE\sclause\sterm\stests\swhen\scoding\sa\sjoin\swhere\sone\nof\sthe\stables\scontains\sa\sOR\sconstraint. +D 2016-01-29T16:57:06.008 F Makefile.in 027c1603f255390c43a426671055a31c0a65fdb4 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 72b7858f02017611c3ac1ddc965251017fed0845 @@ -428,7 +428,7 @@ F src/wal.h 2f7c831cf3b071fa548bf2d5cac640846a7ff19c F src/walker.c 0f142b5bd3ed2041fc52d773880748b212e63354 F src/where.c af9bf5dcec1a0e52726c550924aa91d837166251 F src/whereInt.h 78b6b4de94db84aecbdc07fe3e38f648eb391e9a -F src/wherecode.c 8dee26eb181ea9daa8b1a4d96f34c0860aaf99bd +F src/wherecode.c 22a7fee2360c738533ce12615f487594849adc78 F src/whereexpr.c 197a448b52073aee43eca3a2233fc113369eb2d4 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/affinity2.test a6d901b436328bd67a79b41bb0ac2663918fe3bd @@ -1422,7 +1422,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 5372f800835da61736a64dcee8b476bbe7ee2e46 -R 3b0a4b2b0654f088a973292429d2f71d -U dan -Z daf578eb367bf673fc68218c1dc6fe42 +P 2910ef64097b890c9f8929bf609ea2827db7ac97 +R a5e195d58a480f7623421e36c529b8b4 +U drh +Z 416f01dc8ffa44ad767f5afe8de92edc diff --git a/manifest.uuid b/manifest.uuid index 32fa4e2607..87b521ed65 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -2910ef64097b890c9f8929bf609ea2827db7ac97 \ No newline at end of file +ab94603974a0ad5342e5aee27603162652e70492 \ No newline at end of file diff --git a/src/wherecode.c b/src/wherecode.c index 9d53a20a67..4fd7399efd 100644 --- a/src/wherecode.c +++ b/src/wherecode.c @@ -1401,7 +1401,9 @@ Bitmask sqlite3WhereCodeOneLoopStart( Expr *pExpr = pWC->a[iTerm].pExpr; if( &pWC->a[iTerm] == pTerm ) continue; if( ExprHasProperty(pExpr, EP_FromJoin) ) continue; - if( (pWC->a[iTerm].wtFlags & TERM_VIRTUAL)!=0 ) continue; + testcase( pWC->a[iTerm].wtFlags & TERM_VIRTUAL ); + testcase( pWC->a[iTerm].wtFlags & TERM_CODED ); + if( (pWC->a[iTerm].wtFlags & (TERM_VIRTUAL|TERM_CODED))!=0 ) continue; if( (pWC->a[iTerm].eOperator & WO_ALL)==0 ) continue; testcase( pWC->a[iTerm].wtFlags & TERM_ORINFO ); pExpr = sqlite3ExprDup(db, pExpr, 0); From 83f0ab8087a16eadb29b74a7849a52230ac731b4 Mon Sep 17 00:00:00 2001 From: dan Date: Fri, 29 Jan 2016 18:04:31 +0000 Subject: [PATCH 56/75] Prepend "rc!=SQLITE_OK || " to the nExtraDelete assert() condition. FossilOrigin-Name: 2a055ed0afd56e8c6b17cfc31e7808debe9ec765 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/vdbe.c | 4 +++- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index dc719b86ce..8ccd1f3c1a 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Modifications\sto\sensure\sthe\snExtraDelete-related\sassert()\sstatement\sdoes\snot\sfail. -D 2016-01-28T17:06:17.501 +C Prepend\s"rc!=SQLITE_OK\s||\s"\sto\sthe\snExtraDelete\sassert()\scondition. +D 2016-01-29T18:04:31.311 F Makefile.in 027c1603f255390c43a426671055a31c0a65fdb4 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 6fca5455aaecbd14479f33f091aa19df2d3d2969 @@ -412,7 +412,7 @@ F src/update.c 17332f9fe818cbc0444c36a811800af8498af4c3 F src/utf.c 32d7f82aa921322f3e1c956f4b58f019ebd2c6b3 F src/util.c 72d40df0a52d3f30b462a15f0e094fcbade6dc82 F src/vacuum.c 2ddd5cad2a7b9cef7f9e431b8c7771634c6b1701 -F src/vdbe.c 66c429896ce44ebcbe199f1c7a592c12095158f0 +F src/vdbe.c e86e100a3f90a861f28a5bda9c9abf1bca119a54 F src/vdbe.h 7a733ea8aac1b77305a67698e784fa3484ee3337 F src/vdbeInt.h 40c728712a2975855a2ac6aac44bf02dfd4a4c30 F src/vdbeapi.c ffae8f5af4570fbd548504e815e9fb7227f0822e @@ -1422,7 +1422,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 1d3bf6bebdda9f96734bc139601e9b05344ea0b4 -R 8c4c31e27c8a082a17d0a49af9f3ce1b +P f43ff8f82d6c1239e6f9a32e7716421c1180ac74 +R 089a2135f4238760de692cbeaf9edaeb U dan -Z 9dc5d2517a8a4fb456754e0a3cfe77cf +Z f28c932cf1fbf9988a116d4b713a0ec7 diff --git a/manifest.uuid b/manifest.uuid index b83d35e772..3bf3d8a23c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -f43ff8f82d6c1239e6f9a32e7716421c1180ac74 \ No newline at end of file +2a055ed0afd56e8c6b17cfc31e7808debe9ec765 \ No newline at end of file diff --git a/src/vdbe.c b/src/vdbe.c index c2e70ea8b2..c36802c300 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -6783,7 +6783,9 @@ vdbe_return: testcase( nVmStep>0 ); p->aCounter[SQLITE_STMTSTATUS_VM_STEP] += (int)nVmStep; sqlite3VdbeLeave(p); - assert( nExtraDelete==0 || sqlite3_strlike("DELETE%",p->zSql,0)!=0 ); + assert( rc!=SQLITE_OK || nExtraDelete==0 + || sqlite3_strlike("DELETE%",p->zSql,0)!=0 + ); return rc; /* Jump to here if a string or blob larger than SQLITE_MAX_LENGTH From 47ab455c2bb5e8256181e46fadc53979943075c7 Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 29 Jan 2016 18:48:08 +0000 Subject: [PATCH 57/75] Remove a stray "exit" in a test script. FossilOrigin-Name: 10c88bf9f2c238abbbb54797ee2327ab72713e6f --- manifest | 14 +++++++------- manifest.uuid | 2 +- test/e_changes.test | 1 - 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 8ccd1f3c1a..26f3353966 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Prepend\s"rc!=SQLITE_OK\s||\s"\sto\sthe\snExtraDelete\sassert()\scondition. -D 2016-01-29T18:04:31.311 +C Remove\sa\sstray\s"exit"\sin\sa\stest\sscript. +D 2016-01-29T18:48:08.448 F Makefile.in 027c1603f255390c43a426671055a31c0a65fdb4 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 6fca5455aaecbd14479f33f091aa19df2d3d2969 @@ -595,7 +595,7 @@ F test/e_blobbytes.test 9bea1d3e2b20f3010b04abba58f6ba172301f49f F test/e_blobclose.test df756753f571bc30e42e3a6cba2807576e49e716 F test/e_blobopen.test 234f960d90235a9b51ec3ca1e062e8541dd558d8 F test/e_blobwrite.test 615b405f29feb2cfb5a1f03dab7933258294fa26 -F test/e_changes.test d66e8c1e33f5ec61af32eda729c8a2475404e49b +F test/e_changes.test fd66105385153dbf21fdb35eb8ef6c3e1eade579 F test/e_createtable.test d4c6059d44dcd4b636de9aae322766062b471844 F test/e_delete.test ab39084f26ae1f033c940b70ebdbbd523dc4962e F test/e_droptrigger.test 3cd080807622c13e5bbb61fc9a57bd7754da2412 @@ -1422,7 +1422,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P f43ff8f82d6c1239e6f9a32e7716421c1180ac74 -R 089a2135f4238760de692cbeaf9edaeb -U dan -Z f28c932cf1fbf9988a116d4b713a0ec7 +P 2a055ed0afd56e8c6b17cfc31e7808debe9ec765 +R 4fbaa01893d53f4580e8296002d14aff +U drh +Z dbc978af0b86d437c82a817aee2df876 diff --git a/manifest.uuid b/manifest.uuid index 3bf3d8a23c..79ac026d59 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -2a055ed0afd56e8c6b17cfc31e7808debe9ec765 \ No newline at end of file +10c88bf9f2c238abbbb54797ee2327ab72713e6f \ No newline at end of file diff --git a/test/e_changes.test b/test/e_changes.test index c4b4406f7b..a77e22a2ee 100644 --- a/test/e_changes.test +++ b/test/e_changes.test @@ -65,7 +65,6 @@ foreach {tn schema} { UPDATE t1 SET b=b+1 WHERE a<5; } 5 -exit # Delete 4 rows do_changes_test 1.$tn.4 { DELETE FROM t1 WHERE a>6 From de892d96604b09cf959cd317243a2176b3d9531a Mon Sep 17 00:00:00 2001 From: dan Date: Fri, 29 Jan 2016 19:29:45 +0000 Subject: [PATCH 58/75] Experimental attempt to make better use of covering indexes within OR queries. FossilOrigin-Name: a323ac3a9d42bd5cb38d724c7e1180584b91054c --- manifest | 26 +++++++++++++------------ manifest.uuid | 2 +- src/vdbe.c | 20 +++++++++++++++---- src/vdbeInt.h | 6 ++++-- src/vdbeaux.c | 8 +++++++- src/wherecode.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++- test/whereD.test | 31 +++++++++++++++++++++++++++++- 7 files changed, 121 insertions(+), 22 deletions(-) diff --git a/manifest b/manifest index abb80cb617..4025b2f01a 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Avoid\sunnecessary\sWHERE\sclause\sterm\stests\swhen\scoding\sa\sjoin\swhere\sone\sof\sthe\stables\scontains\sa\sOR\sconstraint. -D 2016-01-29T18:11:04.923 +C Experimental\sattempt\sto\smake\sbetter\suse\sof\scovering\sindexes\swithin\sOR\squeries. +D 2016-01-29T19:29:45.658 F Makefile.in 027c1603f255390c43a426671055a31c0a65fdb4 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 72b7858f02017611c3ac1ddc965251017fed0845 @@ -412,11 +412,11 @@ F src/update.c 17332f9fe818cbc0444c36a811800af8498af4c3 F src/utf.c 32d7f82aa921322f3e1c956f4b58f019ebd2c6b3 F src/util.c 72d40df0a52d3f30b462a15f0e094fcbade6dc82 F src/vacuum.c 2ddd5cad2a7b9cef7f9e431b8c7771634c6b1701 -F src/vdbe.c 3ffbcc413bf793e3f0b95b79ef2f4bd449a5b5a3 +F src/vdbe.c 2e0c42bba0aee55b06b636feb5ad41d77c75abe3 F src/vdbe.h 7a733ea8aac1b77305a67698e784fa3484ee3337 -F src/vdbeInt.h 42eefa4f9e7432b9968d321b44e48821ec13b189 +F src/vdbeInt.h 91f22c4d54a2540fa0da64f04dd9d96969c0f0e0 F src/vdbeapi.c ffae8f5af4570fbd548504e815e9fb7227f0822e -F src/vdbeaux.c fc8926c4232cd5c982f36197b1443212f265d927 +F src/vdbeaux.c 657402ba7d253963e3fca323c6ad9f7b29a9efb9 F src/vdbeblob.c 37c3d11a753e403698c69e17383d282e1ae73e75 F src/vdbemem.c b9181e77eca2a095929d46250daf85c8d2621fc0 F src/vdbesort.c ef3c6d1f1a7d44cf67bb2bee59ea3d1fe5bad174 @@ -428,7 +428,7 @@ F src/wal.h 2f7c831cf3b071fa548bf2d5cac640846a7ff19c F src/walker.c 0f142b5bd3ed2041fc52d773880748b212e63354 F src/where.c af9bf5dcec1a0e52726c550924aa91d837166251 F src/whereInt.h 78b6b4de94db84aecbdc07fe3e38f648eb391e9a -F src/wherecode.c 22a7fee2360c738533ce12615f487594849adc78 +F src/wherecode.c 1b2a96c425048bf96eb97ba49235c71f54917b1d F src/whereexpr.c 197a448b52073aee43eca3a2233fc113369eb2d4 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/affinity2.test a6d901b436328bd67a79b41bb0ac2663918fe3bd @@ -1334,7 +1334,7 @@ F test/where9.test 729c3ba9b47e8f9f1aab96bae7dad2a524f1d1a2 F test/whereA.test 4d253178d135ec46d1671e440cd8f2b916aa6e6b F test/whereB.test 0def95db3bdec220a731c7e4bec5930327c1d8c5 F test/whereC.test cae295158703cb3fc23bf1a108a9ab730efff0f6 -F test/whereD.test 9eba1f9b18e5b19a0b0bcaae5e8c037260195f2b +F test/whereD.test 4b648b4a75911474b7b4dde08a7411b165e3fa39 F test/whereE.test b3a055eef928c992b0a33198a7b8dc10eea5ad2f F test/whereF.test 5b2ba0dbe8074aa13e416b37c753991f0a2492d7 F test/whereG.test dde4c52a97385a55be6a7cd46be8373f0cf35501 @@ -1422,8 +1422,10 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 2910ef64097b890c9f8929bf609ea2827db7ac97 ab94603974a0ad5342e5aee27603162652e70492 -R a5e195d58a480f7623421e36c529b8b4 -T +closed ab94603974a0ad5342e5aee27603162652e70492 -U drh -Z e540fd89ce55e7aa63a8bd5d9b52b2c8 +P 512caa1ad30e6f699e2d006d5ab7674d55d2c746 +R 7c9589ab5b77780aed167682522067f5 +T *branch * covering-or +T *sym-covering-or * +T -sym-trunk * +U dan +Z 8b3097dd603cdb6f18b5a640e7f1b04b diff --git a/manifest.uuid b/manifest.uuid index ebf0893a75..afc72f756f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -512caa1ad30e6f699e2d006d5ab7674d55d2c746 \ No newline at end of file +a323ac3a9d42bd5cb38d724c7e1180584b91054c \ No newline at end of file diff --git a/src/vdbe.c b/src/vdbe.c index cfff895c30..8ad1a17c39 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -2376,12 +2376,16 @@ case OP_Column: { u32 t; /* A type code from the record header */ Mem *pReg; /* PseudoTable input register */ + pC = p->apCsr[pOp->p1]; p2 = pOp->p2; + + /* If the cursor cache is stale, bring it up-to-date */ + rc = sqlite3VdbeCursorMoveto(&pC, &p2); + assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) ); pDest = &aMem[pOp->p3]; memAboutToChange(p, pDest); assert( pOp->p1>=0 && pOp->p1nCursor ); - pC = p->apCsr[pOp->p1]; assert( pC!=0 ); assert( p2nField ); aOffset = pC->aOffset; @@ -2390,8 +2394,6 @@ case OP_Column: { assert( pC->eCurType!=CURTYPE_SORTER ); pCrsr = pC->uc.pCursor; - /* If the cursor cache is stale, bring it up-to-date */ - rc = sqlite3VdbeCursorMoveto(pC); if( rc ) goto abort_due_to_error; if( pC->cacheStatus!=p->cacheCtr ){ if( pC->nullRow ){ @@ -3846,7 +3848,7 @@ seek_not_found: break; } -/* Opcode: Seek P1 P2 * * * +/* Opcode: Seek P1 P2 P3 P4 * ** Synopsis: intkey=r[P2] ** ** P1 is an open table cursor and P2 is a rowid integer. Arrange @@ -3855,6 +3857,13 @@ seek_not_found: ** This is actually a deferred seek. Nothing actually happens until ** the cursor is used to read a record. That way, if no reads ** occur, no unnecessary I/O happens. +** +** P4 may contain an array of integers (type P4_INTARRAY) containing +** one entry for each column in the table P1 is open on. If so, then +** parameter P3 is a cursor open on a database index. If array entry +** a[i] is non-zero, then reading column (a[i]-1) from cursor P3 is +** equivalent to performing the deferred seek and then reading column i +** from P1. */ case OP_Seek: { /* in2 */ VdbeCursor *pC; @@ -3869,6 +3878,9 @@ case OP_Seek: { /* in2 */ pIn2 = &aMem[pOp->p2]; pC->movetoTarget = sqlite3VdbeIntValue(pIn2); pC->deferredMoveto = 1; + assert( pOp->p4type==P4_INTARRAY || pOp->p4.ai==0 ); + pC->aAltMap = pOp->p4.ai; + pC->pAltCursor = p->apCsr[pOp->p3]; break; } diff --git a/src/vdbeInt.h b/src/vdbeInt.h index b231cf908e..e1c6d06567 100644 --- a/src/vdbeInt.h +++ b/src/vdbeInt.h @@ -74,6 +74,7 @@ typedef struct AuxData AuxData; ** * A virtual table ** * A one-row "pseudotable" stored in a single register */ +typedef struct VdbeCursor VdbeCursor; struct VdbeCursor { u8 eCurType; /* One of the CURTYPE_* values above */ i8 iDb; /* Index of cursor database in db->aDb[] (or -1) */ @@ -100,6 +101,8 @@ struct VdbeCursor { int seekResult; /* Result of previous sqlite3BtreeMoveto() */ i64 seqCount; /* Sequence counter */ i64 movetoTarget; /* Argument to the deferred sqlite3BtreeMoveto() */ + VdbeCursor *pAltCursor; /* Set by OP_Seek */ + int *aAltMap; /* Set by OP_Seek */ #ifdef SQLITE_ENABLE_COLUMN_USED_MASK u64 maskUsed; /* Mask of columns used by this cursor */ #endif @@ -124,7 +127,6 @@ struct VdbeCursor { ** static element declared in the structure. nField total array slots for ** aType[] and nField+1 array slots for aOffset[] */ }; -typedef struct VdbeCursor VdbeCursor; /* ** When a sub-program is executed (OP_Program), a structure of this type @@ -423,7 +425,7 @@ struct Vdbe { void sqlite3VdbeError(Vdbe*, const char *, ...); void sqlite3VdbeFreeCursor(Vdbe *, VdbeCursor*); void sqliteVdbePopStack(Vdbe*,int); -int sqlite3VdbeCursorMoveto(VdbeCursor*); +int sqlite3VdbeCursorMoveto(VdbeCursor**, int*); int sqlite3VdbeCursorRestore(VdbeCursor*); #if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE) void sqlite3VdbePrintOp(FILE*, int, Op*); diff --git a/src/vdbeaux.c b/src/vdbeaux.c index 3bbc5aad53..6e368cfdbd 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -3008,9 +3008,15 @@ int sqlite3VdbeCursorRestore(VdbeCursor *p){ ** If the cursor is already pointing to the correct row and that row has ** not been deleted out from under the cursor, then this routine is a no-op. */ -int sqlite3VdbeCursorMoveto(VdbeCursor *p){ +int sqlite3VdbeCursorMoveto(VdbeCursor **pp, int *piCol){ + VdbeCursor *p = *pp; if( p->eCurType==CURTYPE_BTREE ){ if( p->deferredMoveto ){ + if( p->aAltMap && p->aAltMap[*piCol] ){ + *pp = p->pAltCursor; + *piCol = p->aAltMap[*piCol] - 1; + return SQLITE_OK; + } return handleDeferredMoveto(p); } if( sqlite3BtreeCursorHasMoved(p->uc.pCursor) ){ diff --git a/src/wherecode.c b/src/wherecode.c index 4fd7399efd..eacd6d08d1 100644 --- a/src/wherecode.c +++ b/src/wherecode.c @@ -746,6 +746,54 @@ static void codeCursorHint( # define codeCursorHint(A,B,C) /* No-op */ #endif /* SQLITE_ENABLE_CURSOR_HINTS */ +/* +** Cursor iCur is open on an intkey b-tree (a table). Register iRowid contains +** a rowid value just read from cursor iIdxCur, open on index pIdx. This +** function generates code to do a deferred seek of cursor iCur to the +** rowid stored in register iRowid. +** +** Normally, this is just: +** +** OP_Seek $iCur $iRowid +** +** However, if the scan currently being coded is a branch of an OR-loop and +** the statement currently being coded is a SELECT, then P3 of the OP_Seek +** is set to iIdxCur and P4 is set to point to an array of integers +** containing one entry for each column of the table cursor iCur is open +** on. For each table column, if the column is the i'th column of the +** index, then the corresponding array entry is set to (i+1). If the column +** does not appear in the index at all, the array entry is set to 0. +*/ +static void codeDeferredSeek( + WhereInfo *pWInfo, /* Where clause context */ + Index *pIdx, /* Index scan is using */ + int iCur, /* Cursor for IPK b-tree */ + int iRowid, /* Register containing rowid to seek to */ + int iIdxCur /* Index cursor */ +){ + Parse *pParse = pWInfo->pParse; /* Parse context */ + Vdbe *v = pParse->pVdbe; /* Vdbe to generate code within */ + + assert( iIdxCur>0 ); + assert( pIdx->aiColumn[pIdx->nColumn-1]==-1 ); + + sqlite3VdbeAddOp3(v, OP_Seek, iCur, iRowid, iIdxCur); + if( (pWInfo->wctrlFlags & WHERE_FORCE_TABLE) + && sqlite3ParseToplevel(pParse)->writeMask==0 + ){ + int i; + Table *pTab = pIdx->pTable; + int *ai = (int*)sqlite3DbMallocZero(pParse->db, sizeof(int) * pTab->nCol); + if( ai ){ + for(i=0; inColumn-1; i++){ + assert( pIdx->aiColumn[i]nCol ); + if( pIdx->aiColumn[i]>=0 ) ai[pIdx->aiColumn[i]] = i+1; + } + sqlite3VdbeChangeP4(v, -1, (char*)ai, P4_INTARRAY); + } + } +} + /* ** Generate code for the start of the iLevel-th loop in the WHERE clause ** implementation described by pWInfo. @@ -1232,7 +1280,7 @@ Bitmask sqlite3WhereCodeOneLoopStart( sqlite3VdbeAddOp3(v, OP_NotExists, iCur, 0, iRowidReg); VdbeCoverage(v); }else{ - sqlite3VdbeAddOp2(v, OP_Seek, iCur, iRowidReg); /* Deferred seek */ + codeDeferredSeek(pWInfo, pIdx, iCur, iRowidReg, iIdxCur); } }else if( iCur!=iIdxCur ){ Index *pPk = sqlite3PrimaryKeyIndex(pIdx->pTable); diff --git a/test/whereD.test b/test/whereD.test index 17fdac7017..1d70103a70 100644 --- a/test/whereD.test +++ b/test/whereD.test @@ -156,7 +156,7 @@ do_searchcount_test 3.4.4 { do_searchcount_test 3.5.1 { SELECT a, b FROM t3 WHERE (a=1 AND b='one') OR rowid=4 -} {1 one 2 two search 3} +} {1 one 2 two search 2} do_searchcount_test 3.5.2 { SELECT a, c FROM t3 WHERE (a=1 AND b='one') OR rowid=4 } {1 i 2 ii search 3} @@ -271,5 +271,34 @@ do_execsql_test 5.3 { c16=1 or c17=1; } {1 {} {} {} {} {} {} {} {} {} {} {} {} {} {} 1 {} {}} +#------------------------------------------------------------------------- +do_execsql_test 6.1 { + CREATE TABLE x1(a, b, c, d, e); + CREATE INDEX x1a ON x1(a); + CREATE INDEX x1bc ON x1(b, c); + CREATE INDEX x1cd ON x1(c, d); + + INSERT INTO x1 VALUES(1, 2, 3, 4, 'A'); + INSERT INTO x1 VALUES(5, 6, 7, 8, 'B'); + INSERT INTO x1 VALUES(9, 10, 11, 12, 'C'); + INSERT INTO x1 VALUES(13, 14, 15, 16, 'D'); +} + +do_searchcount_test 6.2.1 { + SELECT e FROM x1 WHERE b=2 OR c=7; +} {A B search 6} +do_searchcount_test 6.2.2 { + SELECT c FROM x1 WHERE b=2 OR c=7; +} {3 7 search 4} + +do_searchcount_test 6.3.1 { + SELECT e FROM x1 WHERE a=1 OR b=10; +} {A C search 6} +do_searchcount_test 6.3.2 { + SELECT c FROM x1 WHERE a=1 OR b=10; +} {3 11 search 5} +do_searchcount_test 6.3.3 { + SELECT rowid FROM x1 WHERE a=1 OR b=10; +} {1 3 search 4} finish_test From 945d302215abf771fd9f32e16aae6235e9663d61 Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 29 Jan 2016 20:58:40 +0000 Subject: [PATCH 59/75] Different comment on the alternative cursor fields of VdbeCursor. FossilOrigin-Name: 6e3dcb6d7d960bb513d9a4a002b6cf5ab7159686 --- manifest | 17 +++++++---------- manifest.uuid | 2 +- src/vdbeInt.h | 4 ++-- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/manifest b/manifest index 4025b2f01a..48234554f0 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Experimental\sattempt\sto\smake\sbetter\suse\sof\scovering\sindexes\swithin\sOR\squeries. -D 2016-01-29T19:29:45.658 +C Different\scomment\son\sthe\salternative\scursor\sfields\sof\sVdbeCursor. +D 2016-01-29T20:58:40.189 F Makefile.in 027c1603f255390c43a426671055a31c0a65fdb4 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 72b7858f02017611c3ac1ddc965251017fed0845 @@ -414,7 +414,7 @@ F src/util.c 72d40df0a52d3f30b462a15f0e094fcbade6dc82 F src/vacuum.c 2ddd5cad2a7b9cef7f9e431b8c7771634c6b1701 F src/vdbe.c 2e0c42bba0aee55b06b636feb5ad41d77c75abe3 F src/vdbe.h 7a733ea8aac1b77305a67698e784fa3484ee3337 -F src/vdbeInt.h 91f22c4d54a2540fa0da64f04dd9d96969c0f0e0 +F src/vdbeInt.h 171fdc5f6af4eeb0ff0559dbf0a71244d726a670 F src/vdbeapi.c ffae8f5af4570fbd548504e815e9fb7227f0822e F src/vdbeaux.c 657402ba7d253963e3fca323c6ad9f7b29a9efb9 F src/vdbeblob.c 37c3d11a753e403698c69e17383d282e1ae73e75 @@ -1422,10 +1422,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 512caa1ad30e6f699e2d006d5ab7674d55d2c746 -R 7c9589ab5b77780aed167682522067f5 -T *branch * covering-or -T *sym-covering-or * -T -sym-trunk * -U dan -Z 8b3097dd603cdb6f18b5a640e7f1b04b +P a323ac3a9d42bd5cb38d724c7e1180584b91054c +R 2723ccd4873b2c7d653d59caf129ff2b +U drh +Z c70856a82eab5a5a2e181cbd70b2aa42 diff --git a/manifest.uuid b/manifest.uuid index afc72f756f..5612aca8d6 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -a323ac3a9d42bd5cb38d724c7e1180584b91054c \ No newline at end of file +6e3dcb6d7d960bb513d9a4a002b6cf5ab7159686 \ No newline at end of file diff --git a/src/vdbeInt.h b/src/vdbeInt.h index e1c6d06567..85c1a54512 100644 --- a/src/vdbeInt.h +++ b/src/vdbeInt.h @@ -101,8 +101,8 @@ struct VdbeCursor { int seekResult; /* Result of previous sqlite3BtreeMoveto() */ i64 seqCount; /* Sequence counter */ i64 movetoTarget; /* Argument to the deferred sqlite3BtreeMoveto() */ - VdbeCursor *pAltCursor; /* Set by OP_Seek */ - int *aAltMap; /* Set by OP_Seek */ + VdbeCursor *pAltCursor; /* Associated index cursor from which to read */ + int *aAltMap; /* Mapping from table to index column numbers */ #ifdef SQLITE_ENABLE_COLUMN_USED_MASK u64 maskUsed; /* Mask of columns used by this cursor */ #endif From eaa6cd87e8f81fa7dfdaa7dfc3c195f86cc9f096 Mon Sep 17 00:00:00 2001 From: dan Date: Fri, 29 Jan 2016 21:16:13 +0000 Subject: [PATCH 60/75] Add tests for the change on this branch. FossilOrigin-Name: 7cb697f82932a2581af69350117a29c9c8a2544f --- manifest | 14 +++++++------- manifest.uuid | 2 +- test/whereD.test | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 48234554f0..b6defac38e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Different\scomment\son\sthe\salternative\scursor\sfields\sof\sVdbeCursor. -D 2016-01-29T20:58:40.189 +C Add\stests\sfor\sthe\schange\son\sthis\sbranch. +D 2016-01-29T21:16:13.360 F Makefile.in 027c1603f255390c43a426671055a31c0a65fdb4 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 72b7858f02017611c3ac1ddc965251017fed0845 @@ -1334,7 +1334,7 @@ F test/where9.test 729c3ba9b47e8f9f1aab96bae7dad2a524f1d1a2 F test/whereA.test 4d253178d135ec46d1671e440cd8f2b916aa6e6b F test/whereB.test 0def95db3bdec220a731c7e4bec5930327c1d8c5 F test/whereC.test cae295158703cb3fc23bf1a108a9ab730efff0f6 -F test/whereD.test 4b648b4a75911474b7b4dde08a7411b165e3fa39 +F test/whereD.test 51366b07cb6f546cd30cc803f7e754f063b940de F test/whereE.test b3a055eef928c992b0a33198a7b8dc10eea5ad2f F test/whereF.test 5b2ba0dbe8074aa13e416b37c753991f0a2492d7 F test/whereG.test dde4c52a97385a55be6a7cd46be8373f0cf35501 @@ -1422,7 +1422,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P a323ac3a9d42bd5cb38d724c7e1180584b91054c -R 2723ccd4873b2c7d653d59caf129ff2b -U drh -Z c70856a82eab5a5a2e181cbd70b2aa42 +P 6e3dcb6d7d960bb513d9a4a002b6cf5ab7159686 +R 56d45fd4fdb64a9d12152455ff1bc2b7 +U dan +Z 8c3eb3de3f58e27647eefba9e15f6f8b diff --git a/manifest.uuid b/manifest.uuid index 5612aca8d6..c7e676919d 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -6e3dcb6d7d960bb513d9a4a002b6cf5ab7159686 \ No newline at end of file +7cb697f82932a2581af69350117a29c9c8a2544f \ No newline at end of file diff --git a/test/whereD.test b/test/whereD.test index 1d70103a70..de0f9618d2 100644 --- a/test/whereD.test +++ b/test/whereD.test @@ -301,4 +301,40 @@ do_searchcount_test 6.3.3 { SELECT rowid FROM x1 WHERE a=1 OR b=10; } {1 3 search 4} +do_searchcount_test 6.4.1 { + SELECT a FROM x1 WHERE b BETWEEN 1 AND 4 OR c BETWEEN 8 AND 12 +} {1 9 search 6} +do_searchcount_test 6.4.2 { + SELECT b, c FROM x1 WHERE b BETWEEN 1 AND 4 OR c BETWEEN 8 AND 12 +} {2 3 10 11 search 5} +do_searchcount_test 6.4.3 { + SELECT rowid, c FROM x1 WHERE b BETWEEN 1 AND 4 OR c BETWEEN 8 AND 12 +} {1 3 3 11 search 4} + +do_searchcount_test 6.5.1 { + SELECT a FROM x1 WHERE rowid = 2 OR c=11 +} {5 9 search 3} +do_searchcount_test 6.5.2 { + SELECT d FROM x1 WHERE rowid = 2 OR c=11 +} {8 12 search 2} +do_searchcount_test 6.5.3 { + SELECT d FROM x1 WHERE c=11 OR rowid = 2 +} {12 8 search 2} +do_searchcount_test 6.5.4 { + SELECT a FROM x1 WHERE c=11 OR rowid = 2 +} {9 5 search 3} + +do_searchcount_test 6.6.1 { + SELECT rowid FROM x1 WHERE a=1 OR b=6 OR c=11 +} {1 2 3 search 6} +do_searchcount_test 6.6.2 { + SELECT c FROM x1 WHERE a=1 OR b=6 OR c=11 +} {3 7 11 search 7} +do_searchcount_test 6.6.3 { + SELECT c FROM x1 WHERE c=11 OR a=1 OR b=6 +} {11 3 7 search 7} +do_searchcount_test 6.6.4 { + SELECT c FROM x1 WHERE b=6 OR c=11 OR a=1 +} {7 11 3 search 7} + finish_test From b17020265b4f9ff369845e0fe1adc92c5858b975 Mon Sep 17 00:00:00 2001 From: drh Date: Sat, 30 Jan 2016 00:45:18 +0000 Subject: [PATCH 61/75] Change the P4_INTARRAY so that always begins with a length integer. Print the content of the INTARRAY on EXPLAIN output. FossilOrigin-Name: 6c520d5726e80b4251338c43c405270d150ea81e --- manifest | 20 ++++++++++---------- manifest.uuid | 2 +- src/select.c | 5 +++-- src/vdbe.c | 5 ++++- src/vdbeaux.c | 21 ++++++++++++++++++--- src/wherecode.c | 5 +++-- 6 files changed, 39 insertions(+), 19 deletions(-) diff --git a/manifest b/manifest index b6defac38e..6b3a40d3f9 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\stests\sfor\sthe\schange\son\sthis\sbranch. -D 2016-01-29T21:16:13.360 +C Change\sthe\sP4_INTARRAY\sso\sthat\salways\sbegins\swith\sa\slength\sinteger.\s\sPrint\nthe\scontent\sof\sthe\sINTARRAY\son\sEXPLAIN\soutput. +D 2016-01-30T00:45:18.967 F Makefile.in 027c1603f255390c43a426671055a31c0a65fdb4 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 72b7858f02017611c3ac1ddc965251017fed0845 @@ -347,7 +347,7 @@ F src/printf.c af589a27b7d40f6f4f704e9eea99f02f18ad6d32 F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c 9f7ce3a3c087afb7597b7c916c99126ff3f12f0c F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e -F src/select.c c34292c8ce7fe69c7cf890d933834a22572bd301 +F src/select.c ea6f3b0c279aa37eb3701792d094673a7ad1bf88 F src/shell.c dcd7a83645ef2a58ee9c6d0ea4714d877d7835c4 F src/sqlite.h.in 214476a62012e578f42133a9a3b4f97a9aa421a3 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 @@ -412,11 +412,11 @@ F src/update.c 17332f9fe818cbc0444c36a811800af8498af4c3 F src/utf.c 32d7f82aa921322f3e1c956f4b58f019ebd2c6b3 F src/util.c 72d40df0a52d3f30b462a15f0e094fcbade6dc82 F src/vacuum.c 2ddd5cad2a7b9cef7f9e431b8c7771634c6b1701 -F src/vdbe.c 2e0c42bba0aee55b06b636feb5ad41d77c75abe3 +F src/vdbe.c 0686ef5ee103935548d1aa2c0c28e52f1ae6e5a8 F src/vdbe.h 7a733ea8aac1b77305a67698e784fa3484ee3337 F src/vdbeInt.h 171fdc5f6af4eeb0ff0559dbf0a71244d726a670 F src/vdbeapi.c ffae8f5af4570fbd548504e815e9fb7227f0822e -F src/vdbeaux.c 657402ba7d253963e3fca323c6ad9f7b29a9efb9 +F src/vdbeaux.c 108124021ed02fa4fc6f90a53dcaf58ac3bab941 F src/vdbeblob.c 37c3d11a753e403698c69e17383d282e1ae73e75 F src/vdbemem.c b9181e77eca2a095929d46250daf85c8d2621fc0 F src/vdbesort.c ef3c6d1f1a7d44cf67bb2bee59ea3d1fe5bad174 @@ -428,7 +428,7 @@ F src/wal.h 2f7c831cf3b071fa548bf2d5cac640846a7ff19c F src/walker.c 0f142b5bd3ed2041fc52d773880748b212e63354 F src/where.c af9bf5dcec1a0e52726c550924aa91d837166251 F src/whereInt.h 78b6b4de94db84aecbdc07fe3e38f648eb391e9a -F src/wherecode.c 1b2a96c425048bf96eb97ba49235c71f54917b1d +F src/wherecode.c 3c4757ae85e8237808a4ec1a25c513d83e1395e0 F src/whereexpr.c 197a448b52073aee43eca3a2233fc113369eb2d4 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/affinity2.test a6d901b436328bd67a79b41bb0ac2663918fe3bd @@ -1422,7 +1422,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 6e3dcb6d7d960bb513d9a4a002b6cf5ab7159686 -R 56d45fd4fdb64a9d12152455ff1bc2b7 -U dan -Z 8c3eb3de3f58e27647eefba9e15f6f8b +P 7cb697f82932a2581af69350117a29c9c8a2544f +R e4149e0b983ab1835709b124e27b8f90 +U drh +Z 9c9e55627bd1b33e50ca6caf5cedf1b5 diff --git a/manifest.uuid b/manifest.uuid index c7e676919d..95c87154e9 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -7cb697f82932a2581af69350117a29c9c8a2544f \ No newline at end of file +6c520d5726e80b4251338c43c405270d150ea81e \ No newline at end of file diff --git a/src/select.c b/src/select.c index ea4298e677..891b123543 100644 --- a/src/select.c +++ b/src/select.c @@ -2870,10 +2870,11 @@ static int multiSelectOrderBy( ** to the right and the left are evaluated, they use the correct ** collation. */ - aPermute = sqlite3DbMallocRaw(db, sizeof(int)*nOrderBy); + aPermute = sqlite3DbMallocRaw(db, sizeof(int)*(nOrderBy + 1)); if( aPermute ){ struct ExprList_item *pItem; - for(i=0, pItem=pOrderBy->a; ia; i<=nOrderBy; i++, pItem++){ assert( pItem->u.x.iOrderByCol>0 ); assert( pItem->u.x.iOrderByCol<=p->pEList->nExpr ); aPermute[i] = pItem->u.x.iOrderByCol - 1; diff --git a/src/vdbe.c b/src/vdbe.c index 8ad1a17c39..b7c0258ce6 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -2067,11 +2067,14 @@ case OP_Ge: { /* same as TK_GE, jump, in1, in3 */ ** The permutation is only valid until the next OP_Compare that has ** the OPFLAG_PERMUTE bit set in P5. Typically the OP_Permutation should ** occur immediately prior to the OP_Compare. +** +** The first integer in the P4 integer array is the length of the array +** and does not become part of the permutation. */ case OP_Permutation: { assert( pOp->p4type==P4_INTARRAY ); assert( pOp->p4.ai ); - aPermute = pOp->p4.ai; + aPermute = pOp->p4.ai + 1; break; } diff --git a/src/vdbeaux.c b/src/vdbeaux.c index 6e368cfdbd..aaba2d3d0c 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -1288,7 +1288,21 @@ static char *displayP4(Op *pOp, char *zTemp, int nTemp){ } #endif case P4_INTARRAY: { - sqlite3_snprintf(nTemp, zTemp, "intarray"); + int i, j; + int *ai = pOp->p4.ai; + int n = ai[0]; /* The first element of an INTARRAY is always the + ** count of the number of elements to follow */ + zTemp[0] = '['; + for(i=j=1; i1 ) zTemp[j++] = ','; + sqlite3_snprintf(nTemp-j, zTemp+j, "%d", ai[i]); + j += sqlite3Strlen30(zTemp+j); + } + if( ieCurType==CURTYPE_BTREE ){ if( p->deferredMoveto ){ - if( p->aAltMap && p->aAltMap[*piCol] ){ + int iMap; + if( p->aAltMap && (iMap = p->aAltMap[1+*piCol])>0 ){ *pp = p->pAltCursor; - *piCol = p->aAltMap[*piCol] - 1; + *piCol = iMap - 1; return SQLITE_OK; } return handleDeferredMoveto(p); diff --git a/src/wherecode.c b/src/wherecode.c index eacd6d08d1..fea397c543 100644 --- a/src/wherecode.c +++ b/src/wherecode.c @@ -783,11 +783,12 @@ static void codeDeferredSeek( ){ int i; Table *pTab = pIdx->pTable; - int *ai = (int*)sqlite3DbMallocZero(pParse->db, sizeof(int) * pTab->nCol); + int *ai = (int*)sqlite3DbMallocZero(pParse->db, sizeof(int)*(pTab->nCol+1)); if( ai ){ + ai[0] = pTab->nCol; for(i=0; inColumn-1; i++){ assert( pIdx->aiColumn[i]nCol ); - if( pIdx->aiColumn[i]>=0 ) ai[pIdx->aiColumn[i]] = i+1; + if( pIdx->aiColumn[i]>=0 ) ai[pIdx->aiColumn[i]+1] = i+1; } sqlite3VdbeChangeP4(v, -1, (char*)ai, P4_INTARRAY); } From 5f4a686f8c5f0fa206418ab5970b61beb49aca7c Mon Sep 17 00:00:00 2001 From: drh Date: Sat, 30 Jan 2016 12:50:25 +0000 Subject: [PATCH 62/75] Simplification and size reduction to the printf logic. Remove the bFlags parameter from sqlite3VXPrintf() and sqlite3XPrintf(). Use sqlite3XPrintf() instead of sqlite3_snprintf() for rendering P4 values in EXPLAIN output. FossilOrigin-Name: 0bdb41c45aa1cc8e5c136aaa6605d54b401483bd --- manifest | 29 +++++++------- manifest.uuid | 2 +- src/btree.c | 5 ++- src/build.c | 4 +- src/func.c | 3 +- src/printf.c | 48 +++++++++++----------- src/sqliteInt.h | 14 ++++--- src/treeview.c | 22 +++++------ src/vdbeaux.c | 103 +++++++++++++++++++----------------------------- src/vdbetrace.c | 14 +++---- src/wherecode.c | 16 ++++---- 11 files changed, 121 insertions(+), 139 deletions(-) diff --git a/manifest b/manifest index 9e56090535..d6048a60fe 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Make\suse\sof\scovering\sindexes\sin\sthe\sOR\soptimization. -D 2016-01-30T02:10:38.644 +C Simplification\sand\ssize\sreduction\sto\sthe\sprintf\slogic.\s\sRemove\sthe\sbFlags\nparameter\sfrom\ssqlite3VXPrintf()\sand\ssqlite3XPrintf().\s\sUse\ssqlite3XPrintf()\ninstead\sof\ssqlite3_snprintf()\sfor\srendering\sP4\svalues\sin\sEXPLAIN\soutput. +D 2016-01-30T12:50:25.204 F Makefile.in 027c1603f255390c43a426671055a31c0a65fdb4 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 72b7858f02017611c3ac1ddc965251017fed0845 @@ -290,10 +290,10 @@ F src/auth.c b56c78ebe40a2110fd361379f7e8162d23f92240 F src/backup.c 2869a76c03eb393ee795416e2387005553df72bc F src/bitvec.c 1a78d450a17c5016710eec900bedfc5729bf9bdf F src/btmutex.c bc87dd3b062cc26edfe79918de2200ccb8d41e73 -F src/btree.c f224ae877fde69d1a9d430f502edaf8502752dbe +F src/btree.c 5e3435a31afbe9d839c5ee2630b8390712847415 F src/btree.h 526137361963e746949ab966a910c7f455ac6b04 F src/btreeInt.h c18b7d2a3494695133e4e60ee36061d37f45d9a5 -F src/build.c b4eba1e84752ec9cae7ff3dacd5a8b6d1ab8deb9 +F src/build.c 0510844c48d80732aead74b5727403b493dd1cd5 F src/callback.c 29ae4faba226c7ebb9aee93016b5ce8a8f071261 F src/complete.c addcd8160b081131005d5bc2d34adf20c1c5c92f F src/ctime.c 60e135af364d777a9ab41c97e5e89cd224da6198 @@ -303,7 +303,7 @@ F src/delete.c 00af9f08a15ddc5cba5962d3d3e5bf2d67b2e7da F src/expr.c d10c1cdef5810cdbf73adc9f9b383684230b360a F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb F src/fkey.c c66d3e5b35d4d95b5c1e2ee6c12f5df13a7f9ad6 -F src/func.c ba6c03f9e440f5693086c08ee88e6e60212b3504 +F src/func.c 42b24923328f65849f52f1659efb2a0907ad78fd F src/global.c bd5a0af3f30b0c01be6db756c626cd3c33a3d260 F src/hash.c 4263fbc955f26c2e8cdc0cf214bc42435aa4e4f5 F src/hash.h c8f3c31722cf3277d03713909761e152a5b81094 @@ -343,7 +343,7 @@ F src/pcache1.c 72f644dc9e1468c72922eff5904048427b817051 F src/pragma.c ea290193369faa0a26ae2f924e7b86289b4a7987 F src/pragma.h 64c78a648751b9f4f297276c4eb7507b14b4628c F src/prepare.c db85f0451ba93ecb3c1e497c279abece5cb5aead -F src/printf.c af589a27b7d40f6f4f704e9eea99f02f18ad6d32 +F src/printf.c 98a5cef7fc84577ab8a3098cfa48ecfa5a70b9f8 F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c 9f7ce3a3c087afb7597b7c916c99126ff3f12f0c F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e @@ -352,7 +352,7 @@ F src/shell.c dcd7a83645ef2a58ee9c6d0ea4714d877d7835c4 F src/sqlite.h.in 214476a62012e578f42133a9a3b4f97a9aa421a3 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h dfbe62ffd95b99afe2140d8c35b180d11924072d -F src/sqliteInt.h 74e10a74116df0aec9d4a3e134f1a86cc34c2f14 +F src/sqliteInt.h 5b552cc0eee50d519e2e020f16abbc68947b0e59 F src/sqliteLimit.h 216557999cb45f2e3578ed53ebefe228d779cb46 F src/status.c 70912d7be68e9e2dbc4010c93d344af61d4c59ba F src/table.c 51b46b2a62d1b3a959633d593b89bab5e2c9155e @@ -406,7 +406,7 @@ F src/test_windirent.h b12055cab6227f7be10f5c19296f67c60cc5e2a5 F src/test_wsd.c 41cadfd9d97fe8e3e4e44f61a4a8ccd6f7ca8fe9 F src/threads.c bbfb74450643cb5372a43ad4f6cffd7e9dfcecb0 F src/tokenize.c 5606871a377f390af7040ec3c12e0d183512d785 -F src/treeview.c 78842e90c1f71269e7a73a1d4221b6fe360bab66 +F src/treeview.c dc39ccf04e9331237388b9cb73289c9d87ea050b F src/trigger.c 72d876b2d0c66604a112362bdae07dae9b104816 F src/update.c 17332f9fe818cbc0444c36a811800af8498af4c3 F src/utf.c 32d7f82aa921322f3e1c956f4b58f019ebd2c6b3 @@ -416,11 +416,11 @@ F src/vdbe.c 0686ef5ee103935548d1aa2c0c28e52f1ae6e5a8 F src/vdbe.h 7a733ea8aac1b77305a67698e784fa3484ee3337 F src/vdbeInt.h 171fdc5f6af4eeb0ff0559dbf0a71244d726a670 F src/vdbeapi.c ffae8f5af4570fbd548504e815e9fb7227f0822e -F src/vdbeaux.c 108124021ed02fa4fc6f90a53dcaf58ac3bab941 +F src/vdbeaux.c 221631e40111b5efa96ea557c6e2e7f62fd32b2a F src/vdbeblob.c 37c3d11a753e403698c69e17383d282e1ae73e75 F src/vdbemem.c b9181e77eca2a095929d46250daf85c8d2621fc0 F src/vdbesort.c ef3c6d1f1a7d44cf67bb2bee59ea3d1fe5bad174 -F src/vdbetrace.c 8befe829faff6d9e6f6e4dee5a7d3f85cc85f1a0 +F src/vdbetrace.c f75c5455d8cf389ef86a8bfdfd3177e0e3692484 F src/vtab.c 320682cca733115b4cbe71320b5c5eeb1074ebde F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9 F src/wal.c d21b99fd1458159d0b1ecdccc8ee6ada4fdc4c54 @@ -428,7 +428,7 @@ F src/wal.h 2f7c831cf3b071fa548bf2d5cac640846a7ff19c F src/walker.c 0f142b5bd3ed2041fc52d773880748b212e63354 F src/where.c af9bf5dcec1a0e52726c550924aa91d837166251 F src/whereInt.h 78b6b4de94db84aecbdc07fe3e38f648eb391e9a -F src/wherecode.c 3c4757ae85e8237808a4ec1a25c513d83e1395e0 +F src/wherecode.c ef0d7019029624625416cdf32cc86604c970416f F src/whereexpr.c 197a448b52073aee43eca3a2233fc113369eb2d4 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/affinity2.test a6d901b436328bd67a79b41bb0ac2663918fe3bd @@ -1422,8 +1422,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 512caa1ad30e6f699e2d006d5ab7674d55d2c746 6c520d5726e80b4251338c43c405270d150ea81e -R e4149e0b983ab1835709b124e27b8f90 -T +closed 6c520d5726e80b4251338c43c405270d150ea81e +P 9de3d7123007636aa97da1c70bc34344b0391078 +R 821c09620afbfbde9b9d6d9359867747 U drh -Z 625eb895cdbe3aba3d382c8d078d5321 +Z e57134af984dbdd8b3338eb2a295687a diff --git a/manifest.uuid b/manifest.uuid index a752c98cea..0454e6289a 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -9de3d7123007636aa97da1c70bc34344b0391078 \ No newline at end of file +0bdb41c45aa1cc8e5c136aaa6605d54b401483bd \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index 4e6f6478af..481418a3dc 100644 --- a/src/btree.c +++ b/src/btree.c @@ -8805,9 +8805,9 @@ static void checkAppendMsg( sqlite3StrAccumAppend(&pCheck->errMsg, "\n", 1); } if( pCheck->zPfx ){ - sqlite3XPrintf(&pCheck->errMsg, 0, pCheck->zPfx, pCheck->v1, pCheck->v2); + sqlite3XPrintf(&pCheck->errMsg, pCheck->zPfx, pCheck->v1, pCheck->v2); } - sqlite3VXPrintf(&pCheck->errMsg, 1, zFormat, ap); + sqlite3VXPrintf(&pCheck->errMsg, zFormat, ap); va_end(ap); if( pCheck->errMsg.accError==STRACCUM_NOMEM ){ pCheck->mallocFailed = 1; @@ -9321,6 +9321,7 @@ char *sqlite3BtreeIntegrityCheck( sCheck.aPgRef = 0; sCheck.heap = 0; sqlite3StrAccumInit(&sCheck.errMsg, 0, zErr, sizeof(zErr), SQLITE_MAX_LENGTH); + sCheck.errMsg.printfFlags = SQLITE_PRINTF_INTERNAL; if( sCheck.nPage==0 ){ goto integrity_ck_cleanup; } diff --git a/src/build.c b/src/build.c index 06f5433e37..be320b9c5a 100644 --- a/src/build.c +++ b/src/build.c @@ -4132,14 +4132,14 @@ void sqlite3UniqueConstraint( sqlite3StrAccumInit(&errMsg, pParse->db, 0, 0, 200); if( pIdx->aColExpr ){ - sqlite3XPrintf(&errMsg, 0, "index '%q'", pIdx->zName); + sqlite3XPrintf(&errMsg, "index '%q'", pIdx->zName); }else{ for(j=0; jnKeyCol; j++){ char *zCol; assert( pIdx->aiColumn[j]>=0 ); zCol = pTab->aCol[pIdx->aiColumn[j]].zName; if( j ) sqlite3StrAccumAppend(&errMsg, ", ", 2); - sqlite3XPrintf(&errMsg, 0, "%s.%s", pTab->zName, zCol); + sqlite3XPrintf(&errMsg, "%s.%s", pTab->zName, zCol); } } zErr = sqlite3StrAccumFinish(&errMsg); diff --git a/src/func.c b/src/func.c index b927296782..982a8c2caa 100644 --- a/src/func.c +++ b/src/func.c @@ -239,7 +239,8 @@ static void printfFunc( x.nUsed = 0; x.apArg = argv+1; sqlite3StrAccumInit(&str, db, 0, 0, db->aLimit[SQLITE_LIMIT_LENGTH]); - sqlite3XPrintf(&str, SQLITE_PRINTF_SQLFUNC, zFormat, &x); + str.printfFlags = SQLITE_PRINTF_SQLFUNC; + sqlite3XPrintf(&str, zFormat, &x); n = str.nChar; sqlite3_result_text(context, sqlite3StrAccumFinish(&str), n, SQLITE_DYNAMIC); diff --git a/src/printf.c b/src/printf.c index 969950c154..946161f64c 100644 --- a/src/printf.c +++ b/src/printf.c @@ -171,7 +171,6 @@ static char *getTextArg(PrintfArguments *p){ */ void sqlite3VXPrintf( StrAccum *pAccum, /* Accumulate results here */ - u32 bFlags, /* SQLITE_PRINTF_* flags */ const char *fmt, /* Format string */ va_list ap /* arguments */ ){ @@ -211,11 +210,11 @@ void sqlite3VXPrintf( char buf[etBUFSIZE]; /* Conversion buffer */ bufpt = 0; - if( bFlags ){ - if( (bArgList = (bFlags & SQLITE_PRINTF_SQLFUNC))!=0 ){ + if( pAccum->printfFlags ){ + if( (bArgList = (pAccum->printfFlags & SQLITE_PRINTF_SQLFUNC))!=0 ){ pArgList = va_arg(ap, PrintfArguments*); } - useIntern = bFlags & SQLITE_PRINTF_INTERNAL; + useIntern = pAccum->printfFlags & SQLITE_PRINTF_INTERNAL; }else{ bArgList = useIntern = 0; } @@ -766,9 +765,9 @@ static int sqlite3StrAccumEnlarge(StrAccum *p, int N){ setStrAccumError(p, STRACCUM_TOOBIG); return N; }else{ - char *zOld = p->bMalloced ? p->zText : 0; + char *zOld = isMalloced(p) ? p->zText : 0; i64 szNew = p->nChar; - assert( (p->zText==0 || p->zText==p->zBase)==(p->bMalloced==0) ); + assert( (p->zText==0 || p->zText==p->zBase)==!isMalloced(p) ); szNew += N + 1; if( szNew+p->nChar<=p->mxAlloc ){ /* Force exponential buffer size growth as long as it does not overflow, @@ -789,10 +788,10 @@ static int sqlite3StrAccumEnlarge(StrAccum *p, int N){ } if( zNew ){ assert( p->zText!=0 || p->nChar==0 ); - if( !p->bMalloced && p->nChar>0 ) memcpy(zNew, p->zText, p->nChar); + if( !isMalloced(p) && p->nChar>0 ) memcpy(zNew, p->zText, p->nChar); p->zText = zNew; p->nAlloc = sqlite3DbMallocSize(p->db, zNew); - p->bMalloced = 1; + p->printfFlags |= SQLITE_PRINTF_MALLOCED; }else{ sqlite3StrAccumReset(p); setStrAccumError(p, STRACCUM_NOMEM); @@ -810,7 +809,7 @@ void sqlite3AppendChar(StrAccum *p, int N, char c){ if( p->nChar+(i64)N >= p->nAlloc && (N = sqlite3StrAccumEnlarge(p, N))<=0 ){ return; } - assert( (p->zText==p->zBase)==(p->bMalloced==0) ); + assert( (p->zText==p->zBase)==!isMalloced(p) ); while( (N--)>0 ) p->zText[p->nChar++] = c; } @@ -828,7 +827,7 @@ static void SQLITE_NOINLINE enlargeAndAppend(StrAccum *p, const char *z, int N){ memcpy(&p->zText[p->nChar], z, N); p->nChar += N; } - assert( (p->zText==0 || p->zText==p->zBase)==(p->bMalloced==0) ); + assert( (p->zText==0 || p->zText==p->zBase)==!isMalloced(p) ); } /* @@ -864,13 +863,13 @@ void sqlite3StrAccumAppendAll(StrAccum *p, const char *z){ */ char *sqlite3StrAccumFinish(StrAccum *p){ if( p->zText ){ - assert( (p->zText==p->zBase)==(p->bMalloced==0) ); + assert( (p->zText==p->zBase)==!isMalloced(p) ); p->zText[p->nChar] = 0; - if( p->mxAlloc>0 && p->bMalloced==0 ){ + if( p->mxAlloc>0 && !isMalloced(p) ){ p->zText = sqlite3DbMallocRaw(p->db, p->nChar+1 ); if( p->zText ){ memcpy(p->zText, p->zBase, p->nChar+1); - p->bMalloced = 1; + p->printfFlags |= SQLITE_PRINTF_MALLOCED; }else{ setStrAccumError(p, STRACCUM_NOMEM); } @@ -883,10 +882,10 @@ char *sqlite3StrAccumFinish(StrAccum *p){ ** Reset an StrAccum string. Reclaim all malloced memory. */ void sqlite3StrAccumReset(StrAccum *p){ - assert( (p->zText==0 || p->zText==p->zBase)==(p->bMalloced==0) ); - if( p->bMalloced ){ + assert( (p->zText==0 || p->zText==p->zBase)==!isMalloced(p) ); + if( isMalloced(p) ){ sqlite3DbFree(p->db, p->zText); - p->bMalloced = 0; + p->printfFlags &= ~SQLITE_PRINTF_MALLOCED; } p->zText = 0; } @@ -912,7 +911,7 @@ void sqlite3StrAccumInit(StrAccum *p, sqlite3 *db, char *zBase, int n, int mx){ p->nAlloc = n; p->mxAlloc = mx; p->accError = 0; - p->bMalloced = 0; + p->printfFlags = 0; } /* @@ -926,7 +925,8 @@ char *sqlite3VMPrintf(sqlite3 *db, const char *zFormat, va_list ap){ assert( db!=0 ); sqlite3StrAccumInit(&acc, db, zBase, sizeof(zBase), db->aLimit[SQLITE_LIMIT_LENGTH]); - sqlite3VXPrintf(&acc, SQLITE_PRINTF_INTERNAL, zFormat, ap); + acc.printfFlags = SQLITE_PRINTF_INTERNAL; + sqlite3VXPrintf(&acc, zFormat, ap); z = sqlite3StrAccumFinish(&acc); if( acc.accError==STRACCUM_NOMEM ){ db->mallocFailed = 1; @@ -966,7 +966,7 @@ char *sqlite3_vmprintf(const char *zFormat, va_list ap){ if( sqlite3_initialize() ) return 0; #endif sqlite3StrAccumInit(&acc, 0, zBase, sizeof(zBase), SQLITE_MAX_LENGTH); - sqlite3VXPrintf(&acc, 0, zFormat, ap); + sqlite3VXPrintf(&acc, zFormat, ap); z = sqlite3StrAccumFinish(&acc); return z; } @@ -1011,7 +1011,7 @@ char *sqlite3_vsnprintf(int n, char *zBuf, const char *zFormat, va_list ap){ } #endif sqlite3StrAccumInit(&acc, 0, zBuf, n, 0); - sqlite3VXPrintf(&acc, 0, zFormat, ap); + sqlite3VXPrintf(&acc, zFormat, ap); return sqlite3StrAccumFinish(&acc); } char *sqlite3_snprintf(int n, char *zBuf, const char *zFormat, ...){ @@ -1042,7 +1042,7 @@ static void renderLogMsg(int iErrCode, const char *zFormat, va_list ap){ char zMsg[SQLITE_PRINT_BUF_SIZE*3]; /* Complete log message */ sqlite3StrAccumInit(&acc, 0, zMsg, sizeof(zMsg), 0); - sqlite3VXPrintf(&acc, 0, zFormat, ap); + sqlite3VXPrintf(&acc, zFormat, ap); sqlite3GlobalConfig.xLog(sqlite3GlobalConfig.pLogArg, iErrCode, sqlite3StrAccumFinish(&acc)); } @@ -1071,7 +1071,7 @@ void sqlite3DebugPrintf(const char *zFormat, ...){ char zBuf[500]; sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0); va_start(ap,zFormat); - sqlite3VXPrintf(&acc, 0, zFormat, ap); + sqlite3VXPrintf(&acc, zFormat, ap); va_end(ap); sqlite3StrAccumFinish(&acc); fprintf(stdout,"%s", zBuf); @@ -1084,9 +1084,9 @@ void sqlite3DebugPrintf(const char *zFormat, ...){ ** variable-argument wrapper around sqlite3VXPrintf(). The bFlags argument ** can contain the bit SQLITE_PRINTF_INTERNAL enable internal formats. */ -void sqlite3XPrintf(StrAccum *p, u32 bFlags, const char *zFormat, ...){ +void sqlite3XPrintf(StrAccum *p, const char *zFormat, ...){ va_list ap; va_start(ap,zFormat); - sqlite3VXPrintf(p, bFlags, zFormat, ap); + sqlite3VXPrintf(p, zFormat, ap); va_end(ap); } diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 1a8a5d3a5b..b851399c59 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -2978,10 +2978,16 @@ struct StrAccum { u32 nAlloc; /* Amount of space allocated in zText */ u32 mxAlloc; /* Maximum allowed allocation. 0 for no malloc usage */ u8 accError; /* STRACCUM_NOMEM or STRACCUM_TOOBIG */ - u8 bMalloced; /* zText points to allocated space */ + u8 printfFlags; /* SQLITE_PRINTF flags below */ }; #define STRACCUM_NOMEM 1 #define STRACCUM_TOOBIG 2 +#define SQLITE_PRINTF_INTERNAL 0x01 /* Internal-use-only converters allowed */ +#define SQLITE_PRINTF_SQLFUNC 0x02 /* SQL function arguments to VXPrintf */ +#define SQLITE_PRINTF_MALLOCED 0x04 /* True if xText is allocated space */ + +#define isMalloced(X) (((X)->printfFlags & SQLITE_PRINTF_MALLOCED)!=0) + /* ** A pointer to this structure is used to communicate information @@ -3298,10 +3304,8 @@ struct PrintfArguments { sqlite3_value **apArg; /* The argument values */ }; -#define SQLITE_PRINTF_INTERNAL 0x01 -#define SQLITE_PRINTF_SQLFUNC 0x02 -void sqlite3VXPrintf(StrAccum*, u32, const char*, va_list); -void sqlite3XPrintf(StrAccum*, u32, const char*, ...); +void sqlite3VXPrintf(StrAccum*, const char*, va_list); +void sqlite3XPrintf(StrAccum*, const char*, ...); char *sqlite3MPrintf(sqlite3*,const char*, ...); char *sqlite3VMPrintf(sqlite3*,const char*, va_list); #if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE) diff --git a/src/treeview.c b/src/treeview.c index a26e9e2b9f..2985804314 100644 --- a/src/treeview.c +++ b/src/treeview.c @@ -63,7 +63,7 @@ static void sqlite3TreeViewLine(TreeView *p, const char *zFormat, ...){ sqlite3StrAccumAppend(&acc, p->bLine[i] ? "|-- " : "'-- ", 4); } va_start(ap, zFormat); - sqlite3VXPrintf(&acc, 0, zFormat, ap); + sqlite3VXPrintf(&acc, zFormat, ap); va_end(ap); if( zBuf[acc.nChar-1]!='\n' ) sqlite3StrAccumAppend(&acc, "\n", 1); sqlite3StrAccumFinish(&acc); @@ -98,17 +98,17 @@ void sqlite3TreeViewWith(TreeView *pView, const With *pWith, u8 moreToFollow){ char zLine[1000]; const struct Cte *pCte = &pWith->a[i]; sqlite3StrAccumInit(&x, 0, zLine, sizeof(zLine), 0); - sqlite3XPrintf(&x, 0, "%s", pCte->zName); + sqlite3XPrintf(&x, "%s", pCte->zName); if( pCte->pCols && pCte->pCols->nExpr>0 ){ char cSep = '('; int j; for(j=0; jpCols->nExpr; j++){ - sqlite3XPrintf(&x, 0, "%c%s", cSep, pCte->pCols->a[j].zName); + sqlite3XPrintf(&x, "%c%s", cSep, pCte->pCols->a[j].zName); cSep = ','; } - sqlite3XPrintf(&x, 0, ")"); + sqlite3XPrintf(&x, ")"); } - sqlite3XPrintf(&x, 0, " AS"); + sqlite3XPrintf(&x, " AS"); sqlite3StrAccumFinish(&x); sqlite3TreeViewItem(pView, zLine, inCte-1); sqlite3TreeViewSelect(pView, pCte->pSelect, 0); @@ -159,20 +159,20 @@ void sqlite3TreeViewSelect(TreeView *pView, const Select *p, u8 moreToFollow){ StrAccum x; char zLine[100]; sqlite3StrAccumInit(&x, 0, zLine, sizeof(zLine), 0); - sqlite3XPrintf(&x, 0, "{%d,*}", pItem->iCursor); + sqlite3XPrintf(&x, "{%d,*}", pItem->iCursor); if( pItem->zDatabase ){ - sqlite3XPrintf(&x, 0, " %s.%s", pItem->zDatabase, pItem->zName); + sqlite3XPrintf(&x, " %s.%s", pItem->zDatabase, pItem->zName); }else if( pItem->zName ){ - sqlite3XPrintf(&x, 0, " %s", pItem->zName); + sqlite3XPrintf(&x, " %s", pItem->zName); } if( pItem->pTab ){ - sqlite3XPrintf(&x, 0, " tabname=%Q", pItem->pTab->zName); + sqlite3XPrintf(&x, " tabname=%Q", pItem->pTab->zName); } if( pItem->zAlias ){ - sqlite3XPrintf(&x, 0, " (AS %s)", pItem->zAlias); + sqlite3XPrintf(&x, " (AS %s)", pItem->zAlias); } if( pItem->fg.jointype & JT_LEFT ){ - sqlite3XPrintf(&x, 0, " LEFT-JOIN"); + sqlite3XPrintf(&x, " LEFT-JOIN"); } sqlite3StrAccumFinish(&x); sqlite3TreeViewItem(pView, zLine, ipSrc->nSrc-1); diff --git a/src/vdbeaux.c b/src/vdbeaux.c index aaba2d3d0c..619aada030 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -1117,28 +1117,27 @@ static int displayComment( ** Translate the P4.pExpr value for an OP_CursorHint opcode into text ** that can be displayed in the P4 column of EXPLAIN output. */ -static int displayP4Expr(int nTemp, char *zTemp, Expr *pExpr){ +static void displayP4Expr(StrAccum *p, Expr *pExpr){ const char *zOp = 0; - int n; switch( pExpr->op ){ case TK_STRING: - sqlite3_snprintf(nTemp, zTemp, "%Q", pExpr->u.zToken); + sqlite3XPrintf(p, "%Q", pExpr->u.zToken); break; case TK_INTEGER: - sqlite3_snprintf(nTemp, zTemp, "%d", pExpr->u.iValue); + sqlite3XPrintf(p, "%d", pExpr->u.iValue); break; case TK_NULL: - sqlite3_snprintf(nTemp, zTemp, "NULL"); + sqlite3XPrintf(p, "NULL"); break; case TK_REGISTER: { - sqlite3_snprintf(nTemp, zTemp, "r[%d]", pExpr->iTable); + sqlite3XPrintf(p, "r[%d]", pExpr->iTable); break; } case TK_COLUMN: { if( pExpr->iColumn<0 ){ - sqlite3_snprintf(nTemp, zTemp, "rowid"); + sqlite3XPrintf(p, "rowid"); }else{ - sqlite3_snprintf(nTemp, zTemp, "c%d", (int)pExpr->iColumn); + sqlite3XPrintf(p, "c%d", (int)pExpr->iColumn); } break; } @@ -1170,21 +1169,19 @@ static int displayP4Expr(int nTemp, char *zTemp, Expr *pExpr){ case TK_NOTNULL: zOp = "NOTNULL"; break; default: - sqlite3_snprintf(nTemp, zTemp, "%s", "expr"); + sqlite3XPrintf(p, "%s", "expr"); break; } if( zOp ){ - sqlite3_snprintf(nTemp, zTemp, "%s(", zOp); - n = sqlite3Strlen30(zTemp); - n += displayP4Expr(nTemp-n, zTemp+n, pExpr->pLeft); - if( npRight ){ - zTemp[n++] = ','; - n += displayP4Expr(nTemp-n, zTemp+n, pExpr->pRight); + sqlite3XPrintf(p, "%s(", zOp); + displayP4Expr(p, pExpr->pLeft); + if( pExpr->pRight ){ + sqlite3StrAccumAppend(p, ",", 1); + displayP4Expr(p, pExpr->pRight); } - sqlite3_snprintf(nTemp-n, zTemp+n, ")"); + sqlite3StrAccumAppend(p, ")", 1); } - return sqlite3Strlen30(zTemp); } #endif /* VDBE_DISPLAY_P4 && defined(SQLITE_ENABLE_CURSOR_HINTS) */ @@ -1196,72 +1193,57 @@ static int displayP4Expr(int nTemp, char *zTemp, Expr *pExpr){ */ static char *displayP4(Op *pOp, char *zTemp, int nTemp){ char *zP4 = zTemp; + StrAccum x; assert( nTemp>=20 ); + sqlite3StrAccumInit(&x, 0, zTemp, nTemp, 0); switch( pOp->p4type ){ case P4_KEYINFO: { - int i, j; + int j; KeyInfo *pKeyInfo = pOp->p4.pKeyInfo; assert( pKeyInfo->aSortOrder!=0 ); - sqlite3_snprintf(nTemp, zTemp, "k(%d", pKeyInfo->nField); - i = sqlite3Strlen30(zTemp); + sqlite3XPrintf(&x, "k(%d", pKeyInfo->nField); for(j=0; jnField; j++){ CollSeq *pColl = pKeyInfo->aColl[j]; - const char *zColl = pColl ? pColl->zName : "nil"; - int n = sqlite3Strlen30(zColl); - if( n==6 && memcmp(zColl,"BINARY",6)==0 ){ - zColl = "B"; - n = 1; - } - if( i+n>nTemp-7 ){ - memcpy(&zTemp[i],",...",4); - i += 4; - break; - } - zTemp[i++] = ','; - if( pKeyInfo->aSortOrder[j] ){ - zTemp[i++] = '-'; - } - memcpy(&zTemp[i], zColl, n+1); - i += n; + const char *zColl = pColl ? pColl->zName : ""; + if( strcmp(zColl, "BINARY")==0 ) zColl = "B"; + sqlite3XPrintf(&x, ",%s%s", pKeyInfo->aSortOrder[j] ? "-" : "", zColl); } - zTemp[i++] = ')'; - zTemp[i] = 0; - assert( ip4.pExpr); + displayP4Expr(&x, pOp->p4.pExpr); break; } #endif case P4_COLLSEQ: { CollSeq *pColl = pOp->p4.pColl; - sqlite3_snprintf(nTemp, zTemp, "(%.20s)", pColl->zName); + sqlite3XPrintf(&x, "(%.20s)", pColl->zName); break; } case P4_FUNCDEF: { FuncDef *pDef = pOp->p4.pFunc; - sqlite3_snprintf(nTemp, zTemp, "%s(%d)", pDef->zName, pDef->nArg); + sqlite3XPrintf(&x, "%s(%d)", pDef->zName, pDef->nArg); break; } #ifdef SQLITE_DEBUG case P4_FUNCCTX: { FuncDef *pDef = pOp->p4.pCtx->pFunc; - sqlite3_snprintf(nTemp, zTemp, "%s(%d)", pDef->zName, pDef->nArg); + sqlite3XPrintf(&x, "%s(%d)", pDef->zName, pDef->nArg); break; } #endif case P4_INT64: { - sqlite3_snprintf(nTemp, zTemp, "%lld", *pOp->p4.pI64); + sqlite3XPrintf(&x, "%lld", *pOp->p4.pI64); break; } case P4_INT32: { - sqlite3_snprintf(nTemp, zTemp, "%d", pOp->p4.i); + sqlite3XPrintf(&x, "%d", pOp->p4.i); break; } case P4_REAL: { - sqlite3_snprintf(nTemp, zTemp, "%.16g", *pOp->p4.pReal); + sqlite3XPrintf(&x, "%.16g", *pOp->p4.pReal); break; } case P4_MEM: { @@ -1269,11 +1251,11 @@ static char *displayP4(Op *pOp, char *zTemp, int nTemp){ if( pMem->flags & MEM_Str ){ zP4 = pMem->z; }else if( pMem->flags & MEM_Int ){ - sqlite3_snprintf(nTemp, zTemp, "%lld", pMem->u.i); + sqlite3XPrintf(&x, "%lld", pMem->u.i); }else if( pMem->flags & MEM_Real ){ - sqlite3_snprintf(nTemp, zTemp, "%.16g", pMem->u.r); + sqlite3XPrintf(&x, "%.16g", pMem->u.r); }else if( pMem->flags & MEM_Null ){ - sqlite3_snprintf(nTemp, zTemp, "NULL"); + zP4 = "NULL"; }else{ assert( pMem->flags & MEM_Blob ); zP4 = "(blob)"; @@ -1283,30 +1265,24 @@ static char *displayP4(Op *pOp, char *zTemp, int nTemp){ #ifndef SQLITE_OMIT_VIRTUALTABLE case P4_VTAB: { sqlite3_vtab *pVtab = pOp->p4.pVtab->pVtab; - sqlite3_snprintf(nTemp, zTemp, "vtab:%p", pVtab); + sqlite3XPrintf(&x, "vtab:%p", pVtab); break; } #endif case P4_INTARRAY: { - int i, j; + int i; int *ai = pOp->p4.ai; int n = ai[0]; /* The first element of an INTARRAY is always the ** count of the number of elements to follow */ + for(i=1; i1 ) zTemp[j++] = ','; - sqlite3_snprintf(nTemp-j, zTemp+j, "%d", ai[i]); - j += sqlite3Strlen30(zTemp+j); - } - if( iflags & MEM_Null ){ sqlite3StrAccumAppend(&out, "NULL", 4); }else if( pVar->flags & MEM_Int ){ - sqlite3XPrintf(&out, 0, "%lld", pVar->u.i); + sqlite3XPrintf(&out, "%lld", pVar->u.i); }else if( pVar->flags & MEM_Real ){ - sqlite3XPrintf(&out, 0, "%!.15g", pVar->u.r); + sqlite3XPrintf(&out, "%!.15g", pVar->u.r); }else if( pVar->flags & MEM_Str ){ int nOut; /* Number of bytes of the string text to include in output */ #ifndef SQLITE_OMIT_UTF16 @@ -151,17 +151,17 @@ char *sqlite3VdbeExpandSql( while( nOutn && (pVar->z[nOut]&0xc0)==0x80 ){ nOut++; } } #endif - sqlite3XPrintf(&out, 0, "'%.*q'", nOut, pVar->z); + sqlite3XPrintf(&out, "'%.*q'", nOut, pVar->z); #ifdef SQLITE_TRACE_SIZE_LIMIT if( nOutn ){ - sqlite3XPrintf(&out, 0, "/*+%d bytes*/", pVar->n-nOut); + sqlite3XPrintf(&out, "/*+%d bytes*/", pVar->n-nOut); } #endif #ifndef SQLITE_OMIT_UTF16 if( enc!=SQLITE_UTF8 ) sqlite3VdbeMemRelease(&utf8); #endif }else if( pVar->flags & MEM_Zero ){ - sqlite3XPrintf(&out, 0, "zeroblob(%d)", pVar->u.nZero); + sqlite3XPrintf(&out, "zeroblob(%d)", pVar->u.nZero); }else{ int nOut; /* Number of bytes of the blob to include in output */ assert( pVar->flags & MEM_Blob ); @@ -171,12 +171,12 @@ char *sqlite3VdbeExpandSql( if( nOut>SQLITE_TRACE_SIZE_LIMIT ) nOut = SQLITE_TRACE_SIZE_LIMIT; #endif for(i=0; iz[i]&0xff); + sqlite3XPrintf(&out, "%02x", pVar->z[i]&0xff); } sqlite3StrAccumAppend(&out, "'", 1); #ifdef SQLITE_TRACE_SIZE_LIMIT if( nOutn ){ - sqlite3XPrintf(&out, 0, "/*+%d bytes*/", pVar->n-nOut); + sqlite3XPrintf(&out, "/*+%d bytes*/", pVar->n-nOut); } #endif } diff --git a/src/wherecode.c b/src/wherecode.c index fea397c543..d590203155 100644 --- a/src/wherecode.c +++ b/src/wherecode.c @@ -76,7 +76,7 @@ static void explainIndexRange(StrAccum *pStr, WhereLoop *pLoop){ for(i=0; i=nSkip ? "%s=?" : "ANY(%s)", z); + sqlite3XPrintf(pStr, i>=nSkip ? "%s=?" : "ANY(%s)", z); } j = i; @@ -135,13 +135,13 @@ int sqlite3WhereExplainOneScan( sqlite3StrAccumInit(&str, db, zBuf, sizeof(zBuf), SQLITE_MAX_LENGTH); sqlite3StrAccumAppendAll(&str, isSearch ? "SEARCH" : "SCAN"); if( pItem->pSelect ){ - sqlite3XPrintf(&str, 0, " SUBQUERY %d", pItem->iSelectId); + sqlite3XPrintf(&str, " SUBQUERY %d", pItem->iSelectId); }else{ - sqlite3XPrintf(&str, 0, " TABLE %s", pItem->zName); + sqlite3XPrintf(&str, " TABLE %s", pItem->zName); } if( pItem->zAlias ){ - sqlite3XPrintf(&str, 0, " AS %s", pItem->zAlias); + sqlite3XPrintf(&str, " AS %s", pItem->zAlias); } if( (flags & (WHERE_IPK|WHERE_VIRTUALTABLE))==0 ){ const char *zFmt = 0; @@ -165,7 +165,7 @@ int sqlite3WhereExplainOneScan( } if( zFmt ){ sqlite3StrAccumAppend(&str, " USING ", 7); - sqlite3XPrintf(&str, 0, zFmt, pIdx->zName); + sqlite3XPrintf(&str, zFmt, pIdx->zName); explainIndexRange(&str, pLoop); } }else if( (flags & WHERE_IPK)!=0 && (flags & WHERE_CONSTRAINT)!=0 ){ @@ -180,17 +180,17 @@ int sqlite3WhereExplainOneScan( assert( flags&WHERE_TOP_LIMIT); zRangeOp = "<"; } - sqlite3XPrintf(&str, 0, " USING INTEGER PRIMARY KEY (rowid%s?)",zRangeOp); + sqlite3XPrintf(&str, " USING INTEGER PRIMARY KEY (rowid%s?)",zRangeOp); } #ifndef SQLITE_OMIT_VIRTUALTABLE else if( (flags & WHERE_VIRTUALTABLE)!=0 ){ - sqlite3XPrintf(&str, 0, " VIRTUAL TABLE INDEX %d:%s", + sqlite3XPrintf(&str, " VIRTUAL TABLE INDEX %d:%s", pLoop->u.vtab.idxNum, pLoop->u.vtab.idxStr); } #endif #ifdef SQLITE_EXPLAIN_ESTIMATED_ROWS if( pLoop->nOut>=10 ){ - sqlite3XPrintf(&str, 0, " (~%llu rows)", sqlite3LogEstToInt(pLoop->nOut)); + sqlite3XPrintf(&str, " (~%llu rows)", sqlite3LogEstToInt(pLoop->nOut)); }else{ sqlite3StrAccumAppend(&str, " (~1 row)", 9); } From af30fdf6ed259cd1b32b93b571eebe2836beae18 Mon Sep 17 00:00:00 2001 From: drh Date: Sat, 30 Jan 2016 14:17:10 +0000 Subject: [PATCH 63/75] Output subtype information on register traces for PRAGMA vdbe_trace. FossilOrigin-Name: 96b780209cc95c3f3769bb880591380d94bfe38d --- manifest | 13 ++++++------- manifest.uuid | 2 +- src/vdbe.c | 1 + 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index ee7ea0da28..c42504832e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sthe\sBTREE_FORDELETE\sand\sBTREE_AUXDELETE\sflags\sto\sthe\sb-tree\slayer\sinterface\nand\suse\sthem.\s\sAdd\sassert()\sstatement\sto\sverify\sthat\sthey\sare\scorrect. -D 2016-01-30T13:32:30.291 +C Output\ssubtype\sinformation\son\sregister\straces\sfor\sPRAGMA\svdbe_trace. +D 2016-01-30T14:17:10.486 F Makefile.in 027c1603f255390c43a426671055a31c0a65fdb4 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 72b7858f02017611c3ac1ddc965251017fed0845 @@ -412,7 +412,7 @@ F src/update.c 17332f9fe818cbc0444c36a811800af8498af4c3 F src/utf.c 32d7f82aa921322f3e1c956f4b58f019ebd2c6b3 F src/util.c 72d40df0a52d3f30b462a15f0e094fcbade6dc82 F src/vacuum.c 2ddd5cad2a7b9cef7f9e431b8c7771634c6b1701 -F src/vdbe.c d9d2406d8a3baca537d2b05a2354afaa25e1ca84 +F src/vdbe.c bd4d2cabbafe49bd8e04d7bf57d8e480393268d9 F src/vdbe.h 7a733ea8aac1b77305a67698e784fa3484ee3337 F src/vdbeInt.h 716df83ac45b70ff000b515040ea606d0cb5d0f3 F src/vdbeapi.c ffae8f5af4570fbd548504e815e9fb7227f0822e @@ -1422,8 +1422,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 0bdb41c45aa1cc8e5c136aaa6605d54b401483bd 46080b0474363ca6594d2e5c249a280e2b4fc67a -R 54437ffc6525e4a6d93d7714d1fd6e2f -T +closed 46080b0474363ca6594d2e5c249a280e2b4fc67a +P 85c467041c9378cae3038756da815e9117ee8c7d +R 694b551c33162b646e920ddc57abdc60 U drh -Z 640a4b96ac8cc992fda6dcd328c886fd +Z fd54d0de297ea145965f78cad2cde9ad diff --git a/manifest.uuid b/manifest.uuid index 32d73b4945..6041e7c246 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -85c467041c9378cae3038756da815e9117ee8c7d \ No newline at end of file +96b780209cc95c3f3769bb880591380d94bfe38d \ No newline at end of file diff --git a/src/vdbe.c b/src/vdbe.c index 5ad8b11a46..ebb7e046fe 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -471,6 +471,7 @@ static void memTracePrint(Mem *p){ sqlite3VdbeMemPrettyPrint(p, zBuf); printf(" %s", zBuf); } + if( p->eSubtype ) printf(" subtype=0x%02x", p->eSubtype); } static void registerTrace(int iReg, Mem *p){ printf("REG[%d] = ", iReg); From 5b6c8e4e1d988c5e980106bb7c39aa969004de24 Mon Sep 17 00:00:00 2001 From: dan Date: Sat, 30 Jan 2016 15:46:03 +0000 Subject: [PATCH 64/75] A different way to clear the subtype on VDBE registers when the value of the register is overwritten with new content. To fix [[f45ac567eaa9f93]. FossilOrigin-Name: 2e9fb1295cd31fc29c97444c3dec82fef68e939f --- manifest | 25 ++++++++++++++----------- manifest.uuid | 2 +- src/utf.c | 2 +- src/vdbe.c | 2 +- src/vdbeInt.h | 11 ++++++++--- src/vdbeapi.c | 9 ++++++--- test/json103.test | 15 ++++++++++++++- 7 files changed, 45 insertions(+), 21 deletions(-) diff --git a/manifest b/manifest index c42504832e..16ab0b16b9 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Output\ssubtype\sinformation\son\sregister\straces\sfor\sPRAGMA\svdbe_trace. -D 2016-01-30T14:17:10.486 +C A\sdifferent\sway\sto\sclear\sthe\ssubtype\son\sVDBE\sregisters\swhen\sthe\svalue\sof\sthe\sregister\sis\soverwritten\swith\snew\scontent.\sTo\sfix\s[[f45ac567eaa9f93]. +D 2016-01-30T15:46:03.527 F Makefile.in 027c1603f255390c43a426671055a31c0a65fdb4 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 72b7858f02017611c3ac1ddc965251017fed0845 @@ -409,13 +409,13 @@ F src/tokenize.c 5606871a377f390af7040ec3c12e0d183512d785 F src/treeview.c dc39ccf04e9331237388b9cb73289c9d87ea050b F src/trigger.c 72d876b2d0c66604a112362bdae07dae9b104816 F src/update.c 17332f9fe818cbc0444c36a811800af8498af4c3 -F src/utf.c 32d7f82aa921322f3e1c956f4b58f019ebd2c6b3 +F src/utf.c 10cc2519e82e3369344d0969ad4b1a333dc86d18 F src/util.c 72d40df0a52d3f30b462a15f0e094fcbade6dc82 F src/vacuum.c 2ddd5cad2a7b9cef7f9e431b8c7771634c6b1701 -F src/vdbe.c bd4d2cabbafe49bd8e04d7bf57d8e480393268d9 +F src/vdbe.c 49e0a224526f4307ab80e9d3a63697b28cf0cb21 F src/vdbe.h 7a733ea8aac1b77305a67698e784fa3484ee3337 -F src/vdbeInt.h 716df83ac45b70ff000b515040ea606d0cb5d0f3 -F src/vdbeapi.c ffae8f5af4570fbd548504e815e9fb7227f0822e +F src/vdbeInt.h 4b69d5451bcadd473e745af53ef1e8abfdce0a79 +F src/vdbeapi.c 9d640d5efd9a140a6bda8da53b220aa258167993 F src/vdbeaux.c 221631e40111b5efa96ea557c6e2e7f62fd32b2a F src/vdbeblob.c 37c3d11a753e403698c69e17383d282e1ae73e75 F src/vdbemem.c b9181e77eca2a095929d46250daf85c8d2621fc0 @@ -834,7 +834,7 @@ F test/jrnlmode2.test 81610545a4e6ed239ea8fa661891893385e23a1d F test/jrnlmode3.test 556b447a05be0e0963f4311e95ab1632b11c9eaa F test/json101.test f0178422b3a2418f423fd0d3caf3571c8d1b9863 F test/json102.test bf3fe7a706d30936a76a0f7a0375e1e8e73aff5a -F test/json103.test 923b288a0610ec86c0951778f7db19cbcca36ad1 +F test/json103.test c5f6b85e69de05f6b3195f9f9d5ce9cd179099a0 F test/keyword1.test 37ef6bba5d2ed5b07ecdd6810571de2956599dff F test/lastinsert.test 42e948fd6442f07d60acbd15d33fb86473e0ef63 F test/laststmtchanges.test ae613f53819206b3222771828d024154d51db200 @@ -1422,7 +1422,10 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 85c467041c9378cae3038756da815e9117ee8c7d -R 694b551c33162b646e920ddc57abdc60 -U drh -Z fd54d0de297ea145965f78cad2cde9ad +P 96b780209cc95c3f3769bb880591380d94bfe38d +R bd3d63263e82ae4209cc8f920c59f1ec +T *branch * clear-subtype-flag +T *sym-clear-subtype-flag * +T -sym-trunk * +U dan +Z b20671d59699e15a0872203a064b7cf5 diff --git a/manifest.uuid b/manifest.uuid index 6041e7c246..5e49703813 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -96b780209cc95c3f3769bb880591380d94bfe38d \ No newline at end of file +2e9fb1295cd31fc29c97444c3dec82fef68e939f \ No newline at end of file diff --git a/src/utf.c b/src/utf.c index ee367c1399..e42ab418ad 100644 --- a/src/utf.c +++ b/src/utf.c @@ -316,7 +316,7 @@ SQLITE_NOINLINE int sqlite3VdbeMemTranslate(Mem *pMem, u8 desiredEnc){ c = pMem->flags; sqlite3VdbeMemRelease(pMem); - pMem->flags = MEM_Str|MEM_Term|(c&MEM_AffMask); + pMem->flags = MEM_Str|MEM_Term|(c&(MEM_AffMask|MEM_Subtype)); pMem->enc = desiredEnc; pMem->z = (char*)zOut; pMem->zMalloc = pMem->z; diff --git a/src/vdbe.c b/src/vdbe.c index ebb7e046fe..c6ae836a28 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -471,7 +471,7 @@ static void memTracePrint(Mem *p){ sqlite3VdbeMemPrettyPrint(p, zBuf); printf(" %s", zBuf); } - if( p->eSubtype ) printf(" subtype=0x%02x", p->eSubtype); + if( p->flags & MEM_Subtype ) printf(" subtype=0x%02x", p->eSubtype); } static void registerTrace(int iReg, Mem *p){ printf("REG[%d] = ", iReg); diff --git a/src/vdbeInt.h b/src/vdbeInt.h index 497beb87d5..839c2039be 100644 --- a/src/vdbeInt.h +++ b/src/vdbeInt.h @@ -238,7 +238,7 @@ struct Mem { #define MEM_Frame 0x0040 /* Value is a VdbeFrame object */ #define MEM_Undefined 0x0080 /* Value is undefined */ #define MEM_Cleared 0x0100 /* NULL set by OP_Null, not from data */ -#define MEM_TypeMask 0x01ff /* Mask of type bits */ +#define MEM_TypeMask 0x81ff /* Mask of type bits */ /* Whenever Mem contains a valid string or blob representation, one of @@ -252,11 +252,18 @@ struct Mem { #define MEM_Ephem 0x1000 /* Mem.z points to an ephemeral string */ #define MEM_Agg 0x2000 /* Mem.z points to an agg function context */ #define MEM_Zero 0x4000 /* Mem.i contains count of 0s appended to blob */ +#define MEM_Subtype 0x8000 /* Mem.eSubtype is valid */ #ifdef SQLITE_OMIT_INCRBLOB #undef MEM_Zero #define MEM_Zero 0x0000 #endif +/* Return TRUE if Mem X contains dynamically allocated content - anything +** that needs to be deallocated to avoid a leak. +*/ +#define VdbeMemDynamic(X) \ + (((X)->flags&(MEM_Agg|MEM_Dyn|MEM_RowSet|MEM_Frame))!=0) + /* ** Clear any existing type flags from a Mem and replace them with f */ @@ -472,8 +479,6 @@ int sqlite3VdbeMemNumerify(Mem*); void sqlite3VdbeMemCast(Mem*,u8,u8); int sqlite3VdbeMemFromBtree(BtCursor*,u32,u32,int,Mem*); void sqlite3VdbeMemRelease(Mem *p); -#define VdbeMemDynamic(X) \ - (((X)->flags&(MEM_Agg|MEM_Dyn|MEM_RowSet|MEM_Frame))!=0) int sqlite3VdbeMemFinalize(Mem*, FuncDef*); const char *sqlite3OpcodeName(int); int sqlite3VdbeMemGrow(Mem *pMem, int n, int preserve); diff --git a/src/vdbeapi.c b/src/vdbeapi.c index 4bc912b940..0a15633ddf 100644 --- a/src/vdbeapi.c +++ b/src/vdbeapi.c @@ -188,7 +188,8 @@ sqlite_int64 sqlite3_value_int64(sqlite3_value *pVal){ return sqlite3VdbeIntValue((Mem*)pVal); } unsigned int sqlite3_value_subtype(sqlite3_value *pVal){ - return ((Mem*)pVal)->eSubtype; + Mem *pMem = (Mem*)pVal; + return ((pMem->flags & MEM_Subtype) ? pMem->eSubtype : 0); } const unsigned char *sqlite3_value_text(sqlite3_value *pVal){ return (const unsigned char *)sqlite3ValueText(pVal, SQLITE_UTF8); @@ -369,8 +370,10 @@ void sqlite3_result_null(sqlite3_context *pCtx){ sqlite3VdbeMemSetNull(pCtx->pOut); } void sqlite3_result_subtype(sqlite3_context *pCtx, unsigned int eSubtype){ - assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) ); - pCtx->pOut->eSubtype = eSubtype & 0xff; + Mem *pOut = pCtx->pOut; + assert( sqlite3_mutex_held(pOut->db->mutex) ); + pOut->eSubtype = eSubtype & 0xff; + pOut->flags |= MEM_Subtype; } void sqlite3_result_text( sqlite3_context *pCtx, diff --git a/test/json103.test b/test/json103.test index 0f0241e6fc..d7d12e3378 100644 --- a/test/json103.test +++ b/test/json103.test @@ -60,6 +60,19 @@ do_execsql_test json103-220 { WHERE rowid<7 GROUP BY b ORDER BY b; } {0 {{"n3":3,"n6":6}} 1 {{"n1":1,"n4":4}} 2 {{"n2":2,"n5":5}}} - +# ticket https://www.sqlite.org/src/info/f45ac567eaa9f93c 2016-01-30 +# Invalid JSON generated by json_group_array() +# +# The underlying problem is a failure to reset Mem.eSubtype +# +do_execsql_test json103-300 { + DROP TABLE IF EXISTS t1; + CREATE TABLE t1(x); + INSERT INTO t1 VALUES(1),('abc'); + SELECT + json_group_array(x), + json_group_array(json_object('x',x)) + FROM t1; +} {{[1,"abc"]} {[{"x":1},{"x":"abc"}]}} finish_test From 784c1b93fbf5f206878d9fec62dd3d418b0e678d Mon Sep 17 00:00:00 2001 From: drh Date: Sat, 30 Jan 2016 16:59:56 +0000 Subject: [PATCH 65/75] Merge the implementation of OP_IdxRowid and OP_Seek so that OP_Seek no longer requires the rowid register and a separate OP_IdxRowid call. Shorter and faster prepared statements result. FossilOrigin-Name: 9bec50a1e7796a6e038db9b1cc7cc1e7e350bf74 --- manifest | 15 ++++--- manifest.uuid | 2 +- src/vdbe.c | 103 +++++++++++++++++++++++++----------------------- src/wherecode.c | 11 +++--- 4 files changed, 66 insertions(+), 65 deletions(-) diff --git a/manifest b/manifest index df7711094d..d850d9282e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Only\shonor\sthe\sregister\ssubtype\svalue\sif\sthe\sMEM_Subtype\sflag\sis\sset.\nRevised\sand\simproved\sfix\sfor\sticket\s[f45ac567eaa9f9]. -D 2016-01-30T15:52:39.136 +C Merge\sthe\simplementation\sof\sOP_IdxRowid\sand\sOP_Seek\sso\sthat\sOP_Seek\sno\slonger\nrequires\sthe\srowid\sregister\sand\sa\sseparate\sOP_IdxRowid\scall.\s\sShorter\sand\nfaster\sprepared\sstatements\sresult. +D 2016-01-30T16:59:56.592 F Makefile.in 027c1603f255390c43a426671055a31c0a65fdb4 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 72b7858f02017611c3ac1ddc965251017fed0845 @@ -412,7 +412,7 @@ F src/update.c 17332f9fe818cbc0444c36a811800af8498af4c3 F src/utf.c 10cc2519e82e3369344d0969ad4b1a333dc86d18 F src/util.c 72d40df0a52d3f30b462a15f0e094fcbade6dc82 F src/vacuum.c 2ddd5cad2a7b9cef7f9e431b8c7771634c6b1701 -F src/vdbe.c 49e0a224526f4307ab80e9d3a63697b28cf0cb21 +F src/vdbe.c 73f0f61eb5556e430487671a557d032ecac52240 F src/vdbe.h 7a733ea8aac1b77305a67698e784fa3484ee3337 F src/vdbeInt.h 4b69d5451bcadd473e745af53ef1e8abfdce0a79 F src/vdbeapi.c 9d640d5efd9a140a6bda8da53b220aa258167993 @@ -428,7 +428,7 @@ F src/wal.h 2f7c831cf3b071fa548bf2d5cac640846a7ff19c F src/walker.c 0f142b5bd3ed2041fc52d773880748b212e63354 F src/where.c af9bf5dcec1a0e52726c550924aa91d837166251 F src/whereInt.h 78b6b4de94db84aecbdc07fe3e38f648eb391e9a -F src/wherecode.c ef0d7019029624625416cdf32cc86604c970416f +F src/wherecode.c 7ea737b14e7a35d7f55cbad589a29aa49dfe3f7a F src/whereexpr.c 197a448b52073aee43eca3a2233fc113369eb2d4 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/affinity2.test a6d901b436328bd67a79b41bb0ac2663918fe3bd @@ -1422,8 +1422,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 96b780209cc95c3f3769bb880591380d94bfe38d 2e9fb1295cd31fc29c97444c3dec82fef68e939f -R bd3d63263e82ae4209cc8f920c59f1ec -T +closed 2e9fb1295cd31fc29c97444c3dec82fef68e939f +P 1f4c667f37d63fc3ef2e8f2581ecd3a66c054426 +R c807c9436e91d8aabdffdea0ecd68c4e U drh -Z 5703eae66c478a55119b68d54c8bb9ef +Z a3f05d9c2a4721d817f24f533822e83f diff --git a/manifest.uuid b/manifest.uuid index f4551f775a..01040f34b0 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -1f4c667f37d63fc3ef2e8f2581ecd3a66c054426 \ No newline at end of file +9bec50a1e7796a6e038db9b1cc7cc1e7e350bf74 \ No newline at end of file diff --git a/src/vdbe.c b/src/vdbe.c index c6ae836a28..a1e59e1170 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -3857,42 +3857,6 @@ seek_not_found: } break; } - -/* Opcode: Seek P1 P2 P3 P4 * -** Synopsis: intkey=r[P2] -** -** P1 is an open table cursor and P2 is a rowid integer. Arrange -** for P1 to move so that it points to the rowid given by P2. -** -** This is actually a deferred seek. Nothing actually happens until -** the cursor is used to read a record. That way, if no reads -** occur, no unnecessary I/O happens. -** -** P4 may contain an array of integers (type P4_INTARRAY) containing -** one entry for each column in the table P1 is open on. If so, then -** parameter P3 is a cursor open on a database index. If array entry -** a[i] is non-zero, then reading column (a[i]-1) from cursor P3 is -** equivalent to performing the deferred seek and then reading column i -** from P1. -*/ -case OP_Seek: { /* in2 */ - VdbeCursor *pC; - - assert( pOp->p1>=0 && pOp->p1nCursor ); - pC = p->apCsr[pOp->p1]; - assert( pC!=0 ); - assert( pC->eCurType==CURTYPE_BTREE ); - assert( pC->uc.pCursor!=0 ); - assert( pC->isTable ); - pC->nullRow = 0; - pIn2 = &aMem[pOp->p2]; - pC->movetoTarget = sqlite3VdbeIntValue(pIn2); - pC->deferredMoveto = 1; - assert( pOp->p4type==P4_INTARRAY || pOp->p4.ai==0 ); - pC->aAltMap = pOp->p4.ai; - pC->pAltCursor = p->apCsr[pOp->p3]; - break; -} /* Opcode: Found P1 P2 P3 P4 * @@ -4987,6 +4951,25 @@ case OP_IdxDelete: { break; } +/* Opcode: Seek P1 * P3 P4 * +** Synopsis: Move P3 to P1.rowid +** +** P1 is an open index cursor and P3 is a cursor on the corresponding +** table. This opcode does a deferred seek of the P3 table cursor +** to the row that corresponds to the current row of P1. +** +** This is a deferred seek. Nothing actually happens until +** the cursor is used to read a record. That way, if no reads +** occur, no unnecessary I/O happens. +** +** P4 may be an array of integers (type P4_INTARRAY) containing +** one entry for each column in the P3 table. If array entry a[i] +** is non-zero, then reading column (a[i]-1) from cursor P3 is +** equivalent to performing the deferred seek and then reading column i +** from P1. This information is stored in P3 and used to redirect +** reads against P3 over to P1, thus possibly avoiding the need to +** seek and read cursor P3. +*/ /* Opcode: IdxRowid P1 P2 * * * ** Synopsis: r[P2]=rowid ** @@ -4996,37 +4979,57 @@ case OP_IdxDelete: { ** ** See also: Rowid, MakeRecord. */ +case OP_Seek: case OP_IdxRowid: { /* out2 */ - BtCursor *pCrsr; - VdbeCursor *pC; - i64 rowid; + VdbeCursor *pC; /* The P1 index cursor */ + VdbeCursor *pTabCur; /* The P2 table cursor (OP_Seek only) */ + i64 rowid; /* Rowid that P1 current points to */ - pOut = out2Prerelease(p, pOp); assert( pOp->p1>=0 && pOp->p1nCursor ); pC = p->apCsr[pOp->p1]; assert( pC!=0 ); assert( pC->eCurType==CURTYPE_BTREE ); - pCrsr = pC->uc.pCursor; - assert( pCrsr!=0 ); - pOut->flags = MEM_Null; + assert( pC->uc.pCursor!=0 ); assert( pC->isTable==0 ); assert( pC->deferredMoveto==0 ); + assert( !pC->nullRow || pOp->opcode==OP_IdxRowid ); + + /* The IdxRowid and Seek opcodes are combined because of the commonality + ** of sqlite3VdbeCursorRestore() and sqlite3VdbeIdxRowid(). */ + rc = sqlite3VdbeCursorRestore(pC); /* sqlite3VbeCursorRestore() can only fail if the record has been deleted - ** out from under the cursor. That will never happend for an IdxRowid - ** opcode, hence the NEVER() arround the check of the return value. - */ - rc = sqlite3VdbeCursorRestore(pC); + ** out from under the cursor. That will never happens for an IdxRowid + ** or Seek opcode */ if( NEVER(rc!=SQLITE_OK) ) goto abort_due_to_error; if( !pC->nullRow ){ rowid = 0; /* Not needed. Only used to silence a warning. */ - rc = sqlite3VdbeIdxRowid(db, pCrsr, &rowid); + rc = sqlite3VdbeIdxRowid(db, pC->uc.pCursor, &rowid); if( rc!=SQLITE_OK ){ goto abort_due_to_error; } - pOut->u.i = rowid; - pOut->flags = MEM_Int; + if( pOp->opcode==OP_Seek ){ + assert( pOp->p3>=0 && pOp->p3nCursor ); + pTabCur = p->apCsr[pOp->p3]; + assert( pTabCur!=0 ); + assert( pTabCur->eCurType==CURTYPE_BTREE ); + assert( pTabCur->uc.pCursor!=0 ); + assert( pTabCur->isTable ); + pTabCur->nullRow = 0; + pTabCur->movetoTarget = rowid; + pTabCur->deferredMoveto = 1; + assert( pOp->p4type==P4_INTARRAY || pOp->p4.ai==0 ); + pTabCur->aAltMap = pOp->p4.ai; + pTabCur->pAltCursor = pC; + }else{ + pOut = out2Prerelease(p, pOp); + pOut->u.i = rowid; + pOut->flags = MEM_Int; + } + }else{ + assert( pOp->opcode==OP_IdxRowid ); + sqlite3VdbeMemSetNull(&aMem[pOp->p2]); } break; } diff --git a/src/wherecode.c b/src/wherecode.c index d590203155..3fbd198e31 100644 --- a/src/wherecode.c +++ b/src/wherecode.c @@ -768,7 +768,6 @@ static void codeDeferredSeek( WhereInfo *pWInfo, /* Where clause context */ Index *pIdx, /* Index scan is using */ int iCur, /* Cursor for IPK b-tree */ - int iRowid, /* Register containing rowid to seek to */ int iIdxCur /* Index cursor */ ){ Parse *pParse = pWInfo->pParse; /* Parse context */ @@ -777,7 +776,7 @@ static void codeDeferredSeek( assert( iIdxCur>0 ); assert( pIdx->aiColumn[pIdx->nColumn-1]==-1 ); - sqlite3VdbeAddOp3(v, OP_Seek, iCur, iRowid, iIdxCur); + sqlite3VdbeAddOp3(v, OP_Seek, iIdxCur, 0, iCur); if( (pWInfo->wctrlFlags & WHERE_FORCE_TABLE) && sqlite3ParseToplevel(pParse)->writeMask==0 ){ @@ -1274,14 +1273,14 @@ Bitmask sqlite3WhereCodeOneLoopStart( if( omitTable ){ /* pIdx is a covering index. No need to access the main table. */ }else if( HasRowid(pIdx->pTable) ){ - iRowidReg = ++pParse->nMem; - sqlite3VdbeAddOp2(v, OP_IdxRowid, iIdxCur, iRowidReg); - sqlite3ExprCacheStore(pParse, iCur, -1, iRowidReg); if( pWInfo->eOnePass!=ONEPASS_OFF ){ + iRowidReg = ++pParse->nMem; + sqlite3VdbeAddOp2(v, OP_IdxRowid, iIdxCur, iRowidReg); + sqlite3ExprCacheStore(pParse, iCur, -1, iRowidReg); sqlite3VdbeAddOp3(v, OP_NotExists, iCur, 0, iRowidReg); VdbeCoverage(v); }else{ - codeDeferredSeek(pWInfo, pIdx, iCur, iRowidReg, iIdxCur); + codeDeferredSeek(pWInfo, pIdx, iCur, iIdxCur); } }else if( iCur!=iIdxCur ){ Index *pPk = sqlite3PrimaryKeyIndex(pIdx->pTable); From 52f5d1ba6be88ca71cf8bda71ed519ebe84a93e0 Mon Sep 17 00:00:00 2001 From: dan Date: Sat, 30 Jan 2016 19:16:11 +0000 Subject: [PATCH 66/75] Performance enhancement for fts5 column filter queries on detail=full tables. FossilOrigin-Name: 13fb4aa6a87c5c6258979953da82eedc1a7bf14f --- ext/fts5/fts5_index.c | 24 ++-- ext/fts5/tool/fts5speed.tcl | 1 - ext/fts5/tool/fts5txt2db.tcl | 272 +++++++++++++++++++---------------- manifest | 18 +-- manifest.uuid | 2 +- 5 files changed, 170 insertions(+), 147 deletions(-) diff --git a/ext/fts5/fts5_index.c b/ext/fts5/fts5_index.c index ca3feb86f7..f30c38d91a 100644 --- a/ext/fts5/fts5_index.c +++ b/ext/fts5/fts5_index.c @@ -4333,26 +4333,32 @@ static int fts5IndexExtractCol( int iCurrent = 0; /* Anything before the first 0x01 is col 0 */ const u8 *p = *pa; const u8 *pEnd = &p[n]; /* One byte past end of position list */ - u8 prev = 0; while( iCol>iCurrent ){ /* Advance pointer p until it points to pEnd or an 0x01 byte that is - ** not part of a varint */ - while( (prev & 0x80) || *p!=0x01 ){ - prev = *p++; - if( p==pEnd ) return 0; + ** not part of a varint. Note that it is not possible for a negative + ** or extremely large varint to occur within an uncorrupted position + ** list. So the last byte of each varint may be assumed to have a clear + ** 0x80 bit. */ + while( *p!=0x01 ){ + while( *p++ & 0x80 ); + if( p>=pEnd ) return 0; } *pa = p++; - p += fts5GetVarint32(p, iCurrent); + iCurrent = *p++; + if( iCurrent & 0x80 ){ + p--; + p += fts5GetVarint32(p, iCurrent); + } } if( iCol!=iCurrent ) return 0; /* Advance pointer p until it points to pEnd or an 0x01 byte that is ** not part of a varint */ - assert( (prev & 0x80)==0 ); - while( p [set idx(-tblname) {tblname t1 "table name to use"} - # - # For each position parameter, append its name to $lPosargs. If the ... - # specifier is present, set $zTrailing to the name of the prefix. - # - foreach o $O { - set nm [lindex $o 0] - set nArg [llength $o] - switch -- $nArg { - 1 { - if {[string range $nm end-2 end]=="..."} { - set zTrailing [string range $nm 0 end-3] - } else { - lappend lPosargs $nm +########################################################################### +########################################################################### +# Command line options processor. This is generic code that can be copied +# between scripts. +# +namespace eval cmdline { + proc cmdline_error {O E {msg ""}} { + if {$msg != ""} { + puts stderr "Error: $msg" + puts stderr "" + } + + set L [list] + foreach o $O { + if {[llength $o]==1} { + lappend L [string toupper $o] + } + } + + puts stderr "Usage: $::argv0 ?SWITCHES? $L" + puts stderr "" + puts stderr "Switches are:" + foreach o $O { + if {[llength $o]==3} { + foreach {a b c} $o {} + puts stderr [format " -%-15s %s (default \"%s\")" "$a VAL" $c $b] + } elseif {[llength $o]==2} { + foreach {a b} $o {} + puts stderr [format " -%-15s %s" $a $b] + } + } + puts stderr "" + puts stderr $E + exit -1 + } + + proc process {avar lArgs O E} { + upvar $avar A + set zTrailing "" ;# True if ... is present in $O + set lPosargs [list] + + # Populate A() with default values. Also, for each switch in the command + # line spec, set an entry in the idx() array as follows: + # + # {tblname t1 "table name to use"} + # -> [set idx(-tblname) {tblname t1 "table name to use"} + # + # For each position parameter, append its name to $lPosargs. If the ... + # specifier is present, set $zTrailing to the name of the prefix. + # + foreach o $O { + set nm [lindex $o 0] + set nArg [llength $o] + switch -- $nArg { + 1 { + if {[string range $nm end-2 end]=="..."} { + set zTrailing [string range $nm 0 end-3] + } else { + lappend lPosargs $nm + } + } + 2 { + set A($nm) 0 + set idx(-$nm) $o + } + 3 { + set A($nm) [lindex $o 1] + set idx(-$nm) $o + } + default { + error "Error in command line specification" } } - 2 { - set A($nm) 0 - set idx(-$nm) $o - } - 3 { - set A($nm) [lindex $o 1] - set idx(-$nm) $o - } - default { - error "Error in command line specification" + } + + # Set explicitly specified option values + # + set nArg [llength $lArgs] + for {set i 0} {$i < $nArg} {incr i} { + set opt [lindex $lArgs $i] + if {[string range $opt 0 0]!="-" || $opt=="--"} break + set c [array names idx "${opt}*"] + if {[llength $c]==0} { cmdline_error $O $E "Unrecognized option: $opt"} + if {[llength $c]>1} { cmdline_error $O $E "Ambiguous option: $opt"} + + if {[llength $idx($c)]==3} { + if {$i==[llength $lArgs]-1} { + cmdline_error $O $E "Option requires argument: $c" + } + incr i + set A([lindex $idx($c) 0]) [lindex $lArgs $i] + } else { + set A([lindex $idx($c) 0]) 1 } } - } - - # Set explicitly specified option values - # - set nArg [llength $lArgs] - for {set i 0} {$i < $nArg} {incr i} { - set opt [lindex $lArgs $i] - if {[string range $opt 0 0]!="-" || $opt=="--"} break - set c [array names idx "${opt}*"] - if {[llength $c]==0} { command_line_error $O $E "Unrecognized option: $opt"} - if {[llength $c]>1} { command_line_error $O $E "Ambiguous option: $opt"} - - if {[llength $idx($c)]==3} { - if {$i==[llength $lArgs]-1} { - command_line_error $O $E "Option requires argument: $c" - } - incr i - set A([lindex $idx($c) 0]) [lindex $lArgs $i] - } else { - set A([lindex $idx($c) 0]) 1 + + # Deal with position arguments. + # + set nPosarg [llength $lPosargs] + set nRem [expr $nArg - $i] + if {$nRem < $nPosarg || ($zTrailing=="" && $nRem > $nPosarg)} { + cmdline_error $O $E + } + for {set j 0} {$j < $nPosarg} {incr j} { + set A([lindex $lPosargs $j]) [lindex $lArgs [expr $j+$i]] + } + if {$zTrailing!=""} { + set A($zTrailing) [lrange $lArgs [expr $j+$i] end] } } - - # Deal with position arguments. - # - set nPosarg [llength $lPosargs] - set nRem [expr $nArg - $i] - if {$nRem < $nPosarg || ($zTrailing=="" && $nRem > $nPosarg)} { - command_line_error $O $E - } - for {set j 0} {$j < $nPosarg} {incr j} { - set A([lindex $lPosargs $j]) [lindex $lArgs [expr $j+$i]] - } - if {$zTrailing!=""} { - set A($zTrailing) [lrange $lArgs [expr $j+$i] end] - } -} +} ;# namespace eval cmdline # End of command line options processor. -#------------------------------------------------------------------------- +########################################################################### +########################################################################### +process_cmdline -process_command_line A $argv { - {fts5 "use fts5"} - {fts4 "use fts4"} - {colsize "10 10 10" "list of column sizes"} - {tblname "t1" "table name to create"} - {detail "full" "Fts5 detail mode to use"} - {repeat 1 "Load each file this many times"} - database - file... -} { -This script is designed to create fts4/5 tables with more than one column. -The -colsize option should be set to a Tcl list of integer values, one for -each column in the table. Each value is the number of tokens that will be -inserted into the column value for each row. For example, setting the -colsize -option to "5 10" creates an FTS table with 2 columns, with roughly 5 and 10 -tokens per row in each, respectively. - -Each "FILE" argument should be a text file. The contents of these text files is -split on whitespace characters to form a list of tokens. The first N1 tokens -are used for the first column of the first row, where N1 is the first element -of the -colsize list. The next N2 are used for the second column of the first -row, and so on. Rows are added to the table until the entire list of tokens -is exhausted. -} - +# If -fts4 was specified, use fts4. Otherwise, fts5. if {$A(fts4)} { set A(fts) fts4 } else { @@ -156,7 +173,8 @@ proc create_table {} { set sql "CREATE VIRTUAL TABLE IF NOT EXISTS $A(tblname) USING $A(fts) (" append sql [join $cols ,] - if {$A(fts)=="fts5"} { append sql ",detail=$A(detail));" } + if {$A(fts)=="fts5"} { append sql ",detail=$A(detail)" } + append sql ", prefix='$A(prefix)');" db eval $sql return $cols diff --git a/manifest b/manifest index d850d9282e..75f2023494 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Merge\sthe\simplementation\sof\sOP_IdxRowid\sand\sOP_Seek\sso\sthat\sOP_Seek\sno\slonger\nrequires\sthe\srowid\sregister\sand\sa\sseparate\sOP_IdxRowid\scall.\s\sShorter\sand\nfaster\sprepared\sstatements\sresult. -D 2016-01-30T16:59:56.592 +C Performance\senhancement\sfor\sfts5\scolumn\sfilter\squeries\son\sdetail=full\stables. +D 2016-01-30T19:16:11.820 F Makefile.in 027c1603f255390c43a426671055a31c0a65fdb4 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 72b7858f02017611c3ac1ddc965251017fed0845 @@ -104,7 +104,7 @@ F ext/fts5/fts5_buffer.c f6e0c6018ffc8e39fc0b333b5daa8b8d528ae6e4 F ext/fts5/fts5_config.c 0c384ebdd23fd055e2e50a93277b8d59da538238 F ext/fts5/fts5_expr.c a66b9694519d9c336d9bdbd46ea22e7e14aef412 F ext/fts5/fts5_hash.c 1b113977296cf4212c6ec667d5e3f2bd18036955 -F ext/fts5/fts5_index.c 5558bfbeaf364cc67f937e25753ceed8757cb6d1 +F ext/fts5/fts5_index.c cd1e4faca8b9adc2d89b367075bf93a7f50c406b F ext/fts5/fts5_main.c 3886bbfc5ac1d9df29979823ddf2b68241e1127e F ext/fts5/fts5_storage.c 2a1f44deae090cd711f02cec0c2af8e660360d24 F ext/fts5/fts5_tcl.c f8731e0508299bd43f1a2eff7dbeaac870768966 @@ -190,8 +190,8 @@ F ext/fts5/test/fts5unindexed.test e9539d5b78c677315e7ed8ea911d4fd25437c680 F ext/fts5/test/fts5update.test 57c7012a7919889048947addae10e0613df45529 F ext/fts5/test/fts5version.test 978f59541d8cef7e8591f8be2115ec5ccb863e2e F ext/fts5/test/fts5vocab.test 480d780aa6b699816c5066225fbd86f3a0239477 -F ext/fts5/tool/fts5speed.tcl 47f0031e6ac564964f4f4805e439ea665e848df2 -F ext/fts5/tool/fts5txt2db.tcl ae308338b2da1646dea456ab66706acdde8c714e +F ext/fts5/tool/fts5speed.tcl f9944a9abb9b7685cfbee8101a3dd772ededca66 +F ext/fts5/tool/fts5txt2db.tcl 1343745b89ca2a1e975c23f836d0cee410052975 F ext/fts5/tool/loadfts5.tcl 95b03429ee6b138645703c6ca192c3ac96eaf093 F ext/fts5/tool/mkfts5c.tcl d1c2a9ab8e0ec690a52316f33dd9b1d379942f45 F ext/fts5/tool/showfts5.tcl d54da0e067306663e2d5d523965ca487698e722c @@ -1422,7 +1422,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 1f4c667f37d63fc3ef2e8f2581ecd3a66c054426 -R c807c9436e91d8aabdffdea0ecd68c4e -U drh -Z a3f05d9c2a4721d817f24f533822e83f +P 9bec50a1e7796a6e038db9b1cc7cc1e7e350bf74 +R bc0069e7525e32617bb065c15a24c73f +U dan +Z 0739ff39c83f4f590353add9c7d562e8 diff --git a/manifest.uuid b/manifest.uuid index 01040f34b0..6f555b4e1d 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -9bec50a1e7796a6e038db9b1cc7cc1e7e350bf74 \ No newline at end of file +13fb4aa6a87c5c6258979953da82eedc1a7bf14f \ No newline at end of file From 482721ab7571338de32932d6d9c221a0445bb421 Mon Sep 17 00:00:00 2001 From: dan Date: Sat, 30 Jan 2016 21:09:02 +0000 Subject: [PATCH 67/75] Fix new test cases in stat.test so that they work with -DSQLITE_DEFAULT_AUTOVACUUM=1 builds. FossilOrigin-Name: a2810cf65db13479e2ab255c37abac7841ee985d --- manifest | 12 ++++++------ manifest.uuid | 2 +- test/stat.test | 1 + 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/manifest b/manifest index 75f2023494..6eedebcb19 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Performance\senhancement\sfor\sfts5\scolumn\sfilter\squeries\son\sdetail=full\stables. -D 2016-01-30T19:16:11.820 +C Fix\snew\stest\scases\sin\sstat.test\sso\sthat\sthey\swork\swith\s-DSQLITE_DEFAULT_AUTOVACUUM=1\sbuilds. +D 2016-01-30T21:09:02.039 F Makefile.in 027c1603f255390c43a426671055a31c0a65fdb4 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 72b7858f02017611c3ac1ddc965251017fed0845 @@ -1054,7 +1054,7 @@ F test/spellfix3.test f7bf7b3482971473d32b6b00f6944c5c066cff97 F test/sqldiff1.test 8f6bc7c6a5b3585d350d779c6078869ba402f8f5 F test/sqllimits1.test a74ee2a3740b9f9c2437c246d8fb77354862a142 F test/sqllog.test a8faa2df39610a037dd372ed872d124260d32953 -F test/stat.test fafe6e82dfdb97d8c8be31cd83e36e973079ce0f +F test/stat.test acc91e80517fff447ae8adcfd953cfdaa5efc0af F test/statfault.test f525a7bf633e50afd027700e9a486090684b1ac1 F test/stmt.test 25d64e3dbf9a3ce89558667d7f39d966fe2a71b9 F test/subquery.test d7268d193dd33d5505df965399d3a594e76ae13f @@ -1422,7 +1422,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 9bec50a1e7796a6e038db9b1cc7cc1e7e350bf74 -R bc0069e7525e32617bb065c15a24c73f +P 13fb4aa6a87c5c6258979953da82eedc1a7bf14f +R 47a5bd805bca8e3bfa57e533079ecc85 U dan -Z 0739ff39c83f4f590353add9c7d562e8 +Z 77da8baba44508a2b8a7ef85c127b8a0 diff --git a/manifest.uuid b/manifest.uuid index 6f555b4e1d..480ce59513 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -13fb4aa6a87c5c6258979953da82eedc1a7bf14f \ No newline at end of file +a2810cf65db13479e2ab255c37abac7841ee985d \ No newline at end of file diff --git a/test/stat.test b/test/stat.test index 14751bd6ff..288153dbb3 100644 --- a/test/stat.test +++ b/test/stat.test @@ -192,6 +192,7 @@ do_catchsql_test stat-6.1 { forcedelete test.db2 do_execsql_test 7.1 { ATTACH 'test.db2' AS '123'; + PRAGMA "123".auto_vacuum = OFF; CREATE TABLE "123".x1(a, b); INSERT INTO x1 VALUES(1, 2); } From 38bace84cdc2d654097a89ce1ffb2521eb8dbd04 Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 1 Feb 2016 00:21:08 +0000 Subject: [PATCH 68/75] Fix an assert() that might fail on a corrupt database. FossilOrigin-Name: 22eaced7274764eaf7ab4b5fc52cc2fcfc285708 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/btree.c | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 6eedebcb19..adf078c951 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\snew\stest\scases\sin\sstat.test\sso\sthat\sthey\swork\swith\s-DSQLITE_DEFAULT_AUTOVACUUM=1\sbuilds. -D 2016-01-30T21:09:02.039 +C Fix\san\sassert()\sthat\smight\sfail\son\sa\scorrupt\sdatabase. +D 2016-02-01T00:21:08.846 F Makefile.in 027c1603f255390c43a426671055a31c0a65fdb4 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 72b7858f02017611c3ac1ddc965251017fed0845 @@ -290,7 +290,7 @@ F src/auth.c b56c78ebe40a2110fd361379f7e8162d23f92240 F src/backup.c 2869a76c03eb393ee795416e2387005553df72bc F src/bitvec.c 1a78d450a17c5016710eec900bedfc5729bf9bdf F src/btmutex.c bc87dd3b062cc26edfe79918de2200ccb8d41e73 -F src/btree.c e3929afb9bfbaa6b39685b5e5a207036ac862a75 +F src/btree.c a2a0244ea3f0b3f57f75019c2f229c744ca5d202 F src/btree.h 368ceeb4bd9312dc8df2ffd64b4b7dbcf4db5f8e F src/btreeInt.h c18b7d2a3494695133e4e60ee36061d37f45d9a5 F src/build.c 0510844c48d80732aead74b5727403b493dd1cd5 @@ -1422,7 +1422,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 13fb4aa6a87c5c6258979953da82eedc1a7bf14f -R 47a5bd805bca8e3bfa57e533079ecc85 -U dan -Z 77da8baba44508a2b8a7ef85c127b8a0 +P a2810cf65db13479e2ab255c37abac7841ee985d +R 188fdebacf7930560dd1bef6de7f142e +U drh +Z 4925a52dc50a180b6685bbcef3b9e085 diff --git a/manifest.uuid b/manifest.uuid index 480ce59513..85c92e6bfd 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -a2810cf65db13479e2ab255c37abac7841ee985d \ No newline at end of file +22eaced7274764eaf7ab4b5fc52cc2fcfc285708 \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index b08367cbd7..d5acaf3669 100644 --- a/src/btree.c +++ b/src/btree.c @@ -8239,7 +8239,7 @@ int sqlite3BtreeDelete(BtCursor *pCur, u8 flags){ if( rc==SQLITE_OK ){ if( bSkipnext ){ assert( bPreserve && (pCur->iPage==iCellDepth || CORRUPT_DB) ); - assert( pPage==pCur->apPage[pCur->iPage] ); + assert( pPage==pCur->apPage[pCur->iPage] || CORRUPT_DB ); assert( (pPage->nCell>0 || CORRUPT_DB) && iCellIdx<=pPage->nCell ); pCur->eState = CURSOR_SKIPNEXT; if( iCellIdx>=pPage->nCell ){ From b0c886510f9f691ab382c5af82644ba48684a9f3 Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 1 Feb 2016 13:21:13 +0000 Subject: [PATCH 69/75] Minor simplification to the OP_AutoCommit opcode. Fix some code comments related to transaction control. FossilOrigin-Name: a9b6a0672f84dd205f9333951e4c2a608d027d71 --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/build.c | 11 +++++------ src/vdbe.c | 19 +++++++++---------- src/vdbeaux.c | 2 +- 5 files changed, 24 insertions(+), 26 deletions(-) diff --git a/manifest b/manifest index adf078c951..fbe4e529cf 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\san\sassert()\sthat\smight\sfail\son\sa\scorrupt\sdatabase. -D 2016-02-01T00:21:08.846 +C Minor\ssimplification\sto\sthe\sOP_AutoCommit\sopcode.\s\sFix\ssome\scode\scomments\nrelated\sto\stransaction\scontrol. +D 2016-02-01T13:21:13.072 F Makefile.in 027c1603f255390c43a426671055a31c0a65fdb4 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 72b7858f02017611c3ac1ddc965251017fed0845 @@ -293,7 +293,7 @@ F src/btmutex.c bc87dd3b062cc26edfe79918de2200ccb8d41e73 F src/btree.c a2a0244ea3f0b3f57f75019c2f229c744ca5d202 F src/btree.h 368ceeb4bd9312dc8df2ffd64b4b7dbcf4db5f8e F src/btreeInt.h c18b7d2a3494695133e4e60ee36061d37f45d9a5 -F src/build.c 0510844c48d80732aead74b5727403b493dd1cd5 +F src/build.c c177ca703d7a3ac6ea6bba3a6c396d67ce79bc69 F src/callback.c 29ae4faba226c7ebb9aee93016b5ce8a8f071261 F src/complete.c addcd8160b081131005d5bc2d34adf20c1c5c92f F src/ctime.c 60e135af364d777a9ab41c97e5e89cd224da6198 @@ -412,11 +412,11 @@ F src/update.c 17332f9fe818cbc0444c36a811800af8498af4c3 F src/utf.c 10cc2519e82e3369344d0969ad4b1a333dc86d18 F src/util.c 72d40df0a52d3f30b462a15f0e094fcbade6dc82 F src/vacuum.c 2ddd5cad2a7b9cef7f9e431b8c7771634c6b1701 -F src/vdbe.c 73f0f61eb5556e430487671a557d032ecac52240 +F src/vdbe.c 755b1e2117214549b768efb6e552fcd12a9d859b F src/vdbe.h 7a733ea8aac1b77305a67698e784fa3484ee3337 F src/vdbeInt.h 4b69d5451bcadd473e745af53ef1e8abfdce0a79 F src/vdbeapi.c 9d640d5efd9a140a6bda8da53b220aa258167993 -F src/vdbeaux.c 221631e40111b5efa96ea557c6e2e7f62fd32b2a +F src/vdbeaux.c b8ba8e6d48732fb7a735a23e3040a01f4848498e F src/vdbeblob.c 37c3d11a753e403698c69e17383d282e1ae73e75 F src/vdbemem.c b9181e77eca2a095929d46250daf85c8d2621fc0 F src/vdbesort.c ef3c6d1f1a7d44cf67bb2bee59ea3d1fe5bad174 @@ -1422,7 +1422,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P a2810cf65db13479e2ab255c37abac7841ee985d -R 188fdebacf7930560dd1bef6de7f142e +P 22eaced7274764eaf7ab4b5fc52cc2fcfc285708 +R 48595a32d50edde169d3b975cd1cf3f9 U drh -Z 4925a52dc50a180b6685bbcef3b9e085 +Z 4ace4ad684d082250fc68f1cbbc590b5 diff --git a/manifest.uuid b/manifest.uuid index 85c92e6bfd..f7adbd19c9 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -22eaced7274764eaf7ab4b5fc52cc2fcfc285708 \ No newline at end of file +a9b6a0672f84dd205f9333951e4c2a608d027d71 \ No newline at end of file diff --git a/src/build.c b/src/build.c index be320b9c5a..88ddf406e6 100644 --- a/src/build.c +++ b/src/build.c @@ -3892,7 +3892,7 @@ void sqlite3SrcListShiftJoinType(SrcList *p){ } /* -** Begin a transaction +** Generate VDBE code for a BEGIN statement. */ void sqlite3BeginTransaction(Parse *pParse, int type){ sqlite3 *db; @@ -3902,7 +3902,6 @@ void sqlite3BeginTransaction(Parse *pParse, int type){ assert( pParse!=0 ); db = pParse->db; assert( db!=0 ); -/* if( db->aDb[0].pBt==0 ) return; */ if( sqlite3AuthCheck(pParse, SQLITE_TRANSACTION, "BEGIN", 0, 0) ){ return; } @@ -3914,11 +3913,11 @@ void sqlite3BeginTransaction(Parse *pParse, int type){ sqlite3VdbeUsesBtree(v, i); } } - sqlite3VdbeAddOp2(v, OP_AutoCommit, 0, 0); + sqlite3VdbeAddOp0(v, OP_AutoCommit); } /* -** Commit a transaction +** Generate VDBE code for a COMMIT statement. */ void sqlite3CommitTransaction(Parse *pParse){ Vdbe *v; @@ -3930,12 +3929,12 @@ void sqlite3CommitTransaction(Parse *pParse){ } v = sqlite3GetVdbe(pParse); if( v ){ - sqlite3VdbeAddOp2(v, OP_AutoCommit, 1, 0); + sqlite3VdbeAddOp1(v, OP_AutoCommit, 1); } } /* -** Rollback a transaction +** Generate VDBE code for a ROLLBACK statement. */ void sqlite3RollbackTransaction(Parse *pParse){ Vdbe *v; diff --git a/src/vdbe.c b/src/vdbe.c index a1e59e1170..2bb39c85bf 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -3008,28 +3008,27 @@ case OP_Savepoint: { case OP_AutoCommit: { int desiredAutoCommit; int iRollback; - int turnOnAC; desiredAutoCommit = pOp->p1; iRollback = pOp->p2; - turnOnAC = desiredAutoCommit && !db->autoCommit; assert( desiredAutoCommit==1 || desiredAutoCommit==0 ); assert( desiredAutoCommit==1 || iRollback==0 ); assert( db->nVdbeActive>0 ); /* At least this one VM is active */ assert( p->bIsReader ); - if( turnOnAC && !iRollback && db->nVdbeWrite>0 ){ - /* If this instruction implements a COMMIT and other VMs are writing - ** return an error indicating that the other VMs must complete first. - */ - sqlite3VdbeError(p, "cannot commit transaction - " - "SQL statements in progress"); - rc = SQLITE_BUSY; - }else if( desiredAutoCommit!=db->autoCommit ){ + if( desiredAutoCommit!=db->autoCommit ){ if( iRollback ){ assert( desiredAutoCommit==1 ); sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK); db->autoCommit = 1; + }else if( desiredAutoCommit && db->nVdbeWrite>0 ){ + /* If this instruction implements a COMMIT and other VMs are writing + ** return an error indicating that the other VMs must complete first. + */ + sqlite3VdbeError(p, "cannot commit transaction - " + "SQL statements in progress"); + rc = SQLITE_BUSY; + break; }else if( (rc = sqlite3VdbeCheckFk(p, 1))!=SQLITE_OK ){ goto vdbe_return; }else{ diff --git a/src/vdbeaux.c b/src/vdbeaux.c index 619aada030..d6cf451af4 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -534,7 +534,7 @@ static void resolveP2Values(Vdbe *p, int *pMaxFuncArgs){ for(pOp=p->aOp, i=p->nOp-1; i>=0; i--, pOp++){ u8 opcode = pOp->opcode; - /* NOTE: Be sure to update mkopcodeh.awk when adding or removing + /* NOTE: Be sure to update mkopcodeh.tcl when adding or removing ** cases from this switch! */ switch( opcode ){ case OP_Transaction: { From cddb6ba03bdbe25cd0c466c3189a226adc4462ee Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 1 Feb 2016 13:58:56 +0000 Subject: [PATCH 70/75] Fix a problem causing the OR/covering-index optimization to be disabled if compile time parameter SQLITE_MAX_ATTACHED were set to greater than 30. FossilOrigin-Name: a17712bf8d98dd485560f434a5350e6381cf1411 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/wherecode.c | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index fbe4e529cf..ebebee2b6a 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Minor\ssimplification\sto\sthe\sOP_AutoCommit\sopcode.\s\sFix\ssome\scode\scomments\nrelated\sto\stransaction\scontrol. -D 2016-02-01T13:21:13.072 +C Fix\sa\sproblem\scausing\sthe\sOR/covering-index\soptimization\sto\sbe\sdisabled\sif\scompile\stime\sparameter\sSQLITE_MAX_ATTACHED\swere\sset\sto\sgreater\sthan\s30. +D 2016-02-01T13:58:56.691 F Makefile.in 027c1603f255390c43a426671055a31c0a65fdb4 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 72b7858f02017611c3ac1ddc965251017fed0845 @@ -428,7 +428,7 @@ F src/wal.h 2f7c831cf3b071fa548bf2d5cac640846a7ff19c F src/walker.c 0f142b5bd3ed2041fc52d773880748b212e63354 F src/where.c af9bf5dcec1a0e52726c550924aa91d837166251 F src/whereInt.h 78b6b4de94db84aecbdc07fe3e38f648eb391e9a -F src/wherecode.c 7ea737b14e7a35d7f55cbad589a29aa49dfe3f7a +F src/wherecode.c 923f5d04b379b7417bc29f3b86b5eae9d1923d72 F src/whereexpr.c 197a448b52073aee43eca3a2233fc113369eb2d4 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/affinity2.test a6d901b436328bd67a79b41bb0ac2663918fe3bd @@ -1422,7 +1422,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 22eaced7274764eaf7ab4b5fc52cc2fcfc285708 -R 48595a32d50edde169d3b975cd1cf3f9 -U drh -Z 4ace4ad684d082250fc68f1cbbc590b5 +P a9b6a0672f84dd205f9333951e4c2a608d027d71 +R 2464227ee70c33ffde6d518be2a20c9c +U dan +Z 281424deda7a5f64a5e9ae761e185dda diff --git a/manifest.uuid b/manifest.uuid index f7adbd19c9..ec7821b682 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -a9b6a0672f84dd205f9333951e4c2a608d027d71 \ No newline at end of file +a17712bf8d98dd485560f434a5350e6381cf1411 \ No newline at end of file diff --git a/src/wherecode.c b/src/wherecode.c index 3fbd198e31..f5f45da397 100644 --- a/src/wherecode.c +++ b/src/wherecode.c @@ -778,7 +778,7 @@ static void codeDeferredSeek( sqlite3VdbeAddOp3(v, OP_Seek, iIdxCur, 0, iCur); if( (pWInfo->wctrlFlags & WHERE_FORCE_TABLE) - && sqlite3ParseToplevel(pParse)->writeMask==0 + && DbMaskAllZero(sqlite3ParseToplevel(pParse)->writeMask) ){ int i; Table *pTab = pIdx->pTable; From 3b37bc4206898dd93b5280d3aae4ee3fd8293e77 Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 1 Feb 2016 16:36:47 +0000 Subject: [PATCH 71/75] Update walcrash.test to ensure that, during a particular test, enough data is written to cause SQLite to sync the wal file 14 times. FossilOrigin-Name: 5d7c092869137a0ba69f93324fe4ed56a05b5985 --- manifest | 12 ++++++------ manifest.uuid | 2 +- test/walcrash.test | 3 ++- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index ebebee2b6a..115a4bbaf2 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sproblem\scausing\sthe\sOR/covering-index\soptimization\sto\sbe\sdisabled\sif\scompile\stime\sparameter\sSQLITE_MAX_ATTACHED\swere\sset\sto\sgreater\sthan\s30. -D 2016-02-01T13:58:56.691 +C Update\swalcrash.test\sto\sensure\sthat,\sduring\sa\sparticular\stest,\senough\sdata\sis\swritten\sto\scause\sSQLite\sto\ssync\sthe\swal\sfile\s14\stimes. +D 2016-02-01T16:36:47.969 F Makefile.in 027c1603f255390c43a426671055a31c0a65fdb4 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 72b7858f02017611c3ac1ddc965251017fed0845 @@ -1308,7 +1308,7 @@ F test/walbak.test b9f68e39646375c2b877be906babcc15d38b4877 F test/walbig.test f437473a16cfb314867c6b5d1dbcd519e73e3434 F test/walblock.test be48f3a75eff0b4456209f26b3ce186c2015497d F test/walcksum.test 9afeb96240296c08c72fc524d199c912cfe34daa -F test/walcrash.test 451d79e528add5c42764cea74aa2750754171b25 +F test/walcrash.test 21038858cc552077b0522f50b0fa87e38139306a F test/walcrash2.test a0edab4e5390f03b99a790de89aad15d6ec70b36 F test/walcrash3.test e426aa58122d20f2b9fbe9a507f9eb8cab85b8af F test/walfault.test 1f8389f7709877e9b4cc679033d71d6fe529056b @@ -1422,7 +1422,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P a9b6a0672f84dd205f9333951e4c2a608d027d71 -R 2464227ee70c33ffde6d518be2a20c9c +P a17712bf8d98dd485560f434a5350e6381cf1411 +R 9c14b59494afeacd043f7754f1a985e1 U dan -Z 281424deda7a5f64a5e9ae761e185dda +Z ecc144871fca92cc0fc68693a6e08d49 diff --git a/manifest.uuid b/manifest.uuid index ec7821b682..af8a34f793 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -a17712bf8d98dd485560f434a5350e6381cf1411 \ No newline at end of file +5d7c092869137a0ba69f93324fe4ed56a05b5985 \ No newline at end of file diff --git a/test/walcrash.test b/test/walcrash.test index 2a647188b0..b8ca7fbf34 100644 --- a/test/walcrash.test +++ b/test/walcrash.test @@ -237,12 +237,13 @@ for {set i 1} {$i < $REPEATS} {incr i} { INSERT INTO t1 VALUES(randomblob(9000)); INSERT INTO t1 VALUES(randomblob(9000)); INSERT INTO t1 VALUES(randomblob(9000)); + INSERT INTO t1 VALUES(randomblob(9000)); } } {1 {child process exited abnormally}} do_test walcrash-6.$i.2 { sqlite3 db test.db - execsql { SELECT count(*)==34 OR count(*)==35 FROM t1 WHERE x != 1 } + execsql { SELECT count(*) BETWEEN 34 AND 36 FROM t1 WHERE x != 1 } } {1} do_test walcrash-6.$i.3 { execsql { PRAGMA main.integrity_check } } {ok} do_test walcrash-6.$i.4 { execsql { PRAGMA main.journal_mode } } {wal} From ed94af5eb9b75dc1ad6f3d462a14271b5386396b Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 1 Feb 2016 17:20:08 +0000 Subject: [PATCH 72/75] Number VDBE opcodes starting with 0 instead of 1, as this obviates the lower-bound test on "switch(opcode){...}", making the code smaller and faster. FossilOrigin-Name: 4c9222f75bfac47f5422fff86b2d69a61933b3a2 --- manifest | 18 ++++++++-------- manifest.uuid | 2 +- src/vdbeaux.c | 2 +- tool/mkopcodec.tcl | 4 ++-- tool/mkopcodeh.tcl | 54 +++++++++++++++++++++++++--------------------- 5 files changed, 42 insertions(+), 38 deletions(-) diff --git a/manifest b/manifest index 115a4bbaf2..5ae7fd9d24 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Update\swalcrash.test\sto\sensure\sthat,\sduring\sa\sparticular\stest,\senough\sdata\sis\swritten\sto\scause\sSQLite\sto\ssync\sthe\swal\sfile\s14\stimes. -D 2016-02-01T16:36:47.969 +C Number\sVDBE\sopcodes\sstarting\swith\s0\sinstead\sof\s1,\sas\sthis\sobviates\sthe\nlower-bound\stest\son\s"switch(opcode){...}",\smaking\sthe\scode\ssmaller\sand\sfaster. +D 2016-02-01T17:20:08.707 F Makefile.in 027c1603f255390c43a426671055a31c0a65fdb4 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 72b7858f02017611c3ac1ddc965251017fed0845 @@ -416,7 +416,7 @@ F src/vdbe.c 755b1e2117214549b768efb6e552fcd12a9d859b F src/vdbe.h 7a733ea8aac1b77305a67698e784fa3484ee3337 F src/vdbeInt.h 4b69d5451bcadd473e745af53ef1e8abfdce0a79 F src/vdbeapi.c 9d640d5efd9a140a6bda8da53b220aa258167993 -F src/vdbeaux.c b8ba8e6d48732fb7a735a23e3040a01f4848498e +F src/vdbeaux.c f0e7cfa04f7ac44d69866868531dbaf20659d0a2 F src/vdbeblob.c 37c3d11a753e403698c69e17383d282e1ae73e75 F src/vdbemem.c b9181e77eca2a095929d46250daf85c8d2621fc0 F src/vdbesort.c ef3c6d1f1a7d44cf67bb2bee59ea3d1fe5bad174 @@ -1381,8 +1381,8 @@ F tool/logest.c eef612f8adf4d0993dafed0416064cf50d5d33c6 F tool/mkautoconfamal.sh a29b14d54302b33fd892958f6895582ea90e4a45 F tool/mkkeywordhash.c 06ec0b78bd4fa68c12d90ef2bdfe76b039133ff8 F tool/mkmsvcmin.tcl d57e6efc9428605f5418d0b235721ddf7b5d9c0b -F tool/mkopcodec.tcl edde8adc42621b5e598127f8cdc6d52cfe21f52b -F tool/mkopcodeh.tcl e04177031532b7aa9379ded50e820231ac4abd6e +F tool/mkopcodec.tcl d1b6362bd3aa80d5520d4d6f3765badf01f6c43c +F tool/mkopcodeh.tcl 385c62d78c38b2d92146dcb5abd319dbbc33506d F tool/mkopts.tcl 66ac10d240cc6e86abd37dc908d50382f84ff46e F tool/mkpragmatab.tcl f0d5bb266d1d388cf86fce5ba01a891e95d72d41 F tool/mkspeedsql.tcl a1a334d288f7adfe6e996f2e712becf076745c97 @@ -1422,7 +1422,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P a17712bf8d98dd485560f434a5350e6381cf1411 -R 9c14b59494afeacd043f7754f1a985e1 -U dan -Z ecc144871fca92cc0fc68693a6e08d49 +P 5d7c092869137a0ba69f93324fe4ed56a05b5985 +R c689c18fc524ba4b0a7bb357f3467ad8 +U drh +Z 4a66c8beaa1a93ec6bbf8e1c0f940158 diff --git a/manifest.uuid b/manifest.uuid index af8a34f793..cc32153f40 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -5d7c092869137a0ba69f93324fe4ed56a05b5985 \ No newline at end of file +4c9222f75bfac47f5422fff86b2d69a61933b3a2 \ No newline at end of file diff --git a/src/vdbeaux.c b/src/vdbeaux.c index d6cf451af4..13aef0d7fd 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -171,7 +171,7 @@ int sqlite3VdbeAddOp3(Vdbe *p, int op, int p1, int p2, int p3){ i = p->nOp; assert( p->magic==VDBE_MAGIC_INIT ); - assert( op>0 && op<0xff ); + assert( op>=0 && op<0xff ); if( p->pParse->nOpAlloc<=i ){ return growOp3(p, op, p1, p2, p3); } diff --git a/tool/mkopcodec.tcl b/tool/mkopcodec.tcl index 55d828b14d..abdeaaeb32 100644 --- a/tool/mkopcodec.tcl +++ b/tool/mkopcodec.tcl @@ -19,7 +19,7 @@ puts "#else" puts "# define OpHelp(X)" puts "#endif" puts "const char *sqlite3OpcodeName(int i)\173" -puts " static const char *const azName\[\] = \173 \"?\"," +puts " static const char *const azName\[\] = \173" set mx 0 set in [open [lindex $argv 0] rb] @@ -40,7 +40,7 @@ while {![eof $in]} { } close $in -for {set i 1} {$i<=$mx} {incr i} { +for {set i 0} {$i<=$mx} {incr i} { puts [format " /* %3d */ %-18s OpHelp(\"%s\")," \ $i \"$label($i)\" $synopsis($i)] } diff --git a/tool/mkopcodeh.tcl b/tool/mkopcodeh.tcl index 4c36f24ba4..053c7f8984 100644 --- a/tool/mkopcodeh.tcl +++ b/tool/mkopcodeh.tcl @@ -81,8 +81,8 @@ while {![eof $in]} { set in1($name) 0 set in2($name) 0 set in3($name) 0 - set out1($name) 0 set out2($name) 0 + set out3($name) 0 for {set i 3} {$i<[llength $line]-1} {incr i} { switch [string trim [lindex $line $i] ,] { same { @@ -112,16 +112,19 @@ while {![eof $in]} { # Assign numbers to all opcodes and output the result. # -set cnt 0 -set max 0 puts "/* Automatically generated. Do not edit */" puts "/* See the tool/mkopcodeh.tcl script for details */" -set op(OP_Noop) -1 -set order($nOp) OP_Noop -incr nOp -set op(OP_Explain) -1 -set order($nOp) OP_Explain -incr nOp +foreach name {OP_Noop OP_Explain} { + set jump($name) 0 + set in1($name) 0 + set in2($name) 0 + set in3($name) 0 + set out2($name) 0 + set out3($name) 0 + set op($name) -1 + set order($nOp) $name + incr nOp +} # The following are the opcodes that are processed by resolveP2Values() # @@ -144,7 +147,7 @@ set rp2v_ops { # Assign small values to opcodes that are processed by resolveP2Values() # to make code generation for the switch() statement smaller and faster. # -set cnt 0 +set cnt -1 for {set i 0} {$i<$nOp} {incr i} { set name $order($i) if {[lsearch $rp2v_ops $name]>=0} { @@ -169,7 +172,7 @@ for {set i 0} {$i<$nOp} {incr i} { } } set max $cnt -for {set i 1} {$i<=$nOp} {incr i} { +for {set i 0} {$i<$nOp} {incr i} { if {![info exists used($i)]} { set def($i) "OP_NotUsed_$i" } @@ -196,27 +199,28 @@ for {set i 1} {$i<=$nOp} {incr i} { # Generate the bitvectors: # set bv(0) 0 -for {set i 1} {$i<=$max} {incr i} { +for {set i 0} {$i<=$max} {incr i} { set name $def($i) - if {[info exists jump($name)] && $jump($name)} {set a0 1} {set a0 0} - if {[info exists in1($name)] && $in1($name)} {set a1 2} {set a1 0} - if {[info exists in2($name)] && $in2($name)} {set a2 4} {set a2 0} - if {[info exists in3($name)] && $in3($name)} {set a3 8} {set a3 0} - if {[info exists out2($name)] && $out2($name)} {set a4 16} {set a4 0} - if {[info exists out3($name)] && $out3($name)} {set a5 32} {set a5 0} - set bv($i) [expr {$a0+$a1+$a2+$a3+$a4+$a5}] + set x 0 + if {$jump($name)} {incr x 1} + if {$in1($name)} {incr x 2} + if {$in2($name)} {incr x 4} + if {$in3($name)} {incr x 8} + if {$out2($name)} {incr x 16} + if {$out3($name)} {incr x 32} + set bv($i) $x } puts "" puts "/* Properties such as \"out2\" or \"jump\" that are specified in" puts "** comments following the \"case\" for each opcode in the vdbe.c" puts "** are encoded into bitvectors as follows:" puts "*/" -puts "#define OPFLG_JUMP 0x0001 /* jump: P2 holds jmp target */" -puts "#define OPFLG_IN1 0x0002 /* in1: P1 is an input */" -puts "#define OPFLG_IN2 0x0004 /* in2: P2 is an input */" -puts "#define OPFLG_IN3 0x0008 /* in3: P3 is an input */" -puts "#define OPFLG_OUT2 0x0010 /* out2: P2 is an output */" -puts "#define OPFLG_OUT3 0x0020 /* out3: P3 is an output */" +puts "#define OPFLG_JUMP 0x01 /* jump: P2 holds jmp target */" +puts "#define OPFLG_IN1 0x02 /* in1: P1 is an input */" +puts "#define OPFLG_IN2 0x04 /* in2: P2 is an input */" +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_INITIALIZER \173\\" for {set i 0} {$i<=$max} {incr i} { if {$i%8==0} { From df015945e3fdca65b4bc4b7ef5f431610f405bf0 Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 1 Feb 2016 20:12:41 +0000 Subject: [PATCH 73/75] Improve performance of fts5 queries. FossilOrigin-Name: 2334e88244afe6387208be5d527aba9b5ddf4e4c --- ext/fts5/fts5_expr.c | 115 +++++++++++++++++++++++++--------- ext/fts5/fts5_main.c | 16 ++--- ext/fts5/test/fts5simple.test | 23 ++++++- manifest | 18 +++--- manifest.uuid | 2 +- 5 files changed, 122 insertions(+), 52 deletions(-) diff --git a/ext/fts5/fts5_expr.c b/ext/fts5/fts5_expr.c index 3a1497f05d..7c8e3c87c1 100644 --- a/ext/fts5/fts5_expr.c +++ b/ext/fts5/fts5_expr.c @@ -62,6 +62,9 @@ struct Fts5ExprNode { int bEof; /* True at EOF */ int bNomatch; /* True if entry is not a match */ + /* Next method for this node. */ + int (*xNext)(Fts5Expr*, Fts5ExprNode*, int, i64); + i64 iRowid; /* Current rowid */ Fts5ExprNearset *pNear; /* For FTS5_STRING - cluster of phrases */ @@ -73,6 +76,12 @@ struct Fts5ExprNode { #define Fts5NodeIsString(p) ((p)->eType==FTS5_TERM || (p)->eType==FTS5_STRING) +/* +** Invoke the xNext method of an Fts5ExprNode object. This macro should be +** used as if it has the same signature as the xNext() methods themselves. +*/ +#define fts5ExprNodeNext(a,b,c,d) (b)->xNext((a), (b), (c), (d)) + /* ** An instance of the following structure represents a single search term ** or term prefix. @@ -234,7 +243,15 @@ int sqlite3Fts5ExprNew( sParse.rc = SQLITE_NOMEM; sqlite3Fts5ParseNodeFree(sParse.pExpr); }else{ - pNew->pRoot = sParse.pExpr; + if( !sParse.pExpr ){ + const int nByte = sizeof(Fts5ExprNode); + pNew->pRoot = (Fts5ExprNode*)sqlite3Fts5MallocZero(&sParse.rc, nByte); + if( pNew->pRoot ){ + pNew->pRoot->bEof = 1; + } + }else{ + pNew->pRoot = sParse.pExpr; + } pNew->pIndex = 0; pNew->pConfig = pConfig; pNew->apExprPhrase = sParse.apPhrase; @@ -500,12 +517,6 @@ static int fts5LookaheadReaderInit( return fts5LookaheadReaderNext(p); } -#if 0 -static int fts5LookaheadReaderEof(Fts5LookaheadReader *p){ - return (p->iPos==FTS5_LOOKAHEAD_EOF); -} -#endif - typedef struct Fts5NearTrimmer Fts5NearTrimmer; struct Fts5NearTrimmer { Fts5LookaheadReader reader; /* Input iterator */ @@ -636,6 +647,7 @@ static int fts5ExprNearAdvanceFirst( Fts5ExprTerm *pTerm = &pNode->pNear->apPhrase[0]->aTerm[0]; int rc = SQLITE_OK; + pNode->bNomatch = 0; if( pTerm->pSynonym ){ int bEof = 1; Fts5ExprTerm *p; @@ -765,17 +777,6 @@ static int fts5ExprNearTest( for(pTerm=&pPhrase->aTerm[0]; pTerm; pTerm=pTerm->pSynonym){ Fts5IndexIter *pIter = pTerm->pIter; if( sqlite3Fts5IterEof(pIter)==0 ){ -#if 0 - int n; - i64 iRowid; - rc = sqlite3Fts5IterPoslist(pIter, pNear->pColset, 0, &n, &iRowid); - if( rc!=SQLITE_OK ){ - *pRc = rc; - return 0; - }else if( iRowid==pNode->iRowid && n>0 ){ - pPhrase->poslist.n = 1; - } -#endif if( pIter->iRowid==pNode->iRowid && pIter->nData>0 ){ pPhrase->poslist.n = 1; } @@ -797,11 +798,6 @@ static int fts5ExprNearTest( }else{ Fts5IndexIter *pIter = pPhrase->aTerm[0].pIter; fts5BufferSet(&rc, &pPhrase->poslist, pIter->nData, pIter->pData); -#if 0 - rc = sqlite3Fts5IterPoslistBuffer( - pPhrase->aTerm[0].pIter, &pPhrase->poslist - ); -#endif } } @@ -888,6 +884,7 @@ static int fts5ExprNearNextMatch( if( iRowid==iLast ) continue; bMatch = 0; if( fts5ExprSynonymAdvanceto(pTerm, bDesc, &iLast, &rc) ){ + pNode->bNomatch = 0; pNode->bEof = 1; return rc; } @@ -905,7 +902,8 @@ static int fts5ExprNearNextMatch( }while( bMatch==0 ); pNode->iRowid = iLast; - pNode->bNomatch = (0==fts5ExprNearTest(&rc, pExpr, pNode)); + pNode->bNomatch = ((0==fts5ExprNearTest(&rc, pExpr, pNode)) && rc==SQLITE_OK); + assert( pNode->bEof==0 || pNode->bNomatch==0 ); return rc; } @@ -923,6 +921,7 @@ static int fts5ExprNearInitAll( int i, j; int rc = SQLITE_OK; + assert( pNode->bNomatch==0 ); for(i=0; rc==SQLITE_OK && inPhrase; i++){ Fts5ExprPhrase *pPhrase = pNear->apPhrase[i]; for(j=0; jnTerm; j++){ @@ -990,6 +989,7 @@ static int fts5RowidCmp( static void fts5ExprSetEof(Fts5ExprNode *pNode){ int i; pNode->bEof = 1; + pNode->bNomatch = 0; for(i=0; inChild; i++){ fts5ExprSetEof(pNode->apChild[i]); } @@ -1012,8 +1012,6 @@ static void fts5ExprNodeZeroPoslist(Fts5ExprNode *pNode){ } -static int fts5ExprNodeNext(Fts5Expr*, Fts5ExprNode*, int, i64); - /* ** Argument pNode is an FTS5_AND node. */ @@ -1093,6 +1091,33 @@ static int fts5NodeCompare( return fts5RowidCmp(pExpr, p1->iRowid, p2->iRowid); } +/* +** xNext() method for a node of type FTS5_TERM. +*/ +static int fts5ExprNodeNext_Term( + Fts5Expr *pExpr, + Fts5ExprNode *pNode, + int bFromValid, + i64 iFrom +){ + int rc; + Fts5IndexIter *pIter = pNode->pNear->apPhrase[0]->aTerm[0].pIter; + + assert( pNode->bEof==0 ); + if( bFromValid ){ + rc = sqlite3Fts5IterNextFrom(pIter, iFrom); + }else{ + rc = sqlite3Fts5IterNext(pIter); + } + if( rc==SQLITE_OK && sqlite3Fts5IterEof(pIter)==0 ){ + rc = fts5ExprTokenTest(pExpr, pNode); + }else{ + pNode->bEof = 1; + pNode->bNomatch = 0; + } + return rc; +} + /* ** Advance node iterator pNode, part of expression pExpr. If argument ** bFromValid is zero, then pNode is advanced exactly once. Or, if argument @@ -1100,7 +1125,7 @@ static int fts5NodeCompare( ** rowid value iFrom. Whether "past" means "less than" or "greater than" ** depends on whether this is an ASC or DESC iterator. */ -static int fts5ExprNodeNext( +static int fts5ExprNodeNext_Fallback( Fts5Expr *pExpr, Fts5ExprNode *pNode, int bFromValid, @@ -1127,6 +1152,7 @@ static int fts5ExprNodeNext( rc = fts5ExprTokenTest(pExpr, pNode); }else{ pNode->bEof = 1; + pNode->bNomatch = 0; } return rc; }; @@ -1180,6 +1206,7 @@ static int fts5ExprNodeNext( || pNode->iRowid==iFrom || pExpr->bDesc==(pNode->iRowidbNomatch==0 || rc==SQLITE_OK ); return rc; } @@ -1246,6 +1273,7 @@ static int fts5ExprNodeNextMatch( rc = fts5ExprNodeNext(pExpr, p1, 0, 0); } pNode->bEof = p1->bEof; + pNode->bNomatch = p1->bNomatch; pNode->iRowid = p1->iRowid; if( p1->bEof ){ fts5ExprNodeZeroPoslist(p2); @@ -1268,16 +1296,36 @@ static int fts5ExprNodeNextMatch( static int fts5ExprNodeFirst(Fts5Expr *pExpr, Fts5ExprNode *pNode){ int rc = SQLITE_OK; pNode->bEof = 0; + pNode->bNomatch = 0; if( Fts5NodeIsString(pNode) ){ /* Initialize all term iterators in the NEAR object. */ rc = fts5ExprNearInitAll(pExpr, pNode); }else{ int i; + int nEof = 0; for(i=0; inChild && rc==SQLITE_OK; i++){ + Fts5ExprNode *pChild = pNode->apChild[i]; rc = fts5ExprNodeFirst(pExpr, pNode->apChild[i]); + assert( pChild->bEof==0 || pChild->bEof==1 ); + nEof += pChild->bEof; } pNode->iRowid = pNode->apChild[0]->iRowid; + + switch( pNode->eType ){ + case FTS5_AND: + if( nEof>0 ) fts5ExprSetEof(pNode); + break; + + case FTS5_OR: + if( pNode->nChild==nEof ) fts5ExprSetEof(pNode); + break; + + default: + assert( pNode->eType==FTS5_NOT ); + pNode->bEof = pNode->apChild[0]->bEof; + break; + } } if( rc==SQLITE_OK ){ @@ -1305,7 +1353,7 @@ static int fts5ExprNodeFirst(Fts5Expr *pExpr, Fts5ExprNode *pNode){ int sqlite3Fts5ExprFirst(Fts5Expr *p, Fts5Index *pIdx, i64 iFirst, int bDesc){ Fts5ExprNode *pRoot = p->pRoot; int rc = SQLITE_OK; - if( pRoot ){ + if( pRoot->xNext ){ p->pIndex = pIdx; p->bDesc = bDesc; rc = fts5ExprNodeFirst(p, pRoot); @@ -1333,9 +1381,11 @@ int sqlite3Fts5ExprFirst(Fts5Expr *p, Fts5Index *pIdx, i64 iFirst, int bDesc){ int sqlite3Fts5ExprNext(Fts5Expr *p, i64 iLast){ int rc; Fts5ExprNode *pRoot = p->pRoot; + assert( pRoot->bEof==0 && pRoot->bNomatch==0 ); do { rc = fts5ExprNodeNext(p, pRoot, 0, 0); - }while( pRoot->bNomatch && pRoot->bEof==0 && rc==SQLITE_OK ); + assert( pRoot->bNomatch==0 || (rc==SQLITE_OK && pRoot->bEof==0) ); + }while( pRoot->bNomatch ); if( fts5RowidCmp(p, pRoot->iRowid, iLast)>0 ){ pRoot->bEof = 1; } @@ -1343,7 +1393,7 @@ int sqlite3Fts5ExprNext(Fts5Expr *p, i64 iLast){ } int sqlite3Fts5ExprEof(Fts5Expr *p){ - return (p->pRoot==0 || p->pRoot->bEof); + return p->pRoot->bEof; } i64 sqlite3Fts5ExprRowid(Fts5Expr *p){ @@ -1640,6 +1690,7 @@ int sqlite3Fts5ExprClonePhrase( pNew->apExprPhrase[0] = sCtx.pPhrase; pNew->pRoot->pNear->apPhrase[0] = sCtx.pPhrase; pNew->pRoot->pNear->nPhrase = 1; + pNew->pRoot->xNext = fts5ExprNodeNext_Fallback; sCtx.pPhrase->pNode = pNew->pRoot; if( pOrig->nTerm==1 && pOrig->aTerm[0].pSynonym==0 ){ @@ -1840,6 +1891,7 @@ Fts5ExprNode *sqlite3Fts5ParseNode( pRet = (Fts5ExprNode*)sqlite3Fts5MallocZero(&pParse->rc, nByte); if( pRet ){ + pRet->xNext = fts5ExprNodeNext_Fallback; pRet->eType = eType; pRet->pNear = pNear; if( eType==FTS5_STRING ){ @@ -1850,6 +1902,7 @@ Fts5ExprNode *sqlite3Fts5ParseNode( if( pNear->nPhrase==1 && pNear->apPhrase[0]->nTerm==1 ){ if( pNear->apPhrase[0]->aTerm[0].pSynonym==0 ){ pRet->eType = FTS5_TERM; + pRet->xNext = fts5ExprNodeNext_Term; } }else if( pParse->pConfig->eDetail!=FTS5_DETAIL_FULL ){ assert( pParse->rc==SQLITE_OK ); @@ -2144,7 +2197,7 @@ static void fts5ExprFunction( } if( rc==SQLITE_OK ){ char *zText; - if( pExpr->pRoot==0 ){ + if( pExpr->pRoot->xNext==0 ){ zText = sqlite3_mprintf(""); }else if( bTcl ){ zText = fts5ExprPrintTcl(pConfig, zNearsetCmd, pExpr->pRoot); diff --git a/ext/fts5/fts5_main.c b/ext/fts5/fts5_main.c index ec045da6bf..9ef8d9a01a 100644 --- a/ext/fts5/fts5_main.c +++ b/ext/fts5/fts5_main.c @@ -220,10 +220,10 @@ struct Fts5Cursor { /* ** Values for Fts5Cursor.csrflags */ -#define FTS5CSR_REQUIRE_CONTENT 0x01 -#define FTS5CSR_REQUIRE_DOCSIZE 0x02 -#define FTS5CSR_REQUIRE_INST 0x04 -#define FTS5CSR_EOF 0x08 +#define FTS5CSR_EOF 0x01 +#define FTS5CSR_REQUIRE_CONTENT 0x02 +#define FTS5CSR_REQUIRE_DOCSIZE 0x04 +#define FTS5CSR_REQUIRE_INST 0x08 #define FTS5CSR_FREE_ZRANK 0x10 #define FTS5CSR_REQUIRE_RESEEK 0x20 #define FTS5CSR_REQUIRE_POSLIST 0x40 @@ -778,7 +778,7 @@ static int fts5CursorReseek(Fts5Cursor *pCsr, int *pbSkip){ i64 iRowid = sqlite3Fts5ExprRowid(pCsr->pExpr); rc = sqlite3Fts5ExprFirst(pCsr->pExpr, pTab->pIndex, iRowid, bDesc); - if( rc==SQLITE_OK && iRowid!=sqlite3Fts5ExprRowid(pCsr->pExpr) ){ + if( rc==SQLITE_OK && iRowid!=sqlite3Fts5ExprRowid(pCsr->pExpr) ){ *pbSkip = 1; } @@ -786,6 +786,7 @@ static int fts5CursorReseek(Fts5Cursor *pCsr, int *pbSkip){ fts5CsrNewrow(pCsr); if( sqlite3Fts5ExprEof(pCsr->pExpr) ){ CsrFlagSet(pCsr, FTS5CSR_EOF); + *pbSkip = 1; } } return rc; @@ -807,14 +808,13 @@ static int fts5NextMethod(sqlite3_vtab_cursor *pCursor){ assert( (pCsr->ePlan<3)== (pCsr->ePlan==FTS5_PLAN_MATCH || pCsr->ePlan==FTS5_PLAN_SOURCE) ); + assert( !CsrFlagTest(pCsr, FTS5CSR_EOF) ); if( pCsr->ePlan<3 ){ int bSkip = 0; if( (rc = fts5CursorReseek(pCsr, &bSkip)) || bSkip ) return rc; rc = sqlite3Fts5ExprNext(pCsr->pExpr, pCsr->iLastRowid); - if( sqlite3Fts5ExprEof(pCsr->pExpr) ){ - CsrFlagSet(pCsr, FTS5CSR_EOF); - } + CsrFlagSet(pCsr, sqlite3Fts5ExprEof(pCsr->pExpr)); fts5CsrNewrow(pCsr); }else{ switch( pCsr->ePlan ){ diff --git a/ext/fts5/test/fts5simple.test b/ext/fts5/test/fts5simple.test index e29c13117c..b6563fd9d0 100644 --- a/ext/fts5/test/fts5simple.test +++ b/ext/fts5/test/fts5simple.test @@ -19,7 +19,7 @@ ifcapable !fts5 { return } - if 1 { +if 1 { #------------------------------------------------------------------------- # @@ -363,8 +363,6 @@ do_execsql_test 15.1 { INSERT INTO x2(x2) VALUES('integrity-check'); } -} - #------------------------------------------------------------------------- foreach_detail_mode $testprefix { reset_db @@ -382,5 +380,24 @@ foreach_detail_mode $testprefix { } {{0.0.0 1.0.2}} } +} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 17.0 { + CREATE VIRTUAL TABLE x3 USING fts5(x); + INSERT INTO x3 VALUES('a b c'); +} + +do_execsql_test 17.1 { + SELECT rowid FROM x3('b AND d'); +} + +#------------------------------------------------------------------------- +do_execsql_test 18.1 { + CREATE VIRTUAL TABLE x4 USING fts5(x); + SELECT rowid FROM x4('""'); +} + finish_test diff --git a/manifest b/manifest index 5ae7fd9d24..f5e3ab6b6d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Number\sVDBE\sopcodes\sstarting\swith\s0\sinstead\sof\s1,\sas\sthis\sobviates\sthe\nlower-bound\stest\son\s"switch(opcode){...}",\smaking\sthe\scode\ssmaller\sand\sfaster. -D 2016-02-01T17:20:08.707 +C Improve\sperformance\sof\sfts5\squeries. +D 2016-02-01T20:12:41.276 F Makefile.in 027c1603f255390c43a426671055a31c0a65fdb4 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 72b7858f02017611c3ac1ddc965251017fed0845 @@ -102,10 +102,10 @@ F ext/fts5/fts5Int.h 6e0f90eb4872654a5b98130dec16965716525c9a F ext/fts5/fts5_aux.c b9bcce753ef5b451267b2232f0ca153ddeb3951d F ext/fts5/fts5_buffer.c f6e0c6018ffc8e39fc0b333b5daa8b8d528ae6e4 F ext/fts5/fts5_config.c 0c384ebdd23fd055e2e50a93277b8d59da538238 -F ext/fts5/fts5_expr.c a66b9694519d9c336d9bdbd46ea22e7e14aef412 +F ext/fts5/fts5_expr.c 768d221e592df03b26f46da56aa0a561f00fa4e0 F ext/fts5/fts5_hash.c 1b113977296cf4212c6ec667d5e3f2bd18036955 F ext/fts5/fts5_index.c cd1e4faca8b9adc2d89b367075bf93a7f50c406b -F ext/fts5/fts5_main.c 3886bbfc5ac1d9df29979823ddf2b68241e1127e +F ext/fts5/fts5_main.c 7e8a5f27d504bc04e3de7f1cba8867f0332aee9d F ext/fts5/fts5_storage.c 2a1f44deae090cd711f02cec0c2af8e660360d24 F ext/fts5/fts5_tcl.c f8731e0508299bd43f1a2eff7dbeaac870768966 F ext/fts5/fts5_test_mi.c 1ec66ffdf7632077fbd773b7a6df5153272ec070 @@ -175,7 +175,7 @@ F ext/fts5/test/fts5rank.test 7e9e64eac7245637f6f2033aec4b292aaf611aab F ext/fts5/test/fts5rebuild.test 03935f617ace91ed23a6099c7c74d905227ff29b F ext/fts5/test/fts5restart.test c17728fdea26e7d0f617d22ad5b4b2862b994c17 F ext/fts5/test/fts5rowid.test 16908a99d6efc9ba21081b4f2b86b3fc699839a6 -F ext/fts5/test/fts5simple.test 2bc6451cbe887a9215f5b14ae307c70d850344c9 +F ext/fts5/test/fts5simple.test 7fcacfa473a37355af2e60096650c87b5ba8f3ba F ext/fts5/test/fts5simple2.test 98377ae1ff7749a42c21fe1a139c1ed312522c46 F ext/fts5/test/fts5simple3.test e671b36bc4dbd4f5095e66cb04473cba9f680f53 F ext/fts5/test/fts5synonym.test 6475d189c2e20d60795808f83e36bf9318708d48 @@ -1422,7 +1422,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 5d7c092869137a0ba69f93324fe4ed56a05b5985 -R c689c18fc524ba4b0a7bb357f3467ad8 -U drh -Z 4a66c8beaa1a93ec6bbf8e1c0f940158 +P 4c9222f75bfac47f5422fff86b2d69a61933b3a2 +R 267ad0dad7a7346f85182e52086f7b51 +U dan +Z ee79d8b7c590b68c4d6e9bbdc4c83095 diff --git a/manifest.uuid b/manifest.uuid index cc32153f40..3b468df8c8 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -4c9222f75bfac47f5422fff86b2d69a61933b3a2 \ No newline at end of file +2334e88244afe6387208be5d527aba9b5ddf4e4c \ No newline at end of file From 1861afcdbb48d4e2cb1f6ec491aeaee51bf15774 Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 1 Feb 2016 21:48:34 +0000 Subject: [PATCH 74/75] Change the OP_SetCookie instruction to write the literal P3 value, not the value in register P3. FossilOrigin-Name: 6d7d4703ebf3754bec74123d5ba7e861a705f90f --- manifest | 20 ++++++++++---------- manifest.uuid | 2 +- src/alter.c | 2 +- src/build.c | 12 ++++-------- src/pragma.c | 19 ++++++++----------- src/vdbe.c | 16 +++++++--------- 6 files changed, 31 insertions(+), 40 deletions(-) diff --git a/manifest b/manifest index f5e3ab6b6d..391305ff38 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Improve\sperformance\sof\sfts5\squeries. -D 2016-02-01T20:12:41.276 +C Change\sthe\sOP_SetCookie\sinstruction\sto\swrite\sthe\sliteral\sP3\svalue,\snot\sthe\nvalue\sin\sregister\sP3. +D 2016-02-01T21:48:34.880 F Makefile.in 027c1603f255390c43a426671055a31c0a65fdb4 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 72b7858f02017611c3ac1ddc965251017fed0845 @@ -283,7 +283,7 @@ F spec.template 86a4a43b99ebb3e75e6b9a735d5fd293a24e90ca F sqlite.pc.in 42b7bf0d02e08b9e77734a47798d1a55a9e0716b F sqlite3.1 fc7ad8990fc8409983309bb80de8c811a7506786 F sqlite3.pc.in 48fed132e7cb71ab676105d2a4dc77127d8c1f3a -F src/alter.c 9d649e46c780166e416fb11dbd23f8d49aab8267 +F src/alter.c 3fe13e97ab38317b092e2f3ae11267b40c9b5cbd F src/analyze.c 0043d3e501f04297fed2bb50b488bc08d5c39f36 F src/attach.c 07b3a34a1702dce92a7f1d3888c0c06222b63760 F src/auth.c b56c78ebe40a2110fd361379f7e8162d23f92240 @@ -293,7 +293,7 @@ F src/btmutex.c bc87dd3b062cc26edfe79918de2200ccb8d41e73 F src/btree.c a2a0244ea3f0b3f57f75019c2f229c744ca5d202 F src/btree.h 368ceeb4bd9312dc8df2ffd64b4b7dbcf4db5f8e F src/btreeInt.h c18b7d2a3494695133e4e60ee36061d37f45d9a5 -F src/build.c c177ca703d7a3ac6ea6bba3a6c396d67ce79bc69 +F src/build.c 33dea2cef04c16a902c55f9d83b1a2065f213979 F src/callback.c 29ae4faba226c7ebb9aee93016b5ce8a8f071261 F src/complete.c addcd8160b081131005d5bc2d34adf20c1c5c92f F src/ctime.c 60e135af364d777a9ab41c97e5e89cd224da6198 @@ -340,7 +340,7 @@ F src/parse.y 426a91fbbbf7cdde3fd4b8798de7317a8782bec5 F src/pcache.c 73895411fa6b7bd6f0091212feabbe833b358d23 F src/pcache.h 4d0ccaad264d360981ec5e6a2b596d6e85242545 F src/pcache1.c 72f644dc9e1468c72922eff5904048427b817051 -F src/pragma.c ea290193369faa0a26ae2f924e7b86289b4a7987 +F src/pragma.c 2ac26ac45eedbed3cc8a9a320ad6d2fc299e69a6 F src/pragma.h 64c78a648751b9f4f297276c4eb7507b14b4628c F src/prepare.c db85f0451ba93ecb3c1e497c279abece5cb5aead F src/printf.c 98a5cef7fc84577ab8a3098cfa48ecfa5a70b9f8 @@ -412,7 +412,7 @@ F src/update.c 17332f9fe818cbc0444c36a811800af8498af4c3 F src/utf.c 10cc2519e82e3369344d0969ad4b1a333dc86d18 F src/util.c 72d40df0a52d3f30b462a15f0e094fcbade6dc82 F src/vacuum.c 2ddd5cad2a7b9cef7f9e431b8c7771634c6b1701 -F src/vdbe.c 755b1e2117214549b768efb6e552fcd12a9d859b +F src/vdbe.c a0a0ada4b51161d3950fe30fc696b6c8235a841f F src/vdbe.h 7a733ea8aac1b77305a67698e784fa3484ee3337 F src/vdbeInt.h 4b69d5451bcadd473e745af53ef1e8abfdce0a79 F src/vdbeapi.c 9d640d5efd9a140a6bda8da53b220aa258167993 @@ -1422,7 +1422,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 4c9222f75bfac47f5422fff86b2d69a61933b3a2 -R 267ad0dad7a7346f85182e52086f7b51 -U dan -Z ee79d8b7c590b68c4d6e9bbdc4c83095 +P 2334e88244afe6387208be5d527aba9b5ddf4e4c +R 249f75933f6fe25a197c05fa835262de +U drh +Z 56e6b1659de31a547fab736bcf3cb22f diff --git a/manifest.uuid b/manifest.uuid index 3b468df8c8..54e6aa4e9f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -2334e88244afe6387208be5d527aba9b5ddf4e4c \ No newline at end of file +6d7d4703ebf3754bec74123d5ba7e861a705f90f \ No newline at end of file diff --git a/src/alter.c b/src/alter.c index 2b043ef158..c8102c55d2 100644 --- a/src/alter.c +++ b/src/alter.c @@ -608,7 +608,7 @@ void sqlite3MinimumFileFormat(Parse *pParse, int iDb, int minFormat){ sqlite3VdbeAddOp2(v, OP_Integer, minFormat, r2); addr1 = sqlite3VdbeAddOp3(v, OP_Ge, r2, 0, r1); sqlite3VdbeChangeP5(v, SQLITE_NOTNULL); VdbeCoverage(v); - sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_FILE_FORMAT, r2); + sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_FILE_FORMAT, minFormat); sqlite3VdbeJumpHere(v, addr1); sqlite3ReleaseTempReg(pParse, r1); sqlite3ReleaseTempReg(pParse, r2); diff --git a/src/build.c b/src/build.c index 88ddf406e6..3ca4c99947 100644 --- a/src/build.c +++ b/src/build.c @@ -983,10 +983,8 @@ void sqlite3StartTable( addr1 = sqlite3VdbeAddOp1(v, OP_If, reg3); VdbeCoverage(v); fileFormat = (db->flags & SQLITE_LegacyFileFmt)!=0 ? 1 : SQLITE_MAX_FILE_FORMAT; - sqlite3VdbeAddOp2(v, OP_Integer, fileFormat, reg3); - sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_FILE_FORMAT, reg3); - sqlite3VdbeAddOp2(v, OP_Integer, ENC(db), reg3); - sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_TEXT_ENCODING, reg3); + sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_FILE_FORMAT, fileFormat); + sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_TEXT_ENCODING, ENC(db)); sqlite3VdbeJumpHere(v, addr1); /* This just creates a place-holder record in the sqlite_master table. @@ -1471,13 +1469,11 @@ CollSeq *sqlite3LocateCollSeq(Parse *pParse, const char *zName){ ** 1 chance in 2^32. So we're safe enough. */ void sqlite3ChangeCookie(Parse *pParse, int iDb){ - int r1 = sqlite3GetTempReg(pParse); sqlite3 *db = pParse->db; Vdbe *v = pParse->pVdbe; assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); - sqlite3VdbeAddOp2(v, OP_Integer, db->aDb[iDb].pSchema->schema_cookie+1, r1); - sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_SCHEMA_VERSION, r1); - sqlite3ReleaseTempReg(pParse, r1); + sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_SCHEMA_VERSION, + db->aDb[iDb].pSchema->schema_cookie+1); } /* diff --git a/src/pragma.c b/src/pragma.c index 15f0eecce3..1d827d7b70 100644 --- a/src/pragma.c +++ b/src/pragma.c @@ -444,8 +444,7 @@ void sqlite3Pragma( }else{ int size = sqlite3AbsInt32(sqlite3Atoi(zRight)); sqlite3BeginWriteOperation(pParse, 0, iDb); - sqlite3VdbeAddOp2(v, OP_Integer, size, 1); - sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_DEFAULT_CACHE_SIZE, 1); + sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_DEFAULT_CACHE_SIZE, size); assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); pDb->pSchema->cache_size = size; sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size); @@ -683,8 +682,7 @@ void sqlite3Pragma( { OP_ReadCookie, 0, 1, BTREE_LARGEST_ROOT_PAGE}, { OP_If, 1, 0, 0}, /* 2 */ { OP_Halt, SQLITE_OK, OE_Abort, 0}, /* 3 */ - { OP_Integer, 0, 1, 0}, /* 4 */ - { OP_SetCookie, 0, BTREE_INCR_VACUUM, 1}, /* 5 */ + { OP_SetCookie, 0, BTREE_INCR_VACUUM, 0}, /* 4 */ }; VdbeOp *aOp; int iAddr = sqlite3VdbeCurrentAddr(v); @@ -694,8 +692,8 @@ void sqlite3Pragma( aOp[0].p1 = iDb; aOp[1].p1 = iDb; aOp[2].p2 = iAddr+4; - aOp[4].p1 = eAuto - 1; - aOp[5].p1 = iDb; + aOp[4].p1 = iDb; + aOp[4].p3 = eAuto - 1; sqlite3VdbeUsesBtree(v, iDb); } } @@ -1728,17 +1726,16 @@ void sqlite3Pragma( /* Write the specified cookie value */ static const VdbeOpList setCookie[] = { { OP_Transaction, 0, 1, 0}, /* 0 */ - { OP_Integer, 0, 1, 0}, /* 1 */ - { OP_SetCookie, 0, 0, 1}, /* 2 */ + { OP_SetCookie, 0, 0, 0}, /* 1 */ }; VdbeOp *aOp; sqlite3VdbeVerifyNoMallocRequired(v, ArraySize(setCookie)); aOp = sqlite3VdbeAddOpList(v, ArraySize(setCookie), setCookie, 0); if( ONLY_IF_REALLOC_STRESS(aOp==0) ) break; aOp[0].p1 = iDb; - aOp[1].p1 = sqlite3Atoi(zRight); - aOp[2].p1 = iDb; - aOp[2].p2 = iCookie; + aOp[1].p1 = iDb; + aOp[1].p2 = iCookie; + aOp[1].p3 = sqlite3Atoi(zRight); }else{ /* Read the specified cookie value */ static const VdbeOpList readCookie[] = { diff --git a/src/vdbe.c b/src/vdbe.c index 2bb39c85bf..1cf4cb16a7 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -3213,15 +3213,15 @@ case OP_ReadCookie: { /* out2 */ /* Opcode: SetCookie P1 P2 P3 * * ** -** Write the content of register P3 (interpreted as an integer) -** into cookie number P2 of database P1. P2==1 is the schema version. -** P2==2 is the database format. P2==3 is the recommended pager cache +** Write the integer value P3 into cookie number P2 of database P1. +** P2==1 is the schema version. P2==2 is the database format. +** P2==3 is the recommended pager cache ** size, and so forth. P1==0 is the main database file and P1==1 is the ** database file used to store temporary tables. ** ** A transaction must be started before executing this opcode. */ -case OP_SetCookie: { /* in3 */ +case OP_SetCookie: { Db *pDb; assert( pOp->p2p1>=0 && pOp->p1nDb ); @@ -3230,17 +3230,15 @@ case OP_SetCookie: { /* in3 */ pDb = &db->aDb[pOp->p1]; assert( pDb->pBt!=0 ); assert( sqlite3SchemaMutexHeld(db, pOp->p1, 0) ); - pIn3 = &aMem[pOp->p3]; - sqlite3VdbeMemIntegerify(pIn3); /* See note about index shifting on OP_ReadCookie */ - rc = sqlite3BtreeUpdateMeta(pDb->pBt, pOp->p2, (int)pIn3->u.i); + rc = sqlite3BtreeUpdateMeta(pDb->pBt, pOp->p2, pOp->p3); if( pOp->p2==BTREE_SCHEMA_VERSION ){ /* When the schema cookie changes, record the new cookie internally */ - pDb->pSchema->schema_cookie = (int)pIn3->u.i; + pDb->pSchema->schema_cookie = pOp->p3; db->flags |= SQLITE_InternChanges; }else if( pOp->p2==BTREE_FILE_FORMAT ){ /* Record changes in the file format */ - pDb->pSchema->file_format = (u8)pIn3->u.i; + pDb->pSchema->file_format = pOp->p3; } if( pOp->p1==1 ){ /* Invalidate all prepared statements whenever the TEMP database From b8db549832d2acc2fc30327e6fb5c0474820f122 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 2 Feb 2016 02:04:21 +0000 Subject: [PATCH 75/75] Enhance the comment on the sqlite3_index_constraint object to bring attention to the fact than iColumn field can be negative for a rowid. FossilOrigin-Name: d8b7b1996eefae7768bfcb82d4ff22c69392aa63 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/sqlite.h.in | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 391305ff38..3952435799 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Change\sthe\sOP_SetCookie\sinstruction\sto\swrite\sthe\sliteral\sP3\svalue,\snot\sthe\nvalue\sin\sregister\sP3. -D 2016-02-01T21:48:34.880 +C Enhance\sthe\scomment\son\sthe\ssqlite3_index_constraint\sobject\sto\sbring\sattention\s\nto\sthe\sfact\sthan\siColumn\sfield\scan\sbe\snegative\sfor\sa\srowid. +D 2016-02-02T02:04:21.840 F Makefile.in 027c1603f255390c43a426671055a31c0a65fdb4 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 72b7858f02017611c3ac1ddc965251017fed0845 @@ -349,7 +349,7 @@ F src/resolve.c 9f7ce3a3c087afb7597b7c916c99126ff3f12f0c F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e F src/select.c ea6f3b0c279aa37eb3701792d094673a7ad1bf88 F src/shell.c dcd7a83645ef2a58ee9c6d0ea4714d877d7835c4 -F src/sqlite.h.in 214476a62012e578f42133a9a3b4f97a9aa421a3 +F src/sqlite.h.in cf22ad1d52dca2c9862d63833e581028119aab7e F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h dfbe62ffd95b99afe2140d8c35b180d11924072d F src/sqliteInt.h 2f80b9b1506a8d602b2a99f3f0bfae22df3e7d70 @@ -1422,7 +1422,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 2334e88244afe6387208be5d527aba9b5ddf4e4c -R 249f75933f6fe25a197c05fa835262de +P 6d7d4703ebf3754bec74123d5ba7e861a705f90f +R a0fd58918162f72722cea72a597641d9 U drh -Z 56e6b1659de31a547fab736bcf3cb22f +Z 8a77cde1543981fcb216eb719b02e019 diff --git a/manifest.uuid b/manifest.uuid index 54e6aa4e9f..dae04066fb 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -6d7d4703ebf3754bec74123d5ba7e861a705f90f \ No newline at end of file +d8b7b1996eefae7768bfcb82d4ff22c69392aa63 \ No newline at end of file diff --git a/src/sqlite.h.in b/src/sqlite.h.in index 59b30cdd3a..fce396c0f6 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -5697,7 +5697,7 @@ struct sqlite3_index_info { /* Inputs */ int nConstraint; /* Number of entries in aConstraint */ struct sqlite3_index_constraint { - int iColumn; /* Column on left-hand side of constraint */ + int iColumn; /* Column constrained. -1 for ROWID */ unsigned char op; /* Constraint operator */ unsigned char usable; /* True if this constraint is usable */ int iTermOffset; /* Used internally - xBestIndex should ignore */