From e1bb802c5460325d958bb7e61a2d9399496ef9a2 Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 19 Jan 2015 19:48:52 +0000 Subject: [PATCH 01/62] An alternative way of implementing the assert() that verifies the relative values of KeyInfo.nField+KeyInfo.nXField and the number of columns in a record. This version of the assert() only fires when the high-speed comparison routines are used - which is to say it only fires when the constraint actually matters. FossilOrigin-Name: bf744b4908b096f301565f6a4ea8d56667c1d76a --- manifest | 15 +++++++++------ manifest.uuid | 2 +- src/vdbeaux.c | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 7 deletions(-) diff --git a/manifest b/manifest index 136cb71f94..5e36253afb 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Enhance\sthe\scommand-line\sshell\swith\sthe\sability\sto\sset\sthe\nSQLITE_TESTCTRL_NEVER_CORRUPT\sflag\susing:\s".testctrl\snever_corrupt\s1". -D 2015-01-19T15:05:54.471 +C An\salternative\sway\sof\simplementing\sthe\sassert()\sthat\sverifies\sthe\srelative\nvalues\sof\sKeyInfo.nField+KeyInfo.nXField\sand\sthe\snumber\sof\scolumns\sin\sa\srecord.\nThis\sversion\sof\sthe\sassert()\sonly\sfires\swhen\sthe\shigh-speed\scomparison\nroutines\sare\sused\s-\swhich\sis\sto\ssay\sit\sonly\sfires\swhen\sthe\sconstraint\nactually\smatters. +D 2015-01-19T19:48:52.667 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5407a688f4d77a05c18a8142be8ae5a2829dd610 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -296,7 +296,7 @@ F src/vdbe.c ddfc977981cd6324668aa6b114045eb1c677421a F src/vdbe.h 6fc69d9c5e146302c56e163cb4b31d1ee64a18c3 F src/vdbeInt.h 9bb69ff2447c34b6ccc58b34ec35b615f86ead78 F src/vdbeapi.c 4bc511a46b9839392ae0e90844a71dc96d9dbd71 -F src/vdbeaux.c 07ef87c6d4b5abdf13ff33babb10205702fdab0a +F src/vdbeaux.c d22d71f5928f0170061b6509b72832d307fb581e F src/vdbeblob.c 4af4bfb71f6df7778397b4a0ebc1879793276778 F src/vdbemem.c 31d8eabb0cd78bfeab4e5124c7363c3e9e54db9f F src/vdbesort.c 6d64c5448b64851b99931ede980addc3af70d5e2 @@ -1236,7 +1236,10 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 10321910990195878c0af1e94b34ae0cdc0cb31b -R 1842536563f5d094d57991d4a5161858 +P 824328f9833d01fc155a9d0265ef41d338cf1ffb +R 62f359e43ad9aa835c85ab2bfc9c70b0 +T *branch * tkt-f97c4637 +T *sym-tkt-f97c4637 * +T -sym-trunk * U drh -Z b40ce48cd42cd2dd2358d0667c50be5c +Z e1e735a41c0bcd1d69846f2fcc6f5b85 diff --git a/manifest.uuid b/manifest.uuid index a042232dda..eecb747ee6 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -824328f9833d01fc155a9d0265ef41d338cf1ffb \ No newline at end of file +bf744b4908b096f301565f6a4ea8d56667c1d76a \ No newline at end of file diff --git a/src/vdbeaux.c b/src/vdbeaux.c index 03c229c994..b3f8278eb1 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -3349,6 +3349,39 @@ debugCompareEnd: } #endif +#if SQLITE_DEBUG +/* +** Count the number of fields (a.k.a. columns) in the record given by +** pKey,nKey. The verify that this count is less than or equal to the +** limit given by pKeyInfo->nField + pKeyInfo->nXField. +** +** If this constraint is not satisfied, it means that the high-speed +** vdbeRecordCompareInt() and vdbeRecordCompareString() routines will +** not work correctly. If this assert() ever fires, it probably means +** that the KeyInfo.nField or KeyInfo.nXField values were computed +** incorrectly. +*/ +static void vdbeAssertFieldCountWithinLimits( + int nKey, const void *pKey, /* The record to verify */ + const KeyInfo *pKeyInfo /* Compare size with this KeyInfo */ +){ + int nField = 0; + u32 szHdr; + u32 idx; + u32 notUsed; + const unsigned char *aKey = (const unsigned char*)pKey; + + if( CORRUPT_DB ) return; + idx = getVarint32(aKey, szHdr); + assert( szHdr<=nKey ); + while( idxnField+pKeyInfo->nXField ); +} +#endif + /* ** Both *pMem1 and *pMem2 contain string values. Compare the two values ** using the collation sequence pColl. As usual, return a negative , zero @@ -3760,6 +3793,7 @@ static int vdbeRecordCompareInt( i64 v = pPKey2->aMem[0].u.i; i64 lhs; + vdbeAssertFieldCountWithinLimits(nKey1, pKey1, pPKey2->pKeyInfo); assert( (*(u8*)pKey1)<=0x3F || CORRUPT_DB ); switch( serial_type ){ case 1: { /* 1-byte signed integer */ @@ -3847,6 +3881,7 @@ static int vdbeRecordCompareString( int serial_type; int res; + vdbeAssertFieldCountWithinLimits(nKey1, pKey1, pPKey2->pKeyInfo); getVarint32(&aKey1[1], serial_type); if( serial_type<12 ){ res = pPKey2->r1; /* (pKey1/nKey1) is a number or a null */ From 1af3c64d03c4f899e8f112639e3f5f4fe81a70ef Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 19 Jan 2015 20:57:19 +0000 Subject: [PATCH 02/62] Fix the assert() of the previous check-in so that it works even when compiled without SQLITE_DEBUG. FossilOrigin-Name: 38868f845e1ad4d61354ab1ad39dd19e3e07c7fd --- manifest | 15 ++++++--------- manifest.uuid | 2 +- src/vdbeaux.c | 2 ++ 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index 5e36253afb..95a9ce8219 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C An\salternative\sway\sof\simplementing\sthe\sassert()\sthat\sverifies\sthe\srelative\nvalues\sof\sKeyInfo.nField+KeyInfo.nXField\sand\sthe\snumber\sof\scolumns\sin\sa\srecord.\nThis\sversion\sof\sthe\sassert()\sonly\sfires\swhen\sthe\shigh-speed\scomparison\nroutines\sare\sused\s-\swhich\sis\sto\ssay\sit\sonly\sfires\swhen\sthe\sconstraint\nactually\smatters. -D 2015-01-19T19:48:52.667 +C Fix\sthe\sassert()\sof\sthe\sprevious\scheck-in\sso\sthat\sit\sworks\seven\swhen\ncompiled\swithout\sSQLITE_DEBUG. +D 2015-01-19T20:57:19.823 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5407a688f4d77a05c18a8142be8ae5a2829dd610 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -296,7 +296,7 @@ F src/vdbe.c ddfc977981cd6324668aa6b114045eb1c677421a F src/vdbe.h 6fc69d9c5e146302c56e163cb4b31d1ee64a18c3 F src/vdbeInt.h 9bb69ff2447c34b6ccc58b34ec35b615f86ead78 F src/vdbeapi.c 4bc511a46b9839392ae0e90844a71dc96d9dbd71 -F src/vdbeaux.c d22d71f5928f0170061b6509b72832d307fb581e +F src/vdbeaux.c f06d38c71d7f533348c09869d69fd1b647042a5b F src/vdbeblob.c 4af4bfb71f6df7778397b4a0ebc1879793276778 F src/vdbemem.c 31d8eabb0cd78bfeab4e5124c7363c3e9e54db9f F src/vdbesort.c 6d64c5448b64851b99931ede980addc3af70d5e2 @@ -1236,10 +1236,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 824328f9833d01fc155a9d0265ef41d338cf1ffb -R 62f359e43ad9aa835c85ab2bfc9c70b0 -T *branch * tkt-f97c4637 -T *sym-tkt-f97c4637 * -T -sym-trunk * +P bf744b4908b096f301565f6a4ea8d56667c1d76a +R 41daf6b428d707d4f33647380c4cfa49 U drh -Z e1e735a41c0bcd1d69846f2fcc6f5b85 +Z 452da4f6a59c3f1fc4c567af0e6571ad diff --git a/manifest.uuid b/manifest.uuid index eecb747ee6..453f2b2bad 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -bf744b4908b096f301565f6a4ea8d56667c1d76a \ No newline at end of file +38868f845e1ad4d61354ab1ad39dd19e3e07c7fd \ No newline at end of file diff --git a/src/vdbeaux.c b/src/vdbeaux.c index b3f8278eb1..e07aacbcac 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -3380,6 +3380,8 @@ static void vdbeAssertFieldCountWithinLimits( } assert( nField <= pKeyInfo->nField+pKeyInfo->nXField ); } +#else +# define vdbeAssertFieldCountWithinLimits(A,B,C) #endif /* From 3f39bcf5bc9fa27fd51c0649bbed4d3f8418c808 Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 19 Jan 2015 20:59:34 +0000 Subject: [PATCH 03/62] Make sure that the KeyInfo.nXField value of ephermeral tables used for ORDER BY and GROUP BY is set correctly, so that the correct comparison function can be choosen by sqlite3VdbeFindCompare(). FossilOrigin-Name: c16bae5e699b851f4ca8414c5dfa5370b18f69f0 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/select.c | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index 95a9ce8219..c67989eac9 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sthe\sassert()\sof\sthe\sprevious\scheck-in\sso\sthat\sit\sworks\seven\swhen\ncompiled\swithout\sSQLITE_DEBUG. -D 2015-01-19T20:57:19.823 +C Make\ssure\sthat\sthe\sKeyInfo.nXField\svalue\sof\sephermeral\stables\sused\sfor\nORDER\sBY\sand\sGROUP\sBY\sis\sset\scorrectly,\sso\sthat\sthe\scorrect\scomparison\nfunction\scan\sbe\schoosen\sby\ssqlite3VdbeFindCompare(). +D 2015-01-19T20:59:34.124 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5407a688f4d77a05c18a8142be8ae5a2829dd610 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -229,7 +229,7 @@ F src/printf.c ea82bcb1b83273b4c67177c233c1f78c81fc42f9 F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c f6c46d3434439ab2084618d603e6d6dbeb0d6ada F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e -F src/select.c e4c38c75e36f28aed80a69a725d888751bfd53df +F src/select.c bc02e8b084891af5a3b428faa9cf367aff887d1a F src/shell.c d2d3b46701e44369dd314bd6817541c60e2c39ea F src/sqlite.h.in 9dfc99d6533d36d6a549c4f3f01cacc8be956ada F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad @@ -1236,7 +1236,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P bf744b4908b096f301565f6a4ea8d56667c1d76a -R 41daf6b428d707d4f33647380c4cfa49 +P 38868f845e1ad4d61354ab1ad39dd19e3e07c7fd +R 13f159f0ffd29d3a96e72fa52e241602 U drh -Z 452da4f6a59c3f1fc4c567af0e6571ad +Z 00bba407ebbd95d365912cac0942941c diff --git a/manifest.uuid b/manifest.uuid index 453f2b2bad..7543094f94 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -38868f845e1ad4d61354ab1ad39dd19e3e07c7fd \ No newline at end of file +c16bae5e699b851f4ca8414c5dfa5370b18f69f0 \ No newline at end of file diff --git a/src/select.c b/src/select.c index 78b1caea8d..4037326467 100644 --- a/src/select.c +++ b/src/select.c @@ -1054,7 +1054,7 @@ static KeyInfo *keyInfoFromExprList( int i; nExpr = pList->nExpr; - pInfo = sqlite3KeyInfoAlloc(db, nExpr+nExtra-iStart, 1); + pInfo = sqlite3KeyInfoAlloc(db, nExpr-iStart, nExtra+1); if( pInfo ){ assert( sqlite3KeyInfoIsWriteable(pInfo) ); for(i=iStart, pItem=pList->a+iStart; inExpr); sSort.iECursor = pParse->nTab++; sSort.addrSortIndex = sqlite3VdbeAddOp4(v, OP_OpenEphemeral, @@ -5098,7 +5098,7 @@ int sqlite3Select( ** will be converted into a Noop. */ sAggInfo.sortingIdx = pParse->nTab++; - pKeyInfo = keyInfoFromExprList(pParse, pGroupBy, 0, 0); + pKeyInfo = keyInfoFromExprList(pParse, pGroupBy, 0, sAggInfo.nColumn); addrSortingIdx = sqlite3VdbeAddOp4(v, OP_SorterOpen, sAggInfo.sortingIdx, sAggInfo.nSortingColumn, 0, (char*)pKeyInfo, P4_KEYINFO); From 59b1b58b667ca8f89034ec57e77711ba00ad1d06 Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 19 Jan 2015 21:10:53 +0000 Subject: [PATCH 04/62] There are asserts in place now that will prevent a recurrence of ticket [f97c4637102a3ae7]. Nevertheless, it is good to add some test cases as well. FossilOrigin-Name: e02959b9a0e1bacdd3939548d4434c042aacc2e6 --- manifest | 11 ++++++----- manifest.uuid | 2 +- test/orderby8.test | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 6 deletions(-) create mode 100644 test/orderby8.test diff --git a/manifest b/manifest index c67989eac9..88e87b25f8 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Make\ssure\sthat\sthe\sKeyInfo.nXField\svalue\sof\sephermeral\stables\sused\sfor\nORDER\sBY\sand\sGROUP\sBY\sis\sset\scorrectly,\sso\sthat\sthe\scorrect\scomparison\nfunction\scan\sbe\schoosen\sby\ssqlite3VdbeFindCompare(). -D 2015-01-19T20:59:34.124 +C There\sare\sasserts\sin\splace\snow\sthat\swill\sprevent\sa\srecurrence\sof\nticket\s[f97c4637102a3ae7].\s\sNevertheless,\sit\sis\sgood\sto\sadd\ssome\ntest\scases\sas\swell. +D 2015-01-19T21:10:53.444 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5407a688f4d77a05c18a8142be8ae5a2829dd610 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -769,6 +769,7 @@ F test/orderby4.test 4d39bfbaaa3ae64d026ca2ff166353d2edca4ba4 F test/orderby5.test 8f08a54836d21fb7c70245360751aedd1c2286fb F test/orderby6.test 8b38138ab0972588240b3fca0985d2e400432859 F test/orderby7.test 3d1383d52ade5b9eb3a173b3147fdd296f0202da +F test/orderby8.test 23ef1a5d72bd3adcc2f65561c654295d1b8047bd F test/oserror.test 14fec2796c2b6fe431c7823750e8a18a761176d7 F test/ovfl.test 4f7ca651cba5c059a12d8c67dddd49bec5747799 F test/pager1.test 1acbdb14c5952a72dd43129cabdbf69aaa3ed1fa @@ -1236,7 +1237,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 38868f845e1ad4d61354ab1ad39dd19e3e07c7fd -R 13f159f0ffd29d3a96e72fa52e241602 +P c16bae5e699b851f4ca8414c5dfa5370b18f69f0 +R e27a2655369428e59f07848a6b54ddd6 U drh -Z 00bba407ebbd95d365912cac0942941c +Z e964ea280030c93ae7b89ddabdb22c13 diff --git a/manifest.uuid b/manifest.uuid index 7543094f94..7c623bd1a8 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c16bae5e699b851f4ca8414c5dfa5370b18f69f0 \ No newline at end of file +e02959b9a0e1bacdd3939548d4434c042aacc2e6 \ No newline at end of file diff --git a/test/orderby8.test b/test/orderby8.test new file mode 100644 index 0000000000..53da971b12 --- /dev/null +++ b/test/orderby8.test @@ -0,0 +1,41 @@ +# 2015-01-19 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this file is testing ORDER BY and LIMIT on tables with +# many columns. +# +# These tests verify that ticket [f97c4637102a3ae72b7911167e1d4da12ce60722] +# from 2015-01-19 has been fixed. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set ::testprefix orderby8 + +do_test 1.0 { + db eval { + CREATE TABLE t1(x); + INSERT INTO t1(x) VALUES(1),(5),(9),(7),(3),(2),(4),(6),(8); + } + set ::result_set "x" +} {x} +for {set i 1} {$i<200} {incr i} { + append ::result_set ", x+$i" + do_test 1.$i { + set res {} + db eval "SELECT $::result_set FROM t1 ORDER BY x LIMIT -1" { + lappend res $x + } + set res + } {1 2 3 4 5 6 7 8 9} +} + +finish_test From fe201effbe35d38fdd198be93b23abe7583b2aa9 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 20 Jan 2015 03:04:29 +0000 Subject: [PATCH 05/62] Fix another instance of an incorrect value for KeyInfo.nXField on a sorting index. Ticket [f97c4637102a3ae72b79]. FossilOrigin-Name: 0077f64510f9b9ce90032df2696cb242d097ab84 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/select.c | 4 +++- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 5ab9b699da..045fe9bb3a 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Ensure\sthat\sthe\sKeyInfo.nXField\svalue\sfor\sephemeral\stables\sused\sto\simplement\nORDER\sBY\sor\sGROUP\sBY\sclauses\sis\sset\scorrectly,\sso\sthat\sthe\nsqlite3VdbeFindCompare()\sroutine\scan\schoose\sthe\scorrect\scomparison\sfunction.\nAdd\sassert()\sstatements\sto\sthe\shigh-speed\scomparison\sfunctions\sto\sdetect\ncases\swhere\sthey\sare\sinappropriately\schosen.\nFix\sfor\sticket\s[f97c4637102a3ae72b7911]. -D 2015-01-19T21:36:05.317 +C Fix\sanother\sinstance\sof\san\sincorrect\svalue\sfor\sKeyInfo.nXField\son\sa\nsorting\sindex.\s\sTicket\s[f97c4637102a3ae72b79]. +D 2015-01-20T03:04:29.620 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5407a688f4d77a05c18a8142be8ae5a2829dd610 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -229,7 +229,7 @@ F src/printf.c ea82bcb1b83273b4c67177c233c1f78c81fc42f9 F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c f6c46d3434439ab2084618d603e6d6dbeb0d6ada F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e -F src/select.c bc02e8b084891af5a3b428faa9cf367aff887d1a +F src/select.c a4e8fda24c8eab2682a058bdda0d5d68cfe3919c F src/shell.c d2d3b46701e44369dd314bd6817541c60e2c39ea F src/sqlite.h.in 9dfc99d6533d36d6a549c4f3f01cacc8be956ada F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad @@ -1237,8 +1237,8 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 2037442c582e51d85967bc911ea4a412eb4da573 e02959b9a0e1bacdd3939548d4434c042aacc2e6 -R 5021170f2a6880b445a702735148b9c6 -T +closed e02959b9a0e1bacdd3939548d4434c042aacc2e6 +P f7201bb0cdc9e1425c68599b32434de2231dca36 +Q +dc711db44ec424a7850231a39088229c23238f1b +R 62321acc2f9c598a0f3d605f6dbddb80 U drh -Z b76cf3617d76194e2b83c38054737fb3 +Z 8cb1f44c22f57ba114489669ef914874 diff --git a/manifest.uuid b/manifest.uuid index 06d89b2c82..eb64824593 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -f7201bb0cdc9e1425c68599b32434de2231dca36 \ No newline at end of file +0077f64510f9b9ce90032df2696cb242d097ab84 \ No newline at end of file diff --git a/src/select.c b/src/select.c index 4037326467..39a0550f2a 100644 --- a/src/select.c +++ b/src/select.c @@ -543,7 +543,9 @@ static void pushOntoSorter( pKI = pOp->p4.pKeyInfo; memset(pKI->aSortOrder, 0, pKI->nField); /* Makes OP_Jump below testable */ sqlite3VdbeChangeP4(v, -1, (char*)pKI, P4_KEYINFO); - pOp->p4.pKeyInfo = keyInfoFromExprList(pParse, pSort->pOrderBy, nOBSat, 1); + testcase( pKI->nXField>2 ); + pOp->p4.pKeyInfo = keyInfoFromExprList(pParse, pSort->pOrderBy, nOBSat, + pKI->nXField-1); addrJmp = sqlite3VdbeCurrentAddr(v); sqlite3VdbeAddOp3(v, OP_Jump, addrJmp+1, 0, addrJmp+1); VdbeCoverage(v); pSort->labelBkOut = sqlite3VdbeMakeLabel(v); From e45e0fb21c4987172d8ed8b6d0e71a30878f16fc Mon Sep 17 00:00:00 2001 From: mistachkin Date: Wed, 21 Jan 2015 00:48:46 +0000 Subject: [PATCH 06/62] Enhancements to entropy generation for the Win32 VFS. FossilOrigin-Name: 26190b3c63e18f3116deeb59a58d9b5de48e8eea --- Makefile.msc | 18 ++++++++++++++++++ manifest | 17 ++++++++--------- manifest.uuid | 2 +- src/os_win.c | 35 ++++++++++++++++++++++++++++++++++- 4 files changed, 61 insertions(+), 11 deletions(-) diff --git a/Makefile.msc b/Makefile.msc index 4ebe9fd20c..1908794840 100644 --- a/Makefile.msc +++ b/Makefile.msc @@ -59,6 +59,12 @@ USE_ICU = 0 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. # @@ -501,6 +507,12 @@ RCC = $(RCC) -DSQLITE_TEMP_STORE=1 # 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. # @@ -564,6 +576,12 @@ 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 diff --git a/manifest b/manifest index 045fe9bb3a..36deba019a 100644 --- a/manifest +++ b/manifest @@ -1,9 +1,9 @@ -C Fix\sanother\sinstance\sof\san\sincorrect\svalue\sfor\sKeyInfo.nXField\son\sa\nsorting\sindex.\s\sTicket\s[f97c4637102a3ae72b79]. -D 2015-01-20T03:04:29.620 +C Enhancements\sto\sentropy\sgeneration\sfor\sthe\sWin32\sVFS. +D 2015-01-21T00:48:46.472 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5407a688f4d77a05c18a8142be8ae5a2829dd610 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 -F Makefile.msc 4c057774e6138b9023fc16ec05639ddd3329b152 +F Makefile.msc 2b1cb8881bdefcb0a8ed41c34c81cfa630374222 F Makefile.vxworks e1b65dea203f054e71653415bd8f96dcaed47858 F README.md d58e3bebc0a4145e0f2a87994015fdb575a8e866 F VERSION d846487aff892625eb8e75960234e7285f0462fe @@ -215,7 +215,7 @@ F src/os.h 3e57a24e2794a94d3cf2342c6d9a884888cd96bf F src/os_common.h 92815ed65f805560b66166e3583470ff94478f04 F src/os_setup.h c9d4553b5aaa6f73391448b265b89bed0b890faa F src/os_unix.c aefeaf915aaef9f81aa2645e0d5d06fa1bd83beb -F src/os_win.c a5ac9e249ed0ca33de6de27898a08d313effc40c +F src/os_win.c 8223e7db5b7c4a81d8b161098ac3959400434cdb F src/os_win.h eb7a47aa17b26b77eb97e4823f20a00b8bda12ca F src/pager.c 4120a49ecd37697e28f5ed807f470b9c0b88410c F src/pager.h c3476e7c89cdf1c6914e50a11f3714e30b4e0a77 @@ -1237,8 +1237,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P f7201bb0cdc9e1425c68599b32434de2231dca36 -Q +dc711db44ec424a7850231a39088229c23238f1b -R 62321acc2f9c598a0f3d605f6dbddb80 -U drh -Z 8cb1f44c22f57ba114489669ef914874 +P 0077f64510f9b9ce90032df2696cb242d097ab84 +R 621342f470a9e0b129cd54918ae375f4 +U mistachkin +Z 66078f9f30e92a431d6c7bd5ea435d81 diff --git a/manifest.uuid b/manifest.uuid index eb64824593..2a540fd00c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -0077f64510f9b9ce90032df2696cb242d097ab84 \ No newline at end of file +26190b3c63e18f3116deeb59a58d9b5de48e8eea \ No newline at end of file diff --git a/src/os_win.c b/src/os_win.c index c938a4d7dd..7463778a2f 100644 --- a/src/os_win.c +++ b/src/os_win.c @@ -1066,6 +1066,23 @@ static struct win_syscall { SQLITE_WIN32_VOLATILE*, LONG,LONG))aSyscall[76].pCurrent) #endif /* defined(InterlockedCompareExchange) */ +#if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && SQLITE_WIN32_USE_UUID + { "UuidCreate", (SYSCALL)UuidCreate, 0 }, +#else + { "UuidCreate", (SYSCALL)0, 0 }, +#endif + +#define osUuidCreate ((RPC_STATUS(RPC_ENTRY*)(UUID*))aSyscall[77].pCurrent) + +#if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && SQLITE_WIN32_USE_UUID + { "UuidCreateSequential", (SYSCALL)UuidCreateSequential, 0 }, +#else + { "UuidCreateSequential", (SYSCALL)0, 0 }, +#endif + +#define osUuidCreateSequential \ + ((RPC_STATUS(RPC_ENTRY*)(UUID*))aSyscall[78].pCurrent) + }; /* End of the overrideable system calls */ /* @@ -5344,6 +5361,22 @@ static int winRandomness(sqlite3_vfs *pVfs, int nBuf, char *zBuf){ memcpy(&zBuf[n], &i, sizeof(i)); n += sizeof(i); } +#endif +#if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && SQLITE_WIN32_USE_UUID + if( sizeof(UUID)<=nBuf-n ){ + UUID id; + memset(&id, 0, sizeof(UUID)); + osUuidCreate(&id); + memcpy(zBuf, &id, sizeof(UUID)); + n += sizeof(UUID); + } + if( sizeof(UUID)<=nBuf-n ){ + UUID id; + memset(&id, 0, sizeof(UUID)); + osUuidCreateSequential(&id); + memcpy(zBuf, &id, sizeof(UUID)); + n += sizeof(UUID); + } #endif return n; } @@ -5522,7 +5555,7 @@ int sqlite3_os_init(void){ /* Double-check that the aSyscall[] array has been constructed ** correctly. See ticket [bb3a86e890c8e96ab] */ - assert( ArraySize(aSyscall)==77 ); + assert( ArraySize(aSyscall)==79 ); /* get memory map allocation granularity */ memset(&winSysInfo, 0, sizeof(SYSTEM_INFO)); From 1b3ee49225e9fb46a3d8d1dbbca160885ae6dc9f Mon Sep 17 00:00:00 2001 From: mistachkin Date: Wed, 21 Jan 2015 00:51:08 +0000 Subject: [PATCH 07/62] Fix harmless compiler warning seen with MSVC. FossilOrigin-Name: 78c2e62bb4c529595aaaf2e1f5f26387ad977b1b --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/vdbeaux.c | 3 ++- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 36deba019a..9e4b820180 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Enhancements\sto\sentropy\sgeneration\sfor\sthe\sWin32\sVFS. -D 2015-01-21T00:48:46.472 +C Fix\sharmless\scompiler\swarning\sseen\swith\sMSVC. +D 2015-01-21T00:51:08.964 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5407a688f4d77a05c18a8142be8ae5a2829dd610 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -296,7 +296,7 @@ F src/vdbe.c ddfc977981cd6324668aa6b114045eb1c677421a F src/vdbe.h 6fc69d9c5e146302c56e163cb4b31d1ee64a18c3 F src/vdbeInt.h 9bb69ff2447c34b6ccc58b34ec35b615f86ead78 F src/vdbeapi.c 4bc511a46b9839392ae0e90844a71dc96d9dbd71 -F src/vdbeaux.c f06d38c71d7f533348c09869d69fd1b647042a5b +F src/vdbeaux.c 97911edb61074b871ec4aa2d6bb779071643dee5 F src/vdbeblob.c 4af4bfb71f6df7778397b4a0ebc1879793276778 F src/vdbemem.c 31d8eabb0cd78bfeab4e5124c7363c3e9e54db9f F src/vdbesort.c 6d64c5448b64851b99931ede980addc3af70d5e2 @@ -1237,7 +1237,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 0077f64510f9b9ce90032df2696cb242d097ab84 -R 621342f470a9e0b129cd54918ae375f4 +P 26190b3c63e18f3116deeb59a58d9b5de48e8eea +R 17b31e2924f2250d0d9a55276496f8b8 U mistachkin -Z 66078f9f30e92a431d6c7bd5ea435d81 +Z cec7ce423a7eb7a21c54da9ee537419d diff --git a/manifest.uuid b/manifest.uuid index 2a540fd00c..4ba73d1942 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -26190b3c63e18f3116deeb59a58d9b5de48e8eea \ No newline at end of file +78c2e62bb4c529595aaaf2e1f5f26387ad977b1b \ No newline at end of file diff --git a/src/vdbeaux.c b/src/vdbeaux.c index e07aacbcac..cd9ecaa691 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -3373,7 +3373,8 @@ static void vdbeAssertFieldCountWithinLimits( if( CORRUPT_DB ) return; idx = getVarint32(aKey, szHdr); - assert( szHdr<=nKey ); + assert( nKey>=0 ); + assert( szHdr<=(u32)nKey ); while( idx Date: Wed, 21 Jan 2015 17:00:57 +0000 Subject: [PATCH 08/62] Fix an assert() that may fail following an OOM error. FossilOrigin-Name: 5f592359d6d41708da3b3ac9d987a1631bfa3d88 --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/expr.c | 3 ++- test/mallocK.test | 10 ++++++++++ 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index 9e4b820180..71f218ff4a 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sharmless\scompiler\swarning\sseen\swith\sMSVC. -D 2015-01-21T00:51:08.964 +C Fix\san\sassert()\sthat\smay\sfail\sfollowing\san\sOOM\serror. +D 2015-01-21T17:00:57.118 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5407a688f4d77a05c18a8142be8ae5a2829dd610 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -182,7 +182,7 @@ F src/complete.c 198a0066ba60ab06fc00fba1998d870a4d575463 F src/ctime.c 98f89724adc891a1a4c655bee04e33e716e05887 F src/date.c e4d50b3283696836ec1036b695ead9a19e37a5ac F src/delete.c bd1a91ddd247ce13004075251e0b7fe2bf9925ef -F src/expr.c 7be80f7dc337329a24df45c2f3bdb2ea3b64c90e +F src/expr.c 33a4518b2c786903cb185dbdc66e071ac38d467e F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb F src/fkey.c e0444b61bed271a76840cbe6182df93a9baa3f12 F src/func.c 6d3c4ebd72aa7923ce9b110a7dc15f9b8c548430 @@ -721,7 +721,7 @@ F test/mallocG.test 0ff91b65c50bdaba680fb75d87fe4ad35bb7934f F test/mallocH.test 79b65aed612c9b3ed2dcdaa727c85895fd1bfbdb F test/mallocI.test a88c2b9627c8506bf4703d8397420043a786cdb6 F test/mallocJ.test b5d1839da331d96223e5f458856f8ffe1366f62e -F test/mallocK.test 3cff7c0f64735f6883bacdd294e45a6ed5714817 +F test/mallocK.test 223cc80c870c80d4a9c2014e94133efdf0123f82 F test/mallocL.test 252ddc7eb4fbf75364eab17b938816085ff1fc17 F test/malloc_common.tcl 3663f9001ce3e29bbaa9677ffe15cd468e3ec7e3 F test/manydb.test 28385ae2087967aa05c38624cec7d96ec74feb3e @@ -1237,7 +1237,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 26190b3c63e18f3116deeb59a58d9b5de48e8eea -R 17b31e2924f2250d0d9a55276496f8b8 -U mistachkin -Z cec7ce423a7eb7a21c54da9ee537419d +P 78c2e62bb4c529595aaaf2e1f5f26387ad977b1b +R fadddb94e3f078ed8e5664ef5ad11fc1 +U dan +Z 211832fccf702756128a6ea4845193da diff --git a/manifest.uuid b/manifest.uuid index 4ba73d1942..dfb1a44e74 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -78c2e62bb4c529595aaaf2e1f5f26387ad977b1b \ No newline at end of file +5f592359d6d41708da3b3ac9d987a1631bfa3d88 \ No newline at end of file diff --git a/src/expr.c b/src/expr.c index 32adedf9bf..64fb3c5fd4 100644 --- a/src/expr.c +++ b/src/expr.c @@ -2256,7 +2256,8 @@ void sqlite3ExprCacheStore(Parse *pParse, int iTab, int iCol, int iReg){ int idxLru; struct yColCache *p; - assert( iReg>0 ); /* Register numbers are always positive */ + /* Unless an error has occurred, register numbers are always positive. */ + assert( iReg>0 || pParse->nErr || pParse->db->mallocFailed ); assert( iCol>=-1 && iCol<32768 ); /* Finite column numbers */ /* The SQLITE_ColumnCache flag disables the column cache. This is used diff --git a/test/mallocK.test b/test/mallocK.test index dcf00da9aa..0a21b9fa0a 100644 --- a/test/mallocK.test +++ b/test/mallocK.test @@ -134,5 +134,15 @@ do_faultsim_test 6 -faults oom* -body { faultsim_test_result {0 {12 13 14 15}} } +do_execsql_test 7.1 { + CREATE TABLE x1(a INTEGER PRIMARY KEY, b); +} +do_faultsim_test 7.2 -faults oom* -body { + execsql { SELECT * FROM x1 WHERE a = (SELECT 1) } +} -test { + faultsim_test_result [list 0 {}] +} + + finish_test From 1d9be4f7d3d5c792108a6d12eefc9328bde624c5 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 22 Jan 2015 11:29:25 +0000 Subject: [PATCH 09/62] Change the undocumented ".selecttrace" command in the shell to accept an integer bitmask rather than a boolean. FossilOrigin-Name: bd63bf882c5a925f921adc9cf7425d2e7950f0b2 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/shell.c | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 71f218ff4a..b3404a8541 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\san\sassert()\sthat\smay\sfail\sfollowing\san\sOOM\serror. -D 2015-01-21T17:00:57.118 +C Change\sthe\sundocumented\s".selecttrace"\scommand\sin\sthe\sshell\sto\saccept\nan\sinteger\sbitmask\srather\sthan\sa\sboolean. +D 2015-01-22T11:29:25.197 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5407a688f4d77a05c18a8142be8ae5a2829dd610 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -230,7 +230,7 @@ F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c f6c46d3434439ab2084618d603e6d6dbeb0d6ada F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e F src/select.c a4e8fda24c8eab2682a058bdda0d5d68cfe3919c -F src/shell.c d2d3b46701e44369dd314bd6817541c60e2c39ea +F src/shell.c acdf311a7a6ed5d84454f9b13488a76fd57dbb72 F src/sqlite.h.in 9dfc99d6533d36d6a549c4f3f01cacc8be956ada F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h 17d487c3c91b0b8c584a32fbeb393f6f795eea7d @@ -1237,7 +1237,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 78c2e62bb4c529595aaaf2e1f5f26387ad977b1b -R fadddb94e3f078ed8e5664ef5ad11fc1 -U dan -Z 211832fccf702756128a6ea4845193da +P 5f592359d6d41708da3b3ac9d987a1631bfa3d88 +R 06bf50be530a04b67e63b7751053876a +U drh +Z 7005abb8b52570698504c401137e57e1 diff --git a/manifest.uuid b/manifest.uuid index dfb1a44e74..3b26c8f3c6 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -5f592359d6d41708da3b3ac9d987a1631bfa3d88 \ No newline at end of file +bd63bf882c5a925f921adc9cf7425d2e7950f0b2 \ No newline at end of file diff --git a/src/shell.c b/src/shell.c index 1d9c80798c..0603268cc6 100644 --- a/src/shell.c +++ b/src/shell.c @@ -3329,7 +3329,7 @@ static int do_meta_command(char *zLine, ShellState *p){ #if defined(SQLITE_DEBUG) && defined(SQLITE_ENABLE_SELECTTRACE) if( c=='s' && n==11 && strncmp(azArg[0], "selecttrace", n)==0 ){ extern int sqlite3SelectTrace; - sqlite3SelectTrace = nArg>=2 ? booleanValue(azArg[1]) : 0xff; + sqlite3SelectTrace = integerValue(azArg[1]); }else #endif From 2b8c5a00394382ab5b3ea7e0d685f8b0d94d7c8f Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 22 Jan 2015 12:00:17 +0000 Subject: [PATCH 10/62] Make sure errors in the FROM clause of a SELECT cause analysis to abort and unwind the stack before those errors have a chance to mischief in the "*" column-name wildcard expander. Fix for ticket [32b63d542433ca67]. FossilOrigin-Name: 9e6eae660a02303fd140dac5fbff82364f4120cd --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/select.c | 2 +- test/fuzz2.test | 10 ++++++++++ 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index b3404a8541..45f02f62f5 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Change\sthe\sundocumented\s".selecttrace"\scommand\sin\sthe\sshell\sto\saccept\nan\sinteger\sbitmask\srather\sthan\sa\sboolean. -D 2015-01-22T11:29:25.197 +C Make\ssure\serrors\sin\sthe\sFROM\sclause\sof\sa\sSELECT\scause\sanalysis\sto\sabort\nand\sunwind\sthe\sstack\sbefore\sthose\serrors\shave\sa\schance\sto\smischief\nin\sthe\s"*"\scolumn-name\swildcard\sexpander.\sFix\sfor\sticket\s[32b63d542433ca67]. +D 2015-01-22T12:00:17.073 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5407a688f4d77a05c18a8142be8ae5a2829dd610 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -229,7 +229,7 @@ F src/printf.c ea82bcb1b83273b4c67177c233c1f78c81fc42f9 F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c f6c46d3434439ab2084618d603e6d6dbeb0d6ada F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e -F src/select.c a4e8fda24c8eab2682a058bdda0d5d68cfe3919c +F src/select.c 1f2087523007c42900ffcbdeaef06a23ad9329fc F src/shell.c acdf311a7a6ed5d84454f9b13488a76fd57dbb72 F src/sqlite.h.in 9dfc99d6533d36d6a549c4f3f01cacc8be956ada F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad @@ -620,7 +620,7 @@ F test/func4.test 6beacdfcb0e18c358e6c2dcacf1b65d1fa80955f F test/func5.test cdd224400bc3e48d891827cc913a57051a426fa4 F test/fuzz-oss1.test 4912e528ec9cf2f42134456933659d371c9e0d74 F test/fuzz.test 96083052bf5765e4518c1ba686ce2bab785670d1 -F test/fuzz2.test b34fe575aa10292135421ff4bf315de4cde7824a +F test/fuzz2.test 76dc35b32b6d6f965259508508abce75a6c4d7e1 F test/fuzz3.test efd384b896c647b61a2c1848ba70d42aad60a7b3 F test/fuzz_common.tcl a87dfbb88c2a6b08a38e9a070dabd129e617b45b F test/fuzz_malloc.test 328f70aaca63adf29b4c6f06505ed0cf57ca7c26 @@ -1237,7 +1237,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 5f592359d6d41708da3b3ac9d987a1631bfa3d88 -R 06bf50be530a04b67e63b7751053876a +P bd63bf882c5a925f921adc9cf7425d2e7950f0b2 +R cd80a044c23c0a2610d13740733ffe7d U drh -Z 7005abb8b52570698504c401137e57e1 +Z ca1958b398bcc4529c59936be19170f3 diff --git a/manifest.uuid b/manifest.uuid index 3b26c8f3c6..79ff74b5cb 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -bd63bf882c5a925f921adc9cf7425d2e7950f0b2 \ No newline at end of file +9e6eae660a02303fd140dac5fbff82364f4120cd \ No newline at end of file diff --git a/src/select.c b/src/select.c index 39a0550f2a..8fbd4bb261 100644 --- a/src/select.c +++ b/src/select.c @@ -4153,7 +4153,7 @@ static int selectExpander(Walker *pWalker, Select *p){ /* A sub-query in the FROM clause of a SELECT */ assert( pSel!=0 ); assert( pFrom->pTab==0 ); - sqlite3WalkSelect(pWalker, pSel); + if( sqlite3WalkSelect(pWalker, pSel) ) return WRC_Abort; pFrom->pTab = pTab = sqlite3DbMallocZero(db, sizeof(Table)); if( pTab==0 ) return WRC_Abort; pTab->nRef = 1; diff --git a/test/fuzz2.test b/test/fuzz2.test index 4b3fb72e2d..51dfce140b 100644 --- a/test/fuzz2.test +++ b/test/fuzz2.test @@ -125,5 +125,15 @@ do_test fuzz2-6.4b { db eval {SELECT quote(t) FROM t0} } {NULL} +# Another test case discovered by Michal Zalewski, this on on 2015-01-22. +# Ticket 32b63d542433ca6757cd695aca42addf8ed67aa6 +# +do_test fuzz2-7.1 { + catchsql {select e.*,0 from(s,(L))e;} +} {1 {no such table: s}} +do_test fuzz2-7.2 { + catchsql {SELECT c.* FROM (a,b) AS c} +} {1 {no such table: a}} + finish_test From 81cda6460cb503680b96595b664c3bfbb89c9a59 Mon Sep 17 00:00:00 2001 From: drh Date: Sat, 24 Jan 2015 12:12:57 +0000 Subject: [PATCH 11/62] In the command-line shell, make sure stderr is unbuffered so that it automatically flushes. This has always been the case already for unix and on Windows when the output is a console, but apparently was not the case on Windows when the output was a pipe. FossilOrigin-Name: 2a9ea9b4a7d6904efb2112e32efe84123dfa75d7 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/shell.c | 1 + 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/manifest b/manifest index 45f02f62f5..4aa3c7b51d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Make\ssure\serrors\sin\sthe\sFROM\sclause\sof\sa\sSELECT\scause\sanalysis\sto\sabort\nand\sunwind\sthe\sstack\sbefore\sthose\serrors\shave\sa\schance\sto\smischief\nin\sthe\s"*"\scolumn-name\swildcard\sexpander.\sFix\sfor\sticket\s[32b63d542433ca67]. -D 2015-01-22T12:00:17.073 +C In\sthe\scommand-line\sshell,\smake\ssure\sstderr\sis\sunbuffered\sso\sthat\sit\s\nautomatically\sflushes.\s\sThis\shas\salways\sbeen\sthe\scase\salready\sfor\sunix\sand\non\sWindows\swhen\sthe\soutput\sis\sa\sconsole,\sbut\sapparently\swas\snot\sthe\scase\non\sWindows\swhen\sthe\soutput\swas\sa\spipe. +D 2015-01-24T12:12:57.403 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5407a688f4d77a05c18a8142be8ae5a2829dd610 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -230,7 +230,7 @@ F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c f6c46d3434439ab2084618d603e6d6dbeb0d6ada F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e F src/select.c 1f2087523007c42900ffcbdeaef06a23ad9329fc -F src/shell.c acdf311a7a6ed5d84454f9b13488a76fd57dbb72 +F src/shell.c 37c6d97399121f2d58b556e0c23d6226b7f55c70 F src/sqlite.h.in 9dfc99d6533d36d6a549c4f3f01cacc8be956ada F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h 17d487c3c91b0b8c584a32fbeb393f6f795eea7d @@ -1237,7 +1237,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P bd63bf882c5a925f921adc9cf7425d2e7950f0b2 -R cd80a044c23c0a2610d13740733ffe7d +P 9e6eae660a02303fd140dac5fbff82364f4120cd +R 87737ca6086b9b567816a3eff7fb8992 U drh -Z ca1958b398bcc4529c59936be19170f3 +Z c8a695af526558b07717da2883c990d4 diff --git a/manifest.uuid b/manifest.uuid index 79ff74b5cb..e38480380c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -9e6eae660a02303fd140dac5fbff82364f4120cd \ No newline at end of file +2a9ea9b4a7d6904efb2112e32efe84123dfa75d7 \ No newline at end of file diff --git a/src/shell.c b/src/shell.c index 0603268cc6..40d8cda167 100644 --- a/src/shell.c +++ b/src/shell.c @@ -4195,6 +4195,7 @@ int main(int argc, char **argv){ } #endif setBinaryMode(stdin); + setvbuf(stderr, 0, _IONBF, 0); /* Make sure stderr is unbuffered */ Argv0 = argv[0]; main_init(&data); stdin_is_interactive = isatty(0); From 1466e84187c15ee808a9f04e6da5a46086c4802b Mon Sep 17 00:00:00 2001 From: drh Date: Sun, 25 Jan 2015 20:19:53 +0000 Subject: [PATCH 12/62] The va_list argument cannot take on a NULL value and cannot be compared with NULL on some platforms (ex: ARM). So do not attempt to do so. FossilOrigin-Name: 1964e656b4b420e8d6a4ba12d270ed02db292b88 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/printf.c | 7 ------- 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/manifest b/manifest index 4aa3c7b51d..f00b0e5c05 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C In\sthe\scommand-line\sshell,\smake\ssure\sstderr\sis\sunbuffered\sso\sthat\sit\s\nautomatically\sflushes.\s\sThis\shas\salways\sbeen\sthe\scase\salready\sfor\sunix\sand\non\sWindows\swhen\sthe\soutput\sis\sa\sconsole,\sbut\sapparently\swas\snot\sthe\scase\non\sWindows\swhen\sthe\soutput\swas\sa\spipe. -D 2015-01-24T12:12:57.403 +C The\sva_list\sargument\scannot\stake\son\sa\sNULL\svalue\sand\scannot\sbe\scompared\swith\nNULL\son\ssome\splatforms\s(ex:\sARM).\s\sSo\sdo\snot\sattempt\sto\sdo\sso. +D 2015-01-25T20:19:53.843 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5407a688f4d77a05c18a8142be8ae5a2829dd610 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -225,7 +225,7 @@ F src/pcache.h b44658c9c932d203510279439d891a2a83e12ba8 F src/pcache1.c 1e77432b40b7d3288327d9cdf399dcdfd2b6d3bf F src/pragma.c ba149bbbc90783f84815636c509ced8eac11bbcf F src/prepare.c 173a5a499138451b2561614ecb87d78f9f4644b9 -F src/printf.c ea82bcb1b83273b4c67177c233c1f78c81fc42f9 +F src/printf.c 05edc41450d0eb2c05ef7db113bf32742ae65325 F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c f6c46d3434439ab2084618d603e6d6dbeb0d6ada F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e @@ -1237,7 +1237,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 9e6eae660a02303fd140dac5fbff82364f4120cd -R 87737ca6086b9b567816a3eff7fb8992 +P 2a9ea9b4a7d6904efb2112e32efe84123dfa75d7 +R c61f1e2c587edb0aaed1944a39bd65a6 U drh -Z c8a695af526558b07717da2883c990d4 +Z 4e92b2f1fb46383d9f32b9035c98c869 diff --git a/manifest.uuid b/manifest.uuid index e38480380c..d74709bc23 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -2a9ea9b4a7d6904efb2112e32efe84123dfa75d7 \ No newline at end of file +1964e656b4b420e8d6a4ba12d270ed02db292b88 \ No newline at end of file diff --git a/src/printf.c b/src/printf.c index 428c959cc7..8291002db8 100644 --- a/src/printf.c +++ b/src/printf.c @@ -212,13 +212,6 @@ void sqlite3VXPrintf( PrintfArguments *pArgList = 0; /* Arguments for SQLITE_PRINTF_SQLFUNC */ char buf[etBUFSIZE]; /* Conversion buffer */ -#ifdef SQLITE_ENABLE_API_ARMOR - if( ap==0 ){ - (void)SQLITE_MISUSE_BKPT; - sqlite3StrAccumReset(pAccum); - return; - } -#endif bufpt = 0; if( bFlags ){ if( (bArgList = (bFlags & SQLITE_PRINTF_SQLFUNC))!=0 ){ From a58d4a9612f0ca27344b0802169dca467faa13ca Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 27 Jan 2015 13:17:05 +0000 Subject: [PATCH 13/62] Fix a (almost always harmless) read past the end of a memory allocation that comes about because the Expr.pTab field is checked on an EXPR_REDUCEDSIZE Expr object before checking the Expr.op field to know that the Expr.pTab field is meaningless. FossilOrigin-Name: e098de691002a78270540430b0df1e120582b53f --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/expr.c | 4 ++-- test/misc1.test | 10 ++++++++++ 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index f00b0e5c05..26c720e3c2 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C The\sva_list\sargument\scannot\stake\son\sa\sNULL\svalue\sand\scannot\sbe\scompared\swith\nNULL\son\ssome\splatforms\s(ex:\sARM).\s\sSo\sdo\snot\sattempt\sto\sdo\sso. -D 2015-01-25T20:19:53.843 +C Fix\sa\s(almost\salways\sharmless)\sread\spast\sthe\send\sof\sa\smemory\sallocation\nthat\scomes\sabout\sbecause\sthe\sExpr.pTab\sfield\sis\schecked\son\san\nEXPR_REDUCEDSIZE\sExpr\sobject\sbefore\schecking\sthe\sExpr.op\sfield\sto\nknow\sthat\sthe\sExpr.pTab\sfield\sis\smeaningless. +D 2015-01-27T13:17:05.225 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5407a688f4d77a05c18a8142be8ae5a2829dd610 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -182,7 +182,7 @@ F src/complete.c 198a0066ba60ab06fc00fba1998d870a4d575463 F src/ctime.c 98f89724adc891a1a4c655bee04e33e716e05887 F src/date.c e4d50b3283696836ec1036b695ead9a19e37a5ac F src/delete.c bd1a91ddd247ce13004075251e0b7fe2bf9925ef -F src/expr.c 33a4518b2c786903cb185dbdc66e071ac38d467e +F src/expr.c abe930897ccafae3819fd2855cbc1b00c262fd12 F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb F src/fkey.c e0444b61bed271a76840cbe6182df93a9baa3f12 F src/func.c 6d3c4ebd72aa7923ce9b110a7dc15f9b8c548430 @@ -734,7 +734,7 @@ F test/minmax.test 42fbad0e81afaa6e0de41c960329f2b2c3526efd F test/minmax2.test b44bae787fc7b227597b01b0ca5575c7cb54d3bc F test/minmax3.test cc1e8b010136db0d01a6f2a29ba5a9f321034354 F test/minmax4.test 936941484ebdceb8adec7c86b6cd9b6e5e897c1f -F test/misc1.test 1201a037c24f982cc0e956cdaa34fcaf6439c417 +F test/misc1.test 4864f2834b203cad7f688df8a5f725e4bab08029 F test/misc2.test 00d7de54eda90e237fc9a38b9e5ccc769ebf6d4d F test/misc3.test cf3dda47d5dda3e53fc5804a100d3c82be736c9d F test/misc4.test 9c078510fbfff05a9869a0b6d8b86a623ad2c4f6 @@ -1237,7 +1237,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 2a9ea9b4a7d6904efb2112e32efe84123dfa75d7 -R c61f1e2c587edb0aaed1944a39bd65a6 +P 1964e656b4b420e8d6a4ba12d270ed02db292b88 +R 5d4aecd212970d14e41b3c7464003655 U drh -Z 4e92b2f1fb46383d9f32b9035c98c869 +Z 469718f07e1956a0a1c83ab2938852ec diff --git a/manifest.uuid b/manifest.uuid index d74709bc23..488022b3f9 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -1964e656b4b420e8d6a4ba12d270ed02db292b88 \ No newline at end of file +e098de691002a78270540430b0df1e120582b53f \ No newline at end of file diff --git a/src/expr.c b/src/expr.c index 64fb3c5fd4..25bd958ceb 100644 --- a/src/expr.c +++ b/src/expr.c @@ -132,9 +132,9 @@ CollSeq *sqlite3ExprCollSeq(Parse *pParse, Expr *pExpr){ pColl = sqlite3GetCollSeq(pParse, ENC(db), 0, p->u.zToken); break; } - if( p->pTab!=0 - && (op==TK_AGG_COLUMN || op==TK_COLUMN + if( (op==TK_AGG_COLUMN || op==TK_COLUMN || op==TK_REGISTER || op==TK_TRIGGER) + && p->pTab!=0 ){ /* op==TK_REGISTER && p->pTab!=0 happens when pExpr was originally ** a TK_COLUMN but was previously evaluated and cached in a register */ diff --git a/test/misc1.test b/test/misc1.test index 173b77d637..d18223e67b 100644 --- a/test/misc1.test +++ b/test/misc1.test @@ -621,4 +621,14 @@ do_test misc1-19.2 { set fault_callbacks } {0} +# 2015-01-26: Valgrind-detected over-read. +# Reported on sqlite-users@sqlite.org by Michal Zalewski. Found by afl-fuzz +# presumably. +# +do_execsql_test misc1-20.1 { + CREATE TABLE t0(x INTEGER DEFAULT(0==0) NOT NULL); + REPLACE INTO t0(x) VALUES(''); + SELECT rowid, quote(x) FROM t0; +} {1 ''} + finish_test From 18f6ff9eb7db02356102283c28053b0a602f55d7 Mon Sep 17 00:00:00 2001 From: dan Date: Tue, 27 Jan 2015 18:43:02 +0000 Subject: [PATCH 14/62] Improve the performance of fts3/4 queries that use the OR operator and at least one auxiliary fts function. FossilOrigin-Name: 245e8730451fbdc1c729beff7295c452df604009 --- ext/fts3/fts3.c | 116 +++++++++++++++++++--------------------- ext/fts3/fts3Int.h | 5 ++ ext/fts3/fts3_snippet.c | 52 +++++++++--------- manifest | 18 +++---- manifest.uuid | 2 +- 5 files changed, 96 insertions(+), 97 deletions(-) diff --git a/ext/fts3/fts3.c b/ext/fts3/fts3.c index fe28eb2cfe..ec9f0d3181 100644 --- a/ext/fts3/fts3.c +++ b/ext/fts3/fts3.c @@ -5020,6 +5020,22 @@ static void fts3EvalNextRow( } pExpr->iDocid = pLeft->iDocid; pExpr->bEof = (pLeft->bEof || pRight->bEof); + if( pExpr->eType==FTSQUERY_NEAR && pExpr->bEof ){ + if( pRight->pPhrase && pRight->pPhrase->doclist.aAll ){ + Fts3Doclist *pDl = &pRight->pPhrase->doclist; + while( *pRc==SQLITE_OK && pRight->bEof==0 ){ + memset(pDl->pList, 0, pDl->nList); + fts3EvalNextRow(pCsr, pRight, pRc); + } + } + if( pLeft->pPhrase && pLeft->pPhrase->doclist.aAll ){ + Fts3Doclist *pDl = &pLeft->pPhrase->doclist; + while( *pRc==SQLITE_OK && pLeft->bEof==0 ){ + memset(pDl->pList, 0, pDl->nList); + fts3EvalNextRow(pCsr, pLeft, pRc); + } + } + } } break; } @@ -5392,6 +5408,7 @@ static void fts3EvalRestart( } pPhrase->doclist.pNextDocid = 0; pPhrase->doclist.iDocid = 0; + pPhrase->pOrPoslist = 0; } pExpr->iDocid = 0; @@ -5637,6 +5654,7 @@ int sqlite3Fts3EvalPhrasePoslist( iDocid = pExpr->iDocid; pIter = pPhrase->doclist.pList; if( iDocid!=pCsr->iPrevId || pExpr->bEof ){ + int rc = SQLITE_OK; int bDescDoclist = pTab->bDescIdx; /* For DOCID_CMP macro */ int iMul; /* +1 if csr dir matches index dir, else -1 */ int bOr = 0; @@ -5662,72 +5680,43 @@ int sqlite3Fts3EvalPhrasePoslist( ** an incremental phrase. Load the entire doclist for the phrase ** into memory in this case. */ if( pPhrase->bIncr ){ - int rc = SQLITE_OK; - int bEofSave = pExpr->bEof; - fts3EvalRestart(pCsr, pExpr, &rc); - while( rc==SQLITE_OK && !pExpr->bEof ){ - fts3EvalNextRow(pCsr, pExpr, &rc); - if( bEofSave==0 && pExpr->iDocid==iDocid ) break; + int bEofSave = pNear->bEof; + fts3EvalRestart(pCsr, pNear, &rc); + while( rc==SQLITE_OK && !pNear->bEof ){ + fts3EvalNextRow(pCsr, pNear, &rc); + if( bEofSave==0 && pNear->iDocid==iDocid ) break; } - pIter = pPhrase->doclist.pList; assert( rc!=SQLITE_OK || pPhrase->bIncr==0 ); - if( rc!=SQLITE_OK ) return rc; } - - iMul = ((pCsr->bDesc==bDescDoclist) ? 1 : -1); - while( bTreeEof==1 - && pNear->bEof==0 - && (DOCID_CMP(pNear->iDocid, pCsr->iPrevId) * iMul)<0 - ){ - int rc = SQLITE_OK; - fts3EvalNextRow(pCsr, pExpr, &rc); - if( rc!=SQLITE_OK ) return rc; - iDocid = pExpr->iDocid; - pIter = pPhrase->doclist.pList; - } - - bEof = (pPhrase->doclist.nAll==0); - assert( bDescDoclist==0 || bDescDoclist==1 ); - assert( pCsr->bDesc==0 || pCsr->bDesc==1 ); - - if( bEof==0 ){ - if( pCsr->bDesc==bDescDoclist ){ - int dummy; - if( pNear->bEof ){ - /* This expression is already at EOF. So position it to point to the - ** last entry in the doclist at pPhrase->doclist.aAll[]. Variable - ** iDocid is already set for this entry, so all that is required is - ** to set pIter to point to the first byte of the last position-list - ** in the doclist. - ** - ** It would also be correct to set pIter and iDocid to zero. In - ** this case, the first call to sqltie3Fts4DoclistPrev() below - ** would also move the iterator to point to the last entry in the - ** doclist. However, this is expensive, as to do so it has to - ** iterate through the entire doclist from start to finish (since - ** it does not know the docid for the last entry). */ - pIter = &pPhrase->doclist.aAll[pPhrase->doclist.nAll-1]; - fts3ReversePoslist(pPhrase->doclist.aAll, &pIter); - } - while( (pIter==0 || DOCID_CMP(iDocid, pCsr->iPrevId)>0 ) && bEof==0 ){ - sqlite3Fts3DoclistPrev( - bDescDoclist, pPhrase->doclist.aAll, pPhrase->doclist.nAll, - &pIter, &iDocid, &dummy, &bEof - ); - } - }else{ - if( pNear->bEof ){ - pIter = 0; - iDocid = 0; - } - while( (pIter==0 || DOCID_CMP(iDocid, pCsr->iPrevId)<0 ) && bEof==0 ){ - sqlite3Fts3DoclistNext( - bDescDoclist, pPhrase->doclist.aAll, pPhrase->doclist.nAll, - &pIter, &iDocid, &bEof - ); - } + if( bTreeEof ){ + while( rc==SQLITE_OK && !pNear->bEof ){ + fts3EvalNextRow(pCsr, pNear, &rc); } } + if( rc!=SQLITE_OK ) return rc; + + pIter = pPhrase->pOrPoslist; + iDocid = pPhrase->iOrDocid; + if( pCsr->bDesc==bDescDoclist ){ + bEof = (pIter >= (pPhrase->doclist.aAll + pPhrase->doclist.nAll)); + while( (pIter==0 || DOCID_CMP(iDocid, pCsr->iPrevId)<0 ) && bEof==0 ){ + sqlite3Fts3DoclistNext( + bDescDoclist, pPhrase->doclist.aAll, pPhrase->doclist.nAll, + &pIter, &iDocid, &bEof + ); + } + }else{ + bEof = !pPhrase->doclist.nAll || (pIter && pIter<=pPhrase->doclist.aAll); + while( (pIter==0 || DOCID_CMP(iDocid, pCsr->iPrevId)>0 ) && bEof==0 ){ + int dummy; + sqlite3Fts3DoclistPrev( + bDescDoclist, pPhrase->doclist.aAll, pPhrase->doclist.nAll, + &pIter, &iDocid, &dummy, &bEof + ); + } + } + pPhrase->pOrPoslist = pIter; + pPhrase->iOrDocid = iDocid; if( bEof || iDocid!=pCsr->iPrevId ) pIter = 0; } @@ -5741,10 +5730,13 @@ int sqlite3Fts3EvalPhrasePoslist( } while( iThispExpr, fts3SnippetFindPositions, (void *)&sIter); + rc = fts3ExprIterate(pCsr->pExpr, fts3SnippetFindPositions, (void *)&sIter); + if( rc==SQLITE_OK ){ - /* Set the *pmSeen output variable. */ - for(i=0; iiCol = iCol; - while( !fts3SnippetNextCandidate(&sIter) ){ - int iPos; - int iScore; - u64 mCover; - u64 mHighlight; - fts3SnippetDetails(&sIter, mCovered, &iPos, &iScore, &mCover, &mHighlight); - assert( iScore>=0 ); - if( iScore>iBestScore ){ - pFragment->iPos = iPos; - pFragment->hlmask = mHighlight; - pFragment->covered = mCover; - iBestScore = iScore; + /* Loop through all candidate snippets. Store the best snippet in + ** *pFragment. Store its associated 'score' in iBestScore. + */ + pFragment->iCol = iCol; + while( !fts3SnippetNextCandidate(&sIter) ){ + int iPos; + int iScore; + u64 mCover; + u64 mHighlite; + fts3SnippetDetails(&sIter, mCovered, &iPos, &iScore, &mCover,&mHighlite); + assert( iScore>=0 ); + if( iScore>iBestScore ){ + pFragment->iPos = iPos; + pFragment->hlmask = mHighlite; + pFragment->covered = mCover; + iBestScore = iScore; + } } - } + *piScore = iBestScore; + } sqlite3_free(sIter.aPhrase); - *piScore = iBestScore; - return SQLITE_OK; + return rc; } diff --git a/manifest b/manifest index 26c720e3c2..37143105d6 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\s(almost\salways\sharmless)\sread\spast\sthe\send\sof\sa\smemory\sallocation\nthat\scomes\sabout\sbecause\sthe\sExpr.pTab\sfield\sis\schecked\son\san\nEXPR_REDUCEDSIZE\sExpr\sobject\sbefore\schecking\sthe\sExpr.op\sfield\sto\nknow\sthat\sthe\sExpr.pTab\sfield\sis\smeaningless. -D 2015-01-27T13:17:05.225 +C Improve\sthe\sperformance\sof\sfts3/4\squeries\sthat\suse\sthe\sOR\soperator\sand\sat\sleast\sone\sauxiliary\sfts\sfunction. +D 2015-01-27T18:43:02.971 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5407a688f4d77a05c18a8142be8ae5a2829dd610 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -78,16 +78,16 @@ F ext/fts3/README.content fdc666a70d5257a64fee209f97cf89e0e6e32b51 F ext/fts3/README.syntax a19711dc5458c20734b8e485e75fb1981ec2427a F ext/fts3/README.tokenizers e0a8b81383ea60d0334d274fadf305ea14a8c314 F ext/fts3/README.txt 8c18f41574404623b76917b9da66fcb0ab38328d -F ext/fts3/fts3.c 5c464816508e40feb3c61f1f5566551764698fc8 +F ext/fts3/fts3.c 845f20440dacac6e09f5c7735205609b9a86536b F ext/fts3/fts3.h 3a10a0af180d502cecc50df77b1b22df142817fe -F ext/fts3/fts3Int.h 53d4eca1fb23eab00681fb028fb82eb5705c1e21 +F ext/fts3/fts3Int.h 394858c12a17740f7a1f6bd372c4606d4425a8d1 F ext/fts3/fts3_aux.c 5c211e17a64885faeb16b9ba7772f9d5445c2365 F ext/fts3/fts3_expr.c 40123785eaa3ebd4c45c9b23407cc44ac0c49905 F ext/fts3/fts3_hash.c 29b986e43f4e9dd40110eafa377dc0d63c422c60 F ext/fts3/fts3_hash.h 39cf6874dc239d6b4e30479b1975fe5b22a3caaf F ext/fts3/fts3_icu.c e319e108661147bcca8dd511cd562f33a1ba81b5 F ext/fts3/fts3_porter.c 3565faf04b626cddf85f03825e86056a4562c009 -F ext/fts3/fts3_snippet.c 51beb5c1498176fd9caccaf1c75b55cb803a985a +F ext/fts3/fts3_snippet.c 55c126e07158b2a705f52dee2cdc57208d3e999a F ext/fts3/fts3_term.c a521f75132f9a495bdca1bdd45949b3191c52763 F ext/fts3/fts3_test.c 8a3a78c4458b2d7c631fcf4b152a5cd656fa7038 F ext/fts3/fts3_tokenize_vtab.c becc661223db7898b213f9e8a23d75bac02408c9 @@ -1237,7 +1237,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 1964e656b4b420e8d6a4ba12d270ed02db292b88 -R 5d4aecd212970d14e41b3c7464003655 -U drh -Z 469718f07e1956a0a1c83ab2938852ec +P e098de691002a78270540430b0df1e120582b53f +R 097e5fd012edfb2d64381b5476250a91 +U dan +Z 72e3dfc5e16e519968e47157e86381d8 diff --git a/manifest.uuid b/manifest.uuid index 488022b3f9..771d94784d 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -e098de691002a78270540430b0df1e120582b53f \ No newline at end of file +245e8730451fbdc1c729beff7295c452df604009 \ No newline at end of file From 6f0138e89ecaac3561fbfa297417adbe0a49798d Mon Sep 17 00:00:00 2001 From: dan Date: Tue, 27 Jan 2015 19:01:26 +0000 Subject: [PATCH 15/62] Fix a bug in the fts3 snippet() function causing it to omit leading separator characters from snippets that begin with the first token in a column. FossilOrigin-Name: adc9283dd9bc3a6463f8c4fe23dd58a3712c349d --- ext/fts3/fts3_snippet.c | 8 ++++++-- manifest | 14 +++++++------- manifest.uuid | 2 +- test/fts3snippet.test | 19 +++++++++++++++++++ 4 files changed, 33 insertions(+), 10 deletions(-) diff --git a/ext/fts3/fts3_snippet.c b/ext/fts3/fts3_snippet.c index 93ee86f6af..e40750502b 100644 --- a/ext/fts3/fts3_snippet.c +++ b/ext/fts3/fts3_snippet.c @@ -682,8 +682,12 @@ static int fts3SnippetText( ** required. They are required if (a) this is not the first fragment, ** or (b) this fragment does not begin at position 0 of its column. */ - if( rc==SQLITE_OK && (iPos>0 || iFragment>0) ){ - rc = fts3StringAppend(pOut, zEllipsis, -1); + if( rc==SQLITE_OK ){ + if( iPos>0 || iFragment>0 ){ + rc = fts3StringAppend(pOut, zEllipsis, -1); + }else if( iBegin ){ + rc = fts3StringAppend(pOut, zDoc, iBegin); + } } if( rc!=SQLITE_OK || iCurrentone two three]}} +do_execsql_test 3.2 { + SELECT snippet(t3) FROM t3 WHERE t3 MATCH 'two'; +} {{[one two three]}} +do_execsql_test 3.3 { + SELECT snippet(t3) FROM t3 WHERE t3 MATCH 'three'; +} {{[one two three]}} +do_execsql_test 3.4 { + SELECT snippet(t3) FROM t3 WHERE t3 MATCH 'one OR two OR three'; +} {{[one two three]}} + set sqlite_fts3_enable_parentheses 0 finish_test + From e4a0d79b8a0cd9cb4a3aa63a48402dd936454ded Mon Sep 17 00:00:00 2001 From: mistachkin Date: Tue, 27 Jan 2015 21:24:33 +0000 Subject: [PATCH 16/62] Fix harmless compiler warnings. FossilOrigin-Name: e7d2ec048c88237c124fbe598f8f7e950d43d90f --- ext/fts3/fts3.c | 1 - manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/shell.c | 4 ++-- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/ext/fts3/fts3.c b/ext/fts3/fts3.c index ec9f0d3181..a1ea533a89 100644 --- a/ext/fts3/fts3.c +++ b/ext/fts3/fts3.c @@ -5656,7 +5656,6 @@ int sqlite3Fts3EvalPhrasePoslist( if( iDocid!=pCsr->iPrevId || pExpr->bEof ){ int rc = SQLITE_OK; int bDescDoclist = pTab->bDescIdx; /* For DOCID_CMP macro */ - int iMul; /* +1 if csr dir matches index dir, else -1 */ int bOr = 0; u8 bEof = 0; u8 bTreeEof = 0; diff --git a/manifest b/manifest index 6c3a6a6028..5e1d55e7c7 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sbug\sin\sthe\sfts3\ssnippet()\sfunction\scausing\sit\sto\somit\sleading\sseparator\scharacters\sfrom\ssnippets\sthat\sbegin\swith\sthe\sfirst\stoken\sin\sa\scolumn. -D 2015-01-27T19:01:26.607 +C Fix\sharmless\scompiler\swarnings. +D 2015-01-27T21:24:33.191 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5407a688f4d77a05c18a8142be8ae5a2829dd610 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -78,7 +78,7 @@ F ext/fts3/README.content fdc666a70d5257a64fee209f97cf89e0e6e32b51 F ext/fts3/README.syntax a19711dc5458c20734b8e485e75fb1981ec2427a F ext/fts3/README.tokenizers e0a8b81383ea60d0334d274fadf305ea14a8c314 F ext/fts3/README.txt 8c18f41574404623b76917b9da66fcb0ab38328d -F ext/fts3/fts3.c 845f20440dacac6e09f5c7735205609b9a86536b +F ext/fts3/fts3.c 3b2f792afc04d01d387455932428c8f9ae861cc5 F ext/fts3/fts3.h 3a10a0af180d502cecc50df77b1b22df142817fe F ext/fts3/fts3Int.h 394858c12a17740f7a1f6bd372c4606d4425a8d1 F ext/fts3/fts3_aux.c 5c211e17a64885faeb16b9ba7772f9d5445c2365 @@ -230,7 +230,7 @@ F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c f6c46d3434439ab2084618d603e6d6dbeb0d6ada F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e F src/select.c 1f2087523007c42900ffcbdeaef06a23ad9329fc -F src/shell.c 37c6d97399121f2d58b556e0c23d6226b7f55c70 +F src/shell.c efd35900484377d2159189968c3445afefee3e41 F src/sqlite.h.in 9dfc99d6533d36d6a549c4f3f01cacc8be956ada F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h 17d487c3c91b0b8c584a32fbeb393f6f795eea7d @@ -1237,7 +1237,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 245e8730451fbdc1c729beff7295c452df604009 -R 9b90e66d84773104aa9a7aba84baf66d -U dan -Z f8bb39ab94c5b09db26ae8d1068b8a66 +P adc9283dd9bc3a6463f8c4fe23dd58a3712c349d +R 57729c2b510493b06603a65c6ea41133 +U mistachkin +Z 7155fc25674fe331bcb8023f01301b6b diff --git a/manifest.uuid b/manifest.uuid index 11a99a20cf..fe72374448 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -adc9283dd9bc3a6463f8c4fe23dd58a3712c349d \ No newline at end of file +e7d2ec048c88237c124fbe598f8f7e950d43d90f \ No newline at end of file diff --git a/src/shell.c b/src/shell.c index 40d8cda167..f9a360c7b5 100644 --- a/src/shell.c +++ b/src/shell.c @@ -113,11 +113,11 @@ extern int pclose(FILE*); ** routines take care of that. */ #if defined(_WIN32) || defined(WIN32) -static setBinaryMode(FILE *out){ +static void setBinaryMode(FILE *out){ fflush(out); _setmode(_fileno(out), _O_BINARY); } -static setTextMode(FILE *out){ +static void setTextMode(FILE *out){ fflush(out); _setmode(_fileno(out), _O_TEXT); } From 88392bf3ce405e352025d7707a7c7050614cefe3 Mon Sep 17 00:00:00 2001 From: dan Date: Thu, 29 Jan 2015 11:52:22 +0000 Subject: [PATCH 17/62] Optimize range constraints on the rowid column of fts3/4 tables even if there is no MATCH clause in the query. FossilOrigin-Name: 85dc12625d300fe48f3c096f54ebcb8b6ef4e30a --- ext/fts3/fts3.c | 15 +++++++--- manifest | 16 +++++----- manifest.uuid | 2 +- test/fts3query.test | 72 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 92 insertions(+), 13 deletions(-) diff --git a/ext/fts3/fts3.c b/ext/fts3/fts3.c index a1ea533a89..a31d3f13fe 100644 --- a/ext/fts3/fts3.c +++ b/ext/fts3/fts3.c @@ -3164,10 +3164,17 @@ static int fts3FilterMethod( ** row by docid. */ if( eSearch==FTS3_FULLSCAN_SEARCH ){ - zSql = sqlite3_mprintf( - "SELECT %s ORDER BY rowid %s", - p->zReadExprlist, (pCsr->bDesc ? "DESC" : "ASC") - ); + if( pDocidGe || pDocidLe ){ + zSql = sqlite3_mprintf( + "SELECT %s WHERE rowid BETWEEN %lld AND %lld ORDER BY rowid %s", + p->zReadExprlist, pCsr->iMinDocid, pCsr->iMaxDocid, + (pCsr->bDesc ? "DESC" : "ASC") + ); + }else{ + zSql = sqlite3_mprintf("SELECT %s ORDER BY rowid %s", + p->zReadExprlist, (pCsr->bDesc ? "DESC" : "ASC") + ); + } if( zSql ){ rc = sqlite3_prepare_v2(p->db, zSql, -1, &pCsr->pStmt, 0); sqlite3_free(zSql); diff --git a/manifest b/manifest index 5e1d55e7c7..2b2c56f7bc 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sharmless\scompiler\swarnings. -D 2015-01-27T21:24:33.191 +C Optimize\srange\sconstraints\son\sthe\srowid\scolumn\sof\sfts3/4\stables\seven\sif\sthere\sis\sno\sMATCH\sclause\sin\sthe\squery. +D 2015-01-29T11:52:22.452 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5407a688f4d77a05c18a8142be8ae5a2829dd610 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -78,7 +78,7 @@ F ext/fts3/README.content fdc666a70d5257a64fee209f97cf89e0e6e32b51 F ext/fts3/README.syntax a19711dc5458c20734b8e485e75fb1981ec2427a F ext/fts3/README.tokenizers e0a8b81383ea60d0334d274fadf305ea14a8c314 F ext/fts3/README.txt 8c18f41574404623b76917b9da66fcb0ab38328d -F ext/fts3/fts3.c 3b2f792afc04d01d387455932428c8f9ae861cc5 +F ext/fts3/fts3.c 56a78f7e65e9e59bd0e75a1e10ce406f62034ca8 F ext/fts3/fts3.h 3a10a0af180d502cecc50df77b1b22df142817fe F ext/fts3/fts3Int.h 394858c12a17740f7a1f6bd372c4606d4425a8d1 F ext/fts3/fts3_aux.c 5c211e17a64885faeb16b9ba7772f9d5445c2365 @@ -590,7 +590,7 @@ F test/fts3matchinfo.test 58544fa4d254000fa4e7f494b0a832f7ba61d45e F test/fts3near.test 7e3354d46f155a822b59c0e957fd2a70c1d7e905 F test/fts3prefix.test b36d4f00b128a51e7b386cc013a874246d9d7dc1 F test/fts3prefix2.test e1f0a822ca661dced7f12ce392e14eaf65609dce -F test/fts3query.test 4fefd43ff24993bc2c9b2778f2bec0cc7629e7ed +F test/fts3query.test d81ffb0ab1d4e1a2a330b8eb1e160b60603f4745 F test/fts3rnd.test 1320d8826a845e38a96e769562bf83d7a92a15d0 F test/fts3shared.test 57e26a801f21027b7530da77db54286a6fe4997e F test/fts3snippet.test 03c2f3be7d3b7c8bb105ed237f204833392bd57f @@ -1237,7 +1237,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P adc9283dd9bc3a6463f8c4fe23dd58a3712c349d -R 57729c2b510493b06603a65c6ea41133 -U mistachkin -Z 7155fc25674fe331bcb8023f01301b6b +P e7d2ec048c88237c124fbe598f8f7e950d43d90f +R e192a378398ddf2aeb616257a71bd844 +U dan +Z 0e830c66fc49965a9a24bd9be18f84a6 diff --git a/manifest.uuid b/manifest.uuid index fe72374448..9133dd0737 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -e7d2ec048c88237c124fbe598f8f7e950d43d90f \ No newline at end of file +85dc12625d300fe48f3c096f54ebcb8b6ef4e30a \ No newline at end of file diff --git a/test/fts3query.test b/test/fts3query.test index 2d12351ae9..0b3c2ce1bd 100644 --- a/test/fts3query.test +++ b/test/fts3query.test @@ -208,5 +208,77 @@ do_select_tests 6.2 { {{ZZZthe hand XXXgesturesYYY (called beatsZZZ}} } +# Test some range queries on the rowid field. +# +do_execsql_test 7.1 { + CREATE VIRTUAL TABLE ft4 USING fts4(x); + CREATE TABLE t4(x); +} + +set SMALLINT -9223372036854775808 +set LARGEINT 9223372036854775807 +do_test 7.2 { + db transaction { + foreach {iFirst nEntry} [subst { + 0 100 + $SMALLINT 100 + [expr $LARGEINT - 99] 100 + }] { + for {set i 0} {$i < $nEntry} {incr i} { + set iRowid [expr $i + $iFirst] + execsql { + INSERT INTO ft4(rowid, x) VALUES($iRowid, 'x y z'); + INSERT INTO t4(rowid, x) VALUES($iRowid, 'x y z'); + } + } + } + } +} {} + +foreach {tn iFirst iLast} [subst { + 1 5 10 + 2 $SMALLINT [expr $SMALLINT+5] + 3 $SMALLINT [expr $SMALLINT+50] + 4 [expr $LARGEINT-5] $LARGEINT + 5 $LARGEINT $LARGEINT + 6 $SMALLINT $LARGEINT + 7 $SMALLINT $SMALLINT + 8 $LARGEINT $SMALLINT +}] { + set res [db eval { + SELECT rowid FROM t4 WHERE rowid BETWEEN $iFirst AND $iLast + } ] + + do_execsql_test 7.2.$tn.1.[llength $res] { + SELECT rowid FROM ft4 WHERE rowid BETWEEN $iFirst AND $iLast + } $res + do_execsql_test 7.2.$tn.2.[llength $res] { + SELECT rowid FROM ft4 WHERE rowid BETWEEN $iFirst AND $iLast + ORDER BY rowid DESC + } [lsort -decr -integer $res] +} + +foreach ii [db eval {SELECT rowid FROM t4}] { + set res1 [db eval {SELECT rowid FROM t4 WHERE rowid > $ii}] + set res2 [db eval {SELECT rowid FROM t4 WHERE rowid < $ii}] + + do_execsql_test 7.3.$ii.1 { + SELECT rowid FROM ft4 WHERE rowid > $ii + } $res1 + + do_execsql_test 7.3.$ii.2 { + SELECT rowid FROM ft4 WHERE rowid < $ii + } $res2 + + do_execsql_test 7.3.$ii.3 { + SELECT rowid FROM ft4 WHERE rowid > $ii ORDER BY rowid DESC + } [lsort -integer -decr $res1] + + do_execsql_test 7.3.$ii.4 { + SELECT rowid FROM ft4 WHERE rowid < $ii ORDER BY rowid DESC + } [lsort -integer -decr $res2] +} finish_test + + From 8964b345512612175a8cbdcf636a402f54fea696 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 29 Jan 2015 17:54:52 +0000 Subject: [PATCH 18/62] Add the INITMODE test-control. FossilOrigin-Name: 5940af8e7872209ce41feb958643b23f7e55d258 --- manifest | 21 ++++++++++++--------- manifest.uuid | 2 +- src/main.c | 12 ++++++++++++ src/shell.c | 13 +++++++++++++ src/sqlite.h.in | 3 ++- 5 files changed, 40 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index 2b2c56f7bc..776fb5e978 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Optimize\srange\sconstraints\son\sthe\srowid\scolumn\sof\sfts3/4\stables\seven\sif\sthere\sis\sno\sMATCH\sclause\sin\sthe\squery. -D 2015-01-29T11:52:22.452 +C Add\sthe\sINITMODE\stest-control. +D 2015-01-29T17:54:52.194 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5407a688f4d77a05c18a8142be8ae5a2829dd610 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -195,7 +195,7 @@ F src/journal.c b4124532212b6952f42eb2c12fa3c25701d8ba8d F src/legacy.c ba1863ea58c4c840335a84ec276fc2b25e22bc4e F src/lempar.c 7274c97d24bb46631e504332ccd3bd1b37841770 F src/loadext.c 86bd4e2fccd520b748cba52492ab60c4a770f660 -F src/main.c 05bf368c934cc73d02906030846eb4d1818c10f7 +F src/main.c b0a41ca397083b137b98e6abb829c21611665d07 F src/malloc.c 740db54387204c9a2eb67c6d98e68b08e9ef4eab F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645 F src/mem1.c abe6ee469b6c5a35c7f22bfeb9c9bac664a1c987 @@ -230,8 +230,8 @@ F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c f6c46d3434439ab2084618d603e6d6dbeb0d6ada F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e F src/select.c 1f2087523007c42900ffcbdeaef06a23ad9329fc -F src/shell.c efd35900484377d2159189968c3445afefee3e41 -F src/sqlite.h.in 9dfc99d6533d36d6a549c4f3f01cacc8be956ada +F src/shell.c ed7cf7c29fb1a23d47179affc89cb447868fc976 +F src/sqlite.h.in 6910064681444efb5c467472499b56bb6bcee0f4 F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h 17d487c3c91b0b8c584a32fbeb393f6f795eea7d F src/sqliteInt.h eaf210295b551d4e40e622aec1b2261c0b28f844 @@ -1237,7 +1237,10 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P e7d2ec048c88237c124fbe598f8f7e950d43d90f -R e192a378398ddf2aeb616257a71bd844 -U dan -Z 0e830c66fc49965a9a24bd9be18f84a6 +P 85dc12625d300fe48f3c096f54ebcb8b6ef4e30a +R fe787287eb356b79eb9ba31c0e138e4f +T *branch * initmode-testctrl +T *sym-initmode-testctrl * +T -sym-trunk * +U drh +Z e02e8497217bad1b69deabc72f8cd27d diff --git a/manifest.uuid b/manifest.uuid index 9133dd0737..60ead15a06 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -85dc12625d300fe48f3c096f54ebcb8b6ef4e30a \ No newline at end of file +5940af8e7872209ce41feb958643b23f7e55d258 \ No newline at end of file diff --git a/src/main.c b/src/main.c index 8cf16b001a..26cf24a44a 100644 --- a/src/main.c +++ b/src/main.c @@ -3597,6 +3597,18 @@ int sqlite3_test_control(int op, ...){ if( sqlite3GlobalConfig.isInit==0 ) rc = SQLITE_ERROR; break; } + + /* sqlite3_test_control(SQLITE_TESTCTRL_INITMODE, db, busy, iDb, newTnum); + ** + ** Set the db->init.busy, db->init.iDb, and db->init.tnum fields. + */ + case SQLITE_TESTCTRL_INITMODE: { + sqlite3 *db = va_arg(ap, sqlite3*); + db->init.busy = va_arg(ap,int); + db->init.iDb = va_arg(ap,int); + db->init.newTnum = va_arg(ap,int); + break; + } } va_end(ap); #endif /* SQLITE_OMIT_BUILTIN_TEST */ diff --git a/src/shell.c b/src/shell.c index f9a360c7b5..1a191e0fd0 100644 --- a/src/shell.c +++ b/src/shell.c @@ -3536,6 +3536,7 @@ static int do_meta_command(char *zLine, ShellState *p){ { "scratchmalloc", SQLITE_TESTCTRL_SCRATCHMALLOC }, { "byteorder", SQLITE_TESTCTRL_BYTEORDER }, { "never_corrupt", SQLITE_TESTCTRL_NEVER_CORRUPT }, + { "initmode", SQLITE_TESTCTRL_INITMODE }, }; int testctrl = -1; int rc = 0; @@ -3628,6 +3629,18 @@ static int do_meta_command(char *zLine, ShellState *p){ break; #endif + case SQLITE_TESTCTRL_INITMODE: + if( nArg==5 ){ + rc = sqlite3_test_control(testctrl, p->db, + integerValue(azArg[2]), + integerValue(azArg[3]), + integerValue(azArg[4])); + }else{ + fprintf(stderr,"Usage: .testctrl initmode fBusy iDb newTnum\n"); + rc = 1; + } + break; + case SQLITE_TESTCTRL_BITVEC_TEST: case SQLITE_TESTCTRL_FAULT_INSTALL: case SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS: diff --git a/src/sqlite.h.in b/src/sqlite.h.in index f2e802eb00..722b9235a2 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -6260,7 +6260,8 @@ int sqlite3_test_control(int op, ...); #define SQLITE_TESTCTRL_BYTEORDER 22 #define SQLITE_TESTCTRL_ISINIT 23 #define SQLITE_TESTCTRL_SORTER_MMAP 24 -#define SQLITE_TESTCTRL_LAST 24 +#define SQLITE_TESTCTRL_INITMODE 25 +#define SQLITE_TESTCTRL_LAST 25 /* ** CAPI3REF: SQLite Runtime Status From 6267920b095d5483bc96eb17fc5f918da8735fa2 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 29 Jan 2015 18:38:05 +0000 Subject: [PATCH 19/62] Split up the SRC variable in Makefile.msc to avoid over-long cmd.exe commands when TOP is set to a long pathname. FossilOrigin-Name: 7d70ac65c16f08832a1f0fc4dec0f62a17cbcc85 --- Makefile.msc | 30 ++++++++++++++++++------------ manifest | 14 +++++++------- manifest.uuid | 2 +- 3 files changed, 26 insertions(+), 20 deletions(-) diff --git a/Makefile.msc b/Makefile.msc index 1908794840..f480b30058 100644 --- a/Makefile.msc +++ b/Makefile.msc @@ -714,7 +714,7 @@ LIBRESOBJS = # All of the source code files. # -SRC = \ +SRC1 = \ $(TOP)\src\alter.c \ $(TOP)\src\analyze.c \ $(TOP)\src\attach.c \ @@ -764,7 +764,8 @@ SRC = \ $(TOP)\src\os_setup.h \ $(TOP)\src\os_unix.c \ $(TOP)\src\os_win.c \ - $(TOP)\src\os_win.h \ + $(TOP)\src\os_win.h +SRC2 = \ $(TOP)\src\pager.c \ $(TOP)\src\pager.h \ $(TOP)\src\parse.y \ @@ -811,15 +812,14 @@ SRC = \ # Source code for extensions # -SRC = $(SRC) \ +SRC3 = \ $(TOP)\ext\fts1\fts1.c \ $(TOP)\ext\fts1\fts1.h \ $(TOP)\ext\fts1\fts1_hash.c \ $(TOP)\ext\fts1\fts1_hash.h \ $(TOP)\ext\fts1\fts1_porter.c \ $(TOP)\ext\fts1\fts1_tokenizer.h \ - $(TOP)\ext\fts1\fts1_tokenizer1.c -SRC = $(SRC) \ + $(TOP)\ext\fts1\fts1_tokenizer1.c \ $(TOP)\ext\fts2\fts2.c \ $(TOP)\ext\fts2\fts2.h \ $(TOP)\ext\fts2\fts2_hash.c \ @@ -829,7 +829,7 @@ SRC = $(SRC) \ $(TOP)\ext\fts2\fts2_tokenizer.h \ $(TOP)\ext\fts2\fts2_tokenizer.c \ $(TOP)\ext\fts2\fts2_tokenizer1.c -SRC = $(SRC) \ +SRC4 = \ $(TOP)\ext\fts3\fts3.c \ $(TOP)\ext\fts3\fts3.h \ $(TOP)\ext\fts3\fts3Int.h \ @@ -846,18 +846,16 @@ SRC = $(SRC) \ $(TOP)\ext\fts3\fts3_tokenize_vtab.c \ $(TOP)\ext\fts3\fts3_unicode.c \ $(TOP)\ext\fts3\fts3_unicode2.c \ - $(TOP)\ext\fts3\fts3_write.c -SRC = $(SRC) \ + $(TOP)\ext\fts3\fts3_write.c \ $(TOP)\ext\icu\sqliteicu.h \ - $(TOP)\ext\icu\icu.c -SRC = $(SRC) \ + $(TOP)\ext\icu\icu.c \ $(TOP)\ext\rtree\rtree.h \ $(TOP)\ext\rtree\rtree.c # Generated source code files # -SRC = $(SRC) \ +SRC5 = \ keywordhash.h \ opcodes.c \ opcodes.h \ @@ -865,6 +863,10 @@ SRC = $(SRC) \ parse.h \ sqlite3.h +# All source code files. +# +SRC = $(SRC1) $(SRC2) $(SRC3) $(SRC4) $(SRC5) + # Source code to the test files. # TESTSRC = \ @@ -1052,7 +1054,11 @@ mptester.exe: $(TOP)\mptest\mptest.c libsqlite3.lib $(LIBRESOBJS) sqlite3.h .target_source: $(SRC) $(TOP)\tool\vdbe-compress.tcl -rmdir /S/Q tsrc -mkdir tsrc - for %i in ($(SRC)) do copy /Y %i tsrc + for %i in ($(SRC1)) do copy /Y %i tsrc + for %i in ($(SRC2)) do copy /Y %i tsrc + for %i in ($(SRC3)) do copy /Y %i tsrc + for %i in ($(SRC4)) do copy /Y %i tsrc + for %i in ($(SRC5)) do copy /Y %i tsrc del /Q tsrc\sqlite.h.in tsrc\parse.y $(TCLSH_CMD) $(TOP)\tool\vdbe-compress.tcl $(OPTS) < tsrc\vdbe.c > vdbe.new move vdbe.new tsrc\vdbe.c diff --git a/manifest b/manifest index 2b2c56f7bc..ca90d2b9bd 100644 --- a/manifest +++ b/manifest @@ -1,9 +1,9 @@ -C Optimize\srange\sconstraints\son\sthe\srowid\scolumn\sof\sfts3/4\stables\seven\sif\sthere\sis\sno\sMATCH\sclause\sin\sthe\squery. -D 2015-01-29T11:52:22.452 +C Split\sup\sthe\sSRC\svariable\sin\sMakefile.msc\sto\savoid\sover-long\scmd.exe\scommands\swhen\sTOP\sis\sset\sto\sa\slong\spathname. +D 2015-01-29T18:38:05.899 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5407a688f4d77a05c18a8142be8ae5a2829dd610 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 -F Makefile.msc 2b1cb8881bdefcb0a8ed41c34c81cfa630374222 +F Makefile.msc 1edfd7dd45d98a04f9a2fa81a01c49faeb628578 F Makefile.vxworks e1b65dea203f054e71653415bd8f96dcaed47858 F README.md d58e3bebc0a4145e0f2a87994015fdb575a8e866 F VERSION d846487aff892625eb8e75960234e7285f0462fe @@ -1237,7 +1237,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P e7d2ec048c88237c124fbe598f8f7e950d43d90f -R e192a378398ddf2aeb616257a71bd844 -U dan -Z 0e830c66fc49965a9a24bd9be18f84a6 +P 85dc12625d300fe48f3c096f54ebcb8b6ef4e30a +R 30ab1d1acabeef9590cca414845b1919 +U drh +Z 4d0075f03968634835018469d0d0c906 diff --git a/manifest.uuid b/manifest.uuid index 9133dd0737..d4f0f59f06 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -85dc12625d300fe48f3c096f54ebcb8b6ef4e30a \ No newline at end of file +7d70ac65c16f08832a1f0fc4dec0f62a17cbcc85 \ No newline at end of file From 976b003344df8b2d97d0e587c7a1c4256341439c Mon Sep 17 00:00:00 2001 From: dan Date: Thu, 29 Jan 2015 19:12:12 +0000 Subject: [PATCH 20/62] Ensure that "PRAGMA wal_checkpoint = TRUNCATE|FULL|RESTART" block on other connections and truncate the database file as required even if the entire wal file has already been checkpointed. FossilOrigin-Name: 53429689d4fcf472edbc89cc50b5e69ba3270634 --- manifest | 18 ++--- manifest.uuid | 2 +- src/main.c | 1 + src/wal.c | 183 +++++++++++++++++++++++++------------------------ test/wal5.test | 81 ++++++++++++++++++++++ 5 files changed, 185 insertions(+), 100 deletions(-) diff --git a/manifest b/manifest index ca90d2b9bd..1463f0f1c5 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Split\sup\sthe\sSRC\svariable\sin\sMakefile.msc\sto\savoid\sover-long\scmd.exe\scommands\swhen\sTOP\sis\sset\sto\sa\slong\spathname. -D 2015-01-29T18:38:05.899 +C Ensure\sthat\s"PRAGMA\swal_checkpoint\s=\sTRUNCATE|FULL|RESTART"\sblock\son\sother\sconnections\sand\struncate\sthe\sdatabase\sfile\sas\srequired\seven\sif\sthe\sentire\swal\sfile\shas\salready\sbeen\scheckpointed. +D 2015-01-29T19:12:12.112 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5407a688f4d77a05c18a8142be8ae5a2829dd610 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -195,7 +195,7 @@ F src/journal.c b4124532212b6952f42eb2c12fa3c25701d8ba8d F src/legacy.c ba1863ea58c4c840335a84ec276fc2b25e22bc4e F src/lempar.c 7274c97d24bb46631e504332ccd3bd1b37841770 F src/loadext.c 86bd4e2fccd520b748cba52492ab60c4a770f660 -F src/main.c 05bf368c934cc73d02906030846eb4d1818c10f7 +F src/main.c 341fcc5601a8ca84389fa32bcf5a857f65af8dd0 F src/malloc.c 740db54387204c9a2eb67c6d98e68b08e9ef4eab F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645 F src/mem1.c abe6ee469b6c5a35c7f22bfeb9c9bac664a1c987 @@ -302,7 +302,7 @@ F src/vdbemem.c 31d8eabb0cd78bfeab4e5124c7363c3e9e54db9f F src/vdbesort.c 6d64c5448b64851b99931ede980addc3af70d5e2 F src/vdbetrace.c 7e4222955e07dd707a2f360c0eb73452be1cb010 F src/vtab.c c08ec66f45919eaa726bf88aa53eb08379d607f9 -F src/wal.c 85353539f2d9d0c91ebd057c32525b1e1aa3335e +F src/wal.c 39303f2c9db02a4e422cd8eb2c8760420c6a51fe F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4 F src/walker.c c253b95b4ee44b21c406e2a1052636c31ea27804 F src/where.c d46de821bc604a4fd36fa3928c086950e91aafb1 @@ -1126,7 +1126,7 @@ F test/wal.test 885f32b2b390b30b4aa3dbb0e568f8f78d40f5cc F test/wal2.test 1f841d2048080d32f552942e333fd99ce541dada F test/wal3.test b22eb662bcbc148c5f6d956eaf94b047f7afe9c0 F test/wal4.test 4744e155cd6299c6bd99d3eab1c82f77db9cdb3c -F test/wal5.test 11b8658dd4d5448f4604124bebd9b68be5bc3e66 +F test/wal5.test dba8f5f5de95178bc40521d6edf153b2e2829917 F test/wal6.test 527581f5527bf9c24394991e2be83000aace5f9e F test/wal64k.test 163655ecd2cb8afef4737cac2a40fdd2eeaf20b8 F test/wal7.test 2ae8f427d240099cc4b2dfef63cff44e2a68a1bd @@ -1237,7 +1237,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 85dc12625d300fe48f3c096f54ebcb8b6ef4e30a -R 30ab1d1acabeef9590cca414845b1919 -U drh -Z 4d0075f03968634835018469d0d0c906 +P 7d70ac65c16f08832a1f0fc4dec0f62a17cbcc85 +R 73adf612681872a358f9dbc8b22308b4 +U dan +Z 0d0ede6d5c4b5d769c9edb317c2eb34b diff --git a/manifest.uuid b/manifest.uuid index d4f0f59f06..ee7430a6bc 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -7d70ac65c16f08832a1f0fc4dec0f62a17cbcc85 \ No newline at end of file +53429689d4fcf472edbc89cc50b5e69ba3270634 \ No newline at end of file diff --git a/src/main.c b/src/main.c index 8cf16b001a..5aa37fa492 100644 --- a/src/main.c +++ b/src/main.c @@ -1966,6 +1966,7 @@ int sqlite3_wal_checkpoint_v2( rc = SQLITE_ERROR; sqlite3ErrorWithMsg(db, SQLITE_ERROR, "unknown database: %s", zDb); }else{ + db->busyHandler.nBusy = 0; rc = sqlite3Checkpoint(db, iDb, eMode, pnLog, pnCkpt); sqlite3Error(db, rc); } diff --git a/src/wal.c b/src/wal.c index f2738a6727..71f4a3d452 100644 --- a/src/wal.c +++ b/src/wal.c @@ -1694,7 +1694,7 @@ static int walCheckpoint( int sync_flags, /* Flags for OsSync() (or 0) */ u8 *zBuf /* Temporary buffer to use */ ){ - int rc; /* Return code */ + int rc = SQLITE_OK; /* Return code */ int szPage; /* Database page-size */ WalIterator *pIter = 0; /* Wal iterator context */ u32 iDbpage = 0; /* Next database page to write */ @@ -1708,104 +1708,107 @@ static int walCheckpoint( testcase( szPage<=32768 ); testcase( szPage>=65536 ); pInfo = walCkptInfo(pWal); - if( pInfo->nBackfill>=pWal->hdr.mxFrame ) return SQLITE_OK; + if( pInfo->nBackfillhdr.mxFrame ){ - /* Allocate the iterator */ - rc = walIteratorInit(pWal, &pIter); - if( rc!=SQLITE_OK ){ - return rc; - } - assert( pIter ); - - /* EVIDENCE-OF: R-62920-47450 The busy-handler callback is never invoked - ** in the SQLITE_CHECKPOINT_PASSIVE mode. */ - assert( eMode!=SQLITE_CHECKPOINT_PASSIVE || xBusy==0 ); - - /* Compute in mxSafeFrame the index of the last frame of the WAL that is - ** safe to write into the database. Frames beyond mxSafeFrame might - ** overwrite database pages that are in use by active readers and thus - ** cannot be backfilled from the WAL. - */ - mxSafeFrame = pWal->hdr.mxFrame; - mxPage = pWal->hdr.nPage; - for(i=1; iaReadMark[i]; - if( mxSafeFrame>y ){ - assert( y<=pWal->hdr.mxFrame ); - rc = walBusyLock(pWal, xBusy, pBusyArg, WAL_READ_LOCK(i), 1); - if( rc==SQLITE_OK ){ - pInfo->aReadMark[i] = (i==1 ? mxSafeFrame : READMARK_NOT_USED); - walUnlockExclusive(pWal, WAL_READ_LOCK(i), 1); - }else if( rc==SQLITE_BUSY ){ - mxSafeFrame = y; - xBusy = 0; - }else{ - goto walcheckpoint_out; - } + /* Allocate the iterator */ + rc = walIteratorInit(pWal, &pIter); + if( rc!=SQLITE_OK ){ + return rc; } - } + assert( pIter ); - if( pInfo->nBackfillnBackfill; + /* EVIDENCE-OF: R-62920-47450 The busy-handler callback is never invoked + ** in the SQLITE_CHECKPOINT_PASSIVE mode. */ + assert( eMode!=SQLITE_CHECKPOINT_PASSIVE || xBusy==0 ); - /* Sync the WAL to disk */ - if( sync_flags ){ - rc = sqlite3OsSync(pWal->pWalFd, sync_flags); - } - - /* If the database may grow as a result of this checkpoint, hint - ** about the eventual size of the db file to the VFS layer. + /* Compute in mxSafeFrame the index of the last frame of the WAL that is + ** safe to write into the database. Frames beyond mxSafeFrame might + ** overwrite database pages that are in use by active readers and thus + ** cannot be backfilled from the WAL. */ - if( rc==SQLITE_OK ){ - i64 nReq = ((i64)mxPage * szPage); - rc = sqlite3OsFileSize(pWal->pDbFd, &nSize); - if( rc==SQLITE_OK && nSizepDbFd, SQLITE_FCNTL_SIZE_HINT, &nReq); - } - } - - - /* Iterate through the contents of the WAL, copying data to the db file. */ - while( rc==SQLITE_OK && 0==walIteratorNext(pIter, &iDbpage, &iFrame) ){ - i64 iOffset; - assert( walFramePgno(pWal, iFrame)==iDbpage ); - if( iFrame<=nBackfill || iFrame>mxSafeFrame || iDbpage>mxPage ) continue; - iOffset = walFrameOffset(iFrame, szPage) + WAL_FRAME_HDRSIZE; - /* testcase( IS_BIG_INT(iOffset) ); // requires a 4GiB WAL file */ - rc = sqlite3OsRead(pWal->pWalFd, zBuf, szPage, iOffset); - if( rc!=SQLITE_OK ) break; - iOffset = (iDbpage-1)*(i64)szPage; - testcase( IS_BIG_INT(iOffset) ); - rc = sqlite3OsWrite(pWal->pDbFd, zBuf, szPage, iOffset); - if( rc!=SQLITE_OK ) break; - } - - /* If work was actually accomplished... */ - if( rc==SQLITE_OK ){ - if( mxSafeFrame==walIndexHdr(pWal)->mxFrame ){ - i64 szDb = pWal->hdr.nPage*(i64)szPage; - testcase( IS_BIG_INT(szDb) ); - rc = sqlite3OsTruncate(pWal->pDbFd, szDb); - if( rc==SQLITE_OK && sync_flags ){ - rc = sqlite3OsSync(pWal->pDbFd, sync_flags); + mxSafeFrame = pWal->hdr.mxFrame; + mxPage = pWal->hdr.nPage; + for(i=1; iaReadMark[i]; + if( mxSafeFrame>y ){ + assert( y<=pWal->hdr.mxFrame ); + rc = walBusyLock(pWal, xBusy, pBusyArg, WAL_READ_LOCK(i), 1); + if( rc==SQLITE_OK ){ + pInfo->aReadMark[i] = (i==1 ? mxSafeFrame : READMARK_NOT_USED); + walUnlockExclusive(pWal, WAL_READ_LOCK(i), 1); + }else if( rc==SQLITE_BUSY ){ + mxSafeFrame = y; + xBusy = 0; + }else{ + goto walcheckpoint_out; } } - if( rc==SQLITE_OK ){ - pInfo->nBackfill = mxSafeFrame; - } } - /* Release the reader lock held while backfilling */ - walUnlockExclusive(pWal, WAL_READ_LOCK(0), 1); - } + if( pInfo->nBackfillnBackfill; - if( rc==SQLITE_BUSY ){ - /* Reset the return code so as not to report a checkpoint failure - ** just because there are active readers. */ - rc = SQLITE_OK; + /* Sync the WAL to disk */ + if( sync_flags ){ + rc = sqlite3OsSync(pWal->pWalFd, sync_flags); + } + + /* If the database may grow as a result of this checkpoint, hint + ** about the eventual size of the db file to the VFS layer. + */ + if( rc==SQLITE_OK ){ + i64 nReq = ((i64)mxPage * szPage); + rc = sqlite3OsFileSize(pWal->pDbFd, &nSize); + if( rc==SQLITE_OK && nSizepDbFd, SQLITE_FCNTL_SIZE_HINT, &nReq); + } + } + + + /* Iterate through the contents of the WAL, copying data to the db file */ + while( rc==SQLITE_OK && 0==walIteratorNext(pIter, &iDbpage, &iFrame) ){ + i64 iOffset; + assert( walFramePgno(pWal, iFrame)==iDbpage ); + if( iFrame<=nBackfill || iFrame>mxSafeFrame || iDbpage>mxPage ){ + continue; + } + iOffset = walFrameOffset(iFrame, szPage) + WAL_FRAME_HDRSIZE; + /* testcase( IS_BIG_INT(iOffset) ); // requires a 4GiB WAL file */ + rc = sqlite3OsRead(pWal->pWalFd, zBuf, szPage, iOffset); + if( rc!=SQLITE_OK ) break; + iOffset = (iDbpage-1)*(i64)szPage; + testcase( IS_BIG_INT(iOffset) ); + rc = sqlite3OsWrite(pWal->pDbFd, zBuf, szPage, iOffset); + if( rc!=SQLITE_OK ) break; + } + + /* If work was actually accomplished... */ + if( rc==SQLITE_OK ){ + if( mxSafeFrame==walIndexHdr(pWal)->mxFrame ){ + i64 szDb = pWal->hdr.nPage*(i64)szPage; + testcase( IS_BIG_INT(szDb) ); + rc = sqlite3OsTruncate(pWal->pDbFd, szDb); + if( rc==SQLITE_OK && sync_flags ){ + rc = sqlite3OsSync(pWal->pDbFd, sync_flags); + } + } + if( rc==SQLITE_OK ){ + pInfo->nBackfill = mxSafeFrame; + } + } + + /* Release the reader lock held while backfilling */ + walUnlockExclusive(pWal, WAL_READ_LOCK(0), 1); + } + + if( rc==SQLITE_BUSY ){ + /* Reset the return code so as not to report a checkpoint failure + ** just because there are active readers. */ + rc = SQLITE_OK; + } } /* If this is an SQLITE_CHECKPOINT_RESTART or TRUNCATE operation, and the @@ -1820,7 +1823,7 @@ static int walCheckpoint( }else if( eMode>=SQLITE_CHECKPOINT_RESTART ){ u32 salt1; sqlite3_randomness(4, &salt1); - assert( mxSafeFrame==pWal->hdr.mxFrame ); + assert( pInfo->nBackfill==pWal->hdr.mxFrame ); rc = walBusyLock(pWal, xBusy, pBusyArg, WAL_READ_LOCK(1), WAL_NREADER-1); if( rc==SQLITE_OK ){ if( eMode==SQLITE_CHECKPOINT_TRUNCATE ){ diff --git a/test/wal5.test b/test/wal5.test index 8c1ec8bcc7..2d3522b03c 100644 --- a/test/wal5.test +++ b/test/wal5.test @@ -390,6 +390,87 @@ foreach {testprefix do_wal_checkpoint} { } [wal_file_size 2 1024] } + + # Test that FULL, RESTART and TRUNCATE callbacks block on other clients + # and truncate the wal file as required even if the entire wal file has + # already been checkpointed when they are invoked. + # + do_multiclient_test tn { + + code1 $do_wal_checkpoint + code2 $do_wal_checkpoint + code3 $do_wal_checkpoint + + do_test 5.$tn.1 { + sql1 { + PRAGMA page_size = 1024; + PRAGMA auto_vacuum = 0; + PRAGMA journal_mode = WAL; + PRAGMA synchronous = normal; + CREATE TABLE t1(x, y); + CREATE INDEX i1 ON t1(x, y); + INSERT INTO t1 VALUES(1, 2); + INSERT INTO t1 VALUES(3, 4); + INSERT INTO t1 VALUES(5, 6); + } + file size test.db-wal + } [wal_file_size 10 1024] + + do_test 5.$tn.2 { + sql2 { BEGIN; SELECT * FROM t1 } + } {1 2 3 4 5 6} + + do_test 5.$tn.3 { do_wal_checkpoint db -mode passive } {0 10 10} + + do_test 5.$tn.4 { + sql3 { BEGIN; INSERT INTO t1 VALUES(7, 8); } + } {} + + do_test 5.$tn.5 { do_wal_checkpoint db -mode passive } {0 10 10} + do_test 5.$tn.6 { do_wal_checkpoint db -mode full } {1 10 10} + + do_test 5.$tn.7 { sql3 { ROLLBACK } } {} + + do_test 5.$tn.8 { do_wal_checkpoint db -mode full } {0 10 10} + do_test 5.$tn.9 { do_wal_checkpoint db -mode truncate } {1 10 10} + + do_test 5.$tn.10 { + file size test.db-wal + } [wal_file_size 10 1024] + + proc xBusyHandler {n} { sql2 { COMMIT } ; return 0 } + db busy xBusyHandler + + do_test 5.$tn.11 { do_wal_checkpoint db -mode truncate } {0 0 0} + do_test 5.$tn.12 { file size test.db-wal } 0 + + do_test 5.$tn.13 { + sql1 { + INSERT INTO t1 VALUES(7, 8); + INSERT INTO t1 VALUES(9, 10); + SELECT * FROM t1; + } + } {1 2 3 4 5 6 7 8 9 10} + + do_test 5.$tn.14 { + sql2 { BEGIN; SELECT * FROM t1 } + } {1 2 3 4 5 6 7 8 9 10} + + proc xBusyHandler {n} { return 1 } + do_test 5.$tn.14 { do_wal_checkpoint db -mode truncate } {1 4 4} + do_test 5.$tn.15 { file size test.db-wal } [wal_file_size 4 1024] + + do_test 5.$tn.16 { do_wal_checkpoint db -mode restart } {1 4 4} + + proc xBusyHandler {n} { sql2 { COMMIT } ; return 0 } + db busy xBusyHandler + do_test 5.$tn.17 { do_wal_checkpoint db -mode restart } {0 4 4} + do_test 5.$tn.18 { file size test.db-wal } [wal_file_size 4 1024] + + do_test 5.$tn.19 { do_wal_checkpoint db -mode truncate } {0 0 0} + do_test 5.$tn.20 { file size test.db-wal } 0 + } + } From fdc2e6d3444129d7e582e24f809f4f3b911b3966 Mon Sep 17 00:00:00 2001 From: mistachkin Date: Thu, 29 Jan 2015 19:27:31 +0000 Subject: [PATCH 21/62] Fix some duplicated test names. FossilOrigin-Name: 1797158db2a818134c5cba1578f69ed85948b980 --- manifest | 14 +++++++------- manifest.uuid | 2 +- test/wal5.test | 14 +++++++------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/manifest b/manifest index 1463f0f1c5..a15009da8f 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Ensure\sthat\s"PRAGMA\swal_checkpoint\s=\sTRUNCATE|FULL|RESTART"\sblock\son\sother\sconnections\sand\struncate\sthe\sdatabase\sfile\sas\srequired\seven\sif\sthe\sentire\swal\sfile\shas\salready\sbeen\scheckpointed. -D 2015-01-29T19:12:12.112 +C Fix\ssome\sduplicated\stest\snames. +D 2015-01-29T19:27:31.114 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5407a688f4d77a05c18a8142be8ae5a2829dd610 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -1126,7 +1126,7 @@ F test/wal.test 885f32b2b390b30b4aa3dbb0e568f8f78d40f5cc F test/wal2.test 1f841d2048080d32f552942e333fd99ce541dada F test/wal3.test b22eb662bcbc148c5f6d956eaf94b047f7afe9c0 F test/wal4.test 4744e155cd6299c6bd99d3eab1c82f77db9cdb3c -F test/wal5.test dba8f5f5de95178bc40521d6edf153b2e2829917 +F test/wal5.test 88b5d9a6a3d1532497ee9f4296f010d66f07e33c F test/wal6.test 527581f5527bf9c24394991e2be83000aace5f9e F test/wal64k.test 163655ecd2cb8afef4737cac2a40fdd2eeaf20b8 F test/wal7.test 2ae8f427d240099cc4b2dfef63cff44e2a68a1bd @@ -1237,7 +1237,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 7d70ac65c16f08832a1f0fc4dec0f62a17cbcc85 -R 73adf612681872a358f9dbc8b22308b4 -U dan -Z 0d0ede6d5c4b5d769c9edb317c2eb34b +P 53429689d4fcf472edbc89cc50b5e69ba3270634 +R 5b41e9df20f2feb8a0c6b2313c845804 +U mistachkin +Z 0e7b28947abc40f4a90f6b77b2bfb10f diff --git a/manifest.uuid b/manifest.uuid index ee7430a6bc..0570c439f3 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -53429689d4fcf472edbc89cc50b5e69ba3270634 \ No newline at end of file +1797158db2a818134c5cba1578f69ed85948b980 \ No newline at end of file diff --git a/test/wal5.test b/test/wal5.test index 2d3522b03c..360d9c911e 100644 --- a/test/wal5.test +++ b/test/wal5.test @@ -457,18 +457,18 @@ foreach {testprefix do_wal_checkpoint} { } {1 2 3 4 5 6 7 8 9 10} proc xBusyHandler {n} { return 1 } - do_test 5.$tn.14 { do_wal_checkpoint db -mode truncate } {1 4 4} - do_test 5.$tn.15 { file size test.db-wal } [wal_file_size 4 1024] + do_test 5.$tn.15 { do_wal_checkpoint db -mode truncate } {1 4 4} + do_test 5.$tn.16 { file size test.db-wal } [wal_file_size 4 1024] - do_test 5.$tn.16 { do_wal_checkpoint db -mode restart } {1 4 4} + do_test 5.$tn.17 { do_wal_checkpoint db -mode restart } {1 4 4} proc xBusyHandler {n} { sql2 { COMMIT } ; return 0 } db busy xBusyHandler - do_test 5.$tn.17 { do_wal_checkpoint db -mode restart } {0 4 4} - do_test 5.$tn.18 { file size test.db-wal } [wal_file_size 4 1024] + do_test 5.$tn.18 { do_wal_checkpoint db -mode restart } {0 4 4} + do_test 5.$tn.19 { file size test.db-wal } [wal_file_size 4 1024] - do_test 5.$tn.19 { do_wal_checkpoint db -mode truncate } {0 0 0} - do_test 5.$tn.20 { file size test.db-wal } 0 + do_test 5.$tn.20 { do_wal_checkpoint db -mode truncate } {0 0 0} + do_test 5.$tn.21 { file size test.db-wal } 0 } } From 917682a4f429ae75e2c3cdfa6b62162a5d3a36be Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 30 Jan 2015 15:40:15 +0000 Subject: [PATCH 22/62] Add a few simple test cases for SQLITE_TESTCTRL_INITMODE - cases which also test PRAGMA integrity_check. FossilOrigin-Name: 3a6e2afe408d2b0c8166d00def2048568169d87a --- manifest | 16 ++++---- manifest.uuid | 2 +- src/test1.c | 18 +++++++- test/initmode.test | 100 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 125 insertions(+), 11 deletions(-) create mode 100644 test/initmode.test diff --git a/manifest b/manifest index 776fb5e978..83c59f47c0 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sthe\sINITMODE\stest-control. -D 2015-01-29T17:54:52.194 +C Add\sa\sfew\ssimple\stest\scases\sfor\sSQLITE_TESTCTRL_INITMODE\s-\scases\swhich\nalso\stest\sPRAGMA\sintegrity_check. +D 2015-01-30T15:40:15.485 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5407a688f4d77a05c18a8142be8ae5a2829dd610 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -239,7 +239,7 @@ F src/sqliteLimit.h 164b0e6749d31e0daa1a4589a169d31c0dec7b3d F src/status.c 81712116e826b0089bb221b018929536b2b5406f F src/table.c e7a09215315a978057fb42c640f890160dbcc45e F src/tclsqlite.c b8014393a96a9781bb635c8b1f52fc9b77a2bfcf -F src/test1.c 00a74fbc6604e1bcd240726a9ff8d0cc123374e7 +F src/test1.c 5dcdade99e77b7b9f7760106c80a83cf50f10e1e F src/test2.c 577961fe48961b2f2e5c8b56ee50c3f459d3359d F src/test3.c 64d2afdd68feac1bb5e2ffb8226c8c639f798622 F src/test4.c d168f83cc78d02e8d35567bb5630e40dcd85ac1e @@ -655,6 +655,7 @@ F test/index7.test 917cf1e1c7439bb155abbeabec511b28945e157b F test/indexedby.test b2f22f3e693a53813aa3f50b812eb609ba6df1ec F test/indexfault.test 31d4ab9a7d2f6e9616933eb079722362a883eb1d F test/init.test 15c823093fdabbf7b531fe22cf037134d09587a7 +F test/initmode.test 38bbaefeb47e034a162856e664a0da3b95e6999b F test/insert.test 38742b5e9601c8f8d76e9b7555f7270288c2d371 F test/insert2.test 4f3a04d168c728ed5ec2c88842e772606c7ce435 F test/insert3.test 1b7db95a03ad9c5013fdf7d6722b6cd66ee55e30 @@ -1237,10 +1238,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 85dc12625d300fe48f3c096f54ebcb8b6ef4e30a -R fe787287eb356b79eb9ba31c0e138e4f -T *branch * initmode-testctrl -T *sym-initmode-testctrl * -T -sym-trunk * +P 5940af8e7872209ce41feb958643b23f7e55d258 +R 47cbd38aaccdc229ecba207f260cbca2 U drh -Z e02e8497217bad1b69deabc72f8cd27d +Z f10513d756c3deb9c12d56e187b46090 diff --git a/manifest.uuid b/manifest.uuid index 60ead15a06..18f40e05d3 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -5940af8e7872209ce41feb958643b23f7e55d258 \ No newline at end of file +3a6e2afe408d2b0c8166d00def2048568169d87a \ No newline at end of file diff --git a/src/test1.c b/src/test1.c index d86ec1e84d..b9503cf394 100644 --- a/src/test1.c +++ b/src/test1.c @@ -5914,7 +5914,8 @@ static int test_test_control( int i; } aVerb[] = { { "SQLITE_TESTCTRL_LOCALTIME_FAULT", SQLITE_TESTCTRL_LOCALTIME_FAULT }, - { "SQLITE_TESTCTRL_SORTER_MMAP", SQLITE_TESTCTRL_SORTER_MMAP }, + { "SQLITE_TESTCTRL_SORTER_MMAP", SQLITE_TESTCTRL_SORTER_MMAP }, + { "SQLITE_TESTCTRL_INITMODE", SQLITE_TESTCTRL_INITMODE }, }; int iVerb; int iFlag; @@ -5955,6 +5956,21 @@ static int test_test_control( sqlite3_test_control(SQLITE_TESTCTRL_SORTER_MMAP, db, val); break; } + + case SQLITE_TESTCTRL_INITMODE: { + int fBusy, iDb, newTnum; + sqlite3 *db; + if( objc!=6 ){ + Tcl_WrongNumArgs(interp, 2, objv, "DB fBusy iDb newTnum"); + return TCL_ERROR; + } + if( getDbPointer(interp, Tcl_GetString(objv[2]), &db) ) return TCL_ERROR; + if( Tcl_GetIntFromObj(interp, objv[3], &fBusy) ) return TCL_ERROR; + if( Tcl_GetIntFromObj(interp, objv[4], &iDb) ) return TCL_ERROR; + if( Tcl_GetIntFromObj(interp, objv[5], &newTnum) ) return TCL_ERROR; + sqlite3_test_control(SQLITE_TESTCTRL_INITMODE, db, fBusy, iDb, newTnum); + break; + } } Tcl_ResetResult(interp); diff --git a/test/initmode.test b/test/initmode.test new file mode 100644 index 0000000000..ce3f675857 --- /dev/null +++ b/test/initmode.test @@ -0,0 +1,100 @@ +# 2015-01-30 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# This file implements tests for SQLite library. +# +# The focus of this file is adding extra entries in the symbol table +# using sqlite3_test_control(SQLITE_TESTCTRL_INITMODE) and verifying that +# SQLite handles those as expected. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix initmode + +# Create a bunch of data to sort against +# +do_test initmode-1.0 { + execsql { + CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c, d NOT NULL); + CREATE INDEX t1b ON t1(b); + CREATE UNIQUE INDEX t1c ON t1(c); + WITH RECURSIVE c(i) AS (VALUES(1) UNION ALL SELECT i+1 FROM c WHERE i<30) + INSERT INTO t1(a,b,c,d) SELECT i,1000+i,2000+i,3000+i FROM c; + } + set t1_root [db one {SELECT rootpage FROM sqlite_master WHERE name='t1'}] + set t1a_root [db one {SELECT rootpage FROM sqlite_master WHERE name='t1a'}] + set t1b_root [db one {SELECT rootpage FROM sqlite_master WHERE name='t1b'}] + + # Create a shadow table that uses the same b-tree as t1 but which does + # not have the indexes + # + sqlite3_test_control SQLITE_TESTCTRL_INITMODE db 1 0 $t1_root + db eval {CREATE TABLE xt1(a,b,c,d)} + sqlite3_test_control SQLITE_TESTCTRL_INITMODE db 0 0 0 + + # Create triggers to record changes to xt1. + # + db eval { + CREATE TEMP TABLE chnglog(desc TEXT); + CREATE TEMP TRIGGER xt1_del AFTER DELETE ON xt1 BEGIN + INSERT INTO chnglog VALUES( + printf('DELETE t1: rowid=%d, a=%s, b=%s, c=%s, d=%s', + old.rowid, quote(old.a), quote(old.b), quote(old.c), + quote(old.d))); + END; + CREATE TEMP TRIGGER xt1_ins AFTER INSERT ON xt1 BEGIN + INSERT INTO chnglog VALUES( + printf('INSERT t1: rowid=%d, a=%s, b=%s, c=%s, d=%s', + new.rowid, quote(new.a), quote(new.b), quote(new.c), + quote(new.d))); + END; + } +} {} + +# The xt1 table has separate xt1.rowid and xt1.a columns. The xt1.rowid +# column corresponds to t1.rowid and t1.a, but the xt1.a column is always +# NULL +# +do_execsql_test initmode-1.1 { + SELECT rowid FROM xt1 WHERE a IS NOT NULL; +} {} +do_execsql_test initmode-1.2 { + SELECT a,b,c,d FROM t1 EXCEPT SELECT rowid,b,c,d FROM xt1; + SELECT rowid,b,c,d FROM xt1 EXCEPT SELECT a,b,c,d FROM t1; +} {} + + +# Make changes via the xt1 shadow table. This will not update the +# indexes on t1 nor check the uniqueness constraint on t1.c nor check +# the NOT NULL constraint on t1.d, resulting in a logically inconsistent +# database. +# +do_execsql_test initmode-1.3 { + DELETE FROM xt1 WHERE rowid=5; + INSERT INTO xt1(rowid,a,b,c,d) VALUES(99,'hello',1099,2022,NULL); + SELECT * FROM chnglog ORDER BY rowid; +} [list \ + {DELETE t1: rowid=5, a=NULL, b=1005, c=2005, d=3005} \ + {INSERT t1: rowid=99, a='hello', b=1099, c=2022, d=NULL} \ +] + +do_execsql_test initmode-1.4a { + PRAGMA integrity_check; +} {/NULL value in t1.d/} +do_execsql_test initmode-1.4b { + PRAGMA integrity_check; +} {/row # missing from index t1b/} +do_execsql_test initmode-1.4c { + PRAGMA integrity_check; +} {/row # missing from index t1c/} + +finish_test From 1ffede8c86303506cf7a1536d00b9b5b688ae595 Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 30 Jan 2015 20:59:27 +0000 Subject: [PATCH 23/62] Change SQLITE_TESTCTRL_INITMODE to SQLITE_TESTCTRL_IMPOSTER. Revise the order of parameters. Give it the ability to reset the schema parse table so that imposter tables can be erased. FossilOrigin-Name: 42d5601739c90434e5adfda8fa99ef7b903877db --- manifest | 27 +++++------ manifest.uuid | 2 +- src/btree.c | 6 +++ src/build.c | 11 +++-- src/main.c | 25 ++++++++-- src/shell.c | 8 +-- src/sqlite.h.in | 2 +- src/sqliteInt.h | 1 + src/test1.c | 17 ++++--- test/{initmode.test => imposter1.test} | 67 +++++++++++++++++++++----- 10 files changed, 116 insertions(+), 50 deletions(-) rename test/{initmode.test => imposter1.test} (60%) diff --git a/manifest b/manifest index 09d4bc0fa8..f8fe7806e2 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Added\sSQLITE_TESTCTRL_INITMODE\sfor\simproved\stestability. -D 2015-01-30T15:52:26.210 +C Change\sSQLITE_TESTCTRL_INITMODE\sto\sSQLITE_TESTCTRL_IMPOSTER.\s\sRevise\sthe\sorder\nof\sparameters.\s\sGive\sit\sthe\sability\sto\sreset\sthe\sschema\sparse\stable\sso\sthat\nimposter\stables\scan\sbe\serased. +D 2015-01-30T20:59:27.457 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5407a688f4d77a05c18a8142be8ae5a2829dd610 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -173,10 +173,10 @@ F src/auth.c b56c78ebe40a2110fd361379f7e8162d23f92240 F src/backup.c 7ddee9c7d505e07e959a575b18498f17c71e53ea F src/bitvec.c 19a4ba637bd85f8f63fc8c9bae5ade9fb05ec1cb F src/btmutex.c 49ca66250c7dfa844a4d4cb8272b87420d27d3a5 -F src/btree.c 4c098bb6e8678e4596983862abf78f7a0fcb807e +F src/btree.c 2a1245df0356a229bcd0fd87a8536b5067f16e82 F src/btree.h 94277c1d30c0b75705974bcc8b0c05e79c03d474 F src/btreeInt.h a3d0ae1d511365e1a2b76ad10960dbe55c286f34 -F src/build.c f5cfd7b32216f695b995bbc7c1a395f6d451d11f +F src/build.c eefaa4f1d86bc3c08023a61fdd1e695b47796975 F src/callback.c 7b44ce59674338ad48b0e84e7b72f935ea4f68b0 F src/complete.c 198a0066ba60ab06fc00fba1998d870a4d575463 F src/ctime.c 98f89724adc891a1a4c655bee04e33e716e05887 @@ -195,7 +195,7 @@ F src/journal.c b4124532212b6952f42eb2c12fa3c25701d8ba8d F src/legacy.c ba1863ea58c4c840335a84ec276fc2b25e22bc4e F src/lempar.c 7274c97d24bb46631e504332ccd3bd1b37841770 F src/loadext.c 86bd4e2fccd520b748cba52492ab60c4a770f660 -F src/main.c 81ddebf2feb9cbd8c8ea160cdd979503f645d505 +F src/main.c ce38ddcedf33e5530b0e6c592809bb8822a6e8d0 F src/malloc.c 740db54387204c9a2eb67c6d98e68b08e9ef4eab F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645 F src/mem1.c abe6ee469b6c5a35c7f22bfeb9c9bac664a1c987 @@ -230,16 +230,16 @@ F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c f6c46d3434439ab2084618d603e6d6dbeb0d6ada F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e F src/select.c 1f2087523007c42900ffcbdeaef06a23ad9329fc -F src/shell.c ed7cf7c29fb1a23d47179affc89cb447868fc976 -F src/sqlite.h.in 6910064681444efb5c467472499b56bb6bcee0f4 +F src/shell.c 22b4406b0b59efd14b3b351a5809dda517df6d30 +F src/sqlite.h.in 54678c21401909f72b221344dd560d285a1ba5eb F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h 17d487c3c91b0b8c584a32fbeb393f6f795eea7d -F src/sqliteInt.h eaf210295b551d4e40e622aec1b2261c0b28f844 +F src/sqliteInt.h c4e05f7489cd300f856e2283d5e61302ce826471 F src/sqliteLimit.h 164b0e6749d31e0daa1a4589a169d31c0dec7b3d F src/status.c 81712116e826b0089bb221b018929536b2b5406f F src/table.c e7a09215315a978057fb42c640f890160dbcc45e F src/tclsqlite.c b8014393a96a9781bb635c8b1f52fc9b77a2bfcf -F src/test1.c 5dcdade99e77b7b9f7760106c80a83cf50f10e1e +F src/test1.c 90fbedce75330d48d99eadb7d5f4223e86969585 F src/test2.c 577961fe48961b2f2e5c8b56ee50c3f459d3359d F src/test3.c 64d2afdd68feac1bb5e2ffb8226c8c639f798622 F src/test4.c d168f83cc78d02e8d35567bb5630e40dcd85ac1e @@ -630,6 +630,7 @@ F test/genesis.tcl 1e2e2e8e5cc4058549a154ff1892fe5c9de19f98 F test/hexlit.test f9ecde8145bfc2341573473256c74ae37a200497 F test/hook.test 162d7cef7a2d2b04839fe14402934e6a1b79442f F test/icu.test 70df4faca133254c042d02ae342c0a141f2663f4 +F test/imposter1.test c3f1db2d3db2c24611a6596a3fc0ffc14f1466c8 w test/initmode.test F test/in.test 047c4671328e9032ab95666a67021adbbd36e98e F test/in2.test 5d4c61d17493c832f7d2d32bef785119e87bde75 F test/in3.test 3cbf58c87f4052cee3a58b37b6389777505aa0c0 @@ -655,7 +656,6 @@ F test/index7.test 917cf1e1c7439bb155abbeabec511b28945e157b F test/indexedby.test b2f22f3e693a53813aa3f50b812eb609ba6df1ec F test/indexfault.test 31d4ab9a7d2f6e9616933eb079722362a883eb1d F test/init.test 15c823093fdabbf7b531fe22cf037134d09587a7 -F test/initmode.test 38bbaefeb47e034a162856e664a0da3b95e6999b F test/insert.test 38742b5e9601c8f8d76e9b7555f7270288c2d371 F test/insert2.test 4f3a04d168c728ed5ec2c88842e772606c7ce435 F test/insert3.test 1b7db95a03ad9c5013fdf7d6722b6cd66ee55e30 @@ -1238,8 +1238,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 1797158db2a818134c5cba1578f69ed85948b980 3a6e2afe408d2b0c8166d00def2048568169d87a -R 4fa14bf275b60ddd661b9bd3fb0ea0dd -T +closed 3a6e2afe408d2b0c8166d00def2048568169d87a +P 98e029134dc1300d3ecb48b41b5107ec69ba85db +R ae5f14ccaf584de0786e4614152020d2 U drh -Z b68a5e615b7688be627f33067b9af11c +Z c23d2e36f9e88e779a131b19c0ee1b9b diff --git a/manifest.uuid b/manifest.uuid index d367511342..9eba1b1a54 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -98e029134dc1300d3ecb48b41b5107ec69ba85db \ No newline at end of file +42d5601739c90434e5adfda8fa99ef7b903877db \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index f9f76c2ebb..eb5151351c 100644 --- a/src/btree.c +++ b/src/btree.c @@ -175,6 +175,12 @@ static int hasSharedCacheTableLock( for(p=sqliteHashFirst(&pSchema->idxHash); p; p=sqliteHashNext(p)){ Index *pIdx = (Index *)sqliteHashData(p); if( pIdx->tnum==(int)iRoot ){ + if( iTab ){ + /* Two or more indexes share the same root page. There must + ** be imposter tables. So just return true. The assert is not + ** useful in that case. */ + return 1; + } iTab = pIdx->pTable->tnum; } } diff --git a/src/build.c b/src/build.c index f02989bffe..7e3ce1b76a 100644 --- a/src/build.c +++ b/src/build.c @@ -1731,11 +1731,14 @@ static void convertToWithoutRowidTable(Parse *pParse, Table *pTab){ assert( pPk!=0 ); nPk = pPk->nKeyCol; - /* Make sure every column of the PRIMARY KEY is NOT NULL */ - for(i=0; iaCol[pPk->aiColumn[i]].notNull = 1; + /* Make sure every column of the PRIMARY KEY is NOT NULL. (Except, + ** do not enforce this for imposter tables.) */ + if( !db->init.imposterTable ){ + for(i=0; iaCol[pPk->aiColumn[i]].notNull = 1; + } + pPk->uniqNotNull = 1; } - pPk->uniqNotNull = 1; /* The root page of the PRIMARY KEY is the table root page */ pPk->tnum = pTab->tnum; diff --git a/src/main.c b/src/main.c index 0d6f1be246..11585e7dc5 100644 --- a/src/main.c +++ b/src/main.c @@ -3599,15 +3599,30 @@ int sqlite3_test_control(int op, ...){ break; } - /* sqlite3_test_control(SQLITE_TESTCTRL_INITMODE, db, busy, iDb, newTnum); + /* sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, db, dbName, onOff, tnum); ** - ** Set the db->init.busy, db->init.iDb, and db->init.tnum fields. + ** This test control is used to create imposter tables. "db" is a pointer + ** to the database connection. dbName is the database name (ex: "main" or + ** "temp") which will receive the imposter. "onOff" turns imposter mode on + ** or off. "tnum" is the root page of the b-tree to which the imposter + ** table should connect. + ** + ** Enable imposter mode only when the schema has already been parsed. Then + ** run a single CREATE TABLE statement to construct the imposter table in the + ** parsed schema. Then turn imposter mode back off again. + ** + ** If onOff==0 and tnum>0 then reset the schema for all databases, causing + ** the schema to be reparsed the next time it is needed. This has the + ** effect of erasing all imposter tables. */ - case SQLITE_TESTCTRL_INITMODE: { + case SQLITE_TESTCTRL_IMPOSTER: { sqlite3 *db = va_arg(ap, sqlite3*); - db->init.busy = va_arg(ap,int); - db->init.iDb = va_arg(ap,int); + db->init.iDb = sqlite3FindDbName(db, va_arg(ap,const char*)); + db->init.busy = db->init.imposterTable = va_arg(ap,int); db->init.newTnum = va_arg(ap,int); + if( db->init.busy==0 && db->init.newTnum>0 ){ + sqlite3ResetAllSchemasOfConnection(db); + } break; } } diff --git a/src/shell.c b/src/shell.c index 1a191e0fd0..3130f4c6de 100644 --- a/src/shell.c +++ b/src/shell.c @@ -3536,7 +3536,7 @@ static int do_meta_command(char *zLine, ShellState *p){ { "scratchmalloc", SQLITE_TESTCTRL_SCRATCHMALLOC }, { "byteorder", SQLITE_TESTCTRL_BYTEORDER }, { "never_corrupt", SQLITE_TESTCTRL_NEVER_CORRUPT }, - { "initmode", SQLITE_TESTCTRL_INITMODE }, + { "imposter", SQLITE_TESTCTRL_IMPOSTER }, }; int testctrl = -1; int rc = 0; @@ -3629,14 +3629,14 @@ static int do_meta_command(char *zLine, ShellState *p){ break; #endif - case SQLITE_TESTCTRL_INITMODE: + case SQLITE_TESTCTRL_IMPOSTER: if( nArg==5 ){ rc = sqlite3_test_control(testctrl, p->db, - integerValue(azArg[2]), + azArg[2], integerValue(azArg[3]), integerValue(azArg[4])); }else{ - fprintf(stderr,"Usage: .testctrl initmode fBusy iDb newTnum\n"); + fprintf(stderr,"Usage: .testctrl initmode dbName onoff tnum\n"); rc = 1; } break; diff --git a/src/sqlite.h.in b/src/sqlite.h.in index 722b9235a2..f256cea45d 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -6260,7 +6260,7 @@ int sqlite3_test_control(int op, ...); #define SQLITE_TESTCTRL_BYTEORDER 22 #define SQLITE_TESTCTRL_ISINIT 23 #define SQLITE_TESTCTRL_SORTER_MMAP 24 -#define SQLITE_TESTCTRL_INITMODE 25 +#define SQLITE_TESTCTRL_IMPOSTER 25 #define SQLITE_TESTCTRL_LAST 25 /* diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 379456d5f5..0bc6f679dd 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -1087,6 +1087,7 @@ struct sqlite3 { u8 iDb; /* Which db file is being initialized */ u8 busy; /* TRUE if currently initializing */ u8 orphanTrigger; /* Last statement is orphaned TEMP trigger */ + u8 imposterTable; /* Building an imposter table */ } init; int nVdbeActive; /* Number of VDBEs currently running */ int nVdbeRead; /* Number of active VDBEs that read or write */ diff --git a/src/test1.c b/src/test1.c index b9503cf394..a87fcd859d 100644 --- a/src/test1.c +++ b/src/test1.c @@ -5915,7 +5915,7 @@ static int test_test_control( } aVerb[] = { { "SQLITE_TESTCTRL_LOCALTIME_FAULT", SQLITE_TESTCTRL_LOCALTIME_FAULT }, { "SQLITE_TESTCTRL_SORTER_MMAP", SQLITE_TESTCTRL_SORTER_MMAP }, - { "SQLITE_TESTCTRL_INITMODE", SQLITE_TESTCTRL_INITMODE }, + { "SQLITE_TESTCTRL_IMPOSTER", SQLITE_TESTCTRL_IMPOSTER }, }; int iVerb; int iFlag; @@ -5957,18 +5957,19 @@ static int test_test_control( break; } - case SQLITE_TESTCTRL_INITMODE: { - int fBusy, iDb, newTnum; + case SQLITE_TESTCTRL_IMPOSTER: { + int onOff, tnum; + const char *zDbName; sqlite3 *db; if( objc!=6 ){ - Tcl_WrongNumArgs(interp, 2, objv, "DB fBusy iDb newTnum"); + Tcl_WrongNumArgs(interp, 2, objv, "DB dbName onOff tnum"); return TCL_ERROR; } if( getDbPointer(interp, Tcl_GetString(objv[2]), &db) ) return TCL_ERROR; - if( Tcl_GetIntFromObj(interp, objv[3], &fBusy) ) return TCL_ERROR; - if( Tcl_GetIntFromObj(interp, objv[4], &iDb) ) return TCL_ERROR; - if( Tcl_GetIntFromObj(interp, objv[5], &newTnum) ) return TCL_ERROR; - sqlite3_test_control(SQLITE_TESTCTRL_INITMODE, db, fBusy, iDb, newTnum); + zDbName = Tcl_GetString(objv[3]); + if( Tcl_GetIntFromObj(interp, objv[4], &onOff) ) return TCL_ERROR; + if( Tcl_GetIntFromObj(interp, objv[5], &tnum) ) return TCL_ERROR; + sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, db, zDbName, onOff, tnum); break; } } diff --git a/test/initmode.test b/test/imposter1.test similarity index 60% rename from test/initmode.test rename to test/imposter1.test index ce3f675857..196767be15 100644 --- a/test/initmode.test +++ b/test/imposter1.test @@ -12,17 +12,17 @@ # This file implements tests for SQLite library. # # The focus of this file is adding extra entries in the symbol table -# using sqlite3_test_control(SQLITE_TESTCTRL_INITMODE) and verifying that +# using sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER) and verifying that # SQLite handles those as expected. # set testdir [file dirname $argv0] source $testdir/tester.tcl -set testprefix initmode +set testprefix imposter # Create a bunch of data to sort against # -do_test initmode-1.0 { +do_test imposter-1.0 { execsql { CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c, d NOT NULL); CREATE INDEX t1b ON t1(b); @@ -31,15 +31,21 @@ do_test initmode-1.0 { INSERT INTO t1(a,b,c,d) SELECT i,1000+i,2000+i,3000+i FROM c; } set t1_root [db one {SELECT rootpage FROM sqlite_master WHERE name='t1'}] - set t1a_root [db one {SELECT rootpage FROM sqlite_master WHERE name='t1a'}] set t1b_root [db one {SELECT rootpage FROM sqlite_master WHERE name='t1b'}] + set t1c_root [db one {SELECT rootpage FROM sqlite_master WHERE name='t1c'}] - # Create a shadow table that uses the same b-tree as t1 but which does + # Create an imposter table that uses the same b-tree as t1 but which does # not have the indexes # - sqlite3_test_control SQLITE_TESTCTRL_INITMODE db 1 0 $t1_root + sqlite3_test_control SQLITE_TESTCTRL_IMPOSTER db main 1 $t1_root db eval {CREATE TABLE xt1(a,b,c,d)} - sqlite3_test_control SQLITE_TESTCTRL_INITMODE db 0 0 0 + + # And create an imposter table for the t1c index. + sqlite3_test_control SQLITE_TESTCTRL_IMPOSTER db main 1 $t1c_root + db eval {CREATE TABLE xt1c(c,rowid,PRIMARY KEY(c,rowid))WITHOUT ROWID;} + + # Go out of imposter mode for now. + sqlite3_test_control SQLITE_TESTCTRL_IMPOSTER db main 0 0 # Create triggers to record changes to xt1. # @@ -64,10 +70,10 @@ do_test initmode-1.0 { # column corresponds to t1.rowid and t1.a, but the xt1.a column is always # NULL # -do_execsql_test initmode-1.1 { +do_execsql_test imposter-1.1 { SELECT rowid FROM xt1 WHERE a IS NOT NULL; } {} -do_execsql_test initmode-1.2 { +do_execsql_test imposter-1.2 { SELECT a,b,c,d FROM t1 EXCEPT SELECT rowid,b,c,d FROM xt1; SELECT rowid,b,c,d FROM xt1 EXCEPT SELECT a,b,c,d FROM t1; } {} @@ -78,7 +84,7 @@ do_execsql_test initmode-1.2 { # the NOT NULL constraint on t1.d, resulting in a logically inconsistent # database. # -do_execsql_test initmode-1.3 { +do_execsql_test imposter-1.3 { DELETE FROM xt1 WHERE rowid=5; INSERT INTO xt1(rowid,a,b,c,d) VALUES(99,'hello',1099,2022,NULL); SELECT * FROM chnglog ORDER BY rowid; @@ -87,14 +93,49 @@ do_execsql_test initmode-1.3 { {INSERT t1: rowid=99, a='hello', b=1099, c=2022, d=NULL} \ ] -do_execsql_test initmode-1.4a { +do_execsql_test imposter-1.4a { PRAGMA integrity_check; } {/NULL value in t1.d/} -do_execsql_test initmode-1.4b { +do_execsql_test imposter-1.4b { PRAGMA integrity_check; } {/row # missing from index t1b/} -do_execsql_test initmode-1.4c { +do_execsql_test imposter-1.4c { PRAGMA integrity_check; } {/row # missing from index t1c/} +# Cleanup the corruption. +# Then demonstrate that the xt1c imposter table can insert non-unique +# and NULL values into the UNIQUE index. +# +do_execsql_test imposter-2.0 { + DELETE FROM t1; + WITH RECURSIVE c(i) AS (VALUES(1) UNION ALL SELECT i+1 FROM c WHERE i<10) + INSERT INTO t1(a,b,c,d) SELECT i,i,i,i FROM c; + UPDATE xt1c SET c=NULL WHERE rowid=5; + PRAGMA integrity_check; +} {/row # missing from index t1c/} + +do_execsql_test imposter-2.1 { + DELETE FROM t1; + WITH RECURSIVE c(i) AS (VALUES(1) UNION ALL SELECT i+1 FROM c WHERE i<10) + INSERT INTO t1(a,b,c,d) SELECT i,i,i,i FROM c; + UPDATE xt1c SET c=99 WHERE rowid IN (5,7,9); + SELECT c FROM t1 ORDER BY c; +} {1 2 3 4 6 8 10 99 99 99} +do_execsql_test imposter-2.2 { + UPDATE xt1 SET c=99 WHERE rowid IN (5,7,9); + PRAGMA integrity_check; +} {/non-unique entry in index t1c/} + +# Erase the imposter tables +# +do_test imposter-3.1 { + sqlite3_test_control SQLITE_TESTCTRL_IMPOSTER db main 0 1 + db eval { + DELETE FROM t1 WHERE rowid IN (5,7,9); + PRAGMA integrity_check; + } +} {ok} + + finish_test From c228be5b1f5ae8a5d6f4ebc043a759ffbdcd0a3b Mon Sep 17 00:00:00 2001 From: drh Date: Sat, 31 Jan 2015 02:00:01 +0000 Subject: [PATCH 24/62] Add the "index_xinfo" pragma. Add new columns to the "index_info" and "index_list" pragmas. FossilOrigin-Name: 30f51d7b3b292191e8351223242e708bb7f3dfa6 --- manifest | 21 +++++++++------- manifest.uuid | 2 +- src/pragma.c | 56 +++++++++++++++++++++++++++++-------------- test/pragma.test | 57 +++++++++++++++++++++++++++++++++++--------- tool/mkpragmatab.tcl | 8 +++++++ 5 files changed, 105 insertions(+), 39 deletions(-) diff --git a/manifest b/manifest index f8fe7806e2..effa8658b4 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Change\sSQLITE_TESTCTRL_INITMODE\sto\sSQLITE_TESTCTRL_IMPOSTER.\s\sRevise\sthe\sorder\nof\sparameters.\s\sGive\sit\sthe\sability\sto\sreset\sthe\sschema\sparse\stable\sso\sthat\nimposter\stables\scan\sbe\serased. -D 2015-01-30T20:59:27.457 +C Add\sthe\s"index_xinfo"\spragma.\s\sAdd\snew\scolumns\sto\sthe\s"index_info"\sand\n"index_list"\spragmas. +D 2015-01-31T02:00:01.018 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5407a688f4d77a05c18a8142be8ae5a2829dd610 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -223,7 +223,7 @@ F src/parse.y c5d0d964f9ac023e8154cad512e54b0b6058e086 F src/pcache.c d210cf90d04365a74f85d21374dded65af67b0cb F src/pcache.h b44658c9c932d203510279439d891a2a83e12ba8 F src/pcache1.c 1e77432b40b7d3288327d9cdf399dcdfd2b6d3bf -F src/pragma.c ba149bbbc90783f84815636c509ced8eac11bbcf +F src/pragma.c f4d0326361cc875ecd9c92100c5b17363a6a671a F src/prepare.c 173a5a499138451b2561614ecb87d78f9f4644b9 F src/printf.c 05edc41450d0eb2c05ef7db113bf32742ae65325 F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 @@ -630,7 +630,7 @@ F test/genesis.tcl 1e2e2e8e5cc4058549a154ff1892fe5c9de19f98 F test/hexlit.test f9ecde8145bfc2341573473256c74ae37a200497 F test/hook.test 162d7cef7a2d2b04839fe14402934e6a1b79442f F test/icu.test 70df4faca133254c042d02ae342c0a141f2663f4 -F test/imposter1.test c3f1db2d3db2c24611a6596a3fc0ffc14f1466c8 w test/initmode.test +F test/imposter1.test c3f1db2d3db2c24611a6596a3fc0ffc14f1466c8 F test/in.test 047c4671328e9032ab95666a67021adbbd36e98e F test/in2.test 5d4c61d17493c832f7d2d32bef785119e87bde75 F test/in3.test 3cbf58c87f4052cee3a58b37b6389777505aa0c0 @@ -786,7 +786,7 @@ F test/pcache.test b09104b03160aca0d968d99e8cd2c5b1921a993d F test/pcache2.test a83efe2dec0d392f814bfc998def1d1833942025 F test/percentile.test 4243af26b8f3f4555abe166f723715a1f74c77ff F test/permutations.test f9cc1dd987986c9d4949211c7a4ed55ec9aecba1 -F test/pragma.test aa16dedfe01c02c8895169012f7dfde9c163f0d5 +F test/pragma.test 66776f48f533c7248d04c1473deb3ebb792daacd F test/pragma2.test aea7b3d82c76034a2df2b38a13745172ddc0bc13 F test/pragma3.test 6f849ccffeee7e496d2f2b5e74152306c0b8757c F test/printf.test ec9870c4dce8686a37818e0bf1aba6e6a1863552 @@ -1202,7 +1202,7 @@ F tool/logest.c eef612f8adf4d0993dafed0416064cf50d5d33c6 F tool/mkautoconfamal.sh d1a2da0e15b2ed33d60af35c7e9d483f13a8eb9f F tool/mkkeywordhash.c dfff09dbbfaf950e89af294f48f902181b144670 F tool/mkopts.tcl 66ac10d240cc6e86abd37dc908d50382f84ff46e -F tool/mkpragmatab.tcl 07a5124cf2dbafa1b375eefcf8ac4227028b0f8b +F tool/mkpragmatab.tcl 4a3b465f0a800d22ca419daad34389c6a44858c2 F tool/mkspeedsql.tcl a1a334d288f7adfe6e996f2e712becf076745c97 F tool/mksqlite3c-noext.tcl 9ef48e1748dce7b844f67e2450ff9dfeb0fb4ab5 F tool/mksqlite3c.tcl cfde806851c413db7689b9cb74a4eeb92539c601 @@ -1238,7 +1238,10 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 98e029134dc1300d3ecb48b41b5107ec69ba85db -R ae5f14ccaf584de0786e4614152020d2 +P 42d5601739c90434e5adfda8fa99ef7b903877db +R 6dd4b55c378d1f90a678654a5a3c72aa +T *branch * index_xinfo +T *sym-index_xinfo * +T -sym-trunk * U drh -Z c23d2e36f9e88e779a131b19c0ee1b9b +Z 111ada8400958c014924f86391246d25 diff --git a/manifest.uuid b/manifest.uuid index 9eba1b1a54..6dcf9f25fb 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -42d5601739c90434e5adfda8fa99ef7b903877db \ No newline at end of file +30f51d7b3b292191e8351223242e708bb7f3dfa6 \ No newline at end of file diff --git a/src/pragma.c b/src/pragma.c index 34830e33a6..d1aaa4c913 100644 --- a/src/pragma.c +++ b/src/pragma.c @@ -261,6 +261,10 @@ static const struct sPragmaNames { /* ePragTyp: */ PragTyp_INDEX_LIST, /* ePragFlag: */ PragFlag_NeedSchema, /* iArg: */ 0 }, + { /* zName: */ "index_xinfo", + /* ePragTyp: */ PragTyp_INDEX_INFO, + /* ePragFlag: */ PragFlag_NeedSchema, + /* iArg: */ 1 }, #endif #if !defined(SQLITE_OMIT_INTEGRITY_CHECK) { /* zName: */ "integrity_check", @@ -477,7 +481,7 @@ static const struct sPragmaNames { /* iArg: */ SQLITE_WriteSchema|SQLITE_RecoveryMode }, #endif }; -/* Number of pragmas: 58 on by default, 71 total. */ +/* Number of pragmas: 59 on by default, 72 total. */ /* End of the automatically generated pragma table. ***************************************************************************/ @@ -732,6 +736,7 @@ void sqlite3Pragma( sqlite3 *db = pParse->db; /* The database connection */ Db *pDb; /* The specific database being pragmaed */ Vdbe *v = sqlite3GetVdbe(pParse); /* Prepared statement */ + const struct sPragmaNames *pPragma; if( v==0 ) return; sqlite3VdbeRunOnlyOnce(v); @@ -809,14 +814,15 @@ void sqlite3Pragma( } } if( lwr>upr ) goto pragma_out; + pPragma = &aPragmaNames[mid]; /* Make sure the database schema is loaded if the pragma requires that */ - if( (aPragmaNames[mid].mPragFlag & PragFlag_NeedSchema)!=0 ){ + if( (pPragma->mPragFlag & PragFlag_NeedSchema)!=0 ){ if( sqlite3ReadSchema(pParse) ) goto pragma_out; } /* Jump to the appropriate pragma handler */ - switch( aPragmaNames[mid].ePragTyp ){ + switch( pPragma->ePragTyp ){ #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && !defined(SQLITE_OMIT_DEPRECATED) /* @@ -1395,10 +1401,9 @@ void sqlite3Pragma( #ifndef SQLITE_OMIT_FLAG_PRAGMAS case PragTyp_FLAG: { if( zRight==0 ){ - returnSingleInt(pParse, aPragmaNames[mid].zName, - (db->flags & aPragmaNames[mid].iArg)!=0 ); + returnSingleInt(pParse, pPragma->zName, (db->flags & pPragma->iArg)!=0 ); }else{ - int mask = aPragmaNames[mid].iArg; /* Mask of bits to set or clear. */ + int mask = pPragma->iArg; /* Mask of bits to set or clear. */ if( db->autoCommit==0 ){ /* Foreign key support may not be enabled or disabled while not ** in auto-commit mode. */ @@ -1527,20 +1532,30 @@ void sqlite3Pragma( pIdx = sqlite3FindIndex(db, zRight, zDb); if( pIdx ){ int i; + int mx = pPragma->iArg ? pIdx->nColumn : pIdx->nKeyCol; pTab = pIdx->pTable; - sqlite3VdbeSetNumCols(v, 3); - pParse->nMem = 3; + sqlite3VdbeSetNumCols(v, 6); + pParse->nMem = 6; sqlite3CodeVerifySchema(pParse, iDb); sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seqno", SQLITE_STATIC); sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "cid", SQLITE_STATIC); sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "name", SQLITE_STATIC); - for(i=0; inKeyCol; i++){ + sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "desc", SQLITE_STATIC); + sqlite3VdbeSetColName(v, 4, COLNAME_NAME, "coll", SQLITE_STATIC); + sqlite3VdbeSetColName(v, 5, COLNAME_NAME, "key", SQLITE_STATIC); + for(i=0; iaiColumn[i]; sqlite3VdbeAddOp2(v, OP_Integer, i, 1); sqlite3VdbeAddOp2(v, OP_Integer, cnum, 2); - assert( pTab->nCol>cnum ); - sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, pTab->aCol[cnum].zName, 0); - sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3); + if( cnum<0 ){ + sqlite3VdbeAddOp2(v, OP_Null, 0, 3); + }else{ + sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, pTab->aCol[cnum].zName, 0); + } + sqlite3VdbeAddOp2(v, OP_Integer, pIdx->aSortOrder[i], 4); + sqlite3VdbeAddOp4(v, OP_String8, 0, 5, 0, pIdx->azColl[i], 0); + sqlite3VdbeAddOp2(v, OP_Integer, inKeyCol, 6); + sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 6); } } } @@ -1553,17 +1568,22 @@ void sqlite3Pragma( pTab = sqlite3FindTable(db, zRight, zDb); if( pTab ){ v = sqlite3GetVdbe(pParse); - sqlite3VdbeSetNumCols(v, 3); - pParse->nMem = 3; + sqlite3VdbeSetNumCols(v, 5); + pParse->nMem = 5; sqlite3CodeVerifySchema(pParse, iDb); sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", SQLITE_STATIC); sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", SQLITE_STATIC); sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "unique", SQLITE_STATIC); + sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "origin", SQLITE_STATIC); + sqlite3VdbeSetColName(v, 4, COLNAME_NAME, "partial", SQLITE_STATIC); for(pIdx=pTab->pIndex, i=0; pIdx; pIdx=pIdx->pNext, i++){ + const char *azOrigin[] = { "c", "u", "pk" }; sqlite3VdbeAddOp2(v, OP_Integer, i, 1); sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, pIdx->zName, 0); sqlite3VdbeAddOp2(v, OP_Integer, IsUniqueIndex(pIdx), 3); - sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3); + sqlite3VdbeAddOp4(v, OP_String8, 0, 4, 0, azOrigin[pIdx->idxType], 0); + sqlite3VdbeAddOp2(v, OP_Integer, pIdx->pPartIdxWhere!=0, 5); + sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 5); } } } @@ -2133,9 +2153,9 @@ void sqlite3Pragma( ** applications for any purpose. */ case PragTyp_HEADER_VALUE: { - int iCookie = aPragmaNames[mid].iArg; /* Which cookie to read or write */ + int iCookie = pPragma->iArg; /* Which cookie to read or write */ sqlite3VdbeUsesBtree(v, iDb); - if( zRight && (aPragmaNames[mid].mPragFlag & PragFlag_ReadOnly)==0 ){ + if( zRight && (pPragma->mPragFlag & PragFlag_ReadOnly)==0 ){ /* Write the specified cookie value */ static const VdbeOpList setCookie[] = { { OP_Transaction, 0, 1, 0}, /* 0 */ @@ -2255,7 +2275,7 @@ void sqlite3Pragma( ** disables the timeout. */ /*case PragTyp_BUSY_TIMEOUT*/ default: { - assert( aPragmaNames[mid].ePragTyp==PragTyp_BUSY_TIMEOUT ); + assert( pPragma->ePragTyp==PragTyp_BUSY_TIMEOUT ); if( zRight ){ sqlite3_busy_timeout(db, sqlite3Atoi(zRight)); } diff --git a/test/pragma.test b/test/pragma.test index 09b9b6c14f..1628cbaecf 100644 --- a/test/pragma.test +++ b/test/pragma.test @@ -51,6 +51,30 @@ ifcapable !pragma { return } +# Capture the output of a pragma in a TEMP table. +# +proc capture_pragma {db tabname sql} { + $db eval "DROP TABLE IF EXISTS temp.$tabname" + set once 1 + $db eval $sql x { + if {$once} { + set once 0 + set ins "INSERT INTO $tabname VALUES" + set crtab "CREATE TEMP TABLE $tabname " + set sep "(" + foreach col $x(*) { + append ins ${sep}\$x($col) + append crtab ${sep}\"$col\" + set sep , + } + append ins ) + append crtab ) + $db eval $crtab + } + $db eval $ins + } +} + # Delete the preexisting database to avoid the special setup # that the "all.test" script does. # @@ -620,9 +644,10 @@ ifcapable {foreignkey} { } } {} do_test pragma-6.4 { - execsql { + capture_pragma db out { pragma index_list(t3); } + db eval {SELECT seq, "name", "unique" FROM out ORDER BY seq} } {0 sqlite_autoindex_t3_1 1} } ifcapable {!foreignkey} { @@ -631,8 +656,11 @@ ifcapable {!foreignkey} { do_test pragma-6.5.1 { execsql { CREATE INDEX t3i1 ON t3(a,b); + } + capture_pragma db out { pragma index_info(t3i1); } + db eval {SELECT seqno, cid, name FROM out ORDER BY seqno} } {0 0 a 1 1 b} do_test pragma-6.5.2 { execsql { @@ -676,8 +704,10 @@ do_test pragma-6.7 { four REAL DEFAULT X'abcdef', five DEFAULT CURRENT_TIME ); - PRAGMA table_info(test_table); } + capture_pragma db out {PRAGMA table_info(test_table)} + db eval {SELECT cid, "name", type, "notnull", dflt_value, pk FROM out + ORDER BY cid} } [concat \ {0 one INT 1 -1 0} \ {1 two text 0 {} 0} \ @@ -693,10 +723,9 @@ do_test pragma-7.1.1 { # Make sure a pragma knows to read the schema if it needs to db close sqlite3 db test.db - execsql { - pragma index_list(t3); - } -} {0 t3i1 0 1 sqlite_autoindex_t3_1 1} + capture_pragma db out "PRAGMA index_list(t3)" + db eval {SELECT name, "origin" FROM out ORDER BY name DESC} +} {t3i1 c sqlite_autoindex_t3_1 u} do_test pragma-7.1.2 { execsql { pragma index_list(t3_bogus); @@ -1705,19 +1734,25 @@ do_test 23.1 { } db2 eval {SELECT name FROM sqlite_master} } {t1 i1 i2 t2} -do_test 23.2 { +do_test 23.2a { db eval { DROP INDEX i2; CREATE INDEX i2 ON t1(c,d,b); } - db2 eval {PRAGMA index_info(i2)} -} {0 2 c 1 3 d 2 1 b} + capture_pragma db2 out {PRAGMA index_info(i2)} + db2 eval {SELECT cid, name, "desc", coll, "key", '|' FROM out ORDER BY seqno} +} {2 c 0 BINARY 1 | 3 d 0 BINARY 1 | 1 b 0 BINARY 1 |} +do_test 23.2b { + capture_pragma db2 out {PRAGMA index_xinfo(i2)} + db2 eval {SELECT cid, name, "desc", coll, "key", '|' FROM out ORDER BY seqno} +} {2 c 0 BINARY 1 | 3 d 0 BINARY 1 | 1 b 0 BINARY 1 | -1 {} 0 BINARY 0 |} do_test 23.3 { db eval { CREATE INDEX i3 ON t1(d,b,c); } - db2 eval {PRAGMA index_list(t1)} -} {0 i3 0 1 i2 0 2 i1 0} + capture_pragma db2 out {PRAGMA index_list(t1)} + db2 eval {SELECT name, "unique", origin FROM out ORDER BY seq} +} {i3 0 c i2 0 c i1 0 c} do_test 23.4 { db eval { ALTER TABLE t1 ADD COLUMN e; diff --git a/tool/mkpragmatab.tcl b/tool/mkpragmatab.tcl index 21503d16ee..c842208de5 100644 --- a/tool/mkpragmatab.tcl +++ b/tool/mkpragmatab.tcl @@ -205,6 +205,14 @@ set pragma_def { IF: !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) NAME: index_info + TYPE: INDEX_INFO + ARG: 0 + FLAG: NeedSchema + IF: !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) + + NAME: index_xinfo + TYPE: INDEX_INFO + ARG: 1 FLAG: NeedSchema IF: !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) From 67e65e55ab2fe76874c5db09709a77528a69e872 Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 2 Feb 2015 21:34:54 +0000 Subject: [PATCH 25/62] Break out the (script-generated) pragma parsing tables into a separate file, pragma.h, to make editing easier. FossilOrigin-Name: 32c0325bcb083fe3f0f0cfe999d00f754e15299e --- Makefile.in | 2 + Makefile.msc | 2 + main.mk | 2 + manifest | 25 +-- manifest.uuid | 2 +- src/pragma.c | 465 +------------------------------------------ src/pragma.h | 455 ++++++++++++++++++++++++++++++++++++++++++ tool/mkpragmatab.tcl | 59 +++--- tool/mksqlite3c.tcl | 1 + 9 files changed, 519 insertions(+), 494 deletions(-) create mode 100644 src/pragma.h diff --git a/Makefile.in b/Makefile.in index 3d6e0f250d..1d7be55f74 100644 --- a/Makefile.in +++ b/Makefile.in @@ -255,6 +255,7 @@ SRC = \ $(TOP)/src/pcache.h \ $(TOP)/src/pcache1.c \ $(TOP)/src/pragma.c \ + $(TOP)/src/pragma.h \ $(TOP)/src/prepare.c \ $(TOP)/src/printf.c \ $(TOP)/src/random.c \ @@ -474,6 +475,7 @@ HDR = \ $(TOP)/src/pager.h \ $(TOP)/src/pcache.h \ parse.h \ + $(TOP)/src/pragma.h \ sqlite3.h \ $(TOP)/src/sqlite3ext.h \ $(TOP)/src/sqliteInt.h \ diff --git a/Makefile.msc b/Makefile.msc index f480b30058..4621661ee5 100644 --- a/Makefile.msc +++ b/Makefile.msc @@ -773,6 +773,7 @@ SRC2 = \ $(TOP)\src\pcache.h \ $(TOP)\src\pcache1.c \ $(TOP)\src\pragma.c \ + $(TOP)\src\pragma.h \ $(TOP)\src\prepare.c \ $(TOP)\src\printf.c \ $(TOP)\src\random.c \ @@ -996,6 +997,7 @@ HDR = \ $(TOP)\src\pager.h \ $(TOP)\src\pcache.h \ parse.h \ + $(TOP)\src\pragma.h \ sqlite3.h \ $(TOP)\src\sqlite3ext.h \ $(TOP)\src\sqliteInt.h \ diff --git a/main.mk b/main.mk index 429945b099..f72922b4c1 100644 --- a/main.mk +++ b/main.mk @@ -133,6 +133,7 @@ SRC = \ $(TOP)/src/pcache.h \ $(TOP)/src/pcache1.c \ $(TOP)/src/pragma.c \ + $(TOP)/src/pragma.h \ $(TOP)/src/prepare.c \ $(TOP)/src/printf.c \ $(TOP)/src/random.c \ @@ -356,6 +357,7 @@ HDR = \ $(TOP)/src/pager.h \ $(TOP)/src/pcache.h \ parse.h \ + $(TOP)/src/pragma.h \ sqlite3.h \ $(TOP)/src/sqlite3ext.h \ $(TOP)/src/sqliteInt.h \ diff --git a/manifest b/manifest index f8fe7806e2..a2f72263ab 100644 --- a/manifest +++ b/manifest @@ -1,9 +1,9 @@ -C Change\sSQLITE_TESTCTRL_INITMODE\sto\sSQLITE_TESTCTRL_IMPOSTER.\s\sRevise\sthe\sorder\nof\sparameters.\s\sGive\sit\sthe\sability\sto\sreset\sthe\sschema\sparse\stable\sso\sthat\nimposter\stables\scan\sbe\serased. -D 2015-01-30T20:59:27.457 +C Break\sout\sthe\s(script-generated)\spragma\sparsing\stables\sinto\sa\sseparate\sfile,\npragma.h,\sto\smake\sediting\seasier. +D 2015-02-02T21:34:54.408 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f -F Makefile.in 5407a688f4d77a05c18a8142be8ae5a2829dd610 +F Makefile.in cbe64ed4d90a19062b804f7fbd319080f851b004 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 -F Makefile.msc 1edfd7dd45d98a04f9a2fa81a01c49faeb628578 +F Makefile.msc fc6b0b233b5621f3e56298e4d6a0b3f6c936c520 F Makefile.vxworks e1b65dea203f054e71653415bd8f96dcaed47858 F README.md d58e3bebc0a4145e0f2a87994015fdb575a8e866 F VERSION d846487aff892625eb8e75960234e7285f0462fe @@ -152,7 +152,7 @@ F ext/userauth/userauth.c 5fa3bdb492f481bbc1709fc83c91ebd13460c69e F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 x F ltmain.sh 3ff0879076df340d2e23ae905484d8c15d5fdea8 F magic.txt 8273bf49ba3b0c8559cb2774495390c31fd61c60 -F main.mk e392561ffe17fc4dad945eef852400d5bf2911a0 +F main.mk 0bae136db3f3ce451079ae335124b46163d37020 F mkopcodec.awk c2ff431854d702cdd2d779c9c0d1f58fa16fa4ea F mkopcodeh.awk c6b3fa301db6ef7ac916b14c60868aeaec1337b5 F mkso.sh fd21c06b063bb16a5d25deea1752c2da6ac3ed83 @@ -223,7 +223,8 @@ F src/parse.y c5d0d964f9ac023e8154cad512e54b0b6058e086 F src/pcache.c d210cf90d04365a74f85d21374dded65af67b0cb F src/pcache.h b44658c9c932d203510279439d891a2a83e12ba8 F src/pcache1.c 1e77432b40b7d3288327d9cdf399dcdfd2b6d3bf -F src/pragma.c ba149bbbc90783f84815636c509ced8eac11bbcf +F src/pragma.c 58044728a29a0240d14a850c3870e5ac3da436b2 +F src/pragma.h 28804eae1286aab6f2ffa3682dc0b06b58c51834 F src/prepare.c 173a5a499138451b2561614ecb87d78f9f4644b9 F src/printf.c 05edc41450d0eb2c05ef7db113bf32742ae65325 F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 @@ -630,7 +631,7 @@ F test/genesis.tcl 1e2e2e8e5cc4058549a154ff1892fe5c9de19f98 F test/hexlit.test f9ecde8145bfc2341573473256c74ae37a200497 F test/hook.test 162d7cef7a2d2b04839fe14402934e6a1b79442f F test/icu.test 70df4faca133254c042d02ae342c0a141f2663f4 -F test/imposter1.test c3f1db2d3db2c24611a6596a3fc0ffc14f1466c8 w test/initmode.test +F test/imposter1.test c3f1db2d3db2c24611a6596a3fc0ffc14f1466c8 F test/in.test 047c4671328e9032ab95666a67021adbbd36e98e F test/in2.test 5d4c61d17493c832f7d2d32bef785119e87bde75 F test/in3.test 3cbf58c87f4052cee3a58b37b6389777505aa0c0 @@ -1202,10 +1203,10 @@ F tool/logest.c eef612f8adf4d0993dafed0416064cf50d5d33c6 F tool/mkautoconfamal.sh d1a2da0e15b2ed33d60af35c7e9d483f13a8eb9f F tool/mkkeywordhash.c dfff09dbbfaf950e89af294f48f902181b144670 F tool/mkopts.tcl 66ac10d240cc6e86abd37dc908d50382f84ff46e -F tool/mkpragmatab.tcl 07a5124cf2dbafa1b375eefcf8ac4227028b0f8b +F tool/mkpragmatab.tcl 4b4e91f6b8fc45596686798b918999e923b91fc7 F tool/mkspeedsql.tcl a1a334d288f7adfe6e996f2e712becf076745c97 F tool/mksqlite3c-noext.tcl 9ef48e1748dce7b844f67e2450ff9dfeb0fb4ab5 -F tool/mksqlite3c.tcl cfde806851c413db7689b9cb74a4eeb92539c601 +F tool/mksqlite3c.tcl 6b8e572a90eb4e0086e3ba90d88b76c085919863 F tool/mksqlite3h.tcl ba24038056f51fde07c0079c41885ab85e2cff12 F tool/mksqlite3internalh.tcl eb994013e833359137eb53a55acdad0b5ae1049b F tool/mkvsix.tcl 52a4c613707ac34ae9c226e5ccc69cb948556105 @@ -1238,7 +1239,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 98e029134dc1300d3ecb48b41b5107ec69ba85db -R ae5f14ccaf584de0786e4614152020d2 +P 42d5601739c90434e5adfda8fa99ef7b903877db +R ad79dcf7ddc97ee53618558cb6690870 U drh -Z c23d2e36f9e88e779a131b19c0ee1b9b +Z 0fdc8db6e22e6c93e424fbfcfceed021 diff --git a/manifest.uuid b/manifest.uuid index 9eba1b1a54..b9ef8ce9ed 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -42d5601739c90434e5adfda8fa99ef7b903877db \ No newline at end of file +32c0325bcb083fe3f0f0cfe999d00f754e15299e \ No newline at end of file diff --git a/src/pragma.c b/src/pragma.c index 34830e33a6..f680fb2138 100644 --- a/src/pragma.c +++ b/src/pragma.c @@ -22,464 +22,13 @@ #endif /*************************************************************************** -** The next block of code, including the PragTyp_XXXX macro definitions and -** the aPragmaName[] object is composed of generated code. DO NOT EDIT. -** -** To add new pragmas, edit the code in ../tool/mkpragmatab.tcl and rerun -** that script. Then copy/paste the output in place of the following: -*/ -#define PragTyp_HEADER_VALUE 0 -#define PragTyp_AUTO_VACUUM 1 -#define PragTyp_FLAG 2 -#define PragTyp_BUSY_TIMEOUT 3 -#define PragTyp_CACHE_SIZE 4 -#define PragTyp_CASE_SENSITIVE_LIKE 5 -#define PragTyp_COLLATION_LIST 6 -#define PragTyp_COMPILE_OPTIONS 7 -#define PragTyp_DATA_STORE_DIRECTORY 8 -#define PragTyp_DATABASE_LIST 9 -#define PragTyp_DEFAULT_CACHE_SIZE 10 -#define PragTyp_ENCODING 11 -#define PragTyp_FOREIGN_KEY_CHECK 12 -#define PragTyp_FOREIGN_KEY_LIST 13 -#define PragTyp_INCREMENTAL_VACUUM 14 -#define PragTyp_INDEX_INFO 15 -#define PragTyp_INDEX_LIST 16 -#define PragTyp_INTEGRITY_CHECK 17 -#define PragTyp_JOURNAL_MODE 18 -#define PragTyp_JOURNAL_SIZE_LIMIT 19 -#define PragTyp_LOCK_PROXY_FILE 20 -#define PragTyp_LOCKING_MODE 21 -#define PragTyp_PAGE_COUNT 22 -#define PragTyp_MMAP_SIZE 23 -#define PragTyp_PAGE_SIZE 24 -#define PragTyp_SECURE_DELETE 25 -#define PragTyp_SHRINK_MEMORY 26 -#define PragTyp_SOFT_HEAP_LIMIT 27 -#define PragTyp_STATS 28 -#define PragTyp_SYNCHRONOUS 29 -#define PragTyp_TABLE_INFO 30 -#define PragTyp_TEMP_STORE 31 -#define PragTyp_TEMP_STORE_DIRECTORY 32 -#define PragTyp_THREADS 33 -#define PragTyp_WAL_AUTOCHECKPOINT 34 -#define PragTyp_WAL_CHECKPOINT 35 -#define PragTyp_ACTIVATE_EXTENSIONS 36 -#define PragTyp_HEXKEY 37 -#define PragTyp_KEY 38 -#define PragTyp_REKEY 39 -#define PragTyp_LOCK_STATUS 40 -#define PragTyp_PARSER_TRACE 41 -#define PragFlag_NeedSchema 0x01 -#define PragFlag_ReadOnly 0x02 -static const struct sPragmaNames { - const char *const zName; /* Name of pragma */ - u8 ePragTyp; /* PragTyp_XXX value */ - u8 mPragFlag; /* Zero or more PragFlag_XXX values */ - u32 iArg; /* Extra argument */ -} aPragmaNames[] = { -#if defined(SQLITE_HAS_CODEC) || defined(SQLITE_ENABLE_CEROD) - { /* zName: */ "activate_extensions", - /* ePragTyp: */ PragTyp_ACTIVATE_EXTENSIONS, - /* ePragFlag: */ 0, - /* iArg: */ 0 }, -#endif -#if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS) - { /* zName: */ "application_id", - /* ePragTyp: */ PragTyp_HEADER_VALUE, - /* ePragFlag: */ 0, - /* iArg: */ BTREE_APPLICATION_ID }, -#endif -#if !defined(SQLITE_OMIT_AUTOVACUUM) - { /* zName: */ "auto_vacuum", - /* ePragTyp: */ PragTyp_AUTO_VACUUM, - /* ePragFlag: */ PragFlag_NeedSchema, - /* iArg: */ 0 }, -#endif -#if !defined(SQLITE_OMIT_FLAG_PRAGMAS) -#if !defined(SQLITE_OMIT_AUTOMATIC_INDEX) - { /* zName: */ "automatic_index", - /* ePragTyp: */ PragTyp_FLAG, - /* ePragFlag: */ 0, - /* iArg: */ SQLITE_AutoIndex }, -#endif -#endif - { /* zName: */ "busy_timeout", - /* ePragTyp: */ PragTyp_BUSY_TIMEOUT, - /* ePragFlag: */ 0, - /* iArg: */ 0 }, -#if !defined(SQLITE_OMIT_PAGER_PRAGMAS) - { /* zName: */ "cache_size", - /* ePragTyp: */ PragTyp_CACHE_SIZE, - /* ePragFlag: */ PragFlag_NeedSchema, - /* iArg: */ 0 }, -#endif -#if !defined(SQLITE_OMIT_FLAG_PRAGMAS) - { /* zName: */ "cache_spill", - /* ePragTyp: */ PragTyp_FLAG, - /* ePragFlag: */ 0, - /* iArg: */ SQLITE_CacheSpill }, -#endif - { /* zName: */ "case_sensitive_like", - /* ePragTyp: */ PragTyp_CASE_SENSITIVE_LIKE, - /* ePragFlag: */ 0, - /* iArg: */ 0 }, -#if !defined(SQLITE_OMIT_FLAG_PRAGMAS) - { /* zName: */ "checkpoint_fullfsync", - /* ePragTyp: */ PragTyp_FLAG, - /* ePragFlag: */ 0, - /* iArg: */ SQLITE_CkptFullFSync }, -#endif -#if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) - { /* zName: */ "collation_list", - /* ePragTyp: */ PragTyp_COLLATION_LIST, - /* ePragFlag: */ 0, - /* iArg: */ 0 }, -#endif -#if !defined(SQLITE_OMIT_COMPILEOPTION_DIAGS) - { /* zName: */ "compile_options", - /* ePragTyp: */ PragTyp_COMPILE_OPTIONS, - /* ePragFlag: */ 0, - /* iArg: */ 0 }, -#endif -#if !defined(SQLITE_OMIT_FLAG_PRAGMAS) - { /* zName: */ "count_changes", - /* ePragTyp: */ PragTyp_FLAG, - /* ePragFlag: */ 0, - /* iArg: */ SQLITE_CountRows }, -#endif -#if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && SQLITE_OS_WIN - { /* zName: */ "data_store_directory", - /* ePragTyp: */ PragTyp_DATA_STORE_DIRECTORY, - /* ePragFlag: */ 0, - /* iArg: */ 0 }, -#endif -#if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS) - { /* zName: */ "data_version", - /* ePragTyp: */ PragTyp_HEADER_VALUE, - /* ePragFlag: */ PragFlag_ReadOnly, - /* iArg: */ BTREE_DATA_VERSION }, -#endif -#if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) - { /* zName: */ "database_list", - /* ePragTyp: */ PragTyp_DATABASE_LIST, - /* ePragFlag: */ PragFlag_NeedSchema, - /* iArg: */ 0 }, -#endif -#if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && !defined(SQLITE_OMIT_DEPRECATED) - { /* zName: */ "default_cache_size", - /* ePragTyp: */ PragTyp_DEFAULT_CACHE_SIZE, - /* ePragFlag: */ PragFlag_NeedSchema, - /* iArg: */ 0 }, -#endif -#if !defined(SQLITE_OMIT_FLAG_PRAGMAS) -#if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER) - { /* zName: */ "defer_foreign_keys", - /* ePragTyp: */ PragTyp_FLAG, - /* ePragFlag: */ 0, - /* iArg: */ SQLITE_DeferFKs }, -#endif -#endif -#if !defined(SQLITE_OMIT_FLAG_PRAGMAS) - { /* zName: */ "empty_result_callbacks", - /* ePragTyp: */ PragTyp_FLAG, - /* ePragFlag: */ 0, - /* iArg: */ SQLITE_NullCallback }, -#endif -#if !defined(SQLITE_OMIT_UTF16) - { /* zName: */ "encoding", - /* ePragTyp: */ PragTyp_ENCODING, - /* ePragFlag: */ 0, - /* iArg: */ 0 }, -#endif -#if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER) - { /* zName: */ "foreign_key_check", - /* ePragTyp: */ PragTyp_FOREIGN_KEY_CHECK, - /* ePragFlag: */ PragFlag_NeedSchema, - /* iArg: */ 0 }, -#endif -#if !defined(SQLITE_OMIT_FOREIGN_KEY) - { /* zName: */ "foreign_key_list", - /* ePragTyp: */ PragTyp_FOREIGN_KEY_LIST, - /* ePragFlag: */ PragFlag_NeedSchema, - /* iArg: */ 0 }, -#endif -#if !defined(SQLITE_OMIT_FLAG_PRAGMAS) -#if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER) - { /* zName: */ "foreign_keys", - /* ePragTyp: */ PragTyp_FLAG, - /* ePragFlag: */ 0, - /* iArg: */ SQLITE_ForeignKeys }, -#endif -#endif -#if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS) - { /* zName: */ "freelist_count", - /* ePragTyp: */ PragTyp_HEADER_VALUE, - /* ePragFlag: */ PragFlag_ReadOnly, - /* iArg: */ BTREE_FREE_PAGE_COUNT }, -#endif -#if !defined(SQLITE_OMIT_FLAG_PRAGMAS) - { /* zName: */ "full_column_names", - /* ePragTyp: */ PragTyp_FLAG, - /* ePragFlag: */ 0, - /* iArg: */ SQLITE_FullColNames }, - { /* zName: */ "fullfsync", - /* ePragTyp: */ PragTyp_FLAG, - /* ePragFlag: */ 0, - /* iArg: */ SQLITE_FullFSync }, -#endif -#if defined(SQLITE_HAS_CODEC) - { /* zName: */ "hexkey", - /* ePragTyp: */ PragTyp_HEXKEY, - /* ePragFlag: */ 0, - /* iArg: */ 0 }, - { /* zName: */ "hexrekey", - /* ePragTyp: */ PragTyp_HEXKEY, - /* ePragFlag: */ 0, - /* iArg: */ 0 }, -#endif -#if !defined(SQLITE_OMIT_FLAG_PRAGMAS) -#if !defined(SQLITE_OMIT_CHECK) - { /* zName: */ "ignore_check_constraints", - /* ePragTyp: */ PragTyp_FLAG, - /* ePragFlag: */ 0, - /* iArg: */ SQLITE_IgnoreChecks }, -#endif -#endif -#if !defined(SQLITE_OMIT_AUTOVACUUM) - { /* zName: */ "incremental_vacuum", - /* ePragTyp: */ PragTyp_INCREMENTAL_VACUUM, - /* ePragFlag: */ PragFlag_NeedSchema, - /* iArg: */ 0 }, -#endif -#if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) - { /* zName: */ "index_info", - /* ePragTyp: */ PragTyp_INDEX_INFO, - /* ePragFlag: */ PragFlag_NeedSchema, - /* iArg: */ 0 }, - { /* zName: */ "index_list", - /* ePragTyp: */ PragTyp_INDEX_LIST, - /* ePragFlag: */ PragFlag_NeedSchema, - /* iArg: */ 0 }, -#endif -#if !defined(SQLITE_OMIT_INTEGRITY_CHECK) - { /* zName: */ "integrity_check", - /* ePragTyp: */ PragTyp_INTEGRITY_CHECK, - /* ePragFlag: */ PragFlag_NeedSchema, - /* iArg: */ 0 }, -#endif -#if !defined(SQLITE_OMIT_PAGER_PRAGMAS) - { /* zName: */ "journal_mode", - /* ePragTyp: */ PragTyp_JOURNAL_MODE, - /* ePragFlag: */ PragFlag_NeedSchema, - /* iArg: */ 0 }, - { /* zName: */ "journal_size_limit", - /* ePragTyp: */ PragTyp_JOURNAL_SIZE_LIMIT, - /* ePragFlag: */ 0, - /* iArg: */ 0 }, -#endif -#if defined(SQLITE_HAS_CODEC) - { /* zName: */ "key", - /* ePragTyp: */ PragTyp_KEY, - /* ePragFlag: */ 0, - /* iArg: */ 0 }, -#endif -#if !defined(SQLITE_OMIT_FLAG_PRAGMAS) - { /* zName: */ "legacy_file_format", - /* ePragTyp: */ PragTyp_FLAG, - /* ePragFlag: */ 0, - /* iArg: */ SQLITE_LegacyFileFmt }, -#endif -#if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && SQLITE_ENABLE_LOCKING_STYLE - { /* zName: */ "lock_proxy_file", - /* ePragTyp: */ PragTyp_LOCK_PROXY_FILE, - /* ePragFlag: */ 0, - /* iArg: */ 0 }, -#endif -#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST) - { /* zName: */ "lock_status", - /* ePragTyp: */ PragTyp_LOCK_STATUS, - /* ePragFlag: */ 0, - /* iArg: */ 0 }, -#endif -#if !defined(SQLITE_OMIT_PAGER_PRAGMAS) - { /* zName: */ "locking_mode", - /* ePragTyp: */ PragTyp_LOCKING_MODE, - /* ePragFlag: */ 0, - /* iArg: */ 0 }, - { /* zName: */ "max_page_count", - /* ePragTyp: */ PragTyp_PAGE_COUNT, - /* ePragFlag: */ PragFlag_NeedSchema, - /* iArg: */ 0 }, - { /* zName: */ "mmap_size", - /* ePragTyp: */ PragTyp_MMAP_SIZE, - /* ePragFlag: */ 0, - /* iArg: */ 0 }, - { /* zName: */ "page_count", - /* ePragTyp: */ PragTyp_PAGE_COUNT, - /* ePragFlag: */ PragFlag_NeedSchema, - /* iArg: */ 0 }, - { /* zName: */ "page_size", - /* ePragTyp: */ PragTyp_PAGE_SIZE, - /* ePragFlag: */ 0, - /* iArg: */ 0 }, -#endif -#if defined(SQLITE_DEBUG) - { /* zName: */ "parser_trace", - /* ePragTyp: */ PragTyp_PARSER_TRACE, - /* ePragFlag: */ 0, - /* iArg: */ 0 }, -#endif -#if !defined(SQLITE_OMIT_FLAG_PRAGMAS) - { /* zName: */ "query_only", - /* ePragTyp: */ PragTyp_FLAG, - /* ePragFlag: */ 0, - /* iArg: */ SQLITE_QueryOnly }, -#endif -#if !defined(SQLITE_OMIT_INTEGRITY_CHECK) - { /* zName: */ "quick_check", - /* ePragTyp: */ PragTyp_INTEGRITY_CHECK, - /* ePragFlag: */ PragFlag_NeedSchema, - /* iArg: */ 0 }, -#endif -#if !defined(SQLITE_OMIT_FLAG_PRAGMAS) - { /* zName: */ "read_uncommitted", - /* ePragTyp: */ PragTyp_FLAG, - /* ePragFlag: */ 0, - /* iArg: */ SQLITE_ReadUncommitted }, - { /* zName: */ "recursive_triggers", - /* ePragTyp: */ PragTyp_FLAG, - /* ePragFlag: */ 0, - /* iArg: */ SQLITE_RecTriggers }, -#endif -#if defined(SQLITE_HAS_CODEC) - { /* zName: */ "rekey", - /* ePragTyp: */ PragTyp_REKEY, - /* ePragFlag: */ 0, - /* iArg: */ 0 }, -#endif -#if !defined(SQLITE_OMIT_FLAG_PRAGMAS) - { /* zName: */ "reverse_unordered_selects", - /* ePragTyp: */ PragTyp_FLAG, - /* ePragFlag: */ 0, - /* iArg: */ SQLITE_ReverseOrder }, -#endif -#if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS) - { /* zName: */ "schema_version", - /* ePragTyp: */ PragTyp_HEADER_VALUE, - /* ePragFlag: */ 0, - /* iArg: */ BTREE_SCHEMA_VERSION }, -#endif -#if !defined(SQLITE_OMIT_PAGER_PRAGMAS) - { /* zName: */ "secure_delete", - /* ePragTyp: */ PragTyp_SECURE_DELETE, - /* ePragFlag: */ 0, - /* iArg: */ 0 }, -#endif -#if !defined(SQLITE_OMIT_FLAG_PRAGMAS) - { /* zName: */ "short_column_names", - /* ePragTyp: */ PragTyp_FLAG, - /* ePragFlag: */ 0, - /* iArg: */ SQLITE_ShortColNames }, -#endif - { /* zName: */ "shrink_memory", - /* ePragTyp: */ PragTyp_SHRINK_MEMORY, - /* ePragFlag: */ 0, - /* iArg: */ 0 }, - { /* zName: */ "soft_heap_limit", - /* ePragTyp: */ PragTyp_SOFT_HEAP_LIMIT, - /* ePragFlag: */ 0, - /* iArg: */ 0 }, -#if !defined(SQLITE_OMIT_FLAG_PRAGMAS) -#if defined(SQLITE_DEBUG) - { /* zName: */ "sql_trace", - /* ePragTyp: */ PragTyp_FLAG, - /* ePragFlag: */ 0, - /* iArg: */ SQLITE_SqlTrace }, -#endif -#endif -#if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) - { /* zName: */ "stats", - /* ePragTyp: */ PragTyp_STATS, - /* ePragFlag: */ PragFlag_NeedSchema, - /* iArg: */ 0 }, -#endif -#if !defined(SQLITE_OMIT_PAGER_PRAGMAS) - { /* zName: */ "synchronous", - /* ePragTyp: */ PragTyp_SYNCHRONOUS, - /* ePragFlag: */ PragFlag_NeedSchema, - /* iArg: */ 0 }, -#endif -#if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) - { /* zName: */ "table_info", - /* ePragTyp: */ PragTyp_TABLE_INFO, - /* ePragFlag: */ PragFlag_NeedSchema, - /* iArg: */ 0 }, -#endif -#if !defined(SQLITE_OMIT_PAGER_PRAGMAS) - { /* zName: */ "temp_store", - /* ePragTyp: */ PragTyp_TEMP_STORE, - /* ePragFlag: */ 0, - /* iArg: */ 0 }, - { /* zName: */ "temp_store_directory", - /* ePragTyp: */ PragTyp_TEMP_STORE_DIRECTORY, - /* ePragFlag: */ 0, - /* iArg: */ 0 }, -#endif - { /* zName: */ "threads", - /* ePragTyp: */ PragTyp_THREADS, - /* ePragFlag: */ 0, - /* iArg: */ 0 }, -#if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS) - { /* zName: */ "user_version", - /* ePragTyp: */ PragTyp_HEADER_VALUE, - /* ePragFlag: */ 0, - /* iArg: */ BTREE_USER_VERSION }, -#endif -#if !defined(SQLITE_OMIT_FLAG_PRAGMAS) -#if defined(SQLITE_DEBUG) - { /* zName: */ "vdbe_addoptrace", - /* ePragTyp: */ PragTyp_FLAG, - /* ePragFlag: */ 0, - /* iArg: */ SQLITE_VdbeAddopTrace }, - { /* zName: */ "vdbe_debug", - /* ePragTyp: */ PragTyp_FLAG, - /* ePragFlag: */ 0, - /* iArg: */ SQLITE_SqlTrace|SQLITE_VdbeListing|SQLITE_VdbeTrace }, - { /* zName: */ "vdbe_eqp", - /* ePragTyp: */ PragTyp_FLAG, - /* ePragFlag: */ 0, - /* iArg: */ SQLITE_VdbeEQP }, - { /* zName: */ "vdbe_listing", - /* ePragTyp: */ PragTyp_FLAG, - /* ePragFlag: */ 0, - /* iArg: */ SQLITE_VdbeListing }, - { /* zName: */ "vdbe_trace", - /* ePragTyp: */ PragTyp_FLAG, - /* ePragFlag: */ 0, - /* iArg: */ SQLITE_VdbeTrace }, -#endif -#endif -#if !defined(SQLITE_OMIT_WAL) - { /* zName: */ "wal_autocheckpoint", - /* ePragTyp: */ PragTyp_WAL_AUTOCHECKPOINT, - /* ePragFlag: */ 0, - /* iArg: */ 0 }, - { /* zName: */ "wal_checkpoint", - /* ePragTyp: */ PragTyp_WAL_CHECKPOINT, - /* ePragFlag: */ PragFlag_NeedSchema, - /* iArg: */ 0 }, -#endif -#if !defined(SQLITE_OMIT_FLAG_PRAGMAS) - { /* zName: */ "writable_schema", - /* ePragTyp: */ PragTyp_FLAG, - /* ePragFlag: */ 0, - /* iArg: */ SQLITE_WriteSchema|SQLITE_RecoveryMode }, -#endif -}; -/* Number of pragmas: 58 on by default, 71 total. */ -/* End of the automatically generated pragma table. -***************************************************************************/ +** The "pragma.h" include file is an automatically generated file that +** that includes the PragType_XXXX macro definitions and the aPragmaName[] +** object. This ensures that the aPragmaName[] table is arranged in +** lexicographical order to facility a binary search of the pragma name. +** Do not edit pragma.h directly. Edit and rerun the script in at +** ../tool/mkpragmatab.tcl. */ +#include "pragma.h" /* ** Interpret the given string as a safety level. Return 0 for OFF, diff --git a/src/pragma.h b/src/pragma.h new file mode 100644 index 0000000000..e5ffeb35c9 --- /dev/null +++ b/src/pragma.h @@ -0,0 +1,455 @@ +/* DO NOT EDIT! +** This file is automatically generated by the script at +** ../tool/mkpragmatab.tcl. To update the set of pragmas, edit +** that script and rerun it. +*/ +#define PragTyp_HEADER_VALUE 0 +#define PragTyp_AUTO_VACUUM 1 +#define PragTyp_FLAG 2 +#define PragTyp_BUSY_TIMEOUT 3 +#define PragTyp_CACHE_SIZE 4 +#define PragTyp_CASE_SENSITIVE_LIKE 5 +#define PragTyp_COLLATION_LIST 6 +#define PragTyp_COMPILE_OPTIONS 7 +#define PragTyp_DATA_STORE_DIRECTORY 8 +#define PragTyp_DATABASE_LIST 9 +#define PragTyp_DEFAULT_CACHE_SIZE 10 +#define PragTyp_ENCODING 11 +#define PragTyp_FOREIGN_KEY_CHECK 12 +#define PragTyp_FOREIGN_KEY_LIST 13 +#define PragTyp_INCREMENTAL_VACUUM 14 +#define PragTyp_INDEX_INFO 15 +#define PragTyp_INDEX_LIST 16 +#define PragTyp_INTEGRITY_CHECK 17 +#define PragTyp_JOURNAL_MODE 18 +#define PragTyp_JOURNAL_SIZE_LIMIT 19 +#define PragTyp_LOCK_PROXY_FILE 20 +#define PragTyp_LOCKING_MODE 21 +#define PragTyp_PAGE_COUNT 22 +#define PragTyp_MMAP_SIZE 23 +#define PragTyp_PAGE_SIZE 24 +#define PragTyp_SECURE_DELETE 25 +#define PragTyp_SHRINK_MEMORY 26 +#define PragTyp_SOFT_HEAP_LIMIT 27 +#define PragTyp_STATS 28 +#define PragTyp_SYNCHRONOUS 29 +#define PragTyp_TABLE_INFO 30 +#define PragTyp_TEMP_STORE 31 +#define PragTyp_TEMP_STORE_DIRECTORY 32 +#define PragTyp_THREADS 33 +#define PragTyp_WAL_AUTOCHECKPOINT 34 +#define PragTyp_WAL_CHECKPOINT 35 +#define PragTyp_ACTIVATE_EXTENSIONS 36 +#define PragTyp_HEXKEY 37 +#define PragTyp_KEY 38 +#define PragTyp_REKEY 39 +#define PragTyp_LOCK_STATUS 40 +#define PragTyp_PARSER_TRACE 41 +#define PragFlag_NeedSchema 0x01 +#define PragFlag_ReadOnly 0x02 +static const struct sPragmaNames { + const char *const zName; /* Name of pragma */ + u8 ePragTyp; /* PragTyp_XXX value */ + u8 mPragFlag; /* Zero or more PragFlag_XXX values */ + u32 iArg; /* Extra argument */ +} aPragmaNames[] = { +#if defined(SQLITE_HAS_CODEC) || defined(SQLITE_ENABLE_CEROD) + { /* zName: */ "activate_extensions", + /* ePragTyp: */ PragTyp_ACTIVATE_EXTENSIONS, + /* ePragFlag: */ 0, + /* iArg: */ 0 }, +#endif +#if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS) + { /* zName: */ "application_id", + /* ePragTyp: */ PragTyp_HEADER_VALUE, + /* ePragFlag: */ 0, + /* iArg: */ BTREE_APPLICATION_ID }, +#endif +#if !defined(SQLITE_OMIT_AUTOVACUUM) + { /* zName: */ "auto_vacuum", + /* ePragTyp: */ PragTyp_AUTO_VACUUM, + /* ePragFlag: */ PragFlag_NeedSchema, + /* iArg: */ 0 }, +#endif +#if !defined(SQLITE_OMIT_FLAG_PRAGMAS) +#if !defined(SQLITE_OMIT_AUTOMATIC_INDEX) + { /* zName: */ "automatic_index", + /* ePragTyp: */ PragTyp_FLAG, + /* ePragFlag: */ 0, + /* iArg: */ SQLITE_AutoIndex }, +#endif +#endif + { /* zName: */ "busy_timeout", + /* ePragTyp: */ PragTyp_BUSY_TIMEOUT, + /* ePragFlag: */ 0, + /* iArg: */ 0 }, +#if !defined(SQLITE_OMIT_PAGER_PRAGMAS) + { /* zName: */ "cache_size", + /* ePragTyp: */ PragTyp_CACHE_SIZE, + /* ePragFlag: */ PragFlag_NeedSchema, + /* iArg: */ 0 }, +#endif +#if !defined(SQLITE_OMIT_FLAG_PRAGMAS) + { /* zName: */ "cache_spill", + /* ePragTyp: */ PragTyp_FLAG, + /* ePragFlag: */ 0, + /* iArg: */ SQLITE_CacheSpill }, +#endif + { /* zName: */ "case_sensitive_like", + /* ePragTyp: */ PragTyp_CASE_SENSITIVE_LIKE, + /* ePragFlag: */ 0, + /* iArg: */ 0 }, +#if !defined(SQLITE_OMIT_FLAG_PRAGMAS) + { /* zName: */ "checkpoint_fullfsync", + /* ePragTyp: */ PragTyp_FLAG, + /* ePragFlag: */ 0, + /* iArg: */ SQLITE_CkptFullFSync }, +#endif +#if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) + { /* zName: */ "collation_list", + /* ePragTyp: */ PragTyp_COLLATION_LIST, + /* ePragFlag: */ 0, + /* iArg: */ 0 }, +#endif +#if !defined(SQLITE_OMIT_COMPILEOPTION_DIAGS) + { /* zName: */ "compile_options", + /* ePragTyp: */ PragTyp_COMPILE_OPTIONS, + /* ePragFlag: */ 0, + /* iArg: */ 0 }, +#endif +#if !defined(SQLITE_OMIT_FLAG_PRAGMAS) + { /* zName: */ "count_changes", + /* ePragTyp: */ PragTyp_FLAG, + /* ePragFlag: */ 0, + /* iArg: */ SQLITE_CountRows }, +#endif +#if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && SQLITE_OS_WIN + { /* zName: */ "data_store_directory", + /* ePragTyp: */ PragTyp_DATA_STORE_DIRECTORY, + /* ePragFlag: */ 0, + /* iArg: */ 0 }, +#endif +#if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS) + { /* zName: */ "data_version", + /* ePragTyp: */ PragTyp_HEADER_VALUE, + /* ePragFlag: */ PragFlag_ReadOnly, + /* iArg: */ BTREE_DATA_VERSION }, +#endif +#if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) + { /* zName: */ "database_list", + /* ePragTyp: */ PragTyp_DATABASE_LIST, + /* ePragFlag: */ PragFlag_NeedSchema, + /* iArg: */ 0 }, +#endif +#if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && !defined(SQLITE_OMIT_DEPRECATED) + { /* zName: */ "default_cache_size", + /* ePragTyp: */ PragTyp_DEFAULT_CACHE_SIZE, + /* ePragFlag: */ PragFlag_NeedSchema, + /* iArg: */ 0 }, +#endif +#if !defined(SQLITE_OMIT_FLAG_PRAGMAS) +#if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER) + { /* zName: */ "defer_foreign_keys", + /* ePragTyp: */ PragTyp_FLAG, + /* ePragFlag: */ 0, + /* iArg: */ SQLITE_DeferFKs }, +#endif +#endif +#if !defined(SQLITE_OMIT_FLAG_PRAGMAS) + { /* zName: */ "empty_result_callbacks", + /* ePragTyp: */ PragTyp_FLAG, + /* ePragFlag: */ 0, + /* iArg: */ SQLITE_NullCallback }, +#endif +#if !defined(SQLITE_OMIT_UTF16) + { /* zName: */ "encoding", + /* ePragTyp: */ PragTyp_ENCODING, + /* ePragFlag: */ 0, + /* iArg: */ 0 }, +#endif +#if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER) + { /* zName: */ "foreign_key_check", + /* ePragTyp: */ PragTyp_FOREIGN_KEY_CHECK, + /* ePragFlag: */ PragFlag_NeedSchema, + /* iArg: */ 0 }, +#endif +#if !defined(SQLITE_OMIT_FOREIGN_KEY) + { /* zName: */ "foreign_key_list", + /* ePragTyp: */ PragTyp_FOREIGN_KEY_LIST, + /* ePragFlag: */ PragFlag_NeedSchema, + /* iArg: */ 0 }, +#endif +#if !defined(SQLITE_OMIT_FLAG_PRAGMAS) +#if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER) + { /* zName: */ "foreign_keys", + /* ePragTyp: */ PragTyp_FLAG, + /* ePragFlag: */ 0, + /* iArg: */ SQLITE_ForeignKeys }, +#endif +#endif +#if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS) + { /* zName: */ "freelist_count", + /* ePragTyp: */ PragTyp_HEADER_VALUE, + /* ePragFlag: */ PragFlag_ReadOnly, + /* iArg: */ BTREE_FREE_PAGE_COUNT }, +#endif +#if !defined(SQLITE_OMIT_FLAG_PRAGMAS) + { /* zName: */ "full_column_names", + /* ePragTyp: */ PragTyp_FLAG, + /* ePragFlag: */ 0, + /* iArg: */ SQLITE_FullColNames }, + { /* zName: */ "fullfsync", + /* ePragTyp: */ PragTyp_FLAG, + /* ePragFlag: */ 0, + /* iArg: */ SQLITE_FullFSync }, +#endif +#if defined(SQLITE_HAS_CODEC) + { /* zName: */ "hexkey", + /* ePragTyp: */ PragTyp_HEXKEY, + /* ePragFlag: */ 0, + /* iArg: */ 0 }, + { /* zName: */ "hexrekey", + /* ePragTyp: */ PragTyp_HEXKEY, + /* ePragFlag: */ 0, + /* iArg: */ 0 }, +#endif +#if !defined(SQLITE_OMIT_FLAG_PRAGMAS) +#if !defined(SQLITE_OMIT_CHECK) + { /* zName: */ "ignore_check_constraints", + /* ePragTyp: */ PragTyp_FLAG, + /* ePragFlag: */ 0, + /* iArg: */ SQLITE_IgnoreChecks }, +#endif +#endif +#if !defined(SQLITE_OMIT_AUTOVACUUM) + { /* zName: */ "incremental_vacuum", + /* ePragTyp: */ PragTyp_INCREMENTAL_VACUUM, + /* ePragFlag: */ PragFlag_NeedSchema, + /* iArg: */ 0 }, +#endif +#if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) + { /* zName: */ "index_info", + /* ePragTyp: */ PragTyp_INDEX_INFO, + /* ePragFlag: */ PragFlag_NeedSchema, + /* iArg: */ 0 }, + { /* zName: */ "index_list", + /* ePragTyp: */ PragTyp_INDEX_LIST, + /* ePragFlag: */ PragFlag_NeedSchema, + /* iArg: */ 0 }, +#endif +#if !defined(SQLITE_OMIT_INTEGRITY_CHECK) + { /* zName: */ "integrity_check", + /* ePragTyp: */ PragTyp_INTEGRITY_CHECK, + /* ePragFlag: */ PragFlag_NeedSchema, + /* iArg: */ 0 }, +#endif +#if !defined(SQLITE_OMIT_PAGER_PRAGMAS) + { /* zName: */ "journal_mode", + /* ePragTyp: */ PragTyp_JOURNAL_MODE, + /* ePragFlag: */ PragFlag_NeedSchema, + /* iArg: */ 0 }, + { /* zName: */ "journal_size_limit", + /* ePragTyp: */ PragTyp_JOURNAL_SIZE_LIMIT, + /* ePragFlag: */ 0, + /* iArg: */ 0 }, +#endif +#if defined(SQLITE_HAS_CODEC) + { /* zName: */ "key", + /* ePragTyp: */ PragTyp_KEY, + /* ePragFlag: */ 0, + /* iArg: */ 0 }, +#endif +#if !defined(SQLITE_OMIT_FLAG_PRAGMAS) + { /* zName: */ "legacy_file_format", + /* ePragTyp: */ PragTyp_FLAG, + /* ePragFlag: */ 0, + /* iArg: */ SQLITE_LegacyFileFmt }, +#endif +#if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && SQLITE_ENABLE_LOCKING_STYLE + { /* zName: */ "lock_proxy_file", + /* ePragTyp: */ PragTyp_LOCK_PROXY_FILE, + /* ePragFlag: */ 0, + /* iArg: */ 0 }, +#endif +#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST) + { /* zName: */ "lock_status", + /* ePragTyp: */ PragTyp_LOCK_STATUS, + /* ePragFlag: */ 0, + /* iArg: */ 0 }, +#endif +#if !defined(SQLITE_OMIT_PAGER_PRAGMAS) + { /* zName: */ "locking_mode", + /* ePragTyp: */ PragTyp_LOCKING_MODE, + /* ePragFlag: */ 0, + /* iArg: */ 0 }, + { /* zName: */ "max_page_count", + /* ePragTyp: */ PragTyp_PAGE_COUNT, + /* ePragFlag: */ PragFlag_NeedSchema, + /* iArg: */ 0 }, + { /* zName: */ "mmap_size", + /* ePragTyp: */ PragTyp_MMAP_SIZE, + /* ePragFlag: */ 0, + /* iArg: */ 0 }, + { /* zName: */ "page_count", + /* ePragTyp: */ PragTyp_PAGE_COUNT, + /* ePragFlag: */ PragFlag_NeedSchema, + /* iArg: */ 0 }, + { /* zName: */ "page_size", + /* ePragTyp: */ PragTyp_PAGE_SIZE, + /* ePragFlag: */ 0, + /* iArg: */ 0 }, +#endif +#if defined(SQLITE_DEBUG) + { /* zName: */ "parser_trace", + /* ePragTyp: */ PragTyp_PARSER_TRACE, + /* ePragFlag: */ 0, + /* iArg: */ 0 }, +#endif +#if !defined(SQLITE_OMIT_FLAG_PRAGMAS) + { /* zName: */ "query_only", + /* ePragTyp: */ PragTyp_FLAG, + /* ePragFlag: */ 0, + /* iArg: */ SQLITE_QueryOnly }, +#endif +#if !defined(SQLITE_OMIT_INTEGRITY_CHECK) + { /* zName: */ "quick_check", + /* ePragTyp: */ PragTyp_INTEGRITY_CHECK, + /* ePragFlag: */ PragFlag_NeedSchema, + /* iArg: */ 0 }, +#endif +#if !defined(SQLITE_OMIT_FLAG_PRAGMAS) + { /* zName: */ "read_uncommitted", + /* ePragTyp: */ PragTyp_FLAG, + /* ePragFlag: */ 0, + /* iArg: */ SQLITE_ReadUncommitted }, + { /* zName: */ "recursive_triggers", + /* ePragTyp: */ PragTyp_FLAG, + /* ePragFlag: */ 0, + /* iArg: */ SQLITE_RecTriggers }, +#endif +#if defined(SQLITE_HAS_CODEC) + { /* zName: */ "rekey", + /* ePragTyp: */ PragTyp_REKEY, + /* ePragFlag: */ 0, + /* iArg: */ 0 }, +#endif +#if !defined(SQLITE_OMIT_FLAG_PRAGMAS) + { /* zName: */ "reverse_unordered_selects", + /* ePragTyp: */ PragTyp_FLAG, + /* ePragFlag: */ 0, + /* iArg: */ SQLITE_ReverseOrder }, +#endif +#if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS) + { /* zName: */ "schema_version", + /* ePragTyp: */ PragTyp_HEADER_VALUE, + /* ePragFlag: */ 0, + /* iArg: */ BTREE_SCHEMA_VERSION }, +#endif +#if !defined(SQLITE_OMIT_PAGER_PRAGMAS) + { /* zName: */ "secure_delete", + /* ePragTyp: */ PragTyp_SECURE_DELETE, + /* ePragFlag: */ 0, + /* iArg: */ 0 }, +#endif +#if !defined(SQLITE_OMIT_FLAG_PRAGMAS) + { /* zName: */ "short_column_names", + /* ePragTyp: */ PragTyp_FLAG, + /* ePragFlag: */ 0, + /* iArg: */ SQLITE_ShortColNames }, +#endif + { /* zName: */ "shrink_memory", + /* ePragTyp: */ PragTyp_SHRINK_MEMORY, + /* ePragFlag: */ 0, + /* iArg: */ 0 }, + { /* zName: */ "soft_heap_limit", + /* ePragTyp: */ PragTyp_SOFT_HEAP_LIMIT, + /* ePragFlag: */ 0, + /* iArg: */ 0 }, +#if !defined(SQLITE_OMIT_FLAG_PRAGMAS) +#if defined(SQLITE_DEBUG) + { /* zName: */ "sql_trace", + /* ePragTyp: */ PragTyp_FLAG, + /* ePragFlag: */ 0, + /* iArg: */ SQLITE_SqlTrace }, +#endif +#endif +#if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) + { /* zName: */ "stats", + /* ePragTyp: */ PragTyp_STATS, + /* ePragFlag: */ PragFlag_NeedSchema, + /* iArg: */ 0 }, +#endif +#if !defined(SQLITE_OMIT_PAGER_PRAGMAS) + { /* zName: */ "synchronous", + /* ePragTyp: */ PragTyp_SYNCHRONOUS, + /* ePragFlag: */ PragFlag_NeedSchema, + /* iArg: */ 0 }, +#endif +#if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) + { /* zName: */ "table_info", + /* ePragTyp: */ PragTyp_TABLE_INFO, + /* ePragFlag: */ PragFlag_NeedSchema, + /* iArg: */ 0 }, +#endif +#if !defined(SQLITE_OMIT_PAGER_PRAGMAS) + { /* zName: */ "temp_store", + /* ePragTyp: */ PragTyp_TEMP_STORE, + /* ePragFlag: */ 0, + /* iArg: */ 0 }, + { /* zName: */ "temp_store_directory", + /* ePragTyp: */ PragTyp_TEMP_STORE_DIRECTORY, + /* ePragFlag: */ 0, + /* iArg: */ 0 }, +#endif + { /* zName: */ "threads", + /* ePragTyp: */ PragTyp_THREADS, + /* ePragFlag: */ 0, + /* iArg: */ 0 }, +#if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS) + { /* zName: */ "user_version", + /* ePragTyp: */ PragTyp_HEADER_VALUE, + /* ePragFlag: */ 0, + /* iArg: */ BTREE_USER_VERSION }, +#endif +#if !defined(SQLITE_OMIT_FLAG_PRAGMAS) +#if defined(SQLITE_DEBUG) + { /* zName: */ "vdbe_addoptrace", + /* ePragTyp: */ PragTyp_FLAG, + /* ePragFlag: */ 0, + /* iArg: */ SQLITE_VdbeAddopTrace }, + { /* zName: */ "vdbe_debug", + /* ePragTyp: */ PragTyp_FLAG, + /* ePragFlag: */ 0, + /* iArg: */ SQLITE_SqlTrace|SQLITE_VdbeListing|SQLITE_VdbeTrace }, + { /* zName: */ "vdbe_eqp", + /* ePragTyp: */ PragTyp_FLAG, + /* ePragFlag: */ 0, + /* iArg: */ SQLITE_VdbeEQP }, + { /* zName: */ "vdbe_listing", + /* ePragTyp: */ PragTyp_FLAG, + /* ePragFlag: */ 0, + /* iArg: */ SQLITE_VdbeListing }, + { /* zName: */ "vdbe_trace", + /* ePragTyp: */ PragTyp_FLAG, + /* ePragFlag: */ 0, + /* iArg: */ SQLITE_VdbeTrace }, +#endif +#endif +#if !defined(SQLITE_OMIT_WAL) + { /* zName: */ "wal_autocheckpoint", + /* ePragTyp: */ PragTyp_WAL_AUTOCHECKPOINT, + /* ePragFlag: */ 0, + /* iArg: */ 0 }, + { /* zName: */ "wal_checkpoint", + /* ePragTyp: */ PragTyp_WAL_CHECKPOINT, + /* ePragFlag: */ PragFlag_NeedSchema, + /* iArg: */ 0 }, +#endif +#if !defined(SQLITE_OMIT_FLAG_PRAGMAS) + { /* zName: */ "writable_schema", + /* ePragTyp: */ PragTyp_FLAG, + /* ePragFlag: */ 0, + /* iArg: */ SQLITE_WriteSchema|SQLITE_RecoveryMode }, +#endif +}; +/* Number of pragmas: 58 on by default, 71 total. */ diff --git a/tool/mkpragmatab.tcl b/tool/mkpragmatab.tcl index 21503d16ee..2ba8c9da2a 100644 --- a/tool/mkpragmatab.tcl +++ b/tool/mkpragmatab.tcl @@ -4,10 +4,10 @@ # # To add new pragmas, first add the name and other relevant attributes # of the pragma to the "pragma_def" object below. Then run this script -# to generate the C-code for the lookup table and copy/paste the output -# of this script into the appropriate spot in the pragma.c source file. +# to generate the ../src/pragma.h header file that contains macros and +# the lookup table needed for pragma name lookup in the pragma.c module. # Then add the extra "case PragTyp_XXXXX:" and subsequent code for the -# new pragma. +# new pragma in ../src/pragma.c. # set pragma_def { @@ -308,7 +308,20 @@ set pragma_def { NAME: threads } -fconfigure stdout -translation lf + +# Open the output file +# +set destfile "[file dir [file dir [file normal $argv0]]]/src/pragma.h" +puts "Overwriting $destfile with new pragma table..." +set fd [open $destfile wb] +puts $fd {/* DO NOT EDIT! +** This file is automatically generated by the script at +** ../tool/mkpragmatab.tcl. To update the set of pragmas, edit +** that script and rerun it. +*/} + +# Parse the PRAGMA table above. +# set name {} set type {} set if {} @@ -362,7 +375,7 @@ foreach name $allnames { set if [lindex $allbyname($name) 2] if {[regexp SQLITE_DEBUG $if] || [regexp SQLITE_HAS_CODEC $if]} continue set seentype($type) 1 - puts [format {#define %-35s %4d} PragTyp_$type $pnum] + puts $fd [format {#define %-35s %4d} PragTyp_$type $pnum] incr pnum } foreach name $allnames { @@ -371,14 +384,14 @@ foreach name $allnames { set if [lindex $allbyname($name) 2] if {[regexp SQLITE_DEBUG $if]} continue set seentype($type) 1 - puts [format {#define %-35s %4d} PragTyp_$type $pnum] + puts $fd [format {#define %-35s %4d} PragTyp_$type $pnum] incr pnum } foreach name $allnames { set type [lindex $allbyname($name) 0] if {[info exists seentype($type)]} continue set seentype($type) 1 - puts [format {#define %-35s %4d} PragTyp_$type $pnum] + puts $fd [format {#define %-35s %4d} PragTyp_$type $pnum] incr pnum } @@ -386,18 +399,18 @@ foreach name $allnames { # set fv 1 foreach f [lsort [array names allflags]] { - puts [format {#define PragFlag_%-20s 0x%02x} $f $fv] + puts $fd [format {#define PragFlag_%-20s 0x%02x} $f $fv] set fv [expr {$fv*2}] } # Generate the lookup table # -puts "static const struct sPragmaNames \173" -puts " const char *const zName; /* Name of pragma */" -puts " u8 ePragTyp; /* PragTyp_XXX value */" -puts " u8 mPragFlag; /* Zero or more PragFlag_XXX values */" -puts " u32 iArg; /* Extra argument */" -puts "\175 aPragmaNames\[\] = \173" +puts $fd "static const struct sPragmaNames \173" +puts $fd " const char *const zName; /* Name of pragma */" +puts $fd " u8 ePragTyp; /* PragTyp_XXX value */" +puts $fd " u8 mPragFlag; /* Zero or more PragFlag_XXX values */" +puts $fd " u32 iArg; /* Extra argument */" +puts $fd "\175 aPragmaNames\[\] = \173" set current_if {} set spacer [format { %26s } {}] @@ -406,13 +419,13 @@ foreach name $allnames { if {$if!=$current_if} { if {$current_if!=""} { foreach this_if $current_if { - puts "#endif" + puts $fd "#endif" } } set current_if $if if {$current_if!=""} { foreach this_if $current_if { - puts "#if $this_if" + puts $fd "#if $this_if" } } } @@ -422,17 +435,17 @@ foreach name $allnames { } else { set flagx PragFlag_[join $flag {|PragFlag_}] } - puts " \173 /* zName: */ \"$name\"," - puts " /* ePragTyp: */ PragTyp_$type," - puts " /* ePragFlag: */ $flagx," - puts " /* iArg: */ $arg \175," + puts $fd " \173 /* zName: */ \"$name\"," + puts $fd " /* ePragTyp: */ PragTyp_$type," + puts $fd " /* ePragFlag: */ $flagx," + puts $fd " /* iArg: */ $arg \175," } if {$current_if!=""} { foreach this_if $current_if { - puts "#endif" + puts $fd "#endif" } } -puts "\175;" +puts $fd "\175;" # count the number of pragmas, for information purposes # @@ -444,4 +457,4 @@ foreach name $allnames { if {[regexp {^defined} $if] || [regexp {[^!]defined} $if]} continue incr dfltcnt } -puts "/* Number of pragmas: $dfltcnt on by default, $allcnt total. */" +puts $fd "/* Number of pragmas: $dfltcnt on by default, $allcnt total. */" diff --git a/tool/mksqlite3c.tcl b/tool/mksqlite3c.tcl index 1d597a51a0..4ab8b12b45 100644 --- a/tool/mksqlite3c.tcl +++ b/tool/mksqlite3c.tcl @@ -110,6 +110,7 @@ foreach hdr { pager.h parse.h pcache.h + pragma.h rtree.h sqlite3ext.h sqlite3.h From 1dae26bdab5b7fbeab61bfc0b22d699f920087d1 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 3 Feb 2015 19:20:03 +0000 Subject: [PATCH 26/62] Fix a typo in the --help output for speedtest1. Fix a dependency error in the Makefile.in for speedtest1. FossilOrigin-Name: f30a057aeeac2b863493b6325325b075a76b9d21 --- Makefile.in | 2 +- manifest | 14 +++++++------- manifest.uuid | 2 +- test/speedtest1.c | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Makefile.in b/Makefile.in index 1d7be55f74..750b8fd8b5 100644 --- a/Makefile.in +++ b/Makefile.in @@ -997,7 +997,7 @@ LogEst$(TEXE): $(TOP)/tool/logest.c sqlite3.h wordcount$(TEXE): $(TOP)/test/wordcount.c sqlite3.c $(LTLINK) -o $@ $(TOP)/test/wordcount.c sqlite3.c $(TLIBS) -speedtest1$(TEXE): $(TOP)/test/wordcount.c sqlite3.lo +speedtest1$(TEXE): $(TOP)/test/speedtest1.c sqlite3.lo $(LTLINK) -o $@ $(TOP)/test/speedtest1.c sqlite3.lo $(TLIBS) # This target will fail if the SQLite amalgamation contains any exported diff --git a/manifest b/manifest index a2f72263ab..8ff01bd4f0 100644 --- a/manifest +++ b/manifest @@ -1,7 +1,7 @@ -C Break\sout\sthe\s(script-generated)\spragma\sparsing\stables\sinto\sa\sseparate\sfile,\npragma.h,\sto\smake\sediting\seasier. -D 2015-02-02T21:34:54.408 +C Fix\sa\stypo\sin\sthe\s--help\soutput\sfor\sspeedtest1.\s\sFix\sa\sdependency\serror\nin\sthe\sMakefile.in\sfor\sspeedtest1. +D 2015-02-03T19:20:03.925 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f -F Makefile.in cbe64ed4d90a19062b804f7fbd319080f851b004 +F Makefile.in 6b9e7677829aa94b9f30949656e27312aefb9a46 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 F Makefile.msc fc6b0b233b5621f3e56298e4d6a0b3f6c936c520 F Makefile.vxworks e1b65dea203f054e71653415bd8f96dcaed47858 @@ -888,7 +888,7 @@ F test/speed3.test d32043614c08c53eafdc80f33191d5bd9b920523 F test/speed4.test abc0ad3399dcf9703abed2fff8705e4f8e416715 F test/speed4p.explain 6b5f104ebeb34a038b2f714150f51d01143e59aa F test/speed4p.test 0e51908951677de5a969b723e03a27a1c45db38b -F test/speedtest1.c e4e2aa37ff66bad9f414a50a8cb9edfaac65c9e5 +F test/speedtest1.c 2b416dca3a155fcaa849540b2e7fc1df12896c23 F test/spellfix.test 24f676831acddd2f4056a598fd731a72c6311f49 F test/sqllimits1.test 9014524e7ab16e2a4976b13397db4c29cc29c6d9 F test/stat.test 76fd746b85459e812a0193410fb599f0531f22de @@ -1239,7 +1239,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 42d5601739c90434e5adfda8fa99ef7b903877db -R ad79dcf7ddc97ee53618558cb6690870 +P 32c0325bcb083fe3f0f0cfe999d00f754e15299e +R bad15cd9a09e70db326718a2b46f4f15 U drh -Z 0fdc8db6e22e6c93e424fbfcfceed021 +Z 7d911e25922695ad0d97d7880d37d5b6 diff --git a/manifest.uuid b/manifest.uuid index b9ef8ce9ed..68eca21c3a 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -32c0325bcb083fe3f0f0cfe999d00f754e15299e \ No newline at end of file +f30a057aeeac2b863493b6325325b075a76b9d21 \ No newline at end of file diff --git a/test/speedtest1.c b/test/speedtest1.c index 8e5b74c56e..93f7d145ee 100644 --- a/test/speedtest1.c +++ b/test/speedtest1.c @@ -12,7 +12,7 @@ static const char zHelp[] = " --explain Like --sqlonly but with added EXPLAIN keywords\n" " --heap SZ MIN Memory allocator uses SZ bytes & min allocation MIN\n" " --incrvacuum Enable incremenatal vacuum mode\n" - " --journalmode M Set the journal_mode to MODE\n" + " --journal M Set the journal_mode to M\n" " --key KEY Set the encryption key to KEY\n" " --lookaside N SZ Configure lookaside for N slots of SZ bytes each\n" " --nosync Set PRAGMA synchronous=OFF\n" From 8fb15e3b20ddbf95a09d1cb2605979ece2f61770 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 4 Feb 2015 20:56:49 +0000 Subject: [PATCH 27/62] Fix a missing mutex in SQLITE_TESTCTRL_IMPOSTER. FossilOrigin-Name: 71691c4be54b9ac6a35e35013f939b7d6fd4e6b8 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/main.c | 2 ++ 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/manifest b/manifest index 8ff01bd4f0..a6ffc54bbf 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\stypo\sin\sthe\s--help\soutput\sfor\sspeedtest1.\s\sFix\sa\sdependency\serror\nin\sthe\sMakefile.in\sfor\sspeedtest1. -D 2015-02-03T19:20:03.925 +C Fix\sa\smissing\smutex\sin\sSQLITE_TESTCTRL_IMPOSTER. +D 2015-02-04T20:56:49.607 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 6b9e7677829aa94b9f30949656e27312aefb9a46 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -195,7 +195,7 @@ F src/journal.c b4124532212b6952f42eb2c12fa3c25701d8ba8d F src/legacy.c ba1863ea58c4c840335a84ec276fc2b25e22bc4e F src/lempar.c 7274c97d24bb46631e504332ccd3bd1b37841770 F src/loadext.c 86bd4e2fccd520b748cba52492ab60c4a770f660 -F src/main.c ce38ddcedf33e5530b0e6c592809bb8822a6e8d0 +F src/main.c 17e3a37374f3c13e27311773c30720b61584f5b9 F src/malloc.c 740db54387204c9a2eb67c6d98e68b08e9ef4eab F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645 F src/mem1.c abe6ee469b6c5a35c7f22bfeb9c9bac664a1c987 @@ -1239,7 +1239,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 32c0325bcb083fe3f0f0cfe999d00f754e15299e -R bad15cd9a09e70db326718a2b46f4f15 +P f30a057aeeac2b863493b6325325b075a76b9d21 +R 7062d08c73f32c9ecf1fbd0a908460e5 U drh -Z 7d911e25922695ad0d97d7880d37d5b6 +Z 50e6879801fe010f0d0350ec5e4483dd diff --git a/manifest.uuid b/manifest.uuid index 68eca21c3a..c2bb1d10ac 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -f30a057aeeac2b863493b6325325b075a76b9d21 \ No newline at end of file +71691c4be54b9ac6a35e35013f939b7d6fd4e6b8 \ No newline at end of file diff --git a/src/main.c b/src/main.c index 11585e7dc5..fa87a19cf7 100644 --- a/src/main.c +++ b/src/main.c @@ -3617,12 +3617,14 @@ int sqlite3_test_control(int op, ...){ */ case SQLITE_TESTCTRL_IMPOSTER: { sqlite3 *db = va_arg(ap, sqlite3*); + sqlite3_mutex_enter(db->mutex); db->init.iDb = sqlite3FindDbName(db, va_arg(ap,const char*)); db->init.busy = db->init.imposterTable = va_arg(ap,int); db->init.newTnum = va_arg(ap,int); if( db->init.busy==0 && db->init.newTnum>0 ){ sqlite3ResetAllSchemasOfConnection(db); } + sqlite3_mutex_leave(db->mutex); break; } } From f7502f005e2cbf9e4773f18c0c7440580da3b9d5 Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 6 Feb 2015 14:19:44 +0000 Subject: [PATCH 28/62] Add the ".info" command to the shell. FossilOrigin-Name: 0a3100a7f264ffce6078c35e341f2f0af6c09fbb --- manifest | 13 ++++--- manifest.uuid | 2 +- src/shell.c | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 103 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index cd30735549..fe39ae0018 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sthe\sindex_xinfo\spragma\swhich\sgives\sinformation\sabout\sthe\sfields\sthat\nreference\sthe\stable\sPRIMARY\sKEY\sin\saddition\sto\sthe\sindex\skey\sfields.\nAdd\sextra\scolumns\s"desc",\s"coll",\sand\s"key"\sto\sthe\sindex_info\sand\sindex_xinfo\npragmas.\s\sAdd\sthe\s"origin"\sand\s"partial"\scolumns\sto\sthe\sindex_list\spragma. -D 2015-02-06T01:07:15.913 +C Add\sthe\s".info"\scommand\sto\sthe\sshell. +D 2015-02-06T14:19:44.541 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 6b9e7677829aa94b9f30949656e27312aefb9a46 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -231,7 +231,7 @@ F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c f6c46d3434439ab2084618d603e6d6dbeb0d6ada F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e F src/select.c 1f2087523007c42900ffcbdeaef06a23ad9329fc -F src/shell.c 22b4406b0b59efd14b3b351a5809dda517df6d30 +F src/shell.c bb60212d7dc9698e97128b9599db31a946f9b09e F src/sqlite.h.in 54678c21401909f72b221344dd560d285a1ba5eb F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h 17d487c3c91b0b8c584a32fbeb393f6f795eea7d @@ -1239,8 +1239,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 71691c4be54b9ac6a35e35013f939b7d6fd4e6b8 3af19f84446ba5fc1ed754d0d73f6a6d7fb2f365 -R 378ae50354305236538b7809f97882cb -T +closed 3af19f84446ba5fc1ed754d0d73f6a6d7fb2f365 +P 2743846cdba572f616f56d310633703b8b50959e +R d4e7fe78c9cdff1cd20452301eb37621 U drh -Z 9e4d57322f408f6027b92b8bd8c22512 +Z c6460a2ceed946b50a764986e8bd6e0e diff --git a/manifest.uuid b/manifest.uuid index 61e3ef24f0..e0dfaca80e 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -2743846cdba572f616f56d310633703b8b50959e \ No newline at end of file +0a3100a7f264ffce6078c35e341f2f0af6c09fbb \ No newline at end of file diff --git a/src/shell.c b/src/shell.c index 3130f4c6de..f0e9743bc3 100644 --- a/src/shell.c +++ b/src/shell.c @@ -1748,6 +1748,7 @@ static char zHelp[] = ".indices ?TABLE? Show names of all indices\n" " If TABLE specified, only show indices for tables\n" " matching LIKE pattern TABLE.\n" + ".info Show status information about the database\n" #ifdef SQLITE_ENABLE_IOTRACE ".iotrace FILE Enable I/O diagnostic logging to FILE\n" #endif @@ -2426,6 +2427,97 @@ static void output_reset(ShellState *p){ p->out = stdout; } +/* +** Run an SQL command and return the single integer result. +*/ +static int db_int(ShellState *p, const char *zSql){ + sqlite3_stmt *pStmt; + int res = 0; + sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0); + if( pStmt && sqlite3_step(pStmt)==SQLITE_ROW ){ + res = sqlite3_column_int(pStmt,0); + } + sqlite3_finalize(pStmt); + return res; +} + +/* +** Convert a 2-byte or 4-byte big-endian integer into a native integer +*/ +unsigned int get2byteInt(unsigned char *a){ + return (a[0]<<8) + a[1]; +} +unsigned int get4byteInt(unsigned char *a){ + return (a[0]<<24) + (a[1]<<16) + (a[2]<<8) + a[3]; +} + +/* +** Implementation of the ".info" command. +** +** Return 1 on error, 2 to exit, and 0 otherwise. +*/ +static int shell_info_command(ShellState *p){ + sqlite3_file *pFile; + int i; + unsigned char aHdr[100]; + static const struct { const char *zName; int ofst; } aField[] = { + { "file change counter:", 24 }, + { "database page count:", 28 }, + { "freelist page count:", 36 }, + { "schema cookie:", 40 }, + { "schema format:", 44 }, + { "default cache size:", 48 }, + { "autovacuum top root:", 52 }, + { "incremental vacuum:", 64 }, + { "text encoding:", 56 }, + { "user version:", 60 }, + { "application id:", 68 }, + { "software version:", 96 }, + }; + open_db(p, 0); + if( p->db==0 ) return 1; + sqlite3_file_control(p->db, "main", SQLITE_FCNTL_FILE_POINTER, &pFile); + if( pFile==0 || pFile->pMethods==0 || pFile->pMethods->xRead==0 ){ + return 1; + } + i = pFile->pMethods->xRead(pFile, aHdr, 100, 0); + if( i!=SQLITE_OK ){ + fprintf(stderr, "unable to read database header\n"); + return 1; + } + i = get2byteInt(aHdr+16); + if( i==1 ) i = 65536; + fprintf(p->out, "%-20s %d\n", "database page size:", i); + fprintf(p->out, "%-20s %d\n", "write format:", aHdr[18]); + fprintf(p->out, "%-20s %d\n", "read format:", aHdr[19]); + fprintf(p->out, "%-20s %d\n", "reserved bytes:", aHdr[20]); + for(i=0; iout, "%-20s %u", aField[i].zName, val); + switch( ofst ){ + case 56: { + if( val==1 ) fprintf(p->out, " (utf8)"); + if( val==2 ) fprintf(p->out, " (utf16le)"); + if( val==3 ) fprintf(p->out, " (utf16be)"); + } + } + fprintf(p->out, "\n"); + } + fprintf(p->out, "%-20s %d\n", "number of tables:", + db_int(p, "SELECT count(*) FROM sqlite_master WHERE type='table'")); + fprintf(p->out, "%-20s %d\n", "number of indexes:", + db_int(p, "SELECT count(*) FROM sqlite_master WHERE type='index'")); + fprintf(p->out, "%-20s %d\n", "number of triggers:", + db_int(p, "SELECT count(*) FROM sqlite_master WHERE type='trigger'")); + fprintf(p->out, "%-20s %d\n", "number of views:", + db_int(p, "SELECT count(*) FROM sqlite_master WHERE type='view'")); + fprintf(p->out, "%-20s %d\n", "schema size:", + db_int(p, "SELECT total(length(sql)) FROM sqlite_master")); + return 0; +} + + /* ** If an input line begins with "." then invoke this routine to ** process that line. @@ -2980,6 +3072,10 @@ static int do_meta_command(char *zLine, ShellState *p){ } }else + if( c=='i' && strncmp(azArg[0], "info", n)==0 ){ + rc = shell_info_command(p); + }else + #ifdef SQLITE_ENABLE_IOTRACE if( c=='i' && strncmp(azArg[0], "iotrace", n)==0 ){ extern void (*sqlite3IoTrace)(const char*, ...); From 0e55db1cd8748942e3284eb94e774d825ff223fb Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 6 Feb 2015 14:51:13 +0000 Subject: [PATCH 29/62] Change the name of ".info" to ".dbinfo" and add an optional second argument which is the ATTACH-ed DB about which information is provided. Provide ".indexes" as an alternative name to the legacy ".indices" command. FossilOrigin-Name: 0f65a7e2e09f801b66897479d501607caeae4abf --- manifest | 14 +++++----- manifest.uuid | 2 +- src/shell.c | 67 +++++++++++++++++++++++++++++++----------------- test/shell1.test | 13 ++++++---- 4 files changed, 59 insertions(+), 37 deletions(-) diff --git a/manifest b/manifest index fe39ae0018..b31e5b6454 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sthe\s".info"\scommand\sto\sthe\sshell. -D 2015-02-06T14:19:44.541 +C Change\sthe\sname\sof\s".info"\sto\s".dbinfo"\sand\sadd\san\soptional\ssecond\sargument\nwhich\sis\sthe\sATTACH-ed\sDB\sabout\swhich\sinformation\sis\sprovided.\s\sProvide\n".indexes"\sas\san\salternative\sname\sto\sthe\slegacy\s".indices"\scommand. +D 2015-02-06T14:51:13.355 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 6b9e7677829aa94b9f30949656e27312aefb9a46 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -231,7 +231,7 @@ F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c f6c46d3434439ab2084618d603e6d6dbeb0d6ada F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e F src/select.c 1f2087523007c42900ffcbdeaef06a23ad9329fc -F src/shell.c bb60212d7dc9698e97128b9599db31a946f9b09e +F src/shell.c 82c25508dac802b32198af6f5256ca1597c6a1af F src/sqlite.h.in 54678c21401909f72b221344dd560d285a1ba5eb F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h 17d487c3c91b0b8c584a32fbeb393f6f795eea7d @@ -858,7 +858,7 @@ F test/sharedA.test 0cdf1a76dfa00e6beee66af5b534b1e8df2720f5 F test/sharedB.test 16cc7178e20965d75278f410943109b77b2e645e F test/shared_err.test 2f2aee20db294b9924e81f6ccbe60f19e21e8506 F test/sharedlock.test 5ede3c37439067c43b0198f580fd374ebf15d304 -F test/shell1.test cdeb849acc2c37aada70d084564b0cc0a2c7df08 +F test/shell1.test ca88b14a8fc8b1f3543a24e519d019585ac9c903 F test/shell2.test 12b8bf901b0e3a8ac58cf5c0c63a0a388d4d1862 F test/shell3.test 5e8545ec72c4413a0e8d4c6be56496e3c257ca29 F test/shell4.test 8a9c08976291e6c6c808b4d718f4a8b299f339f5 @@ -1239,7 +1239,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 2743846cdba572f616f56d310633703b8b50959e -R d4e7fe78c9cdff1cd20452301eb37621 +P 0a3100a7f264ffce6078c35e341f2f0af6c09fbb +R a582dddcff23f4b3aa0ab625ed7ba566 U drh -Z c6460a2ceed946b50a764986e8bd6e0e +Z 91c27780af6a4d5e0c7b8a8aa90c189d diff --git a/manifest.uuid b/manifest.uuid index e0dfaca80e..408d77792f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -0a3100a7f264ffce6078c35e341f2f0af6c09fbb \ No newline at end of file +0f65a7e2e09f801b66897479d501607caeae4abf \ No newline at end of file diff --git a/src/shell.c b/src/shell.c index f0e9743bc3..77c9ab9e05 100644 --- a/src/shell.c +++ b/src/shell.c @@ -1733,6 +1733,7 @@ static char zHelp[] = ".bail on|off Stop after hitting an error. Default OFF\n" ".clone NEWDB Clone data into NEWDB from the existing database\n" ".databases List names and files of attached databases\n" + ".dbinfo ?DB? Show status information about the database\n" ".dump ?TABLE? ... Dump the database in an SQL text format\n" " If TABLE specified, only dump tables matching\n" " LIKE pattern TABLE.\n" @@ -1745,10 +1746,9 @@ static char zHelp[] = ".headers on|off Turn display of headers on or off\n" ".help Show this message\n" ".import FILE TABLE Import data from FILE into TABLE\n" - ".indices ?TABLE? Show names of all indices\n" - " If TABLE specified, only show indices for tables\n" + ".indexes ?TABLE? Show names of all indexes\n" + " If TABLE specified, only show indexes for tables\n" " matching LIKE pattern TABLE.\n" - ".info Show status information about the database\n" #ifdef SQLITE_ENABLE_IOTRACE ".iotrace FILE Enable I/O diagnostic logging to FILE\n" #endif @@ -2456,10 +2456,7 @@ unsigned int get4byteInt(unsigned char *a){ ** ** Return 1 on error, 2 to exit, and 0 otherwise. */ -static int shell_info_command(ShellState *p){ - sqlite3_file *pFile; - int i; - unsigned char aHdr[100]; +static int shell_dbinfo_command(ShellState *p, int nArg, char **azArg){ static const struct { const char *zName; int ofst; } aField[] = { { "file change counter:", 24 }, { "database page count:", 28 }, @@ -2474,9 +2471,26 @@ static int shell_info_command(ShellState *p){ { "application id:", 68 }, { "software version:", 96 }, }; + static const struct { const char *zName; const char *zSql; } aQuery[] = { + { "number of tables:", + "SELECT count(*) FROM %s WHERE type='table'" }, + { "number of indexes:", + "SELECT count(*) FROM %s WHERE type='index'" }, + { "number of triggers:", + "SELECT count(*) FROM %s WHERE type='trigger'" }, + { "number of views:", + "SELECT count(*) FROM %s WHERE type='view'" }, + { "schema size:", + "SELECT total(length(sql)) FROM %s" }, + }; + sqlite3_file *pFile; + int i; + char *zSchemaTab; + char *zDb = nArg>=2 ? azArg[1] : "main"; + unsigned char aHdr[100]; open_db(p, 0); if( p->db==0 ) return 1; - sqlite3_file_control(p->db, "main", SQLITE_FCNTL_FILE_POINTER, &pFile); + sqlite3_file_control(p->db, zDb, SQLITE_FCNTL_FILE_POINTER, &pFile); if( pFile==0 || pFile->pMethods==0 || pFile->pMethods->xRead==0 ){ return 1; } @@ -2504,16 +2518,20 @@ static int shell_info_command(ShellState *p){ } fprintf(p->out, "\n"); } - fprintf(p->out, "%-20s %d\n", "number of tables:", - db_int(p, "SELECT count(*) FROM sqlite_master WHERE type='table'")); - fprintf(p->out, "%-20s %d\n", "number of indexes:", - db_int(p, "SELECT count(*) FROM sqlite_master WHERE type='index'")); - fprintf(p->out, "%-20s %d\n", "number of triggers:", - db_int(p, "SELECT count(*) FROM sqlite_master WHERE type='trigger'")); - fprintf(p->out, "%-20s %d\n", "number of views:", - db_int(p, "SELECT count(*) FROM sqlite_master WHERE type='view'")); - fprintf(p->out, "%-20s %d\n", "schema size:", - db_int(p, "SELECT total(length(sql)) FROM sqlite_master")); + if( zDb==0 ){ + zSchemaTab = sqlite3_mprintf("main.sqlite_master"); + }else if( strcmp(zDb,"temp")==0 ){ + zSchemaTab = sqlite3_mprintf("%s", "sqlite_temp_master"); + }else{ + zSchemaTab = sqlite3_mprintf("\"%w\".sqlite_master", zDb); + } + for(i=0; iout, "%-20s %d\n", aQuery[i].zName, val); + } + sqlite3_free(zSchemaTab); return 0; } @@ -2660,6 +2678,10 @@ static int do_meta_command(char *zLine, ShellState *p){ } }else + if( c=='d' && strncmp(azArg[0], "dbinfo", n)==0 ){ + rc = shell_dbinfo_command(p, nArg, azArg); + }else + if( c=='d' && strncmp(azArg[0], "dump", n)==0 ){ open_db(p, 0); /* When playing back a "dump", the content might appear in an order @@ -3028,7 +3050,8 @@ static int do_meta_command(char *zLine, ShellState *p){ if( needCommit ) sqlite3_exec(db, "COMMIT", 0, 0, 0); }else - if( c=='i' && strncmp(azArg[0], "indices", n)==0 ){ + if( c=='i' && (strncmp(azArg[0], "indices", n)==0 + || strncmp(azArg[0], "indexes", n)==0) ){ ShellState data; char *zErrMsg = 0; open_db(p, 0); @@ -3058,7 +3081,7 @@ static int do_meta_command(char *zLine, ShellState *p){ ); zShellStatic = 0; }else{ - fprintf(stderr, "Usage: .indices ?LIKE-PATTERN?\n"); + fprintf(stderr, "Usage: .indexes ?LIKE-PATTERN?\n"); rc = 1; goto meta_command_exit; } @@ -3072,10 +3095,6 @@ static int do_meta_command(char *zLine, ShellState *p){ } }else - if( c=='i' && strncmp(azArg[0], "info", n)==0 ){ - rc = shell_info_command(p); - }else - #ifdef SQLITE_ENABLE_IOTRACE if( c=='i' && strncmp(azArg[0], "iotrace", n)==0 ){ extern void (*sqlite3IoTrace)(const char*, ...); diff --git a/test/shell1.test b/test/shell1.test index f24b00d494..874718447c 100644 --- a/test/shell1.test +++ b/test/shell1.test @@ -406,19 +406,22 @@ do_test shell1-3.11.3 { catchcmd "test.db" ".import FOO BAR BAD" } {1 {Usage: .import FILE TABLE}} -# .indices ?TABLE? Show names of all indices -# If TABLE specified, only show indices for tables +# .indexes ?TABLE? Show names of all indexes +# If TABLE specified, only show indexes for tables # matching LIKE pattern TABLE. do_test shell1-3.12.1 { - catchcmd "test.db" ".indices" + catchcmd "test.db" ".indexes" } {0 {}} do_test shell1-3.12.2 { + catchcmd "test.db" ".indexes FOO" +} {0 {}} +do_test shell1-3.12.2-legacy { catchcmd "test.db" ".indices FOO" } {0 {}} do_test shell1-3.12.3 { # too many arguments - catchcmd "test.db" ".indices FOO BAD" -} {1 {Usage: .indices ?LIKE-PATTERN?}} + catchcmd "test.db" ".indexes FOO BAD" +} {1 {Usage: .indexes ?LIKE-PATTERN?}} # .mode MODE ?TABLE? Set output mode where MODE is one of: # ascii Columns/rows delimited by 0x1F and 0x1E From d10d18da5f65a36ed76c09289e33ed13432d0ca3 Mon Sep 17 00:00:00 2001 From: drh Date: Sat, 7 Feb 2015 15:16:35 +0000 Subject: [PATCH 30/62] Fix potential 32-bit integer overflow problems on the offset and length parameters to sqlite3_blob_read() and sqlite3_blob_write(). For sqlite3_blob_open(), make sure the *ppBlob return parameter is zeroed if the interface fails with SQLITE_MISUSE. FossilOrigin-Name: 5df02f50f8348dfde4fc15126abc7b7ef7803e69 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/vdbeblob.c | 11 ++++++++--- test/incrblob2.test | 22 ++++++++++++++++++++++ 4 files changed, 38 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index b31e5b6454..033c8ecf04 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Change\sthe\sname\sof\s".info"\sto\s".dbinfo"\sand\sadd\san\soptional\ssecond\sargument\nwhich\sis\sthe\sATTACH-ed\sDB\sabout\swhich\sinformation\sis\sprovided.\s\sProvide\n".indexes"\sas\san\salternative\sname\sto\sthe\slegacy\s".indices"\scommand. -D 2015-02-06T14:51:13.355 +C Fix\spotential\s32-bit\sinteger\soverflow\sproblems\son\sthe\soffset\sand\slength\nparameters\sto\ssqlite3_blob_read()\sand\ssqlite3_blob_write().\s\sFor\nsqlite3_blob_open(),\smake\ssure\sthe\s*ppBlob\sreturn\sparameter\sis\szeroed\sif\nthe\sinterface\sfails\swith\sSQLITE_MISUSE. +D 2015-02-07T15:16:35.893 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 6b9e7677829aa94b9f30949656e27312aefb9a46 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -298,7 +298,7 @@ F src/vdbe.h 6fc69d9c5e146302c56e163cb4b31d1ee64a18c3 F src/vdbeInt.h 9bb69ff2447c34b6ccc58b34ec35b615f86ead78 F src/vdbeapi.c 4bc511a46b9839392ae0e90844a71dc96d9dbd71 F src/vdbeaux.c 97911edb61074b871ec4aa2d6bb779071643dee5 -F src/vdbeblob.c 4af4bfb71f6df7778397b4a0ebc1879793276778 +F src/vdbeblob.c 4f2e8e075d238392df98c5e03a64342465b03f90 F src/vdbemem.c 31d8eabb0cd78bfeab4e5124c7363c3e9e54db9f F src/vdbesort.c 6d64c5448b64851b99931ede980addc3af70d5e2 F src/vdbetrace.c 7e4222955e07dd707a2f360c0eb73452be1cb010 @@ -638,7 +638,7 @@ F test/in3.test 3cbf58c87f4052cee3a58b37b6389777505aa0c0 F test/in4.test d2b38cba404bc4320f4fe1b595b3d163f212c068 F test/in5.test 1de657472fa9ac2924be25c2c959ac5ca1aae554 F test/incrblob.test e81846d214f3637622620fbde7cd526781cfe328 -F test/incrblob2.test bf4d549aa4a466d7fbe3e3a3693d3861263d5600 +F test/incrblob2.test 0d8821730a84f90af78a9dd547fe7a2480a06240 F test/incrblob3.test d8d036fde015d4a159cd3cbae9d29003b37227a4 F test/incrblob4.test f26502a5697893e5acea268c910f16478c2f0fab F test/incrblob_err.test af1f12ba60d220c9752073ff2bda2ad59e88960d @@ -1239,7 +1239,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 0a3100a7f264ffce6078c35e341f2f0af6c09fbb -R a582dddcff23f4b3aa0ab625ed7ba566 +P 0f65a7e2e09f801b66897479d501607caeae4abf +R a72e608518946b8cddba99b1913bccc8 U drh -Z 91c27780af6a4d5e0c7b8a8aa90c189d +Z 826c67b7d3493617a37693ae1605b2c3 diff --git a/manifest.uuid b/manifest.uuid index 408d77792f..c363eec9d9 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -0f65a7e2e09f801b66897479d501607caeae4abf \ No newline at end of file +5df02f50f8348dfde4fc15126abc7b7ef7803e69 \ No newline at end of file diff --git a/src/vdbeblob.c b/src/vdbeblob.c index cf1eb59054..ea01f5ce80 100644 --- a/src/vdbeblob.c +++ b/src/vdbeblob.c @@ -154,12 +154,17 @@ int sqlite3_blob_open( Incrblob *pBlob = 0; #ifdef SQLITE_ENABLE_API_ARMOR - if( !sqlite3SafetyCheckOk(db) || ppBlob==0 || zTable==0 ){ + if( ppBlob==0 ){ + return SQLITE_MISUSE_BKPT; + } +#endif + *ppBlob = 0; +#ifdef SQLITE_ENABLE_API_ARMOR + if( !sqlite3SafetyCheckOk(db) || zTable==0 ){ return SQLITE_MISUSE_BKPT; } #endif flags = !!flags; /* flags = (flags ? 1 : 0); */ - *ppBlob = 0; sqlite3_mutex_enter(db->mutex); @@ -373,7 +378,7 @@ static int blobReadWrite( sqlite3_mutex_enter(db->mutex); v = (Vdbe*)p->pStmt; - if( n<0 || iOffset<0 || (iOffset+n)>p->nByte ){ + if( n<0 || iOffset<0 || ((sqlite3_int64)iOffset+n)>p->nByte ){ /* Request is out of range. Return a transient error. */ rc = SQLITE_ERROR; }else if( v==0 ){ diff --git a/test/incrblob2.test b/test/incrblob2.test index a8f40f09dc..1a235f7d22 100644 --- a/test/incrblob2.test +++ b/test/incrblob2.test @@ -324,12 +324,34 @@ do_test incrblob2-6.2 { sqlite3_blob_read $rdHandle 0 2 } {AB} +do_test incrblob2-6.2b { + set rc [catch { + # Prior to 2015-02-07, the following caused a segfault due to + # integer overflow. + sqlite3_blob_read $rdHandle 2147483647 2147483647 + } errmsg] + lappend rc $errmsg +} {1 SQLITE_ERROR} + do_test incrblob2-6.3 { set wrHandle [db incrblob t1 data 1] sqlite3_blob_write $wrHandle 0 ZZZZZZZZZZ sqlite3_blob_read $rdHandle 2 4 } {ZZZZ} +do_test incrblob2-6.3b { + set rc [catch { + # Prior to 2015-02-07, the following caused a segfault due to + # integer overflow. + sqlite3_blob_write $wrHandle 2147483647 YYYYYYYYYYYYYYYYYY + } errmsg] + lappend rc $errmsg +} {1 SQLITE_ERROR} +do_test incrblob2-6.3c { + sqlite3_blob_read $rdHandle 2 4 +} {ZZZZ} + + do_test incrblob2-6.4 { close $wrHandle close $rdHandle From 31e7147dfa40c6278722d1ac30b74b77a0c5a970 Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 9 Feb 2015 10:20:19 +0000 Subject: [PATCH 31/62] Fix over-length source code lines in resolver.c. No logic changes. FossilOrigin-Name: c12edb85076d0832e3a0abbbba4d07f3cb5d7f0e --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/resolve.c | 41 ++++++++++++++++++++++++----------------- 3 files changed, 31 insertions(+), 24 deletions(-) diff --git a/manifest b/manifest index 033c8ecf04..ecfb3a4eab 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\spotential\s32-bit\sinteger\soverflow\sproblems\son\sthe\soffset\sand\slength\nparameters\sto\ssqlite3_blob_read()\sand\ssqlite3_blob_write().\s\sFor\nsqlite3_blob_open(),\smake\ssure\sthe\s*ppBlob\sreturn\sparameter\sis\szeroed\sif\nthe\sinterface\sfails\swith\sSQLITE_MISUSE. -D 2015-02-07T15:16:35.893 +C Fix\sover-length\ssource\scode\slines\sin\sresolver.c.\s\sNo\slogic\schanges. +D 2015-02-09T10:20:19.068 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 6b9e7677829aa94b9f30949656e27312aefb9a46 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -228,7 +228,7 @@ F src/pragma.h 09c89bca58e9a44de2116cc8272b8d454657129f F src/prepare.c 173a5a499138451b2561614ecb87d78f9f4644b9 F src/printf.c 05edc41450d0eb2c05ef7db113bf32742ae65325 F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 -F src/resolve.c f6c46d3434439ab2084618d603e6d6dbeb0d6ada +F src/resolve.c 4ebd1064bded2556a8856c6f00fe2b9642f6efc3 F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e F src/select.c 1f2087523007c42900ffcbdeaef06a23ad9329fc F src/shell.c 82c25508dac802b32198af6f5256ca1597c6a1af @@ -1239,7 +1239,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 0f65a7e2e09f801b66897479d501607caeae4abf -R a72e608518946b8cddba99b1913bccc8 +P 5df02f50f8348dfde4fc15126abc7b7ef7803e69 +R a6e72909415716c47fbdc8c9892a4441 U drh -Z 826c67b7d3493617a37693ae1605b2c3 +Z da26ece2df8d0d323ede5e0a841cad93 diff --git a/manifest.uuid b/manifest.uuid index c363eec9d9..86b84ce37d 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -5df02f50f8348dfde4fc15126abc7b7ef7803e69 \ No newline at end of file +c12edb85076d0832e3a0abbbba4d07f3cb5d7f0e \ No newline at end of file diff --git a/src/resolve.c b/src/resolve.c index d4bd548c93..3cca168325 100644 --- a/src/resolve.c +++ b/src/resolve.c @@ -247,9 +247,10 @@ static int lookupName( testcase( pNC->ncFlags & NC_PartIdx ); testcase( pNC->ncFlags & NC_IsCheck ); if( (pNC->ncFlags & (NC_PartIdx|NC_IsCheck))!=0 ){ - /* Silently ignore database qualifiers inside CHECK constraints and partial - ** indices. Do not raise errors because that might break legacy and - ** because it does not hurt anything to just ignore the database name. */ + /* Silently ignore database qualifiers inside CHECK constraints and + ** partial indices. Do not raise errors because that might break + ** legacy and because it does not hurt anything to just ignore the + ** database name. */ zDb = 0; }else{ for(i=0; inDb; i++){ @@ -320,7 +321,8 @@ static int lookupName( if( pMatch ){ pExpr->iTable = pMatch->iCursor; pExpr->pTab = pMatch->pTab; - assert( (pMatch->jointype & JT_RIGHT)==0 ); /* RIGHT JOIN not (yet) supported */ + /* RIGHT JOIN not (yet) supported */ + assert( (pMatch->jointype & JT_RIGHT)==0 ); if( (pMatch->jointype & JT_LEFT)!=0 ){ ExprSetProperty(pExpr, EP_CanBeNull); } @@ -641,7 +643,8 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){ pExpr->affinity = SQLITE_AFF_INTEGER; break; } -#endif /* defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) && !defined(SQLITE_OMIT_SUBQUERY) */ +#endif /* defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) + && !defined(SQLITE_OMIT_SUBQUERY) */ /* A lone identifier is the name of a column. */ @@ -706,19 +709,20 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){ if( n==2 ){ pExpr->iTable = exprProbability(pList->a[1].pExpr); if( pExpr->iTable<0 ){ - sqlite3ErrorMsg(pParse, "second argument to likelihood() must be a " - "constant between 0.0 and 1.0"); + sqlite3ErrorMsg(pParse, + "second argument to likelihood() must be a " + "constant between 0.0 and 1.0"); pNC->nErr++; } }else{ - /* EVIDENCE-OF: R-61304-29449 The unlikely(X) function is equivalent to - ** likelihood(X, 0.0625). - ** EVIDENCE-OF: R-01283-11636 The unlikely(X) function is short-hand for - ** likelihood(X,0.0625). - ** EVIDENCE-OF: R-36850-34127 The likely(X) function is short-hand for - ** likelihood(X,0.9375). - ** EVIDENCE-OF: R-53436-40973 The likely(X) function is equivalent to - ** likelihood(X,0.9375). */ + /* EVIDENCE-OF: R-61304-29449 The unlikely(X) function is + ** equivalent to likelihood(X, 0.0625). + ** EVIDENCE-OF: R-01283-11636 The unlikely(X) function is + ** short-hand for likelihood(X,0.0625). + ** EVIDENCE-OF: R-36850-34127 The likely(X) function is short-hand + ** for likelihood(X,0.9375). + ** EVIDENCE-OF: R-53436-40973 The likely(X) function is equivalent + ** to likelihood(X,0.9375). */ /* TUNING: unlikely() probability is 0.0625. likely() is 0.9375 */ pExpr->iTable = pDef->zName[0]=='u' ? 8388608 : 125829120; } @@ -735,7 +739,9 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){ return WRC_Prune; } #endif - if( pDef->funcFlags & SQLITE_FUNC_CONSTANT ) ExprSetProperty(pExpr,EP_Constant); + if( pDef->funcFlags & SQLITE_FUNC_CONSTANT ){ + ExprSetProperty(pExpr,EP_Constant); + } } if( is_agg && (pNC->ncFlags & NC_AllowAgg)==0 ){ sqlite3ErrorMsg(pParse, "misuse of aggregate function %.*s()", nId,zId); @@ -1046,7 +1052,8 @@ int sqlite3ResolveOrderGroupBy( resolveOutOfRangeError(pParse, zType, i+1, pEList->nExpr); return 1; } - resolveAlias(pParse, pEList, pItem->u.x.iOrderByCol-1, pItem->pExpr, zType,0); + resolveAlias(pParse, pEList, pItem->u.x.iOrderByCol-1, pItem->pExpr, + zType,0); } } return 0; From 0e86a1ac087e4e97be51cfa8e175da4a90a85f23 Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 9 Feb 2015 11:54:41 +0000 Subject: [PATCH 32/62] In selecttrace mode 0x100, show a complete parse-tree both before and after query flattening. This is a change to debugging code only. FossilOrigin-Name: b3c6b8a3c1075d2a87cef68f061d6a0098e6d8d0 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/select.c | 7 +++++++ 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/manifest b/manifest index ecfb3a4eab..b716294ece 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sover-length\ssource\scode\slines\sin\sresolver.c.\s\sNo\slogic\schanges. -D 2015-02-09T10:20:19.068 +C In\sselecttrace\smode\s0x100,\sshow\sa\scomplete\sparse-tree\sboth\sbefore\sand\safter\nquery\sflattening.\s\sThis\sis\sa\schange\sto\sdebugging\scode\sonly. +D 2015-02-09T11:54:41.074 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 6b9e7677829aa94b9f30949656e27312aefb9a46 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -230,7 +230,7 @@ F src/printf.c 05edc41450d0eb2c05ef7db113bf32742ae65325 F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c 4ebd1064bded2556a8856c6f00fe2b9642f6efc3 F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e -F src/select.c 1f2087523007c42900ffcbdeaef06a23ad9329fc +F src/select.c 6ea3518b8863ec631c0481ba03dc283ea9140747 F src/shell.c 82c25508dac802b32198af6f5256ca1597c6a1af F src/sqlite.h.in 54678c21401909f72b221344dd560d285a1ba5eb F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad @@ -1239,7 +1239,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 5df02f50f8348dfde4fc15126abc7b7ef7803e69 -R a6e72909415716c47fbdc8c9892a4441 +P c12edb85076d0832e3a0abbbba4d07f3cb5d7f0e +R 592949bfa9cc2e6e32d5144cda2bc252 U drh -Z da26ece2df8d0d323ede5e0a841cad93 +Z 15610b55190883b540f12ad788effd4f diff --git a/manifest.uuid b/manifest.uuid index 86b84ce37d..86de97c36c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c12edb85076d0832e3a0abbbba4d07f3cb5d7f0e \ No newline at end of file +b3c6b8a3c1075d2a87cef68f061d6a0098e6d8d0 \ No newline at end of file diff --git a/src/select.c b/src/select.c index 8fbd4bb261..8563ec1006 100644 --- a/src/select.c +++ b/src/select.c @@ -3444,6 +3444,13 @@ static int flattenSubquery( /***** If we reach this point, flattening is permitted. *****/ SELECTTRACE(1,pParse,p,("flatten %s.%p from term %d\n", pSub->zSelName, pSub, iFrom)); +#if SELECTTRACE_ENABLED + if( sqlite3SelectTrace & 0x100 ){ + sqlite3DebugPrintf("Befor flattening:\n"); + sqlite3TreeViewSelect(0, p, 0); + } +#endif + /* Authorize the subquery */ pParse->zAuthContext = pSubitem->zName; From 17645f5eecb950205481179bb0dee1e5332a2e8e Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 9 Feb 2015 13:42:59 +0000 Subject: [PATCH 33/62] In selecttrace 0x100 mode, show the parse tree after name resolution instead of before flattening, so that it is always seen even if flattening does not occur. Also: add the hex pointer value to the top of each SELECT tree. FossilOrigin-Name: aa093fef2d2a7e26d987b46654963e4d7e66d444 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/select.c | 18 +++++++++--------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/manifest b/manifest index b716294ece..aac267bbad 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C In\sselecttrace\smode\s0x100,\sshow\sa\scomplete\sparse-tree\sboth\sbefore\sand\safter\nquery\sflattening.\s\sThis\sis\sa\schange\sto\sdebugging\scode\sonly. -D 2015-02-09T11:54:41.074 +C In\sselecttrace\s0x100\smode,\sshow\sthe\sparse\stree\safter\sname\sresolution\sinstead\nof\sbefore\sflattening,\sso\sthat\sit\sis\salways\sseen\seven\sif\sflattening\sdoes\snot\noccur.\s\sAlso:\sadd\sthe\shex\spointer\svalue\sto\sthe\stop\sof\seach\sSELECT\stree. +D 2015-02-09T13:42:59.910 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 6b9e7677829aa94b9f30949656e27312aefb9a46 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -230,7 +230,7 @@ F src/printf.c 05edc41450d0eb2c05ef7db113bf32742ae65325 F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c 4ebd1064bded2556a8856c6f00fe2b9642f6efc3 F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e -F src/select.c 6ea3518b8863ec631c0481ba03dc283ea9140747 +F src/select.c edcf8ba8163526f2340f10f19b0a71547c6f97ba F src/shell.c 82c25508dac802b32198af6f5256ca1597c6a1af F src/sqlite.h.in 54678c21401909f72b221344dd560d285a1ba5eb F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad @@ -1239,7 +1239,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P c12edb85076d0832e3a0abbbba4d07f3cb5d7f0e -R 592949bfa9cc2e6e32d5144cda2bc252 +P b3c6b8a3c1075d2a87cef68f061d6a0098e6d8d0 +R d021c59225e931bc74b845a3c2d5b904 U drh -Z 15610b55190883b540f12ad788effd4f +Z ece5ae1a696e0ba02ef3e8bf97d71c38 diff --git a/manifest.uuid b/manifest.uuid index 86de97c36c..036d4651a7 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -b3c6b8a3c1075d2a87cef68f061d6a0098e6d8d0 \ No newline at end of file +aa093fef2d2a7e26d987b46654963e4d7e66d444 \ No newline at end of file diff --git a/src/select.c b/src/select.c index 8563ec1006..058bf3d577 100644 --- a/src/select.c +++ b/src/select.c @@ -3444,13 +3444,6 @@ static int flattenSubquery( /***** If we reach this point, flattening is permitted. *****/ SELECTTRACE(1,pParse,p,("flatten %s.%p from term %d\n", pSub->zSelName, pSub, iFrom)); -#if SELECTTRACE_ENABLED - if( sqlite3SelectTrace & 0x100 ){ - sqlite3DebugPrintf("Befor flattening:\n"); - sqlite3TreeViewSelect(0, p, 0); - } -#endif - /* Authorize the subquery */ pParse->zAuthContext = pSubitem->zName; @@ -4759,6 +4752,13 @@ int sqlite3Select( } isAgg = (p->selFlags & SF_Aggregate)!=0; assert( pEList!=0 ); +#if SELECTTRACE_ENABLED + if( sqlite3SelectTrace & 0x100 ){ + SELECTTRACE(0x100,pParse,p, ("after name resolution:\n")); + sqlite3TreeViewSelect(0, p, 0); + } +#endif + /* Begin generating code. */ @@ -5504,9 +5504,9 @@ select_end: void sqlite3TreeViewSelect(TreeView *pView, const Select *p, u8 moreToFollow){ int n = 0; pView = sqlite3TreeViewPush(pView, moreToFollow); - sqlite3TreeViewLine(pView, "SELECT%s%s", + sqlite3TreeViewLine(pView, "SELECT%s%s (0x%p)", ((p->selFlags & SF_Distinct) ? " DISTINCT" : ""), - ((p->selFlags & SF_Aggregate) ? " agg_flag" : "") + ((p->selFlags & SF_Aggregate) ? " agg_flag" : ""), p ); if( p->pSrc && p->pSrc->nSrc ) n++; if( p->pWhere ) n++; From 63f845734e7de67fb04ad1e8990c41850547ce07 Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 9 Feb 2015 14:07:07 +0000 Subject: [PATCH 34/62] Rename the internal "EP_Constant" bitmask to a less misleading "EP_ConstFunc". FossilOrigin-Name: 4ef7ceced2b0000d21f7f8014384c04a0e4661d3 --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/expr.c | 2 +- src/resolve.c | 2 +- src/sqliteInt.h | 2 +- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/manifest b/manifest index aac267bbad..10002ebccf 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C In\sselecttrace\s0x100\smode,\sshow\sthe\sparse\stree\safter\sname\sresolution\sinstead\nof\sbefore\sflattening,\sso\sthat\sit\sis\salways\sseen\seven\sif\sflattening\sdoes\snot\noccur.\s\sAlso:\sadd\sthe\shex\spointer\svalue\sto\sthe\stop\sof\seach\sSELECT\stree. -D 2015-02-09T13:42:59.910 +C Rename\sthe\sinternal\s"EP_Constant"\sbitmask\sto\sa\sless\smisleading\s"EP_ConstFunc". +D 2015-02-09T14:07:07.358 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 6b9e7677829aa94b9f30949656e27312aefb9a46 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -182,7 +182,7 @@ F src/complete.c 198a0066ba60ab06fc00fba1998d870a4d575463 F src/ctime.c 98f89724adc891a1a4c655bee04e33e716e05887 F src/date.c e4d50b3283696836ec1036b695ead9a19e37a5ac F src/delete.c bd1a91ddd247ce13004075251e0b7fe2bf9925ef -F src/expr.c abe930897ccafae3819fd2855cbc1b00c262fd12 +F src/expr.c d66424535d3155eca7f2d8820d26b96870dfcb2d F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb F src/fkey.c e0444b61bed271a76840cbe6182df93a9baa3f12 F src/func.c 6d3c4ebd72aa7923ce9b110a7dc15f9b8c548430 @@ -228,14 +228,14 @@ F src/pragma.h 09c89bca58e9a44de2116cc8272b8d454657129f F src/prepare.c 173a5a499138451b2561614ecb87d78f9f4644b9 F src/printf.c 05edc41450d0eb2c05ef7db113bf32742ae65325 F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 -F src/resolve.c 4ebd1064bded2556a8856c6f00fe2b9642f6efc3 +F src/resolve.c f4d79e31ffa5820c2e3d1740baa5e9b190425f2b F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e F src/select.c edcf8ba8163526f2340f10f19b0a71547c6f97ba F src/shell.c 82c25508dac802b32198af6f5256ca1597c6a1af F src/sqlite.h.in 54678c21401909f72b221344dd560d285a1ba5eb F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h 17d487c3c91b0b8c584a32fbeb393f6f795eea7d -F src/sqliteInt.h c4e05f7489cd300f856e2283d5e61302ce826471 +F src/sqliteInt.h 436c02d0877b9b9a1c3351717c2c93bd248000e9 F src/sqliteLimit.h 164b0e6749d31e0daa1a4589a169d31c0dec7b3d F src/status.c 81712116e826b0089bb221b018929536b2b5406f F src/table.c e7a09215315a978057fb42c640f890160dbcc45e @@ -1239,7 +1239,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P b3c6b8a3c1075d2a87cef68f061d6a0098e6d8d0 -R d021c59225e931bc74b845a3c2d5b904 +P aa093fef2d2a7e26d987b46654963e4d7e66d444 +R f51c0a3a4046c27eeedc2e4a71b172ba U drh -Z ece5ae1a696e0ba02ef3e8bf97d71c38 +Z 4b79838e5fc774abeed8438ce319eb67 diff --git a/manifest.uuid b/manifest.uuid index 036d4651a7..c03c5df094 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -aa093fef2d2a7e26d987b46654963e4d7e66d444 \ No newline at end of file +4ef7ceced2b0000d21f7f8014384c04a0e4661d3 \ No newline at end of file diff --git a/src/expr.c b/src/expr.c index 25bd958ceb..2f0fe4a581 100644 --- a/src/expr.c +++ b/src/expr.c @@ -1249,7 +1249,7 @@ static int exprNodeIsConstant(Walker *pWalker, Expr *pExpr){ ** and either pWalker->eCode==4 or 5 or the function has the ** SQLITE_FUNC_CONST flag. */ case TK_FUNCTION: - if( pWalker->eCode>=4 || ExprHasProperty(pExpr,EP_Constant) ){ + if( pWalker->eCode>=4 || ExprHasProperty(pExpr,EP_ConstFunc) ){ return WRC_Continue; }else{ pWalker->eCode = 0; diff --git a/src/resolve.c b/src/resolve.c index 3cca168325..47df7243f8 100644 --- a/src/resolve.c +++ b/src/resolve.c @@ -740,7 +740,7 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){ } #endif if( pDef->funcFlags & SQLITE_FUNC_CONSTANT ){ - ExprSetProperty(pExpr,EP_Constant); + ExprSetProperty(pExpr,EP_ConstFunc); } } if( is_agg && (pNC->ncFlags & NC_AllowAgg)==0 ){ diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 0bc6f679dd..f5892db4bc 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -2044,7 +2044,7 @@ struct Expr { #define EP_MemToken 0x010000 /* Need to sqlite3DbFree() Expr.zToken */ #define EP_NoReduce 0x020000 /* Cannot EXPRDUP_REDUCE this Expr */ #define EP_Unlikely 0x040000 /* unlikely() or likelihood() function */ -#define EP_Constant 0x080000 /* Node is a constant */ +#define EP_ConstFunc 0x080000 /* Node is a SQLITE_FUNC_CONSTANT function */ #define EP_CanBeNull 0x100000 /* Can be null despite NOT NULL constraint */ /* From 885a5b030ee3717b78bfb82d61e6ee38ef0892ea Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 9 Feb 2015 15:21:36 +0000 Subject: [PATCH 35/62] Disable the query flattener for aggregate subqueries if the parent query uses other subqueries in its result set or WHERE clause or ORDER BY clause. Preliminary fix for ticket [2f7170d73bf9abf8]. However it still contains a defect similar to the COLLATE problem of [ca0d20b6cddd]. FossilOrigin-Name: 0b7d65e3fda676d193347cb782854c28a48252af --- manifest | 21 ++++++++++++--------- manifest.uuid | 2 +- src/expr.c | 17 +++++++++++++++-- src/parse.y | 8 ++++---- src/select.c | 18 +++++++++++++++--- src/sqliteInt.h | 7 +++++++ 6 files changed, 54 insertions(+), 19 deletions(-) diff --git a/manifest b/manifest index 10002ebccf..fffe5424f6 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Rename\sthe\sinternal\s"EP_Constant"\sbitmask\sto\sa\sless\smisleading\s"EP_ConstFunc". -D 2015-02-09T14:07:07.358 +C Disable\sthe\squery\sflattener\sfor\saggregate\ssubqueries\sif\sthe\sparent\squery\nuses\sother\ssubqueries\sin\sits\sresult\sset\sor\sWHERE\sclause\sor\sORDER\sBY\sclause.\nPreliminary\sfix\sfor\sticket\s[2f7170d73bf9abf8].\s\sHowever\sit\sstill\scontains\na\sdefect\ssimilar\sto\sthe\sCOLLATE\sproblem\sof\s[ca0d20b6cddd]. +D 2015-02-09T15:21:36.228 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 6b9e7677829aa94b9f30949656e27312aefb9a46 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -182,7 +182,7 @@ F src/complete.c 198a0066ba60ab06fc00fba1998d870a4d575463 F src/ctime.c 98f89724adc891a1a4c655bee04e33e716e05887 F src/date.c e4d50b3283696836ec1036b695ead9a19e37a5ac F src/delete.c bd1a91ddd247ce13004075251e0b7fe2bf9925ef -F src/expr.c d66424535d3155eca7f2d8820d26b96870dfcb2d +F src/expr.c 3fbe5a2a0be67b337b4947adde81694b4d48a84d F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb F src/fkey.c e0444b61bed271a76840cbe6182df93a9baa3f12 F src/func.c 6d3c4ebd72aa7923ce9b110a7dc15f9b8c548430 @@ -219,7 +219,7 @@ F src/os_win.c 8223e7db5b7c4a81d8b161098ac3959400434cdb F src/os_win.h eb7a47aa17b26b77eb97e4823f20a00b8bda12ca F src/pager.c 4120a49ecd37697e28f5ed807f470b9c0b88410c F src/pager.h c3476e7c89cdf1c6914e50a11f3714e30b4e0a77 -F src/parse.y c5d0d964f9ac023e8154cad512e54b0b6058e086 +F src/parse.y d6507371513e94c03e61f7ec097d7b7e90a66665 F src/pcache.c d210cf90d04365a74f85d21374dded65af67b0cb F src/pcache.h b44658c9c932d203510279439d891a2a83e12ba8 F src/pcache1.c 1e77432b40b7d3288327d9cdf399dcdfd2b6d3bf @@ -230,12 +230,12 @@ F src/printf.c 05edc41450d0eb2c05ef7db113bf32742ae65325 F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c f4d79e31ffa5820c2e3d1740baa5e9b190425f2b F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e -F src/select.c edcf8ba8163526f2340f10f19b0a71547c6f97ba +F src/select.c 15490b9da27a688a9fa09f943ebf4e6c749dc33b F src/shell.c 82c25508dac802b32198af6f5256ca1597c6a1af F src/sqlite.h.in 54678c21401909f72b221344dd560d285a1ba5eb F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h 17d487c3c91b0b8c584a32fbeb393f6f795eea7d -F src/sqliteInt.h 436c02d0877b9b9a1c3351717c2c93bd248000e9 +F src/sqliteInt.h b7b14a15f2c60e15f99145e9f5a90f5280e98582 F src/sqliteLimit.h 164b0e6749d31e0daa1a4589a169d31c0dec7b3d F src/status.c 81712116e826b0089bb221b018929536b2b5406f F src/table.c e7a09215315a978057fb42c640f890160dbcc45e @@ -1239,7 +1239,10 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P aa093fef2d2a7e26d987b46654963e4d7e66d444 -R f51c0a3a4046c27eeedc2e4a71b172ba +P 4ef7ceced2b0000d21f7f8014384c04a0e4661d3 +R b512281a09e1b31cff93e7ca5bacbcdc +T *branch * tkt-2f7170d7 +T *sym-tkt-2f7170d7 * +T -sym-trunk * U drh -Z 4b79838e5fc774abeed8438ce319eb67 +Z f683ca0757ba5ade9ef6c768a943d35e diff --git a/manifest.uuid b/manifest.uuid index c03c5df094..1553ada2f8 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -4ef7ceced2b0000d21f7f8014384c04a0e4661d3 \ No newline at end of file +0b7d65e3fda676d193347cb782854c28a48252af \ No newline at end of file diff --git a/src/expr.c b/src/expr.c index 2f0fe4a581..2def950f23 100644 --- a/src/expr.c +++ b/src/expr.c @@ -490,11 +490,11 @@ void sqlite3ExprAttachSubtrees( }else{ if( pRight ){ pRoot->pRight = pRight; - pRoot->flags |= EP_Collate & pRight->flags; + pRoot->flags |= EP_Propagate & pRight->flags; } if( pLeft ){ pRoot->pLeft = pLeft; - pRoot->flags |= EP_Collate & pLeft->flags; + pRoot->flags |= EP_Propagate & pLeft->flags; } exprSetHeight(pRoot); } @@ -1209,6 +1209,19 @@ void sqlite3ExprListDelete(sqlite3 *db, ExprList *pList){ sqlite3DbFree(db, pList); } +/* +** Return TRUE if any expression in ExprList has any of the EP_* +** properties given by "m" +*/ +int sqlite3AnyExprListHasProperty(const ExprList *pList, u32 m){ + int i; + if( pList==0 ) return 0; + for(i=0; inExpr; i++){ + if( ExprHasProperty(pList->a[i].pExpr, m) ) return 1; + } + return 0; +} + /* ** These routines are Walker callbacks used to check expressions to ** see if they are "constant" for some definition of constant. The diff --git a/src/parse.y b/src/parse.y index 544888a228..6730312d7c 100644 --- a/src/parse.y +++ b/src/parse.y @@ -1091,7 +1091,7 @@ expr(A) ::= expr(W) between_op(N) expr(X) AND expr(Y). [BETWEEN] { A.pExpr = sqlite3PExpr(pParse, TK_SELECT, 0, 0, 0); if( A.pExpr ){ A.pExpr->x.pSelect = X; - ExprSetProperty(A.pExpr, EP_xIsSelect); + ExprSetProperty(A.pExpr, EP_xIsSelect|EP_Subquery); sqlite3ExprSetHeight(pParse, A.pExpr); }else{ sqlite3SelectDelete(pParse->db, X); @@ -1103,7 +1103,7 @@ expr(A) ::= expr(W) between_op(N) expr(X) AND expr(Y). [BETWEEN] { A.pExpr = sqlite3PExpr(pParse, TK_IN, X.pExpr, 0, 0); if( A.pExpr ){ A.pExpr->x.pSelect = Y; - ExprSetProperty(A.pExpr, EP_xIsSelect); + ExprSetProperty(A.pExpr, EP_xIsSelect|EP_Subquery); sqlite3ExprSetHeight(pParse, A.pExpr); }else{ sqlite3SelectDelete(pParse->db, Y); @@ -1117,7 +1117,7 @@ expr(A) ::= expr(W) between_op(N) expr(X) AND expr(Y). [BETWEEN] { A.pExpr = sqlite3PExpr(pParse, TK_IN, X.pExpr, 0, 0); if( A.pExpr ){ A.pExpr->x.pSelect = sqlite3SelectNew(pParse, 0,pSrc,0,0,0,0,0,0,0); - ExprSetProperty(A.pExpr, EP_xIsSelect); + ExprSetProperty(A.pExpr, EP_xIsSelect|EP_Subquery); sqlite3ExprSetHeight(pParse, A.pExpr); }else{ sqlite3SrcListDelete(pParse->db, pSrc); @@ -1130,7 +1130,7 @@ expr(A) ::= expr(W) between_op(N) expr(X) AND expr(Y). [BETWEEN] { Expr *p = A.pExpr = sqlite3PExpr(pParse, TK_EXISTS, 0, 0, 0); if( p ){ p->x.pSelect = Y; - ExprSetProperty(p, EP_xIsSelect); + ExprSetProperty(p, EP_xIsSelect|EP_Subquery); sqlite3ExprSetHeight(pParse, p); }else{ sqlite3SelectDelete(pParse->db, Y); diff --git a/src/select.c b/src/select.c index 058bf3d577..2c4c9e41f9 100644 --- a/src/select.c +++ b/src/select.c @@ -3194,7 +3194,10 @@ static void substSelect( ** ** (1) The subquery and the outer query do not both use aggregates. ** -** (2) The subquery is not an aggregate or the outer query is not a join. +** (2) The subquery is not an aggregate or (2a) the outer query is not a join +** and (2b) the outer query does not use subqueries other than the one +** FROM-clause subquery that is a candidate for flattening. (2b is +** due to ticket [2f7170d73bf9abf80] from 2015-02-09.) ** ** (3) The subquery is not the right operand of a left outer join ** (Originally ticket #306. Strengthened by ticket #3300) @@ -3331,8 +3334,17 @@ static int flattenSubquery( iParent = pSubitem->iCursor; pSub = pSubitem->pSelect; assert( pSub!=0 ); - if( isAgg && subqueryIsAgg ) return 0; /* Restriction (1) */ - if( subqueryIsAgg && pSrc->nSrc>1 ) return 0; /* Restriction (2) */ + if( subqueryIsAgg ){ + if( isAgg ) return 0; /* Restriction (1) */ + if( pSrc->nSrc>1 ) return 0; /* Restriction (2a) */ + if( (p->pWhere && ExprHasProperty(p->pWhere,EP_Subquery)) + || sqlite3AnyExprListHasProperty(p->pEList,EP_Subquery) + || sqlite3AnyExprListHasProperty(p->pOrderBy,EP_Subquery) + ){ + return 0; /* Restriction (2b) */ + } + } + pSubSrc = pSub->pSrc; assert( pSubSrc ); /* Prior to version 3.1.2, when LIMIT and OFFSET had to be simple constants, diff --git a/src/sqliteInt.h b/src/sqliteInt.h index f5892db4bc..e07ee4a5bd 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -2046,6 +2046,12 @@ struct Expr { #define EP_Unlikely 0x040000 /* unlikely() or likelihood() function */ #define EP_ConstFunc 0x080000 /* Node is a SQLITE_FUNC_CONSTANT function */ #define EP_CanBeNull 0x100000 /* Can be null despite NOT NULL constraint */ +#define EP_Subquery 0x200000 /* Tree contains a TK_SELECT operator */ + +/* +** Combinations of two or more EP_* flags +*/ +#define EP_Propagate (EP_Collate|EP_Subquery) /* Propagate these bits up tree */ /* ** These macros can be used to test, set, or clear bits in the @@ -3153,6 +3159,7 @@ ExprList *sqlite3ExprListAppend(Parse*,ExprList*,Expr*); void sqlite3ExprListSetName(Parse*,ExprList*,Token*,int); void sqlite3ExprListSetSpan(Parse*,ExprList*,ExprSpan*); void sqlite3ExprListDelete(sqlite3*, ExprList*); +int sqlite3AnyExprListHasProperty(const ExprList*,u32); int sqlite3Init(sqlite3*, char**); int sqlite3InitCallback(void*, int, char**, char**); void sqlite3Pragma(Parse*,Token*,Token*,Token*,int); From 2308ed385462208621ce052e5736b317fa81068f Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 9 Feb 2015 16:09:34 +0000 Subject: [PATCH 36/62] Propagate the COLLATE operator upward through function calls. Initial fix for ticket [ca0d20b6cdddec5e8]. FossilOrigin-Name: c053448a55f9d030e8ffe88cf4fc14ada7f6ec19 --- manifest | 25 +++++++++------------ manifest.uuid | 2 +- src/delete.c | 2 +- src/expr.c | 56 ++++++++++++++++++++++++++++++++++------------ src/parse.y | 12 +++++----- src/select.c | 4 ++-- src/sqliteInt.h | 5 ++--- test/collate8.test | 34 +++++++++++++++++++++++++++- 8 files changed, 98 insertions(+), 42 deletions(-) diff --git a/manifest b/manifest index fffe5424f6..30d2176730 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Disable\sthe\squery\sflattener\sfor\saggregate\ssubqueries\sif\sthe\sparent\squery\nuses\sother\ssubqueries\sin\sits\sresult\sset\sor\sWHERE\sclause\sor\sORDER\sBY\sclause.\nPreliminary\sfix\sfor\sticket\s[2f7170d73bf9abf8].\s\sHowever\sit\sstill\scontains\na\sdefect\ssimilar\sto\sthe\sCOLLATE\sproblem\sof\s[ca0d20b6cddd]. -D 2015-02-09T15:21:36.228 +C Propagate\sthe\sCOLLATE\soperator\supward\sthrough\sfunction\scalls.\nInitial\sfix\sfor\sticket\s[ca0d20b6cdddec5e8]. +D 2015-02-09T16:09:34.923 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 6b9e7677829aa94b9f30949656e27312aefb9a46 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -181,8 +181,8 @@ F src/callback.c 7b44ce59674338ad48b0e84e7b72f935ea4f68b0 F src/complete.c 198a0066ba60ab06fc00fba1998d870a4d575463 F src/ctime.c 98f89724adc891a1a4c655bee04e33e716e05887 F src/date.c e4d50b3283696836ec1036b695ead9a19e37a5ac -F src/delete.c bd1a91ddd247ce13004075251e0b7fe2bf9925ef -F src/expr.c 3fbe5a2a0be67b337b4947adde81694b4d48a84d +F src/delete.c 37964e6c1d73ff49cbea9ff690c9605fb15f600e +F src/expr.c f40082f5d31a76ea53302e202899a4959555b009 F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb F src/fkey.c e0444b61bed271a76840cbe6182df93a9baa3f12 F src/func.c 6d3c4ebd72aa7923ce9b110a7dc15f9b8c548430 @@ -219,7 +219,7 @@ F src/os_win.c 8223e7db5b7c4a81d8b161098ac3959400434cdb F src/os_win.h eb7a47aa17b26b77eb97e4823f20a00b8bda12ca F src/pager.c 4120a49ecd37697e28f5ed807f470b9c0b88410c F src/pager.h c3476e7c89cdf1c6914e50a11f3714e30b4e0a77 -F src/parse.y d6507371513e94c03e61f7ec097d7b7e90a66665 +F src/parse.y 0f8e7d60f0ab3cb53d270adef69259ac307d83a8 F src/pcache.c d210cf90d04365a74f85d21374dded65af67b0cb F src/pcache.h b44658c9c932d203510279439d891a2a83e12ba8 F src/pcache1.c 1e77432b40b7d3288327d9cdf399dcdfd2b6d3bf @@ -230,12 +230,12 @@ F src/printf.c 05edc41450d0eb2c05ef7db113bf32742ae65325 F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c f4d79e31ffa5820c2e3d1740baa5e9b190425f2b F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e -F src/select.c 15490b9da27a688a9fa09f943ebf4e6c749dc33b +F src/select.c e46cef4c224549b439384c88fc7f57ba064dad54 F src/shell.c 82c25508dac802b32198af6f5256ca1597c6a1af F src/sqlite.h.in 54678c21401909f72b221344dd560d285a1ba5eb F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h 17d487c3c91b0b8c584a32fbeb393f6f795eea7d -F src/sqliteInt.h b7b14a15f2c60e15f99145e9f5a90f5280e98582 +F src/sqliteInt.h 57a405ae6d2ed10fff52de376d18f21e04d96609 F src/sqliteLimit.h 164b0e6749d31e0daa1a4589a169d31c0dec7b3d F src/status.c 81712116e826b0089bb221b018929536b2b5406f F src/table.c e7a09215315a978057fb42c640f890160dbcc45e @@ -403,7 +403,7 @@ F test/collate4.test f04d5168685f2eef637ecfa2d4ddf8ec0d600177 F test/collate5.test 65d928034d30d2d263a80f6359f7549ee1598ec6 F test/collate6.test 8be65a182abaac8011a622131486dafb8076e907 F test/collate7.test 8ec29d98f3ee4ccebce6e16ce3863fb6b8c7b868 -F test/collate8.test df26649cfcbddf109c04122b340301616d3a88f6 +F test/collate8.test cd9b3d3f999b8520ffaa7cc1647061fc5bab1334 F test/collate9.test 3adcc799229545940df2f25308dd1ad65869145a F test/collateA.test b8218ab90d1fa5c59dcf156efabb1b2599c580d6 F test/colmeta.test 2c765ea61ee37bc43bbe6d6047f89004e6508eb1 @@ -1239,10 +1239,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 4ef7ceced2b0000d21f7f8014384c04a0e4661d3 -R b512281a09e1b31cff93e7ca5bacbcdc -T *branch * tkt-2f7170d7 -T *sym-tkt-2f7170d7 * -T -sym-trunk * +P 0b7d65e3fda676d193347cb782854c28a48252af +R 0fcf0b67c1cdaee9bbc7c2fe09760751 U drh -Z f683ca0757ba5ade9ef6c768a943d35e +Z d2e1dd3a2a5ed2929029c668f1fd20a5 diff --git a/manifest.uuid b/manifest.uuid index 1553ada2f8..35da9caa79 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -0b7d65e3fda676d193347cb782854c28a48252af \ No newline at end of file +c053448a55f9d030e8ffe88cf4fc14ada7f6ec19 \ No newline at end of file diff --git a/src/delete.c b/src/delete.c index 011fb80dee..ef6aace1c8 100644 --- a/src/delete.c +++ b/src/delete.c @@ -189,7 +189,7 @@ Expr *sqlite3LimitWhere( pInClause->x.pSelect = pSelect; pInClause->flags |= EP_xIsSelect; - sqlite3ExprSetHeight(pParse, pInClause); + sqlite3ExprSetHeightAndFlags(pParse, pInClause); return pInClause; /* something went wrong. clean up anything allocated. */ diff --git a/src/expr.c b/src/expr.c index 2def950f23..496c7a3176 100644 --- a/src/expr.c +++ b/src/expr.c @@ -146,10 +146,20 @@ CollSeq *sqlite3ExprCollSeq(Parse *pParse, Expr *pExpr){ break; } if( p->flags & EP_Collate ){ - if( ALWAYS(p->pLeft) && (p->pLeft->flags & EP_Collate)!=0 ){ + if( p->pLeft && (p->pLeft->flags & EP_Collate)!=0 ){ p = p->pLeft; }else{ - p = p->pRight; + Expr *pNext = p->pRight; + if( p->x.pList!=0 && !ExprHasProperty(p, EP_xIsSelect) ){ + int i; + for(i=0; ix.pList->nExpr; i++){ + if( ExprHasProperty(p->x.pList->a[i].pExpr, EP_Collate) ){ + pNext = p->x.pList->a[i].pExpr; + break; + } + } + } + p = pNext; } }else{ break; @@ -355,6 +365,9 @@ static void heightOfSelect(Select *p, int *pnHeight){ ** Expr.pSelect member has a height of 1. Any other expression ** has a height equal to the maximum height of any other ** referenced Expr plus one. +** +** Also propagate EP_Propagate flags up from Expr.x.pList to Expr.flags, +** if appropriate. */ static void exprSetHeight(Expr *p){ int nHeight = 0; @@ -362,8 +375,9 @@ static void exprSetHeight(Expr *p){ heightOfExpr(p->pRight, &nHeight); if( ExprHasProperty(p, EP_xIsSelect) ){ heightOfSelect(p->x.pSelect, &nHeight); - }else{ + }else if( p->x.pList ){ heightOfExprList(p->x.pList, &nHeight); + p->flags |= EP_Propagate & sqlite3ExprListFlags(p->x.pList); } p->nHeight = nHeight + 1; } @@ -372,8 +386,11 @@ static void exprSetHeight(Expr *p){ ** Set the Expr.nHeight variable using the exprSetHeight() function. If ** the height is greater than the maximum allowed expression depth, ** leave an error in pParse. +** +** Also propagate all EP_Propagate flags from the Expr.x.pList into +** Expr.flags. */ -void sqlite3ExprSetHeight(Parse *pParse, Expr *p){ +void sqlite3ExprSetHeightAndFlags(Parse *pParse, Expr *p){ exprSetHeight(p); sqlite3ExprCheckHeight(pParse, p->nHeight); } @@ -387,8 +404,17 @@ int sqlite3SelectExprHeight(Select *p){ heightOfSelect(p, &nHeight); return nHeight; } -#else - #define exprSetHeight(y) +#else /* ABOVE: Height enforcement enabled. BELOW: Height enforcement off */ +/* +** Propagate all EP_Propagate flags from the Expr.x.pList into +** Expr.flags. +*/ +void sqlite3ExprSetHeightAndFlags(Parse *pParse, Expr *p){ + if( p && p->x.pList && !ExprHasProperty(p, EP_xIsSelect) ){ + p->flags |= EP_Propagate & sqlite3ExprListFlags(p->x.pList); + } +} +#define exprSetHeight(y) #endif /* SQLITE_MAX_EXPR_DEPTH>0 */ /* @@ -594,7 +620,7 @@ Expr *sqlite3ExprFunction(Parse *pParse, ExprList *pList, Token *pToken){ } pNew->x.pList = pList; assert( !ExprHasProperty(pNew, EP_xIsSelect) ); - sqlite3ExprSetHeight(pParse, pNew); + sqlite3ExprSetHeightAndFlags(pParse, pNew); return pNew; } @@ -1210,16 +1236,18 @@ void sqlite3ExprListDelete(sqlite3 *db, ExprList *pList){ } /* -** Return TRUE if any expression in ExprList has any of the EP_* -** properties given by "m" +** Return the bitwise-OR of all Expr.flags fields in the given +** ExprList. */ -int sqlite3AnyExprListHasProperty(const ExprList *pList, u32 m){ +u32 sqlite3ExprListFlags(const ExprList *pList){ int i; - if( pList==0 ) return 0; - for(i=0; inExpr; i++){ - if( ExprHasProperty(pList->a[i].pExpr, m) ) return 1; + u32 m = 0; + if( pList ){ + for(i=0; inExpr; i++){ + m |= pList->a[i].pExpr->flags; + } } - return 0; + return m; } /* diff --git a/src/parse.y b/src/parse.y index 6730312d7c..78e79cd361 100644 --- a/src/parse.y +++ b/src/parse.y @@ -1078,7 +1078,7 @@ expr(A) ::= expr(W) between_op(N) expr(X) AND expr(Y). [BETWEEN] { A.pExpr = sqlite3PExpr(pParse, TK_IN, X.pExpr, 0, 0); if( A.pExpr ){ A.pExpr->x.pList = Y; - sqlite3ExprSetHeight(pParse, A.pExpr); + sqlite3ExprSetHeightAndFlags(pParse, A.pExpr); }else{ sqlite3ExprListDelete(pParse->db, Y); } @@ -1092,7 +1092,7 @@ expr(A) ::= expr(W) between_op(N) expr(X) AND expr(Y). [BETWEEN] { if( A.pExpr ){ A.pExpr->x.pSelect = X; ExprSetProperty(A.pExpr, EP_xIsSelect|EP_Subquery); - sqlite3ExprSetHeight(pParse, A.pExpr); + sqlite3ExprSetHeightAndFlags(pParse, A.pExpr); }else{ sqlite3SelectDelete(pParse->db, X); } @@ -1104,7 +1104,7 @@ expr(A) ::= expr(W) between_op(N) expr(X) AND expr(Y). [BETWEEN] { if( A.pExpr ){ A.pExpr->x.pSelect = Y; ExprSetProperty(A.pExpr, EP_xIsSelect|EP_Subquery); - sqlite3ExprSetHeight(pParse, A.pExpr); + sqlite3ExprSetHeightAndFlags(pParse, A.pExpr); }else{ sqlite3SelectDelete(pParse->db, Y); } @@ -1118,7 +1118,7 @@ expr(A) ::= expr(W) between_op(N) expr(X) AND expr(Y). [BETWEEN] { if( A.pExpr ){ A.pExpr->x.pSelect = sqlite3SelectNew(pParse, 0,pSrc,0,0,0,0,0,0,0); ExprSetProperty(A.pExpr, EP_xIsSelect|EP_Subquery); - sqlite3ExprSetHeight(pParse, A.pExpr); + sqlite3ExprSetHeightAndFlags(pParse, A.pExpr); }else{ sqlite3SrcListDelete(pParse->db, pSrc); } @@ -1131,7 +1131,7 @@ expr(A) ::= expr(W) between_op(N) expr(X) AND expr(Y). [BETWEEN] { if( p ){ p->x.pSelect = Y; ExprSetProperty(p, EP_xIsSelect|EP_Subquery); - sqlite3ExprSetHeight(pParse, p); + sqlite3ExprSetHeightAndFlags(pParse, p); }else{ sqlite3SelectDelete(pParse->db, Y); } @@ -1145,7 +1145,7 @@ expr(A) ::= CASE(C) case_operand(X) case_exprlist(Y) case_else(Z) END(E). { A.pExpr = sqlite3PExpr(pParse, TK_CASE, X, 0, 0); if( A.pExpr ){ A.pExpr->x.pList = Z ? sqlite3ExprListAppend(pParse,Y,Z) : Y; - sqlite3ExprSetHeight(pParse, A.pExpr); + sqlite3ExprSetHeightAndFlags(pParse, A.pExpr); }else{ sqlite3ExprListDelete(pParse->db, Y); sqlite3ExprDelete(pParse->db, Z); diff --git a/src/select.c b/src/select.c index 2c4c9e41f9..91b3d4345f 100644 --- a/src/select.c +++ b/src/select.c @@ -3338,8 +3338,8 @@ static int flattenSubquery( if( isAgg ) return 0; /* Restriction (1) */ if( pSrc->nSrc>1 ) return 0; /* Restriction (2a) */ if( (p->pWhere && ExprHasProperty(p->pWhere,EP_Subquery)) - || sqlite3AnyExprListHasProperty(p->pEList,EP_Subquery) - || sqlite3AnyExprListHasProperty(p->pOrderBy,EP_Subquery) + || (sqlite3ExprListFlags(p->pEList) & EP_Subquery)!=0 + || (sqlite3ExprListFlags(p->pOrderBy) & EP_Subquery)!=0 ){ return 0; /* Restriction (2b) */ } diff --git a/src/sqliteInt.h b/src/sqliteInt.h index e07ee4a5bd..3f9a3a7cc7 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -3159,7 +3159,7 @@ ExprList *sqlite3ExprListAppend(Parse*,ExprList*,Expr*); void sqlite3ExprListSetName(Parse*,ExprList*,Token*,int); void sqlite3ExprListSetSpan(Parse*,ExprList*,ExprSpan*); void sqlite3ExprListDelete(sqlite3*, ExprList*); -int sqlite3AnyExprListHasProperty(const ExprList*,u32); +u32 sqlite3ExprListFlags(const ExprList*); int sqlite3Init(sqlite3*, char**); int sqlite3InitCallback(void*, int, char**, char**); void sqlite3Pragma(Parse*,Token*,Token*,Token*,int); @@ -3743,12 +3743,11 @@ void sqlite3MemJournalOpen(sqlite3_file *); int sqlite3MemJournalSize(void); int sqlite3IsMemJournal(sqlite3_file *); +void sqlite3ExprSetHeightAndFlags(Parse *pParse, Expr *p); #if SQLITE_MAX_EXPR_DEPTH>0 - void sqlite3ExprSetHeight(Parse *pParse, Expr *p); int sqlite3SelectExprHeight(Select *); int sqlite3ExprCheckHeight(Parse*, int); #else - #define sqlite3ExprSetHeight(x,y) #define sqlite3SelectExprHeight(x) 0 #define sqlite3ExprCheckHeight(x,y) #endif diff --git a/test/collate8.test b/test/collate8.test index 60a89162dd..b06c87d2f8 100644 --- a/test/collate8.test +++ b/test/collate8.test @@ -13,7 +13,9 @@ # focus of this script is making sure collations pass through the # unary + operator. # -# $Id: collate8.test,v 1.2 2008/08/25 12:14:09 drh Exp $ +# 2015-02-09: Added tests to make sure COLLATE passes through function +# calls. Ticket [ca0d20b6cdddec5e81b8d66f89c46a5583b5f6f6]. +# set testdir [file dirname $argv0] source $testdir/tester.tcl @@ -122,4 +124,34 @@ do_test collate8-2.8 { } } {abc} +# Make sure the COLLATE operator perculates up through function calls +# and other Expr structures that use the Expr.x.pList field. +# +do_execsql_test collate8-3.1 { + SELECT 'abc'==('ABC'||'') COLLATE nocase; + SELECT 'abc'==('ABC'||'' COLLATE nocase); + SELECT 'abc'==('ABC'||('' COLLATE nocase)); + SELECT 'abc'==('ABC'||upper('' COLLATE nocase)); +} {1 1 1 1} +do_execsql_test collate8-3.2 { + SELECT 'abc'==('ABC'||max('' COLLATE nocase,'' COLLATE binary)); +} {1} + +# The COLLATE binary is on the left and so takes precedence +do_execsql_test collate8-3.3 { + SELECT 'abc'==('ABC'||max('' COLLATE binary,'' COLLATE nocase)); +} {0} + +do_execsql_test collate8-3.4 { + SELECT 'abc'==('ABC'||CASE WHEN 1-1=2 THEN '' COLLATE nocase + ELSE '' COLLATE binary END); + SELECT 'abc'==('ABC'||CASE WHEN 1+1=2 THEN '' COLLATE nocase + ELSE '' COLLATE binary END); +} {1 1} +do_execsql_test collate8-3.5 { + SELECT 'abc'==('ABC'||CASE WHEN 1=2 THEN '' COLLATE binary + ELSE '' COLLATE nocase END); +} {0} + + finish_test From 2c5e9b56721f110016d99b4ba32ccb111e39971c Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 9 Feb 2015 16:34:33 +0000 Subject: [PATCH 37/62] Add test cases for the query flattener fix for ticket [2f7170d73bf9abf8]. FossilOrigin-Name: dd8f7f7511639a1baa41a6ff2e359dc6f1e66943 --- manifest | 12 +++++----- manifest.uuid | 2 +- test/select6.test | 56 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 7 deletions(-) diff --git a/manifest b/manifest index 30d2176730..3dc1515cc4 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Propagate\sthe\sCOLLATE\soperator\supward\sthrough\sfunction\scalls.\nInitial\sfix\sfor\sticket\s[ca0d20b6cdddec5e8]. -D 2015-02-09T16:09:34.923 +C Add\stest\scases\sfor\sthe\squery\sflattener\sfix\sfor\nticket\s[2f7170d73bf9abf8]. +D 2015-02-09T16:34:33.249 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 6b9e7677829aa94b9f30949656e27312aefb9a46 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -834,7 +834,7 @@ F test/select2.test 352480e0e9c66eda9c3044e412abdf5be0215b56 F test/select3.test 2ce595f8fb8e2ac10071d3b4e424cadd4634a054 F test/select4.test 8c5a60d439e2df824aed56223566877a883c5c84 F test/select5.test e758b8ef94f69b111df4cb819008856655dcd535 -F test/select6.test e76bd10a56988f15726c097a5d5a7966fe82d3b2 +F test/select6.test 39eac4a5c03650b2b473c532882273283ee8b7a0 F test/select7.test 7fd2ef598cfabb6b9ff6ac13973b91d0527df49d F test/select8.test 391de11bdd52339c30580dabbbbe97e3e9a3c79d F test/select9.test aebc2bb0c3bc44606125033cbcaac2c8d1f33a95 @@ -1239,7 +1239,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 0b7d65e3fda676d193347cb782854c28a48252af -R 0fcf0b67c1cdaee9bbc7c2fe09760751 +P c053448a55f9d030e8ffe88cf4fc14ada7f6ec19 +R 2d5172d7784b0dfa3e9c983c86806f6a U drh -Z d2e1dd3a2a5ed2929029c668f1fd20a5 +Z 7fd9b7cb5d6f8f4f67ff4b5b0cf25a38 diff --git a/manifest.uuid b/manifest.uuid index 35da9caa79..9cc0e5086e 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c053448a55f9d030e8ffe88cf4fc14ada7f6ec19 \ No newline at end of file +dd8f7f7511639a1baa41a6ff2e359dc6f1e66943 \ No newline at end of file diff --git a/test/select6.test b/test/select6.test index 64a8519d89..590512a6b0 100644 --- a/test/select6.test +++ b/test/select6.test @@ -557,5 +557,61 @@ do_catchsql_test 10.8 { ) } $err +# 2015-02-09 Ticket [2f7170d73bf9abf80339187aa3677dce3dbcd5ca] +# "misuse of aggregate" error if aggregate column from FROM +# subquery is used in correlated subquery +# +do_execsql_test 11.1 { + DROP TABLE IF EXISTS t1; + CREATE TABLE t1(w INT, x INT); + INSERT INTO t1(w,x) + VALUES(1,10),(2,20),(3,30), + (2,21),(3,31), + (3,32); + CREATE INDEX t1wx ON t1(w,x); + + DROP TABLE IF EXISTS t2; + CREATE TABLE t2(w INT, y VARCHAR(8)); + INSERT INTO t2(w,y) VALUES(1,'one'),(2,'two'),(3,'three'),(4,'four'); + CREATE INDEX t2wy ON t2(w,y); + + SELECT cnt, xyz, (SELECT y FROM t2 WHERE w=cnt), '|' + FROM (SELECT count(*) AS cnt, w AS xyz FROM t1 GROUP BY 2) + ORDER BY cnt, xyz; +} {1 1 one | 2 2 two | 3 3 three |} +do_execsql_test 11.2 { + SELECT cnt, xyz, lower((SELECT y FROM t2 WHERE w=cnt)), '|' + FROM (SELECT count(*) AS cnt, w AS xyz FROM t1 GROUP BY 2) + ORDER BY cnt, xyz; +} {1 1 one | 2 2 two | 3 3 three |} +do_execsql_test 11.3 { + SELECT cnt, xyz, '|' + FROM (SELECT count(*) AS cnt, w AS xyz FROM t1 GROUP BY 2) + WHERE (SELECT y FROM t2 WHERE w=cnt)!='two' + ORDER BY cnt, xyz; +} {1 1 | 3 3 |} +do_execsql_test 11.4 { + SELECT cnt, xyz, '|' + FROM (SELECT count(*) AS cnt, w AS xyz FROM t1 GROUP BY 2) + ORDER BY lower((SELECT y FROM t2 WHERE w=cnt)); +} {1 1 | 3 3 | 2 2 |} +do_execsql_test 11.5 { + SELECT cnt, xyz, + CASE WHEN (SELECT y FROM t2 WHERE w=cnt)=='two' + THEN 'aaa' ELSE 'bbb' + END, '|' + FROM (SELECT count(*) AS cnt, w AS xyz FROM t1 GROUP BY 2) + ORDER BY +cnt; +} {1 1 bbb | 2 2 aaa | 3 3 bbb |} + +do_execsql_test 11.100 { + DROP TABLE t1; + DROP TABLE t2; + CREATE TABLE t1(x); + CREATE TABLE t2(y, z); + SELECT ( SELECT y FROM t2 WHERE z = cnt ) + FROM ( SELECT count(*) AS cnt FROM t1 ); +} {{}} + finish_test From 9fab5ed01f7b1cdb4f56ee1c3a2bc9de67c5c36c Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 9 Feb 2015 17:46:11 +0000 Subject: [PATCH 38/62] Fix WITHOUT ROWID table handing in sqlite3_analyzer. FossilOrigin-Name: 937e0fe7008c0f76b6a584180df9a9457166a0b1 --- manifest | 14 +++++++------- manifest.uuid | 2 +- tool/spaceanal.tcl | 35 +++++++++++++++++++++++++++-------- 3 files changed, 35 insertions(+), 16 deletions(-) diff --git a/manifest b/manifest index 10002ebccf..13b7009965 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Rename\sthe\sinternal\s"EP_Constant"\sbitmask\sto\sa\sless\smisleading\s"EP_ConstFunc". -D 2015-02-09T14:07:07.358 +C Fix\sWITHOUT\sROWID\stable\shanding\sin\ssqlite3_analyzer. +D 2015-02-09T17:46:11.315 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 6b9e7677829aa94b9f30949656e27312aefb9a46 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -1222,7 +1222,7 @@ F tool/showstat4.c 9515faa8ec176599d4a8288293ba8ec61f7b728a F tool/showwal.c 85cb36d4fe3e93e2fbd63e786e0d1ce42d0c4fad F tool/soak1.tcl 8d407956e1a45b485a8e072470a3e629a27037fe F tool/space_used.tcl f714c41a59e326b8b9042f415b628b561bafa06b -F tool/spaceanal.tcl 8e50b217c56a6a086a1b47eac9d09c5cd65b996f +F tool/spaceanal.tcl d5a09620c66a6c144576cb9d2bdfa9a6fbe362a5 F tool/speedtest.tcl 06c76698485ccf597b9e7dbb1ac70706eb873355 F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81 F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff @@ -1239,7 +1239,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P aa093fef2d2a7e26d987b46654963e4d7e66d444 -R f51c0a3a4046c27eeedc2e4a71b172ba -U drh -Z 4b79838e5fc774abeed8438ce319eb67 +P 4ef7ceced2b0000d21f7f8014384c04a0e4661d3 +R 3dfd2d57b7936b7d1030a6a9083d3a68 +U dan +Z 936b36142dcc1fcccff0b983a2ef7c1f diff --git a/manifest.uuid b/manifest.uuid index c03c5df094..dd3e606fa8 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -4ef7ceced2b0000d21f7f8014384c04a0e4661d3 \ No newline at end of file +937e0fe7008c0f76b6a584180df9a9457166a0b1 \ No newline at end of file diff --git a/tool/spaceanal.tcl b/tool/spaceanal.tcl index a227b85243..516d282445 100644 --- a/tool/spaceanal.tcl +++ b/tool/spaceanal.tcl @@ -4,6 +4,24 @@ # if {[catch { + +# Argument $tname is the name of a table within the database opened by +# database handle [db]. Return true if it is a WITHOUT ROWID table, or +# false otherwise. +# +proc is_without_rowid {tname} { + set t [string map {' ''} $tname] + db eval "PRAGMA index_list = '$t'" o { + if {$o(origin) == "pk"} { + set n $o(name) + if {0==[db one { SELECT count(*) FROM sqlite_master WHERE name=$n }]} { + return 1 + } + } + } + return 0 +} + # Get the name of the database to analyze # proc usage {} { @@ -167,20 +185,21 @@ set sql { SELECT name, tbl_name FROM sqlite_master WHERE rootpage>0 } foreach {name tblname} [concat sqlite_master sqlite_master [db eval $sql]] { set is_index [expr {$name!=$tblname}] + set idx_btree [expr {$is_index || [is_without_rowid $name]}] db eval { SELECT sum(ncell) AS nentry, - sum(isleaf(pagetype, $is_index) * ncell) AS leaf_entries, + sum(isleaf(pagetype, $idx_btree) * ncell) AS leaf_entries, sum(payload) AS payload, - sum(isoverflow(pagetype, $is_index) * payload) AS ovfl_payload, + sum(isoverflow(pagetype, $idx_btree) * payload) AS ovfl_payload, sum(path LIKE '%+000000') AS ovfl_cnt, max(mx_payload) AS mx_payload, - sum(isinternal(pagetype, $is_index)) AS int_pages, - sum(isleaf(pagetype, $is_index)) AS leaf_pages, - sum(isoverflow(pagetype, $is_index)) AS ovfl_pages, - sum(isinternal(pagetype, $is_index) * unused) AS int_unused, - sum(isleaf(pagetype, $is_index) * unused) AS leaf_unused, - sum(isoverflow(pagetype, $is_index) * unused) AS ovfl_unused, + sum(isinternal(pagetype, $idx_btree)) AS int_pages, + sum(isleaf(pagetype, $idx_btree)) AS leaf_pages, + sum(isoverflow(pagetype, $idx_btree)) AS ovfl_pages, + sum(isinternal(pagetype, $idx_btree) * unused) AS int_unused, + sum(isleaf(pagetype, $idx_btree) * unused) AS leaf_unused, + sum(isoverflow(pagetype, $idx_btree) * unused) AS ovfl_unused, sum(pgsize) AS compressed_size FROM temp.dbstat WHERE name = $name } break From a0efb1ae110ca9627afd7fbe88b8523105819e4e Mon Sep 17 00:00:00 2001 From: mistachkin Date: Thu, 12 Feb 2015 22:45:25 +0000 Subject: [PATCH 39/62] For the shell '.import' command, make sure the last column value present is considered before NULL filling any missing ones. FossilOrigin-Name: 9c5bcad1f7d04c16f3ec7fc483280059ae93961b --- manifest | 17 ++++++++--------- manifest.uuid | 2 +- src/shell.c | 2 +- test/shell5.test | 30 ++++++++++++++++++++++++++++++ 4 files changed, 40 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index e802b5a3d1..6016792600 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Propagate\sCOLLATE\soperators\supward\sthrough\sfunction\scalls\sand\sCASE\soperations.\nAnd\sdo\snot\sflatten\san\saggregate\ssubquery\sinto\sa\squery\sthat\suses\sother\nsubqueries.\s\sFixes\sfor\stickets\s[ca0d20b6cdddec5]\sand\n[2f7170d73bf9],\srespectively. -D 2015-02-09T18:28:03.590 +C For\sthe\sshell\s'.import'\scommand,\smake\ssure\sthe\slast\scolumn\svalue\spresent\sis\sconsidered\sbefore\sNULL\sfilling\sany\smissing\sones. +D 2015-02-12T22:45:25.976 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 6b9e7677829aa94b9f30949656e27312aefb9a46 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -231,7 +231,7 @@ F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c f4d79e31ffa5820c2e3d1740baa5e9b190425f2b F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e F src/select.c e46cef4c224549b439384c88fc7f57ba064dad54 -F src/shell.c 82c25508dac802b32198af6f5256ca1597c6a1af +F src/shell.c 6276582ee4e9114e0bb0795772414caaf21c0f8e F src/sqlite.h.in 54678c21401909f72b221344dd560d285a1ba5eb F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h 17d487c3c91b0b8c584a32fbeb393f6f795eea7d @@ -862,7 +862,7 @@ F test/shell1.test ca88b14a8fc8b1f3543a24e519d019585ac9c903 F test/shell2.test 12b8bf901b0e3a8ac58cf5c0c63a0a388d4d1862 F test/shell3.test 5e8545ec72c4413a0e8d4c6be56496e3c257ca29 F test/shell4.test 8a9c08976291e6c6c808b4d718f4a8b299f339f5 -F test/shell5.test 81aba4793fa7441b1300daae1aec4f7e4b5741c1 +F test/shell5.test c04e9f9f948305706b88377c464c7f08ce7479f9 F test/shortread1.test bb591ef20f0fd9ed26d0d12e80eee6d7ac8897a3 F test/show_speedtest1_rtree.tcl 32e6c5f073d7426148a6936a0408f4b5b169aba5 F test/shrink.test 8c70f62b6e8eb4d54533de6d65bd06b1b9a17868 @@ -1239,8 +1239,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 937e0fe7008c0f76b6a584180df9a9457166a0b1 dd8f7f7511639a1baa41a6ff2e359dc6f1e66943 -R eaedb0adeed807300663dae355946d49 -T +closed dd8f7f7511639a1baa41a6ff2e359dc6f1e66943 -U drh -Z 20be3d681a1333c92b781a8eb61382fe +P 24e78b8d65734a6a8ae21a20542cd1839e756fb1 +R 5a56d277a5a92f00ac805dba68a851da +U mistachkin +Z bd61b6f3a5ec40c1d25c581a9db673bd diff --git a/manifest.uuid b/manifest.uuid index 1b38cd06bf..fa75f3e8fe 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -24e78b8d65734a6a8ae21a20542cd1839e756fb1 \ No newline at end of file +9c5bcad1f7d04c16f3ec7fc483280059ae93961b \ No newline at end of file diff --git a/src/shell.c b/src/shell.c index 77c9ab9e05..e0d0b78b7d 100644 --- a/src/shell.c +++ b/src/shell.c @@ -3021,7 +3021,7 @@ static int do_meta_command(char *zLine, ShellState *p){ fprintf(stderr, "%s:%d: expected %d columns but found %d - " "filling the rest with NULL\n", sCtx.zFile, startLine, nCol, i+1); - i++; + i += 2; while( i<=nCol ){ sqlite3_bind_null(pStmt, i); i++; } } } diff --git a/test/shell5.test b/test/shell5.test index e22db04d80..b921accca5 100644 --- a/test/shell5.test +++ b/test/shell5.test @@ -405,4 +405,34 @@ SELECT * FROM t5; set x } "0 \{\"test 1\"\x1F,test 2\x1Etest 3\x1Ftest 4\x1E\}" +do_test shell5-4.1 { + forcedelete shell5.csv + set fd [open shell5.csv w] + puts $fd "1,2,3" + puts $fd "4,5" + puts $fd "6,7,8" + close $fd + catchcmd test.db [string trim { +.mode csv +CREATE TABLE t6(a, b, c); +.import shell5.csv t6 + }] + db eval { SELECT * FROM t6 ORDER BY a } +} {1 2 3 4 5 {} 6 7 8} + +do_test shell5-4.2 { + forcedelete shell5.csv + set fd [open shell5.csv w] + puts $fd "1,2,3" + puts $fd "4,5" + puts $fd "6,7,8,9" + close $fd + catchcmd test.db [string trim { +.mode csv +CREATE TABLE t7(a, b, c); +.import shell5.csv t7 + }] + db eval { SELECT * FROM t7 ORDER BY a } +} {1 2 3 4 5 {} 6 7 8} + finish_test From 983b5ee73df642d1bfe5a1fcf61219c1608aec88 Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 13 Feb 2015 12:05:56 +0000 Subject: [PATCH 40/62] Make sure the prepared statement auto-resets on extended error codes of SQLITE_BUSY and SQLITE_LOCKED even when compiled using SQLITE_OMIT_AUTORESET. FossilOrigin-Name: 3c6ca414879feb1f5d31d5fd95a1737530aca624 --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/vdbeInt.h | 3 +++ src/vdbeapi.c | 10 ++++++++-- 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index 6016792600..3c7339464d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C For\sthe\sshell\s'.import'\scommand,\smake\ssure\sthe\slast\scolumn\svalue\spresent\sis\sconsidered\sbefore\sNULL\sfilling\sany\smissing\sones. -D 2015-02-12T22:45:25.976 +C Make\ssure\sthe\sprepared\sstatement\sauto-resets\son\sextended\serror\scodes\nof\sSQLITE_BUSY\sand\sSQLITE_LOCKED\seven\swhen\scompiled\susing\nSQLITE_OMIT_AUTORESET. +D 2015-02-13T12:05:56.027 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 6b9e7677829aa94b9f30949656e27312aefb9a46 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -295,8 +295,8 @@ F src/util.c 98a7627ca48ad3265b6940915a1d08355eb3fc7e F src/vacuum.c 9b30ec729337dd012ed88d4c292922c8ef9cf00c F src/vdbe.c ddfc977981cd6324668aa6b114045eb1c677421a F src/vdbe.h 6fc69d9c5e146302c56e163cb4b31d1ee64a18c3 -F src/vdbeInt.h 9bb69ff2447c34b6ccc58b34ec35b615f86ead78 -F src/vdbeapi.c 4bc511a46b9839392ae0e90844a71dc96d9dbd71 +F src/vdbeInt.h bb56fd199d8af1a2c1b9639ee2f70724b4338e3a +F src/vdbeapi.c 3d88089b10f71750b019a806224f0277d371a072 F src/vdbeaux.c 97911edb61074b871ec4aa2d6bb779071643dee5 F src/vdbeblob.c 4f2e8e075d238392df98c5e03a64342465b03f90 F src/vdbemem.c 31d8eabb0cd78bfeab4e5124c7363c3e9e54db9f @@ -1239,7 +1239,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 24e78b8d65734a6a8ae21a20542cd1839e756fb1 -R 5a56d277a5a92f00ac805dba68a851da -U mistachkin -Z bd61b6f3a5ec40c1d25c581a9db673bd +P 9c5bcad1f7d04c16f3ec7fc483280059ae93961b +R af13864c4a0da0631b5572a97e90dd3a +U drh +Z e7512897192b3651fafc4db87dc1b0b1 diff --git a/manifest.uuid b/manifest.uuid index fa75f3e8fe..741fd57b6f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -9c5bcad1f7d04c16f3ec7fc483280059ae93961b \ No newline at end of file +3c6ca414879feb1f5d31d5fd95a1737530aca624 \ No newline at end of file diff --git a/src/vdbeInt.h b/src/vdbeInt.h index 1a7297e946..877da1143c 100644 --- a/src/vdbeInt.h +++ b/src/vdbeInt.h @@ -344,6 +344,9 @@ struct Vdbe { u32 cacheCtr; /* VdbeCursor row cache generation counter */ int pc; /* The program counter */ int rc; /* Value to return */ +#ifdef SQLITE_DEBUG + int rcApp; /* errcode set by sqlite3_result_error_code() */ +#endif u16 nResColumn; /* Number of columns in one row of the result set */ u8 errorAction; /* Recovery action to do in case of an error */ u8 minWriteFileFormat; /* Minimum file format for writable database files */ diff --git a/src/vdbeapi.c b/src/vdbeapi.c index 21c537d776..b29338eb3d 100644 --- a/src/vdbeapi.c +++ b/src/vdbeapi.c @@ -365,6 +365,9 @@ void sqlite3_result_zeroblob(sqlite3_context *pCtx, int n){ void sqlite3_result_error_code(sqlite3_context *pCtx, int errCode){ pCtx->isError = errCode; pCtx->fErrorOrAux = 1; +#ifdef SQLITE_DEBUG + pCtx->pVdbe->rcApp = errCode; +#endif if( pCtx->pOut->flags & MEM_Null ){ sqlite3VdbeMemSetStr(pCtx->pOut, sqlite3ErrStr(errCode), -1, SQLITE_UTF8, SQLITE_STATIC); @@ -445,7 +448,7 @@ static int sqlite3Step(Vdbe *p){ ** or SQLITE_BUSY error. */ #ifdef SQLITE_OMIT_AUTORESET - if( p->rc==SQLITE_BUSY || p->rc==SQLITE_LOCKED ){ + if( (rc = p->rc&0xff)==SQLITE_BUSY || rc==SQLITE_LOCKED ){ sqlite3_reset((sqlite3_stmt*)p); }else{ return SQLITE_MISUSE_BKPT; @@ -491,6 +494,9 @@ static int sqlite3Step(Vdbe *p){ if( p->bIsReader ) db->nVdbeRead++; p->pc = 0; } +#ifdef SQLITE_DEBUG + p->rcApp = SQLITE_OK; +#endif #ifndef SQLITE_OMIT_EXPLAIN if( p->explain ){ rc = sqlite3VdbeList(p); @@ -535,7 +541,7 @@ end_of_step: assert( rc==SQLITE_ROW || rc==SQLITE_DONE || rc==SQLITE_ERROR || rc==SQLITE_BUSY || rc==SQLITE_MISUSE ); - assert( p->rc!=SQLITE_ROW && p->rc!=SQLITE_DONE ); + assert( (p->rc!=SQLITE_ROW && p->rc!=SQLITE_DONE) || p->rc==p->rcApp ); if( p->isPrepareV2 && rc!=SQLITE_ROW && rc!=SQLITE_DONE ){ /* If this statement was prepared using sqlite3_prepare_v2(), and an ** error has occurred, then return the error code in p->rc to the From 96c707a3c285141f3f5764422bdce7a01aaa319f Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 13 Feb 2015 16:36:14 +0000 Subject: [PATCH 41/62] Improvements to SQLITE_ENABLE_API_ARMOR. FossilOrigin-Name: 823ad40ccb5b51aaa0d5a48da63b465df9d0649a --- manifest | 26 +++++++++++++------------- manifest.uuid | 2 +- src/build.c | 4 ---- src/main.c | 10 ++++++++-- src/mutex_noop.c | 17 +++++++++++++---- src/mutex_unix.c | 31 ++++++++++++++++++------------- src/mutex_w32.c | 15 +++++++-------- src/printf.c | 2 +- src/tokenize.c | 5 +---- src/vtab.c | 4 +++- 10 files changed, 65 insertions(+), 51 deletions(-) diff --git a/manifest b/manifest index 3c7339464d..9d690c6549 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Make\ssure\sthe\sprepared\sstatement\sauto-resets\son\sextended\serror\scodes\nof\sSQLITE_BUSY\sand\sSQLITE_LOCKED\seven\swhen\scompiled\susing\nSQLITE_OMIT_AUTORESET. -D 2015-02-13T12:05:56.027 +C Improvements\sto\sSQLITE_ENABLE_API_ARMOR. +D 2015-02-13T16:36:14.430 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 6b9e7677829aa94b9f30949656e27312aefb9a46 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -176,7 +176,7 @@ F src/btmutex.c 49ca66250c7dfa844a4d4cb8272b87420d27d3a5 F src/btree.c 2a1245df0356a229bcd0fd87a8536b5067f16e82 F src/btree.h 94277c1d30c0b75705974bcc8b0c05e79c03d474 F src/btreeInt.h a3d0ae1d511365e1a2b76ad10960dbe55c286f34 -F src/build.c eefaa4f1d86bc3c08023a61fdd1e695b47796975 +F src/build.c ba45ebd02904e84d98839a6ea74c3eb948596587 F src/callback.c 7b44ce59674338ad48b0e84e7b72f935ea4f68b0 F src/complete.c 198a0066ba60ab06fc00fba1998d870a4d575463 F src/ctime.c 98f89724adc891a1a4c655bee04e33e716e05887 @@ -195,7 +195,7 @@ F src/journal.c b4124532212b6952f42eb2c12fa3c25701d8ba8d F src/legacy.c ba1863ea58c4c840335a84ec276fc2b25e22bc4e F src/lempar.c 7274c97d24bb46631e504332ccd3bd1b37841770 F src/loadext.c 86bd4e2fccd520b748cba52492ab60c4a770f660 -F src/main.c 17e3a37374f3c13e27311773c30720b61584f5b9 +F src/main.c 3780c966059a5fcb0afa42fd89e3b74ec1f72b9e F src/malloc.c 740db54387204c9a2eb67c6d98e68b08e9ef4eab F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645 F src/mem1.c abe6ee469b6c5a35c7f22bfeb9c9bac664a1c987 @@ -206,9 +206,9 @@ F src/memjournal.c 3eb2c0b51adbd869cb6a44780323f05fa904dc85 F src/msvc.h e78002098966e39b2fd9915bd70b7bc3ec8398b7 F src/mutex.c 19bf9acba69ca2f367c3761080f8a9f0cf4670a8 F src/mutex.h 779d588e3b7756ec3ecf7d78cde1d84aba414f85 -F src/mutex_noop.c f3f09fd7a2eb4287cfc799753ffc30380e7b71a1 -F src/mutex_unix.c 551e2f25f0fa0ee8fd7a43f50fc3d8be00e95dde -F src/mutex_w32.c df48fe07562a45c5c927c45b8d5873a27f98bbb0 +F src/mutex_noop.c 529bab0743c3321c940f32c3464de494fd38cfa9 +F src/mutex_unix.c 5cf676464bd19e0a866297515d146e8bf1669dfb +F src/mutex_w32.c a6f0b84068db2cbd96a94f23c622aeb875c57dff F src/notify.c 9711a7575036f0d3040ba61bc6e217f13a9888e7 F src/os.c 8fd25588eeba74068d41102d26810e216999b6c8 F src/os.h 3e57a24e2794a94d3cf2342c6d9a884888cd96bf @@ -226,7 +226,7 @@ F src/pcache1.c 1e77432b40b7d3288327d9cdf399dcdfd2b6d3bf F src/pragma.c ea0be138a99784b14e87bd4522fea40e7b979e9c F src/pragma.h 09c89bca58e9a44de2116cc8272b8d454657129f F src/prepare.c 173a5a499138451b2561614ecb87d78f9f4644b9 -F src/printf.c 05edc41450d0eb2c05ef7db113bf32742ae65325 +F src/printf.c 8da9a2687a396daa19860f4dc90975d319304744 F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c f4d79e31ffa5820c2e3d1740baa5e9b190425f2b F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e @@ -287,7 +287,7 @@ F src/test_vfs.c 5a14c63da9579ba148138c1fb233100f2eb58ebb F src/test_vfstrace.c bab9594adc976cbe696ff3970728830b4c5ed698 F src/test_wsd.c 41cadfd9d97fe8e3e4e44f61a4a8ccd6f7ca8fe9 F src/threads.c 6bbcc9fe50c917864d48287b4792d46d6e873481 -F src/tokenize.c e00458c9938072b0ea711c850b8dcf4ddcb5fe18 +F src/tokenize.c 05e52378c46efbc1fd63cbbbf7f3c555f840f4bf F src/trigger.c 25571661fdeae8c7f975ff40ffec205520a3f92f F src/update.c 3c4ecc282accf12d39edb8d524cf089645e55a13 F src/utf.c fc6b889ba0779b7722634cdeaa25f1930d93820c @@ -302,7 +302,7 @@ F src/vdbeblob.c 4f2e8e075d238392df98c5e03a64342465b03f90 F src/vdbemem.c 31d8eabb0cd78bfeab4e5124c7363c3e9e54db9f F src/vdbesort.c 6d64c5448b64851b99931ede980addc3af70d5e2 F src/vdbetrace.c 7e4222955e07dd707a2f360c0eb73452be1cb010 -F src/vtab.c c08ec66f45919eaa726bf88aa53eb08379d607f9 +F src/vtab.c 699f2b8d509cfe379c33dde33827875d5b030e01 F src/wal.c 39303f2c9db02a4e422cd8eb2c8760420c6a51fe F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4 F src/walker.c c253b95b4ee44b21c406e2a1052636c31ea27804 @@ -1239,7 +1239,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 9c5bcad1f7d04c16f3ec7fc483280059ae93961b -R af13864c4a0da0631b5572a97e90dd3a +P 3c6ca414879feb1f5d31d5fd95a1737530aca624 +R f6208f1be504ea76c76eb647c7a3e38c U drh -Z e7512897192b3651fafc4db87dc1b0b1 +Z 5fa0aaf45cc565051b14e7b2d21a11e0 diff --git a/manifest.uuid b/manifest.uuid index 741fd57b6f..2047ee0ac5 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -3c6ca414879feb1f5d31d5fd95a1737530aca624 \ No newline at end of file +823ad40ccb5b51aaa0d5a48da63b465df9d0649a \ No newline at end of file diff --git a/src/build.c b/src/build.c index 7e3ce1b76a..54dd526b56 100644 --- a/src/build.c +++ b/src/build.c @@ -308,10 +308,6 @@ Table *sqlite3FindTable(sqlite3 *db, const char *zName, const char *zDatabase){ Table *p = 0; int i; -#ifdef SQLITE_ENABLE_API_ARMOR - if( !sqlite3SafetyCheckOk(db) || zName==0 ) return 0; -#endif - /* All mutexes are required for schema access. Make sure we hold them. */ assert( zDatabase!=0 || sqlite3BtreeHoldsAllMutexes(db) ); #if SQLITE_USER_AUTHENTICATION diff --git a/src/main.c b/src/main.c index fa87a19cf7..d0bd55c1db 100644 --- a/src/main.c +++ b/src/main.c @@ -1414,7 +1414,7 @@ int sqlite3_busy_handler( void *pArg ){ #ifdef SQLITE_ENABLE_API_ARMOR - if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE; + if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT; #endif sqlite3_mutex_enter(db->mutex); db->busyHandler.xFunc = xBusy; @@ -3142,13 +3142,19 @@ int sqlite3_table_column_metadata( Table *pTab = 0; Column *pCol = 0; int iCol = 0; - char const *zDataType = 0; char const *zCollSeq = 0; int notnull = 0; int primarykey = 0; int autoinc = 0; + +#ifdef SQLITE_ENABLE_API_ARMOR + if( !sqlite3SafetyCheckOk(db) || zTableName==0 ){ + return SQLITE_MISUSE_BKPT; + } +#endif + /* Ensure the database schema has been loaded */ sqlite3_mutex_enter(db->mutex); sqlite3BtreeEnterAll(db); diff --git a/src/mutex_noop.c b/src/mutex_noop.c index 1a900c225a..7f68aea6c1 100644 --- a/src/mutex_noop.c +++ b/src/mutex_noop.c @@ -120,8 +120,12 @@ static sqlite3_mutex *debugMutexAlloc(int id){ break; } default: { - assert( id-2 >= 0 ); - assert( id-2 < (int)(sizeof(aStatic)/sizeof(aStatic[0])) ); +#ifdef SQLITE_ENABLE_API_ARMOR + if( id-2<0 || id-2>=ArraySize(aStatic) ){ + (void)SQLITE_MISUSE_BKPT; + return 0; + } +#endif pNew = &aStatic[id-2]; pNew->id = id; break; @@ -136,8 +140,13 @@ static sqlite3_mutex *debugMutexAlloc(int id){ static void debugMutexFree(sqlite3_mutex *pX){ sqlite3_debug_mutex *p = (sqlite3_debug_mutex*)pX; assert( p->cnt==0 ); - assert( p->id==SQLITE_MUTEX_FAST || p->id==SQLITE_MUTEX_RECURSIVE ); - sqlite3_free(p); + if( p->id==SQLITE_MUTEX_RECURSIVE || p->id==SQLITE_MUTEX_FAST ){ + sqlite3_free(p); + }else{ +#ifdef SQLITE_ENABLE_API_ARMOR + (void)SQLITE_MISUSE_BKPT; +#endif + } } /* diff --git a/src/mutex_unix.c b/src/mutex_unix.c index c936914d8a..e08448e022 100644 --- a/src/mutex_unix.c +++ b/src/mutex_unix.c @@ -40,8 +40,10 @@ */ struct sqlite3_mutex { pthread_mutex_t mutex; /* Mutex controlling the lock */ -#if SQLITE_MUTEX_NREF +#if SQLITE_MUTEX_NREF || defined(SQLITE_ENABLE_API_ARMOR) int id; /* Mutex type */ +#endif +#if SQLITE_MUTEX_NREF volatile int nRef; /* Number of entrances */ volatile pthread_t owner; /* Thread that is within this mutex */ int trace; /* True to trace changes */ @@ -157,9 +159,6 @@ static sqlite3_mutex *pthreadMutexAlloc(int iType){ pthread_mutexattr_settype(&recursiveAttr, PTHREAD_MUTEX_RECURSIVE); pthread_mutex_init(&p->mutex, &recursiveAttr); pthread_mutexattr_destroy(&recursiveAttr); -#endif -#if SQLITE_MUTEX_NREF - p->id = iType; #endif } break; @@ -167,9 +166,6 @@ static sqlite3_mutex *pthreadMutexAlloc(int iType){ case SQLITE_MUTEX_FAST: { p = sqlite3MallocZero( sizeof(*p) ); if( p ){ -#if SQLITE_MUTEX_NREF - p->id = iType; -#endif pthread_mutex_init(&p->mutex, 0); } break; @@ -182,12 +178,12 @@ static sqlite3_mutex *pthreadMutexAlloc(int iType){ } #endif p = &staticMutexes[iType-2]; -#if SQLITE_MUTEX_NREF - p->id = iType; -#endif break; } } +#if SQLITE_MUTEX_NREF || defined(SQLITE_ENABLE_API_ARMOR) + if( p ) p->id = iType; +#endif return p; } @@ -199,9 +195,18 @@ static sqlite3_mutex *pthreadMutexAlloc(int iType){ */ static void pthreadMutexFree(sqlite3_mutex *p){ assert( p->nRef==0 ); - assert( p->id==SQLITE_MUTEX_FAST || p->id==SQLITE_MUTEX_RECURSIVE ); - pthread_mutex_destroy(&p->mutex); - sqlite3_free(p); +#if SQLITE_ENABLE_API_ARMOR + if( p->id==SQLITE_MUTEX_FAST || p->id==SQLITE_MUTEX_RECURSIVE ) +#endif + { + pthread_mutex_destroy(&p->mutex); + sqlite3_free(p); + } +#ifdef SQLITE_ENABLE_API_ARMOR + else{ + (void)SQLITE_MISUSE_BKPT; + } +#endif } /* diff --git a/src/mutex_w32.c b/src/mutex_w32.c index a799c86159..284355f578 100644 --- a/src/mutex_w32.c +++ b/src/mutex_w32.c @@ -215,9 +215,6 @@ static sqlite3_mutex *winMutexAlloc(int iType){ return 0; } #endif - assert( iType-2 >= 0 ); - assert( iType-2 < ArraySize(winMutex_staticMutexes) ); - assert( winMutex_isInit==1 ); p = &winMutex_staticMutexes[iType-2]; #ifdef SQLITE_DEBUG p->id = iType; @@ -239,13 +236,15 @@ static sqlite3_mutex *winMutexAlloc(int iType){ */ static void winMutexFree(sqlite3_mutex *p){ assert( p ); -#ifdef SQLITE_DEBUG assert( p->nRef==0 && p->owner==0 ); - assert( p->id==SQLITE_MUTEX_FAST || p->id==SQLITE_MUTEX_RECURSIVE ); + if( p->id==SQLITE_MUTEX_FAST || p->id==SQLITE_MUTEX_RECURSIVE ){ + DeleteCriticalSection(&p->mutex); + sqlite3_free(p); + }else{ +#ifdef SQLITE_ENABLE_API_ARMOR + (void)SQLITE_MISUSE_BKPT; #endif - assert( winMutex_isInit==1 ); - DeleteCriticalSection(&p->mutex); - sqlite3_free(p); + } } /* diff --git a/src/printf.c b/src/printf.c index 8291002db8..81efa057fc 100644 --- a/src/printf.c +++ b/src/printf.c @@ -995,7 +995,7 @@ char *sqlite3_vsnprintf(int n, char *zBuf, const char *zFormat, va_list ap){ #ifdef SQLITE_ENABLE_API_ARMOR if( zBuf==0 || zFormat==0 ) { (void)SQLITE_MISUSE_BKPT; - if( zBuf && n>0 ) zBuf[0] = 0; + if( zBuf ) zBuf[0] = 0; return zBuf; } #endif diff --git a/src/tokenize.c b/src/tokenize.c index f0360eef61..6fb5a35c3d 100644 --- a/src/tokenize.c +++ b/src/tokenize.c @@ -390,10 +390,7 @@ int sqlite3RunParser(Parse *pParse, const char *zSql, char **pzErrMsg){ sqlite3 *db = pParse->db; /* The database connection */ int mxSqlLen; /* Max length of an SQL string */ - -#ifdef SQLITE_ENABLE_API_ARMOR - if( zSql==0 || pzErrMsg==0 ) return SQLITE_MISUSE_BKPT; -#endif + assert( zSql!=0 ); mxSqlLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH]; if( db->nVdbeActive==0 ){ db->u1.isInterrupted = 0; diff --git a/src/vtab.c b/src/vtab.c index 00d0882b04..96a1289dea 100644 --- a/src/vtab.c +++ b/src/vtab.c @@ -710,7 +710,9 @@ int sqlite3_declare_vtab(sqlite3 *db, const char *zCreateTable){ char *zErr = 0; #ifdef SQLITE_ENABLE_API_ARMOR - if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT; + if( !sqlite3SafetyCheckOk(db) || zCreateTable==0 ){ + return SQLITE_MISUSE_BKPT; + } #endif sqlite3_mutex_enter(db->mutex); if( !db->pVtabCtx || !(pTab = db->pVtabCtx->pTab) ){ From 883ad04985496dfeb54135a23066cf9fb0b9a1e3 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 19 Feb 2015 00:29:11 +0000 Subject: [PATCH 42/62] First small steps toward brining trunk and apple-osx closer together. FossilOrigin-Name: 28284ccc0d7301503f6d2d7bee9093738d52e331 --- manifest | 26 +++++++++++++------------- manifest.uuid | 2 +- src/func.c | 8 ++++++++ src/main.c | 5 ++++- src/sqlite.h.in | 17 ++++++++++++++--- src/test_backup.c | 2 +- src/test_demovfs.c | 2 +- src/test_rtree.c | 2 +- src/test_superlock.c | 2 +- test/incrvacuum2.test | 4 +++- 10 files changed, 47 insertions(+), 23 deletions(-) diff --git a/manifest b/manifest index 9d690c6549..4f1e6dabe1 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Improvements\sto\sSQLITE_ENABLE_API_ARMOR. -D 2015-02-13T16:36:14.430 +C First\ssmall\ssteps\stoward\sbrining\strunk\sand\sapple-osx\scloser\stogether. +D 2015-02-19T00:29:11.820 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 6b9e7677829aa94b9f30949656e27312aefb9a46 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -185,7 +185,7 @@ F src/delete.c 37964e6c1d73ff49cbea9ff690c9605fb15f600e F src/expr.c 3ef111b88ae2941b84b6b6ea4be8d501ba1af0cb F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb F src/fkey.c e0444b61bed271a76840cbe6182df93a9baa3f12 -F src/func.c 6d3c4ebd72aa7923ce9b110a7dc15f9b8c548430 +F src/func.c f7f0f44b0a2cb568a9c42b1b07e613380ee0b9c6 F src/global.c 12561d70a1b25f67b21154622bb1723426724f75 F src/hash.c 4263fbc955f26c2e8cdc0cf214bc42435aa4e4f5 F src/hash.h c8f3c31722cf3277d03713909761e152a5b81094 @@ -195,7 +195,7 @@ F src/journal.c b4124532212b6952f42eb2c12fa3c25701d8ba8d F src/legacy.c ba1863ea58c4c840335a84ec276fc2b25e22bc4e F src/lempar.c 7274c97d24bb46631e504332ccd3bd1b37841770 F src/loadext.c 86bd4e2fccd520b748cba52492ab60c4a770f660 -F src/main.c 3780c966059a5fcb0afa42fd89e3b74ec1f72b9e +F src/main.c 80edeba383aac89f72498b2572a115e21d0ecbbd F src/malloc.c 740db54387204c9a2eb67c6d98e68b08e9ef4eab F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645 F src/mem1.c abe6ee469b6c5a35c7f22bfeb9c9bac664a1c987 @@ -232,7 +232,7 @@ F src/resolve.c f4d79e31ffa5820c2e3d1740baa5e9b190425f2b F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e F src/select.c e46cef4c224549b439384c88fc7f57ba064dad54 F src/shell.c 6276582ee4e9114e0bb0795772414caaf21c0f8e -F src/sqlite.h.in 54678c21401909f72b221344dd560d285a1ba5eb +F src/sqlite.h.in b02d8d19c5adc73bd02b225054103247aff64425 F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h 17d487c3c91b0b8c584a32fbeb393f6f795eea7d F src/sqliteInt.h 57a405ae6d2ed10fff52de376d18f21e04d96609 @@ -251,11 +251,11 @@ F src/test8.c 610e3d523018ca63b08081795e76794a2121ec38 F src/test9.c bea1e8cf52aa93695487badedd6e1886c321ea60 F src/test_async.c 21e11293a2f72080eda70e1124e9102044531cd8 F src/test_autoext.c dea8a01a7153b9adc97bd26161e4226329546e12 -F src/test_backup.c 3875e899222b651e18b662f86e0e50daa946344e +F src/test_backup.c 2e6e6a081870150f20c526a2e9d0d29cda47d803 F src/test_blob.c 1f2e3e25255b731c4fcf15ee7990d06347cb6c09 F src/test_btree.c 2e9978eca99a9a4bfa8cae949efb00886860a64f F src/test_config.c e7b2e1634324d746aa5e1c7e0929470e8be27953 -F src/test_demovfs.c 69b2085076654ebc18014cbc6386f04409c959a9 +F src/test_demovfs.c 0de72c2c89551629f58486fde5734b7d90758852 F src/test_devsym.c e7498904e72ba7491d142d5c83b476c4e76993bc F src/test_fs.c ced436e3d4b8e4681328409b8081051ce614e28f F src/test_func.c 14e543ae4d905ee31dc322b2f8d31bfac1769d45 @@ -274,12 +274,12 @@ F src/test_osinst.c 3d0340bc31a9f3d8a3547e0272373e80f78dde25 F src/test_pcache.c a5cd24730cb43c5b18629043314548c9169abb00 F src/test_quota.c 180813f43683be5725458fc1ff13ac455d8e722d F src/test_quota.h 2a8ad1952d1d2ca9af0ce0465e56e6c023b5e15d -F src/test_rtree.c fdd8d29ca5165c7857987a2ba263fac5c69e231f +F src/test_rtree.c bfe6f4386517f70054311109f3528adffec34485 F src/test_schema.c 2bdba21b82f601da69793e1f1d11bf481a79b091 F src/test_server.c a2615049954cbb9cfb4a62e18e2f0616e4dc38fe F src/test_sqllog.c b690c12933f50ff46491e0d56a251f84ae16e914 F src/test_stat.c 9898687a6c2beca733b0dd6fe19163d987826d31 -F src/test_superlock.c 2b97936ca127d13962c3605dbc9a4ef269c424cd +F src/test_superlock.c 06797157176eb7085027d9dd278c0d7a105e3ec9 F src/test_syscall.c 2e21ca7f7dc54a028f1967b63f1e76155c356f9b F src/test_tclvar.c f4dc67d5f780707210d6bb0eb6016a431c04c7fa F src/test_thread.c af391ec03d23486dffbcc250b7e58e073f172af9 @@ -644,7 +644,7 @@ F test/incrblob4.test f26502a5697893e5acea268c910f16478c2f0fab F test/incrblob_err.test af1f12ba60d220c9752073ff2bda2ad59e88960d F test/incrblobfault.test 280474078f6da9e732cd2a215d3d854969014b6e F test/incrvacuum.test d2a6ddf5e429720b5fe502766af747915ccf6c32 -F test/incrvacuum2.test 379eeb8740b0ef60c372c439ad4cbea20b34bb9b +F test/incrvacuum2.test 676c41428765d58f1da7dbe659ef27726d3d30ac F test/incrvacuum3.test 75256fb1377e7c39ef2de62bfc42bbff67be295a F test/incrvacuum_ioerr.test 6ae2f783424e47a0033304808fe27789cf93e635 F test/index.test 4d990005a67a36984e4f1a5f1bdccea8d08da4ee @@ -1239,7 +1239,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 3c6ca414879feb1f5d31d5fd95a1737530aca624 -R f6208f1be504ea76c76eb647c7a3e38c +P 823ad40ccb5b51aaa0d5a48da63b465df9d0649a +R 89f0ec75057f909c87616e4bd9a4303a U drh -Z 5fa0aaf45cc565051b14e7b2d21a11e0 +Z a5ec369c1615e4ac0e151fe8f03569e6 diff --git a/manifest.uuid b/manifest.uuid index 2047ee0ac5..d18b48bb6f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -823ad40ccb5b51aaa0d5a48da63b465df9d0649a \ No newline at end of file +28284ccc0d7301503f6d2d7bee9093738d52e331 \ No newline at end of file diff --git a/src/func.c b/src/func.c index a057993413..30990a30f3 100644 --- a/src/func.c +++ b/src/func.c @@ -291,6 +291,14 @@ static void substrFunc( } } } +#ifdef SQLITE_SUBSTR_COMPATIBILITY + /* If SUBSTR_COMPATIBILITY is defined then substr(X,0,N) work the same as + ** as substr(X,1,N) - it returns the first N characters of X. This + ** is essentially a back-out of the bug-fix in check-in [5fc125d362df4b8] + ** from 2009-02-02 for compatibility of applications that exploited the + ** old buggy behavior. */ + if( p1==0 ) p1 = 1; /* */ +#endif if( argc==3 ){ p2 = sqlite3_value_int(argv[2]); if( p2<0 ){ diff --git a/src/main.c b/src/main.c index d0bd55c1db..371bb1fede 100644 --- a/src/main.c +++ b/src/main.c @@ -2707,6 +2707,9 @@ static int openDatabase( #if !defined(SQLITE_DEFAULT_AUTOMATIC_INDEX) || SQLITE_DEFAULT_AUTOMATIC_INDEX | SQLITE_AutoIndex #endif +#if SQLITE_DEFAULT_CKPTFULLFSYNC + | SQLITE_CkptFullFSync +#endif #if SQLITE_DEFAULT_FILE_FORMAT<4 | SQLITE_LegacyFileFmt #endif @@ -3301,7 +3304,7 @@ int sqlite3_file_control(sqlite3 *db, const char *zDbName, int op, void *pArg){ sqlite3BtreeLeave(pBtree); } sqlite3_mutex_leave(db->mutex); - return rc; + return rc; } /* diff --git a/src/sqlite.h.in b/src/sqlite.h.in index f256cea45d..8a358dbb2f 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -944,9 +944,9 @@ struct sqlite3_io_methods { ** */ #define SQLITE_FCNTL_LOCKSTATE 1 -#define SQLITE_GET_LOCKPROXYFILE 2 -#define SQLITE_SET_LOCKPROXYFILE 3 -#define SQLITE_LAST_ERRNO 4 +#define SQLITE_FCNTL_GET_LOCKPROXYFILE 2 +#define SQLITE_FCNTL_SET_LOCKPROXYFILE 3 +#define SQLITE_FCNTL_LAST_ERRNO 4 #define SQLITE_FCNTL_SIZE_HINT 5 #define SQLITE_FCNTL_CHUNK_SIZE 6 #define SQLITE_FCNTL_FILE_POINTER 7 @@ -966,6 +966,12 @@ struct sqlite3_io_methods { #define SQLITE_FCNTL_COMMIT_PHASETWO 22 #define SQLITE_FCNTL_WIN32_SET_HANDLE 23 +/* deprecated names */ +#define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE +#define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE +#define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO + + /* ** CAPI3REF: Mutex Handle ** @@ -5061,6 +5067,11 @@ void *sqlite3_update_hook( ** future releases of SQLite. Applications that care about shared ** cache setting should set it explicitly. ** +** Note: This method is disabled on MacOS X 10.7 and iOS version 5.0 +** and will always return SQLITE_MISUSE. On those systems, +** shared cache mode should be enabled per-database connection via +** [sqlite3_open_v2()] with [SQLITE_OPEN_SHAREDCACHE]. +** ** This interface is threadsafe on processors where writing a ** 32-bit integer is atomic. ** diff --git a/src/test_backup.c b/src/test_backup.c index e967424a29..6b4d6b9b1c 100644 --- a/src/test_backup.c +++ b/src/test_backup.c @@ -14,7 +14,7 @@ */ #include "tcl.h" -#include +#include "sqlite3.h" #include /* These functions are implemented in main.c. */ diff --git a/src/test_demovfs.c b/src/test_demovfs.c index c63b0a8b7a..9410a309a6 100644 --- a/src/test_demovfs.c +++ b/src/test_demovfs.c @@ -115,7 +115,7 @@ #if !defined(SQLITE_TEST) || SQLITE_OS_UNIX -#include +#include "sqlite3.h" #include #include diff --git a/src/test_rtree.c b/src/test_rtree.c index 9d19fa0e2c..7beec66455 100644 --- a/src/test_rtree.c +++ b/src/test_rtree.c @@ -13,7 +13,7 @@ ** is not included in the SQLite library. */ -#include +#include "sqlite3.h" #include /* Solely for the UNUSED_PARAMETER() macro. */ diff --git a/src/test_superlock.c b/src/test_superlock.c index 936fcad0c5..cac789842d 100644 --- a/src/test_superlock.c +++ b/src/test_superlock.c @@ -18,7 +18,7 @@ ** sqlite3demo_superunlock() */ -#include +#include "sqlite3.h" #include /* memset(), strlen() */ #include /* assert() */ diff --git a/test/incrvacuum2.test b/test/incrvacuum2.test index 6e8e1bed5e..2219d54195 100644 --- a/test/incrvacuum2.test +++ b/test/incrvacuum2.test @@ -188,8 +188,10 @@ ifcapable wal { execsql { PRAGMA journal_mode = WAL; PRAGMA incremental_vacuum(1); - PRAGMA wal_checkpoint; } + } {wal} + do_test 4.2.1 { + execsql { PRAGMA wal_checkpoint } file size test.db-wal } [expr {32+2*(512+24)}] From 4bf66fd6f39c310eabd214b176b75d30a6073181 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 19 Feb 2015 02:43:02 +0000 Subject: [PATCH 43/62] Move the os_unix.c file closer to apple-osx. FossilOrigin-Name: 81f242e338d6122e27aad86986bfd140012c6582 --- manifest | 12 ++--- manifest.uuid | 2 +- src/os_unix.c | 141 +++++++++++++++++++++++++++++--------------------- 3 files changed, 90 insertions(+), 65 deletions(-) diff --git a/manifest b/manifest index 4f1e6dabe1..df5da3164f 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C First\ssmall\ssteps\stoward\sbrining\strunk\sand\sapple-osx\scloser\stogether. -D 2015-02-19T00:29:11.820 +C Move\sthe\sos_unix.c\sfile\scloser\sto\sapple-osx. +D 2015-02-19T02:43:02.884 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 6b9e7677829aa94b9f30949656e27312aefb9a46 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -214,7 +214,7 @@ F src/os.c 8fd25588eeba74068d41102d26810e216999b6c8 F src/os.h 3e57a24e2794a94d3cf2342c6d9a884888cd96bf F src/os_common.h 92815ed65f805560b66166e3583470ff94478f04 F src/os_setup.h c9d4553b5aaa6f73391448b265b89bed0b890faa -F src/os_unix.c aefeaf915aaef9f81aa2645e0d5d06fa1bd83beb +F src/os_unix.c 9922c8f5b2e32c0f0be2292feca5f72d88f6a833 F src/os_win.c 8223e7db5b7c4a81d8b161098ac3959400434cdb F src/os_win.h eb7a47aa17b26b77eb97e4823f20a00b8bda12ca F src/pager.c 4120a49ecd37697e28f5ed807f470b9c0b88410c @@ -1239,7 +1239,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 823ad40ccb5b51aaa0d5a48da63b465df9d0649a -R 89f0ec75057f909c87616e4bd9a4303a +P 28284ccc0d7301503f6d2d7bee9093738d52e331 +R de5d87b1cb4f744ff7cb90b036adcd40 U drh -Z a5ec369c1615e4ac0e151fe8f03569e6 +Z 45842533d15e073070e1f1a9e9241135 diff --git a/manifest.uuid b/manifest.uuid index d18b48bb6f..084bab91e8 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -28284ccc0d7301503f6d2d7bee9093738d52e331 \ No newline at end of file +81f242e338d6122e27aad86986bfd140012c6582 \ No newline at end of file diff --git a/src/os_unix.c b/src/os_unix.c index ddd6a802eb..d81618f610 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -1178,6 +1178,14 @@ static void robust_close(unixFile *pFile, int h, int lineno){ } } +/* +** Set the pFile->lastErrno. Do this in a subroutine as that provides a convenient +** place to set a breakpoint. +*/ +static void storeLastErrno(unixFile *pFile, int error){ + pFile->lastErrno = error; +} + /* ** Close all file descriptors accumuated in the unixInodeInfo->pUnused list. */ @@ -1251,7 +1259,7 @@ static int findInodeInfo( fd = pFile->h; rc = osFstat(fd, &statbuf); if( rc!=0 ){ - pFile->lastErrno = errno; + storeLastErrno(pFile, errno); #ifdef EOVERFLOW if( pFile->lastErrno==EOVERFLOW ) return SQLITE_NOLFS; #endif @@ -1272,12 +1280,12 @@ static int findInodeInfo( if( statbuf.st_size==0 && (pFile->fsFlags & SQLITE_FSFLAGS_IS_MSDOS)!=0 ){ do{ rc = osWrite(fd, "S", 1); }while( rc<0 && errno==EINTR ); if( rc!=1 ){ - pFile->lastErrno = errno; + storeLastErrno(pFile, errno); return SQLITE_IOERR; } rc = osFstat(fd, &statbuf); if( rc!=0 ){ - pFile->lastErrno = errno; + storeLastErrno(pFile, errno); return SQLITE_IOERR; } } @@ -1400,7 +1408,7 @@ static int unixCheckReservedLock(sqlite3_file *id, int *pResOut){ lock.l_type = F_WRLCK; if( osFcntl(pFile->h, F_GETLK, &lock) ){ rc = SQLITE_IOERR_CHECKRESERVEDLOCK; - pFile->lastErrno = errno; + storeLastErrno(pFile, errno); } else if( lock.l_type!=F_UNLCK ){ reserved = 1; } @@ -1600,7 +1608,7 @@ static int unixLock(sqlite3_file *id, int eFileLock){ tErrno = errno; rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_LOCK); if( rc!=SQLITE_BUSY ){ - pFile->lastErrno = tErrno; + storeLastErrno(pFile, tErrno); } goto end_lock; } @@ -1635,7 +1643,7 @@ static int unixLock(sqlite3_file *id, int eFileLock){ if( rc ){ if( rc!=SQLITE_BUSY ){ - pFile->lastErrno = tErrno; + storeLastErrno(pFile, tErrno); } goto end_lock; }else{ @@ -1668,7 +1676,7 @@ static int unixLock(sqlite3_file *id, int eFileLock){ tErrno = errno; rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_LOCK); if( rc!=SQLITE_BUSY ){ - pFile->lastErrno = tErrno; + storeLastErrno(pFile, tErrno); } } } @@ -1775,6 +1783,7 @@ static int posixUnlock(sqlite3_file *id, int eFileLock, int handleNFSUnlock){ ** 4: [RRRR.] */ if( eFileLock==SHARED_LOCK ){ + int tErrno; /* Error code from system call errors */ #if !defined(__APPLE__) || !SQLITE_ENABLE_LOCKING_STYLE (void)handleNFSUnlock; @@ -1782,7 +1791,6 @@ static int posixUnlock(sqlite3_file *id, int eFileLock, int handleNFSUnlock){ #endif #if defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE if( handleNFSUnlock ){ - int tErrno; /* Error code from system call errors */ off_t divSize = SHARED_SIZE - 1; lock.l_type = F_UNLCK; @@ -1793,7 +1801,7 @@ static int posixUnlock(sqlite3_file *id, int eFileLock, int handleNFSUnlock){ tErrno = errno; rc = SQLITE_IOERR_UNLOCK; if( IS_LOCK_ERROR(rc) ){ - pFile->lastErrno = tErrno; + storeLastErrno(pFile, tErrno); } goto end_unlock; } @@ -1805,7 +1813,7 @@ static int posixUnlock(sqlite3_file *id, int eFileLock, int handleNFSUnlock){ tErrno = errno; rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_RDLOCK); if( IS_LOCK_ERROR(rc) ){ - pFile->lastErrno = tErrno; + storeLastErrno(pFile, tErrno); } goto end_unlock; } @@ -1817,7 +1825,7 @@ static int posixUnlock(sqlite3_file *id, int eFileLock, int handleNFSUnlock){ tErrno = errno; rc = SQLITE_IOERR_UNLOCK; if( IS_LOCK_ERROR(rc) ){ - pFile->lastErrno = tErrno; + storeLastErrno(pFile, tErrno); } goto end_unlock; } @@ -1836,7 +1844,7 @@ static int posixUnlock(sqlite3_file *id, int eFileLock, int handleNFSUnlock){ ** SQLITE_BUSY would confuse the upper layer (in practice it causes ** an assert to fail). */ rc = SQLITE_IOERR_RDLOCK; - pFile->lastErrno = errno; + storeLastErrno(pFile, errno); goto end_unlock; } } @@ -1849,7 +1857,7 @@ static int posixUnlock(sqlite3_file *id, int eFileLock, int handleNFSUnlock){ pInode->eFileLock = SHARED_LOCK; }else{ rc = SQLITE_IOERR_UNLOCK; - pFile->lastErrno = errno; + storeLastErrno(pFile, errno); goto end_unlock; } } @@ -1867,7 +1875,7 @@ static int posixUnlock(sqlite3_file *id, int eFileLock, int handleNFSUnlock){ pInode->eFileLock = NO_LOCK; }else{ rc = SQLITE_IOERR_UNLOCK; - pFile->lastErrno = errno; + storeLastErrno(pFile, errno); pInode->eFileLock = NO_LOCK; pFile->eFileLock = NO_LOCK; } @@ -2142,7 +2150,7 @@ static int dotlockLock(sqlite3_file *id, int eFileLock) { } else { rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_LOCK); if( IS_LOCK_ERROR(rc) ){ - pFile->lastErrno = tErrno; + storeLastErrno(pFile, tErrno); } } return rc; @@ -2196,7 +2204,7 @@ static int dotlockUnlock(sqlite3_file *id, int eFileLock) { rc = SQLITE_IOERR_UNLOCK; } if( IS_LOCK_ERROR(rc) ){ - pFile->lastErrno = tErrno; + storeLastErrno(pFile, tErrno); } return rc; } @@ -2283,7 +2291,7 @@ static int flockCheckReservedLock(sqlite3_file *id, int *pResOut){ /* unlock failed with an error */ lrc = SQLITE_IOERR_UNLOCK; if( IS_LOCK_ERROR(lrc) ){ - pFile->lastErrno = tErrno; + storeLastErrno(pFile, tErrno); rc = lrc; } } @@ -2293,7 +2301,7 @@ static int flockCheckReservedLock(sqlite3_file *id, int *pResOut){ /* someone else might have it reserved */ lrc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_LOCK); if( IS_LOCK_ERROR(lrc) ){ - pFile->lastErrno = tErrno; + storeLastErrno(pFile, tErrno); rc = lrc; } } @@ -2359,7 +2367,7 @@ static int flockLock(sqlite3_file *id, int eFileLock) { /* didn't get, must be busy */ rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_LOCK); if( IS_LOCK_ERROR(rc) ){ - pFile->lastErrno = tErrno; + storeLastErrno(pFile, tErrno); } } else { /* got it, set the type and return ok */ @@ -2471,7 +2479,7 @@ static int semCheckReservedLock(sqlite3_file *id, int *pResOut) { int tErrno = errno; if( EAGAIN != tErrno ){ rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_CHECKRESERVEDLOCK); - pFile->lastErrno = tErrno; + storeLastErrno(pFile, tErrno); } else { /* someone else has the lock when we are in NO_LOCK */ reserved = (pFile->eFileLock < SHARED_LOCK); @@ -2575,7 +2583,7 @@ static int semUnlock(sqlite3_file *id, int eFileLock) { int rc, tErrno = errno; rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_UNLOCK); if( IS_LOCK_ERROR(rc) ){ - pFile->lastErrno = tErrno; + storeLastErrno(pFile, tErrno); } return rc; } @@ -2677,7 +2685,7 @@ static int afpSetLock( setLockFlag ? SQLITE_IOERR_LOCK : SQLITE_IOERR_UNLOCK); #endif /* SQLITE_IGNORE_AFP_LOCK_ERRORS */ if( IS_LOCK_ERROR(rc) ){ - pFile->lastErrno = tErrno; + storeLastErrno(pFile, tErrno); } return rc; } else { @@ -2860,7 +2868,7 @@ static int afpLock(sqlite3_file *id, int eFileLock){ lrc2 = afpSetLock(context->dbPath, pFile, PENDING_BYTE, 1, 0); if( IS_LOCK_ERROR(lrc1) ) { - pFile->lastErrno = lrc1Errno; + storeLastErrno(pFile, lrc1Errno); rc = lrc1; goto afp_end_lock; } else if( IS_LOCK_ERROR(lrc2) ){ @@ -3147,9 +3155,9 @@ static int seekAndRead(unixFile *id, sqlite3_int64 offset, void *pBuf, int cnt){ SimulateIOError( newOffset-- ); if( newOffset!=offset ){ if( newOffset == -1 ){ - ((unixFile*)id)->lastErrno = errno; + storeLastErrno((unixFile*)id, errno); }else{ - ((unixFile*)id)->lastErrno = 0; + storeLastErrno((unixFile*)id, 0); } return -1; } @@ -3159,7 +3167,7 @@ static int seekAndRead(unixFile *id, sqlite3_int64 offset, void *pBuf, int cnt){ if( got<0 ){ if( errno==EINTR ){ got = 1; continue; } prior = 0; - ((unixFile*)id)->lastErrno = errno; + storeLastErrno((unixFile*)id, errno); break; }else if( got>0 ){ cnt -= got; @@ -3224,7 +3232,7 @@ static int unixRead( /* lastErrno set by seekAndRead */ return SQLITE_IOERR_READ; }else{ - pFile->lastErrno = 0; /* not a system error */ + storeLastErrno(pFile, 0); /* not a system error */ /* Unread parts of the buffer must be zero-filled */ memset(&((char*)pBuf)[got], 0, amt-got); return SQLITE_IOERR_SHORT_READ; @@ -3365,7 +3373,7 @@ static int unixWrite( /* lastErrno set by seekAndWrite */ return SQLITE_IOERR_WRITE; }else{ - pFile->lastErrno = 0; /* not a system error */ + storeLastErrno(pFile, 0); /* not a system error */ return SQLITE_FULL; } } @@ -3574,7 +3582,7 @@ static int unixSync(sqlite3_file *id, int flags){ rc = full_fsync(pFile->h, isFullsync, isDataOnly); SimulateIOError( rc=1 ); if( rc ){ - pFile->lastErrno = errno; + storeLastErrno(pFile, errno); return unixLogError(SQLITE_IOERR_FSYNC, "full_fsync", pFile->zPath); } @@ -3618,7 +3626,7 @@ static int unixTruncate(sqlite3_file *id, i64 nByte){ rc = robust_ftruncate(pFile->h, nByte); if( rc ){ - pFile->lastErrno = errno; + storeLastErrno(pFile, errno); return unixLogError(SQLITE_IOERR_TRUNCATE, "ftruncate", pFile->zPath); }else{ #ifdef SQLITE_DEBUG @@ -3658,7 +3666,7 @@ static int unixFileSize(sqlite3_file *id, i64 *pSize){ rc = osFstat(((unixFile*)id)->h, &buf); SimulateIOError( rc=1 ); if( rc!=0 ){ - ((unixFile*)id)->lastErrno = errno; + storeLastErrno((unixFile*)id, errno); return SQLITE_IOERR_FSTAT; } *pSize = buf.st_size; @@ -3694,7 +3702,9 @@ static int fcntlSizeHint(unixFile *pFile, i64 nByte){ i64 nSize; /* Required file size */ struct stat buf; /* Used to hold return values of fstat() */ - if( osFstat(pFile->h, &buf) ) return SQLITE_IOERR_FSTAT; + if( osFstat(pFile->h, &buf) ){ + return SQLITE_IOERR_FSTAT; + } nSize = ((nByte+pFile->szChunk-1) / pFile->szChunk) * pFile->szChunk; if( nSize>(i64)buf.st_size ){ @@ -3741,7 +3751,7 @@ static int fcntlSizeHint(unixFile *pFile, i64 nByte){ int rc; if( pFile->szChunk<=0 ){ if( robust_ftruncate(pFile->h, nByte) ){ - pFile->lastErrno = errno; + storeLastErrno(pFile, errno); return unixLogError(SQLITE_IOERR_TRUNCATE, "ftruncate", pFile->zPath); } } @@ -3783,7 +3793,7 @@ static int unixFileControl(sqlite3_file *id, int op, void *pArg){ *(int*)pArg = pFile->eFileLock; return SQLITE_OK; } - case SQLITE_LAST_ERRNO: { + case SQLITE_FCNTL_LAST_ERRNO: { *(int*)pArg = pFile->lastErrno; return SQLITE_OK; } @@ -3852,8 +3862,8 @@ static int unixFileControl(sqlite3_file *id, int op, void *pArg){ } #endif #if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__) - case SQLITE_SET_LOCKPROXYFILE: - case SQLITE_GET_LOCKPROXYFILE: { + case SQLITE_FCNTL_SET_LOCKPROXYFILE: + case SQLITE_FCNTL_GET_LOCKPROXYFILE: { return proxyFileControl(id,op,pArg); } #endif /* SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__) */ @@ -4258,6 +4268,9 @@ static int unixOpenSharedMemory(unixFile *pDbFd){ pShmNode = pInode->pShmNode; if( pShmNode==0 ){ struct stat sStat; /* fstat() info for database file */ +#ifndef SQLITE_SHM_DIRECTORY + const char *zBasePath = pDbFd->zPath; +#endif /* Call fstat() to figure out the permissions on the database file. If ** a new *-shm file is created, an attempt will be made to create it @@ -4271,7 +4284,7 @@ static int unixOpenSharedMemory(unixFile *pDbFd){ #ifdef SQLITE_SHM_DIRECTORY nShmFilename = sizeof(SQLITE_SHM_DIRECTORY) + 31; #else - nShmFilename = 6 + (int)strlen(pDbFd->zPath); + nShmFilename = 6 + (int)strlen(zBasePath); #endif pShmNode = sqlite3_malloc( sizeof(*pShmNode) + nShmFilename ); if( pShmNode==0 ){ @@ -4285,7 +4298,7 @@ static int unixOpenSharedMemory(unixFile *pDbFd){ SQLITE_SHM_DIRECTORY "/sqlite-shm-%x-%x", (u32)sStat.st_ino, (u32)sStat.st_dev); #else - sqlite3_snprintf(nShmFilename, zShmFilename, "%s-shm", pDbFd->zPath); + sqlite3_snprintf(nShmFilename, zShmFilename, "%s-shm", zBasePath); sqlite3FileSuffix3(pDbFd->zPath, zShmFilename); #endif pShmNode->h = -1; @@ -4678,7 +4691,9 @@ static int unixShmUnmap( assert( pShmNode->nRef>0 ); pShmNode->nRef--; if( pShmNode->nRef==0 ){ - if( deleteFlag && pShmNode->h>=0 ) osUnlink(pShmNode->zFilename); + if( deleteFlag && pShmNode->h>=0 ){ + osUnlink(pShmNode->zFilename); + } unixShmPurge(pDbFd); } unixLeaveMutex(); @@ -5383,7 +5398,7 @@ static int fillInUnixFile( } #endif - pNew->lastErrno = 0; + storeLastErrno(pNew, 0); #if OS_VXWORKS if( rc!=SQLITE_OK ){ if( h>=0 ) robust_close(pNew, h, __LINE__); @@ -5831,13 +5846,16 @@ static int unixOpen( #if defined(__APPLE__) || SQLITE_ENABLE_LOCKING_STYLE if( fstatfs(fd, &fsInfo) == -1 ){ - ((unixFile*)pFile)->lastErrno = errno; + storeLastErrno(p, errno); robust_close(p, fd, __LINE__); return SQLITE_IOERR_ACCESS; } if (0 == strncmp("msdos", fsInfo.f_fstypename, 5)) { ((unixFile*)pFile)->fsFlags |= SQLITE_FSFLAGS_IS_MSDOS; } + if (0 == strncmp("exfat", fsInfo.f_fstypename, 5)) { + ((unixFile*)pFile)->fsFlags |= SQLITE_FSFLAGS_IS_MSDOS; + } #endif /* Set up appropriate ctrlFlags */ @@ -5868,7 +5886,7 @@ static int unixOpen( ** we're assuming that statfs() doesn't fail very often. At least ** not while other file descriptors opened by the same process on ** the same file are working. */ - p->lastErrno = errno; + storeLastErrno(p, errno); robust_close(p, fd, __LINE__); rc = SQLITE_IOERR_ACCESS; goto open_finished; @@ -6298,9 +6316,10 @@ static int unixGetLastError(sqlite3_vfs *NotUsed, int NotUsed2, char *NotUsed3){ ** ** C APIs ** -** sqlite3_file_control(db, dbname, SQLITE_SET_LOCKPROXYFILE, +** sqlite3_file_control(db, dbname, SQLITE_FCNTL_SET_LOCKPROXYFILE, ** | ":auto:"); -** sqlite3_file_control(db, dbname, SQLITE_GET_LOCKPROXYFILE, &); +** sqlite3_file_control(db, dbname, SQLITE_FCNTL_GET_LOCKPROXYFILE, +** &); ** ** ** SQL pragmas @@ -6393,7 +6412,7 @@ static int unixGetLastError(sqlite3_vfs *NotUsed, int NotUsed2, char *NotUsed3){ ** setting the environment variable SQLITE_FORCE_PROXY_LOCKING to 1 will ** force proxy locking to be used for every database file opened, and 0 ** will force automatic proxy locking to be disabled for all database -** files (explicitly calling the SQLITE_SET_LOCKPROXYFILE pragma or +** files (explicitly calling the SQLITE_FCNTL_SET_LOCKPROXYFILE pragma or ** sqlite_file_control API is not affected by SQLITE_FORCE_PROXY_LOCKING). */ @@ -6414,6 +6433,7 @@ struct proxyLockingContext { char *lockProxyPath; /* Name of the proxy lock file */ char *dbPath; /* Name of the open file */ int conchHeld; /* 1 if the conch is held, -1 if lockless */ + int nFails; /* Number of conch taking failures */ void *oldLockingContext; /* Original lockingcontext to restore on close */ sqlite3_io_methods const *pOldMethod; /* Original I/O methods for close */ }; @@ -6602,10 +6622,10 @@ extern int gethostuuid(uuid_t id, const struct timespec *wait); static int proxyGetHostID(unsigned char *pHostID, int *pError){ assert(PROXY_HOSTIDLEN == sizeof(uuid_t)); memset(pHostID, 0, PROXY_HOSTIDLEN); -#if defined(__MAX_OS_X_VERSION_MIN_REQUIRED)\ - && __MAC_OS_X_VERSION_MIN_REQUIRED<1050 +# if defined(__APPLE__) && ((__MAC_OS_X_VERSION_MIN_REQUIRED > 1050) || \ + (__IPHONE_OS_VERSION_MIN_REQUIRED > 2000)) { - static const struct timespec timeout = {1, 0}; /* 1 sec timeout */ + struct timespec timeout = {1, 0}; /* 1 sec timeout */ if( gethostuuid(pHostID, &timeout) ){ int err = errno; if( pError ){ @@ -6720,7 +6740,7 @@ static int proxyConchLock(unixFile *pFile, uuid_t myHostID, int lockType){ */ struct stat buf; if( osFstat(conchFile->h, &buf) ){ - pFile->lastErrno = errno; + storeLastErrno(pFile, errno); return SQLITE_IOERR_LOCK; } @@ -6740,7 +6760,7 @@ static int proxyConchLock(unixFile *pFile, uuid_t myHostID, int lockType){ char tBuf[PROXY_MAXCONCHLEN]; int len = osPread(conchFile->h, tBuf, PROXY_MAXCONCHLEN, 0); if( len<0 ){ - pFile->lastErrno = errno; + storeLastErrno(pFile, errno); return SQLITE_IOERR_LOCK; } if( len>PROXY_PATHINDEX && tBuf[0]==(char)PROXY_CONCHVERSION){ @@ -6802,7 +6822,7 @@ static int proxyTakeConch(unixFile *pFile){ rc = proxyGetHostID(myHostID, &pError); if( (rc&0xff)==SQLITE_IOERR ){ - pFile->lastErrno = pError; + storeLastErrno(pFile, pError); goto end_takeconch; } rc = proxyConchLock(pFile, myHostID, SHARED_LOCK); @@ -6813,7 +6833,7 @@ static int proxyTakeConch(unixFile *pFile){ readLen = seekAndRead((unixFile*)conchFile, 0, readBuf, PROXY_MAXCONCHLEN); if( readLen<0 ){ /* I/O error: lastErrno set by seekAndRead */ - pFile->lastErrno = conchFile->lastErrno; + storeLastErrno(pFile, conchFile->lastErrno); rc = SQLITE_IOERR_READ; goto end_takeconch; }else if( readLen<=(PROXY_HEADERLEN+PROXY_HOSTIDLEN) || @@ -6886,7 +6906,7 @@ static int proxyTakeConch(unixFile *pFile){ rc = proxyConchLock(pFile, myHostID, EXCLUSIVE_LOCK); } }else{ - rc = conchFile->pMethod->xLock((sqlite3_file*)conchFile, EXCLUSIVE_LOCK); + rc = proxyConchLock(pFile, myHostID, EXCLUSIVE_LOCK); } if( rc==SQLITE_OK ){ char writeBuffer[PROXY_MAXCONCHLEN]; @@ -6895,7 +6915,8 @@ static int proxyTakeConch(unixFile *pFile){ writeBuffer[0] = (char)PROXY_CONCHVERSION; memcpy(&writeBuffer[PROXY_HEADERLEN], myHostID, PROXY_HOSTIDLEN); if( pCtx->lockProxyPath!=NULL ){ - strlcpy(&writeBuffer[PROXY_PATHINDEX], pCtx->lockProxyPath, MAXPATHLEN); + strlcpy(&writeBuffer[PROXY_PATHINDEX], pCtx->lockProxyPath, + MAXPATHLEN); }else{ strlcpy(&writeBuffer[PROXY_PATHINDEX], tempLockPath, MAXPATHLEN); } @@ -7107,7 +7128,8 @@ static int proxyGetDbPathForUnixFile(unixFile *pFile, char *dbPath){ /* afp style keeps a reference to the db path in the filePath field ** of the struct */ assert( (int)strlen((char*)pFile->lockingContext)<=MAXPATHLEN ); - strlcpy(dbPath, ((afpLockingContext *)pFile->lockingContext)->dbPath, MAXPATHLEN); + strlcpy(dbPath, ((afpLockingContext *)pFile->lockingContext)->dbPath, + MAXPATHLEN); } else #endif if( pFile->pMethod == &dotlockIoMethods ){ @@ -7220,7 +7242,7 @@ static int proxyTransformUnixFile(unixFile *pFile, const char *path) { */ static int proxyFileControl(sqlite3_file *id, int op, void *pArg){ switch( op ){ - case SQLITE_GET_LOCKPROXYFILE: { + case SQLITE_FCNTL_GET_LOCKPROXYFILE: { unixFile *pFile = (unixFile*)id; if( pFile->pMethod == &proxyIoMethods ){ proxyLockingContext *pCtx = (proxyLockingContext*)pFile->lockingContext; @@ -7235,13 +7257,16 @@ static int proxyFileControl(sqlite3_file *id, int op, void *pArg){ } return SQLITE_OK; } - case SQLITE_SET_LOCKPROXYFILE: { + case SQLITE_FCNTL_SET_LOCKPROXYFILE: { unixFile *pFile = (unixFile*)id; int rc = SQLITE_OK; int isProxyStyle = (pFile->pMethod == &proxyIoMethods); if( pArg==NULL || (const char *)pArg==0 ){ if( isProxyStyle ){ - /* turn off proxy locking - not supported */ + /* turn off proxy locking - not supported. If support is added for + ** switching proxy locking mode off then it will need to fail if + ** the journal mode is WAL mode. + */ rc = SQLITE_ERROR /*SQLITE_PROTOCOL? SQLITE_MISUSE?*/; }else{ /* turn off proxy locking - already off - NOOP */ From a712b4bb97628129bf08b0bc35d91277bfa429b4 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 19 Feb 2015 16:12:04 +0000 Subject: [PATCH 44/62] Remove a redundant call to statfs() in the xOpen() method of the unix VFS. Also fix an unused local variable warning. FossilOrigin-Name: 8215727dda384351765ab1d5c53ea80775b4ec65 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/os_unix.c | 16 +--------------- 3 files changed, 8 insertions(+), 22 deletions(-) diff --git a/manifest b/manifest index df5da3164f..438d907e73 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Move\sthe\sos_unix.c\sfile\scloser\sto\sapple-osx. -D 2015-02-19T02:43:02.884 +C Remove\sa\sredundant\scall\sto\sstatfs()\sin\sthe\sxOpen()\smethod\sof\sthe\sunix\sVFS.\nAlso\sfix\san\sunused\slocal\svariable\swarning. +D 2015-02-19T16:12:04.194 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 6b9e7677829aa94b9f30949656e27312aefb9a46 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -214,7 +214,7 @@ F src/os.c 8fd25588eeba74068d41102d26810e216999b6c8 F src/os.h 3e57a24e2794a94d3cf2342c6d9a884888cd96bf F src/os_common.h 92815ed65f805560b66166e3583470ff94478f04 F src/os_setup.h c9d4553b5aaa6f73391448b265b89bed0b890faa -F src/os_unix.c 9922c8f5b2e32c0f0be2292feca5f72d88f6a833 +F src/os_unix.c 16ad795ef98966d9bdb3c967585fdadf9a2cfcb9 F src/os_win.c 8223e7db5b7c4a81d8b161098ac3959400434cdb F src/os_win.h eb7a47aa17b26b77eb97e4823f20a00b8bda12ca F src/pager.c 4120a49ecd37697e28f5ed807f470b9c0b88410c @@ -1239,7 +1239,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 28284ccc0d7301503f6d2d7bee9093738d52e331 -R de5d87b1cb4f744ff7cb90b036adcd40 +P 81f242e338d6122e27aad86986bfd140012c6582 +R 02e43373b368494c6578c4a98382bae8 U drh -Z 45842533d15e073070e1f1a9e9241135 +Z 3ab050a0ccd2941539e2053f07648364 diff --git a/manifest.uuid b/manifest.uuid index 084bab91e8..1991f8fafa 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -81f242e338d6122e27aad86986bfd140012c6582 \ No newline at end of file +8215727dda384351765ab1d5c53ea80775b4ec65 \ No newline at end of file diff --git a/src/os_unix.c b/src/os_unix.c index d81618f610..522617212f 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -1783,14 +1783,13 @@ static int posixUnlock(sqlite3_file *id, int eFileLock, int handleNFSUnlock){ ** 4: [RRRR.] */ if( eFileLock==SHARED_LOCK ){ - int tErrno; /* Error code from system call errors */ - #if !defined(__APPLE__) || !SQLITE_ENABLE_LOCKING_STYLE (void)handleNFSUnlock; assert( handleNFSUnlock==0 ); #endif #if defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE if( handleNFSUnlock ){ + int tErrno; /* Error code from system call errors */ off_t divSize = SHARED_SIZE - 1; lock.l_type = F_UNLCK; @@ -5878,19 +5877,6 @@ static int unixOpen( if( envforce!=NULL ){ useProxy = atoi(envforce)>0; }else{ - if( statfs(zPath, &fsInfo) == -1 ){ - /* In theory, the close(fd) call is sub-optimal. If the file opened - ** with fd is a database file, and there are other connections open - ** on that file that are currently holding advisory locks on it, - ** then the call to close() will cancel those locks. In practice, - ** we're assuming that statfs() doesn't fail very often. At least - ** not while other file descriptors opened by the same process on - ** the same file are working. */ - storeLastErrno(p, errno); - robust_close(p, fd, __LINE__); - rc = SQLITE_IOERR_ACCESS; - goto open_finished; - } useProxy = !(fsInfo.f_flags&MNT_LOCAL); } if( useProxy ){ From db222adfd3620e797d9cea7de60b520c33c7ce76 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 19 Feb 2015 17:16:14 +0000 Subject: [PATCH 45/62] Fix errors in the EBCDIC upper-case to lower-case translation table. FossilOrigin-Name: 905009f6723040d4da4776b6fd07e83c628dea2b --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/global.c | 10 +++++----- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/manifest b/manifest index 438d907e73..116b2466ba 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Remove\sa\sredundant\scall\sto\sstatfs()\sin\sthe\sxOpen()\smethod\sof\sthe\sunix\sVFS.\nAlso\sfix\san\sunused\slocal\svariable\swarning. -D 2015-02-19T16:12:04.194 +C Fix\serrors\sin\sthe\sEBCDIC\supper-case\sto\slower-case\stranslation\stable. +D 2015-02-19T17:16:14.345 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 6b9e7677829aa94b9f30949656e27312aefb9a46 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -186,7 +186,7 @@ F src/expr.c 3ef111b88ae2941b84b6b6ea4be8d501ba1af0cb F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb F src/fkey.c e0444b61bed271a76840cbe6182df93a9baa3f12 F src/func.c f7f0f44b0a2cb568a9c42b1b07e613380ee0b9c6 -F src/global.c 12561d70a1b25f67b21154622bb1723426724f75 +F src/global.c 4f77cadbc5427d00139ba43d0f3979804cbb700e F src/hash.c 4263fbc955f26c2e8cdc0cf214bc42435aa4e4f5 F src/hash.h c8f3c31722cf3277d03713909761e152a5b81094 F src/hwtime.h d32741c8f4df852c7d959236615444e2b1063b08 @@ -1239,7 +1239,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 81f242e338d6122e27aad86986bfd140012c6582 -R 02e43373b368494c6578c4a98382bae8 +P 8215727dda384351765ab1d5c53ea80775b4ec65 +R ed42099f889d81b7ba10262d93840087 U drh -Z 3ab050a0ccd2941539e2053f07648364 +Z c9abd15eefd1ceffcd5e72613bc587bc diff --git a/manifest.uuid b/manifest.uuid index 1991f8fafa..e2d70db74c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -8215727dda384351765ab1d5c53ea80775b4ec65 \ No newline at end of file +905009f6723040d4da4776b6fd07e83c628dea2b \ No newline at end of file diff --git a/src/global.c b/src/global.c index c7043bba48..61450b3d35 100644 --- a/src/global.c +++ b/src/global.c @@ -46,16 +46,16 @@ const unsigned char sqlite3UpperToLower[] = { 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, /* 3x */ 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, /* 4x */ 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, /* 5x */ - 96, 97, 66, 67, 68, 69, 70, 71, 72, 73,106,107,108,109,110,111, /* 6x */ - 112, 81, 82, 83, 84, 85, 86, 87, 88, 89,122,123,124,125,126,127, /* 7x */ + 96, 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111, /* 6x */ + 112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127, /* 7x */ 128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143, /* 8x */ - 144,145,146,147,148,149,150,151,152,153,154,155,156,157,156,159, /* 9x */ + 144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159, /* 9x */ 160,161,162,163,164,165,166,167,168,169,170,171,140,141,142,175, /* Ax */ 176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191, /* Bx */ 192,129,130,131,132,133,134,135,136,137,202,203,204,205,206,207, /* Cx */ 208,145,146,147,148,149,150,151,152,153,218,219,220,221,222,223, /* Dx */ - 224,225,162,163,164,165,166,167,168,169,232,203,204,205,206,207, /* Ex */ - 239,240,241,242,243,244,245,246,247,248,249,219,220,221,222,255, /* Fx */ + 224,225,162,163,164,165,166,167,168,169,234,235,236,237,238,239, /* Ex */ + 240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255, /* Fx */ #endif }; From ad0961b31b11f210aeb85803788e4b401d6ba85c Mon Sep 17 00:00:00 2001 From: drh Date: Sat, 21 Feb 2015 00:19:25 +0000 Subject: [PATCH 46/62] Keep track of the optimal number of reserved bytes (by looking at reserve byte requests in calls to sqlite3BtreeSetPageSize()) and then change the reserve byte count to the optimal when doing a VACUUM or when using the backup API. FossilOrigin-Name: 28c2b726285ea88b334acfd6390a057d2d244838 --- manifest | 24 ++++++++++++------------ manifest.uuid | 2 +- src/attach.c | 2 +- src/backup.c | 2 +- src/btree.c | 23 ++++++++++++++++------- src/btree.h | 4 +--- src/btreeInt.h | 3 +++ src/test_stat.c | 11 +++++++++-- src/vacuum.c | 2 +- 9 files changed, 45 insertions(+), 28 deletions(-) diff --git a/manifest b/manifest index 116b2466ba..18ce942edb 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\serrors\sin\sthe\sEBCDIC\supper-case\sto\slower-case\stranslation\stable. -D 2015-02-19T17:16:14.345 +C Keep\strack\sof\sthe\soptimal\snumber\sof\sreserved\sbytes\s(by\slooking\sat\sreserve\nbyte\srequests\sin\scalls\sto\ssqlite3BtreeSetPageSize())\sand\sthen\schange\sthe\nreserve\sbyte\scount\sto\sthe\soptimal\swhen\sdoing\sa\sVACUUM\sor\swhen\susing\sthe\nbackup\sAPI. +D 2015-02-21T00:19:25.084 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 6b9e7677829aa94b9f30949656e27312aefb9a46 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -168,14 +168,14 @@ F sqlite3.1 fc7ad8990fc8409983309bb80de8c811a7506786 F sqlite3.pc.in 48fed132e7cb71ab676105d2a4dc77127d8c1f3a F src/alter.c ba266a779bc7ce10e52e59e7d3dc79fa342e8fdb F src/analyze.c 91540f835163d5369ccbae78e2e6c74d0dd53c1d -F src/attach.c 7f6b3fafa2290b407e4a94dcf1afda7ec0fe394b +F src/attach.c 880f9b8641a829c563e52dd13c452ce457ae4dd8 F src/auth.c b56c78ebe40a2110fd361379f7e8162d23f92240 -F src/backup.c 7ddee9c7d505e07e959a575b18498f17c71e53ea +F src/backup.c ff743689c4d6c5cb55ad42ed9d174b2b3e71f1e3 F src/bitvec.c 19a4ba637bd85f8f63fc8c9bae5ade9fb05ec1cb F src/btmutex.c 49ca66250c7dfa844a4d4cb8272b87420d27d3a5 -F src/btree.c 2a1245df0356a229bcd0fd87a8536b5067f16e82 -F src/btree.h 94277c1d30c0b75705974bcc8b0c05e79c03d474 -F src/btreeInt.h a3d0ae1d511365e1a2b76ad10960dbe55c286f34 +F src/btree.c a31ac00e30fb7bb49e90e48ce29ef8a61591be96 +F src/btree.h 9cbbb92aab22ef8b50493c40aa3f8de87c43a2fb +F src/btreeInt.h 2bfefc01875d8da066504c233ec259fcb3b2ef72 F src/build.c ba45ebd02904e84d98839a6ea74c3eb948596587 F src/callback.c 7b44ce59674338ad48b0e84e7b72f935ea4f68b0 F src/complete.c 198a0066ba60ab06fc00fba1998d870a4d575463 @@ -278,7 +278,7 @@ F src/test_rtree.c bfe6f4386517f70054311109f3528adffec34485 F src/test_schema.c 2bdba21b82f601da69793e1f1d11bf481a79b091 F src/test_server.c a2615049954cbb9cfb4a62e18e2f0616e4dc38fe F src/test_sqllog.c b690c12933f50ff46491e0d56a251f84ae16e914 -F src/test_stat.c 9898687a6c2beca733b0dd6fe19163d987826d31 +F src/test_stat.c ffc8177f6e69de32a8a89fa6bca73facb6c5face F src/test_superlock.c 06797157176eb7085027d9dd278c0d7a105e3ec9 F src/test_syscall.c 2e21ca7f7dc54a028f1967b63f1e76155c356f9b F src/test_tclvar.c f4dc67d5f780707210d6bb0eb6016a431c04c7fa @@ -292,7 +292,7 @@ F src/trigger.c 25571661fdeae8c7f975ff40ffec205520a3f92f F src/update.c 3c4ecc282accf12d39edb8d524cf089645e55a13 F src/utf.c fc6b889ba0779b7722634cdeaa25f1930d93820c F src/util.c 98a7627ca48ad3265b6940915a1d08355eb3fc7e -F src/vacuum.c 9b30ec729337dd012ed88d4c292922c8ef9cf00c +F src/vacuum.c 9460b9de7b2d4e34b0d374894aa6c8a0632be8ec F src/vdbe.c ddfc977981cd6324668aa6b114045eb1c677421a F src/vdbe.h 6fc69d9c5e146302c56e163cb4b31d1ee64a18c3 F src/vdbeInt.h bb56fd199d8af1a2c1b9639ee2f70724b4338e3a @@ -1239,7 +1239,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 8215727dda384351765ab1d5c53ea80775b4ec65 -R ed42099f889d81b7ba10262d93840087 +P 905009f6723040d4da4776b6fd07e83c628dea2b +R 9a7352553472f105646c8fe233cf7b38 U drh -Z c9abd15eefd1ceffcd5e72613bc587bc +Z d63bd336672b94104d11cd96538a1a36 diff --git a/manifest.uuid b/manifest.uuid index e2d70db74c..67f04903f9 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -905009f6723040d4da4776b6fd07e83c628dea2b \ No newline at end of file +28c2b726285ea88b334acfd6390a057d2d244838 \ No newline at end of file diff --git a/src/attach.c b/src/attach.c index de8742938b..7e35fa67c6 100644 --- a/src/attach.c +++ b/src/attach.c @@ -191,7 +191,7 @@ static void attachFunc( case SQLITE_NULL: /* No key specified. Use the key from the main database */ sqlite3CodecGetKey(db, 0, (void**)&zKey, &nKey); - if( nKey>0 || sqlite3BtreeGetReserve(db->aDb[0].pBt)>0 ){ + if( nKey>0 || sqlite3BtreeGetOptimalReserve(db->aDb[0].pBt)>0 ){ rc = sqlite3CodecAttach(db, db->nDb-1, zKey, nKey); } break; diff --git a/src/backup.c b/src/backup.c index e3f869035e..81c8b5c5f4 100644 --- a/src/backup.c +++ b/src/backup.c @@ -247,7 +247,7 @@ static int backupOnePage( ** guaranteed that the shared-mutex is held by this thread, handle ** p->pSrc may not actually be the owner. */ int nSrcReserve = sqlite3BtreeGetReserveNoMutex(p->pSrc); - int nDestReserve = sqlite3BtreeGetReserve(p->pDest); + int nDestReserve = sqlite3BtreeGetOptimalReserve(p->pDest); #endif int rc = SQLITE_OK; i64 iOff; diff --git a/src/btree.c b/src/btree.c index eb5151351c..8957b74c19 100644 --- a/src/btree.c +++ b/src/btree.c @@ -2405,6 +2405,9 @@ int sqlite3BtreeSetPageSize(Btree *p, int pageSize, int nReserve, int iFix){ BtShared *pBt = p->pBt; assert( nReserve>=-1 && nReserve<=255 ); sqlite3BtreeEnter(p); +#if SQLITE_HAS_CODEC + if( nReserve>pBt->optimalReserve ) pBt->optimalReserve = (u8)nReserve; +#endif if( pBt->btsFlags & BTS_PAGESIZE_FIXED ){ sqlite3BtreeLeave(p); return SQLITE_READONLY; @@ -2434,7 +2437,6 @@ int sqlite3BtreeGetPageSize(Btree *p){ return p->pBt->pageSize; } -#if defined(SQLITE_HAS_CODEC) || defined(SQLITE_DEBUG) /* ** This function is similar to sqlite3BtreeGetReserve(), except that it ** may only be called if it is guaranteed that the b-tree mutex is already @@ -2447,25 +2449,33 @@ int sqlite3BtreeGetPageSize(Btree *p){ ** database handle that owns *p, causing undefined behavior. */ int sqlite3BtreeGetReserveNoMutex(Btree *p){ + int n; assert( sqlite3_mutex_held(p->pBt->mutex) ); - return p->pBt->pageSize - p->pBt->usableSize; + n = p->pBt->pageSize - p->pBt->usableSize; + return n; } -#endif /* SQLITE_HAS_CODEC || SQLITE_DEBUG */ -#if !defined(SQLITE_OMIT_PAGER_PRAGMAS) || !defined(SQLITE_OMIT_VACUUM) /* ** Return the number of bytes of space at the end of every page that ** are intentually left unused. This is the "reserved" space that is ** sometimes used by extensions. +** +** If SQLITE_HAS_MUTEX is defined then the number returned is the +** greater of the current reserved space and the maximum requested +** reserve space. */ -int sqlite3BtreeGetReserve(Btree *p){ +int sqlite3BtreeGetOptimalReserve(Btree *p){ int n; sqlite3BtreeEnter(p); - n = p->pBt->pageSize - p->pBt->usableSize; + n = sqlite3BtreeGetReserveNoMutex(p); +#ifdef SQLITE_HAS_CODEC + if( npBt->optimalReserve ) n = p->pBt->optimalReserve; +#endif sqlite3BtreeLeave(p); return n; } + /* ** Set the maximum page count for a database if mxPage is positive. ** No changes are made if mxPage is 0 or negative. @@ -2496,7 +2506,6 @@ int sqlite3BtreeSecureDelete(Btree *p, int newFlag){ sqlite3BtreeLeave(p); return b; } -#endif /* !defined(SQLITE_OMIT_PAGER_PRAGMAS) || !defined(SQLITE_OMIT_VACUUM) */ /* ** Change the 'auto-vacuum' property of the database. If the 'autoVacuum' diff --git a/src/btree.h b/src/btree.h index b57d500c77..77d12f78d3 100644 --- a/src/btree.h +++ b/src/btree.h @@ -73,10 +73,8 @@ int sqlite3BtreeGetPageSize(Btree*); int sqlite3BtreeMaxPageCount(Btree*,int); u32 sqlite3BtreeLastPage(Btree*); int sqlite3BtreeSecureDelete(Btree*,int); -int sqlite3BtreeGetReserve(Btree*); -#if defined(SQLITE_HAS_CODEC) || defined(SQLITE_DEBUG) +int sqlite3BtreeGetOptimalReserve(Btree*); int sqlite3BtreeGetReserveNoMutex(Btree *p); -#endif int sqlite3BtreeSetAutoVacuum(Btree *, int); int sqlite3BtreeGetAutoVacuum(Btree *); int sqlite3BtreeBeginTrans(Btree*,int); diff --git a/src/btreeInt.h b/src/btreeInt.h index ed4d75ee9f..87d0ef1bb8 100644 --- a/src/btreeInt.h +++ b/src/btreeInt.h @@ -418,6 +418,9 @@ struct BtShared { #endif u8 inTransaction; /* Transaction state */ u8 max1bytePayload; /* Maximum first byte of cell for a 1-byte payload */ +#ifdef SQLITE_HAS_CODEC + u8 optimalReserve; /* Desired amount of reserved space per page */ +#endif u16 btsFlags; /* Boolean parameters. See BTS_* macros below */ u16 maxLocal; /* Maximum local payload in non-LEAFDATA tables */ u16 minLocal; /* Minimum local payload in non-LEAFDATA tables */ diff --git a/src/test_stat.c b/src/test_stat.c index 615df3d80f..daa84de2c0 100644 --- a/src/test_stat.c +++ b/src/test_stat.c @@ -301,8 +301,11 @@ static int statDecodePage(Btree *pBt, StatPage *p){ if( p->nCell ){ int i; /* Used to iterate through cells */ - int nUsable = szPage - sqlite3BtreeGetReserve(pBt); + int nUsable; /* Usable bytes per page */ + sqlite3BtreeEnter(pBt); + nUsable = szPage - sqlite3BtreeGetReserveNoMutex(pBt); + sqlite3BtreeLeave(pBt); p->aCell = sqlite3_malloc((p->nCell+1) * sizeof(StatCell)); memset(p->aCell, 0, (p->nCell+1) * sizeof(StatCell)); @@ -425,7 +428,11 @@ statNextRestart: while( p->iCellnCell ){ StatCell *pCell = &p->aCell[p->iCell]; if( pCell->iOvflnOvfl ){ - int nUsable = sqlite3BtreeGetPageSize(pBt)-sqlite3BtreeGetReserve(pBt); + int nUsable; + sqlite3BtreeEnter(pBt); + nUsable = sqlite3BtreeGetPageSize(pBt) - + sqlite3BtreeGetReserveNoMutex(pBt); + sqlite3BtreeLeave(pBt); pCsr->zName = (char *)sqlite3_column_text(pCsr->pStmt, 0); pCsr->iPageno = pCell->aOvfl[pCell->iOvfl]; pCsr->zPagetype = "overflow"; diff --git a/src/vacuum.c b/src/vacuum.c index 9df8e08b22..dca43e217e 100644 --- a/src/vacuum.c +++ b/src/vacuum.c @@ -184,7 +184,7 @@ int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db){ ** cause problems for the call to BtreeSetPageSize() below. */ sqlite3BtreeCommit(pTemp); - nRes = sqlite3BtreeGetReserve(pMain); + nRes = sqlite3BtreeGetOptimalReserve(pMain); /* A VACUUM cannot change the pagesize of an encrypted database. */ #ifdef SQLITE_HAS_CODEC From e6d4173b7877d3bc3ee1c9c599e1e02c1f749d5f Mon Sep 17 00:00:00 2001 From: drh Date: Sat, 21 Feb 2015 00:49:00 +0000 Subject: [PATCH 47/62] Fix over-length source code lines in os_unix.c. FossilOrigin-Name: 7560a9fa50236ecaa0617f1ab5bb5662f4a61c72 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/os_unix.c | 16 ++++++++-------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/manifest b/manifest index 18ce942edb..4ab4606db5 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Keep\strack\sof\sthe\soptimal\snumber\sof\sreserved\sbytes\s(by\slooking\sat\sreserve\nbyte\srequests\sin\scalls\sto\ssqlite3BtreeSetPageSize())\sand\sthen\schange\sthe\nreserve\sbyte\scount\sto\sthe\soptimal\swhen\sdoing\sa\sVACUUM\sor\swhen\susing\sthe\nbackup\sAPI. -D 2015-02-21T00:19:25.084 +C Fix\sover-length\ssource\scode\slines\sin\sos_unix.c. +D 2015-02-21T00:49:00.792 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 6b9e7677829aa94b9f30949656e27312aefb9a46 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -214,7 +214,7 @@ F src/os.c 8fd25588eeba74068d41102d26810e216999b6c8 F src/os.h 3e57a24e2794a94d3cf2342c6d9a884888cd96bf F src/os_common.h 92815ed65f805560b66166e3583470ff94478f04 F src/os_setup.h c9d4553b5aaa6f73391448b265b89bed0b890faa -F src/os_unix.c 16ad795ef98966d9bdb3c967585fdadf9a2cfcb9 +F src/os_unix.c 77e169d82b1bc679df00a3a59eb8ee2b5547c1a1 F src/os_win.c 8223e7db5b7c4a81d8b161098ac3959400434cdb F src/os_win.h eb7a47aa17b26b77eb97e4823f20a00b8bda12ca F src/pager.c 4120a49ecd37697e28f5ed807f470b9c0b88410c @@ -1239,7 +1239,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 905009f6723040d4da4776b6fd07e83c628dea2b -R 9a7352553472f105646c8fe233cf7b38 +P 28c2b726285ea88b334acfd6390a057d2d244838 +R 40164bdb5e6758b7e802bc3a998c4356 U drh -Z d63bd336672b94104d11cd96538a1a36 +Z d7418837f1bb2d2284bd9d06bcf9bb52 diff --git a/manifest.uuid b/manifest.uuid index 67f04903f9..c117f67f8d 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -28c2b726285ea88b334acfd6390a057d2d244838 \ No newline at end of file +7560a9fa50236ecaa0617f1ab5bb5662f4a61c72 \ No newline at end of file diff --git a/src/os_unix.c b/src/os_unix.c index 522617212f..5f583402ab 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -254,7 +254,7 @@ static int randomnessPid = 0; #define UNIXFILE_DELETE 0x20 /* Delete on close */ #define UNIXFILE_URI 0x40 /* Filename might have query parameters */ #define UNIXFILE_NOLOCK 0x80 /* Do no file locking */ -#define UNIXFILE_WARNED 0x0100 /* verifyDbFile() warnings have been issued */ +#define UNIXFILE_WARNED 0x0100 /* verifyDbFile() warnings issued */ /* ** Include code that is common to all os_*.c files @@ -717,9 +717,9 @@ static int lockTrace(int fd, int op, struct flock *p){ /* ** Retry ftruncate() calls that fail due to EINTR ** -** All calls to ftruncate() within this file should be made through this wrapper. -** On the Android platform, bypassing the logic below could lead to a corrupt -** database. +** All calls to ftruncate() within this file should be made through +** this wrapper. On the Android platform, bypassing the logic below +** could lead to a corrupt database. */ static int robust_ftruncate(int h, sqlite3_int64 sz){ int rc; @@ -1179,8 +1179,8 @@ static void robust_close(unixFile *pFile, int h, int lineno){ } /* -** Set the pFile->lastErrno. Do this in a subroutine as that provides a convenient -** place to set a breakpoint. +** Set the pFile->lastErrno. Do this in a subroutine as that provides +** a convenient place to set a breakpoint. */ static void storeLastErrno(unixFile *pFile, int error){ pFile->lastErrno = error; @@ -4969,7 +4969,7 @@ static int unixUnfetch(sqlite3_file *fd, i64 iOff, void *p){ ** * An I/O method finder function called FINDER that returns a pointer ** to the METHOD object in the previous bullet. */ -#define IOMETHODS(FINDER, METHOD, VERSION, CLOSE, LOCK, UNLOCK, CKLOCK, SHMMAP) \ +#define IOMETHODS(FINDER,METHOD,VERSION,CLOSE,LOCK,UNLOCK,CKLOCK,SHMMAP) \ static const sqlite3_io_methods METHOD = { \ VERSION, /* iVersion */ \ CLOSE, /* xClose */ \ @@ -6766,7 +6766,7 @@ static int proxyConchLock(unixFile *pFile, uuid_t myHostID, int lockType){ if( 0==proxyBreakConchLock(pFile, myHostID) ){ rc = SQLITE_OK; if( lockType==EXCLUSIVE_LOCK ){ - rc = conchFile->pMethod->xLock((sqlite3_file*)conchFile, SHARED_LOCK); + rc = conchFile->pMethod->xLock((sqlite3_file*)conchFile, SHARED_LOCK); } if( !rc ){ rc = conchFile->pMethod->xLock((sqlite3_file*)conchFile, lockType); From 2da47d38691b74a6cfa2ce2e5bdce3bb7d8fc186 Mon Sep 17 00:00:00 2001 From: drh Date: Sat, 21 Feb 2015 00:56:05 +0000 Subject: [PATCH 48/62] Fix a compiler warning associated with USE_PREAD64. FossilOrigin-Name: c299e55a661c04f71ab43cb8aed04f8ece6e0567 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/os_unix.c | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 4ab4606db5..fbd8198361 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sover-length\ssource\scode\slines\sin\sos_unix.c. -D 2015-02-21T00:49:00.792 +C Fix\sa\scompiler\swarning\sassociated\swith\sUSE_PREAD64. +D 2015-02-21T00:56:05.294 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 6b9e7677829aa94b9f30949656e27312aefb9a46 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -214,7 +214,7 @@ F src/os.c 8fd25588eeba74068d41102d26810e216999b6c8 F src/os.h 3e57a24e2794a94d3cf2342c6d9a884888cd96bf F src/os_common.h 92815ed65f805560b66166e3583470ff94478f04 F src/os_setup.h c9d4553b5aaa6f73391448b265b89bed0b890faa -F src/os_unix.c 77e169d82b1bc679df00a3a59eb8ee2b5547c1a1 +F src/os_unix.c c06b1b263d52e14473ccc619422af6b64570a3b8 F src/os_win.c 8223e7db5b7c4a81d8b161098ac3959400434cdb F src/os_win.h eb7a47aa17b26b77eb97e4823f20a00b8bda12ca F src/pager.c 4120a49ecd37697e28f5ed807f470b9c0b88410c @@ -1239,7 +1239,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 28c2b726285ea88b334acfd6390a057d2d244838 -R 40164bdb5e6758b7e802bc3a998c4356 +P 7560a9fa50236ecaa0617f1ab5bb5662f4a61c72 +R afd779aaccfbda112c52de91ea006a71 U drh -Z d7418837f1bb2d2284bd9d06bcf9bb52 +Z 8991d0e22753a2d2a931885c01f739fa diff --git a/manifest.uuid b/manifest.uuid index c117f67f8d..799d2f85ad 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -7560a9fa50236ecaa0617f1ab5bb5662f4a61c72 \ No newline at end of file +c299e55a661c04f71ab43cb8aed04f8ece6e0567 \ No newline at end of file diff --git a/src/os_unix.c b/src/os_unix.c index 5f583402ab..48aac166d0 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -3260,9 +3260,9 @@ static int seekAndWriteFd( TIMER_START; #if defined(USE_PREAD) - do{ rc = osPwrite(fd, pBuf, nBuf, iOff); }while( rc<0 && errno==EINTR ); + do{ rc = (int)osPwrite(fd, pBuf, nBuf, iOff); }while( rc<0 && errno==EINTR ); #elif defined(USE_PREAD64) - do{ rc = osPwrite64(fd, pBuf, nBuf, iOff);}while( rc<0 && errno==EINTR); + do{ rc = (int)osPwrite64(fd, pBuf, nBuf, iOff);}while( rc<0 && errno==EINTR); #else do{ i64 iSeek = lseek(fd, iOff, SEEK_SET); From d4ef026ebb87b2d4504b73ce08cde8da2a849b9e Mon Sep 17 00:00:00 2001 From: drh Date: Sat, 21 Feb 2015 15:42:57 +0000 Subject: [PATCH 49/62] Update document on sqlite3_mprintf() and related functions. Discuss the %w format and point out that obscure ANSI-C formats are not supported. No changes to code. FossilOrigin-Name: f8917ba4d917bc762b3b252466ab72a8a70dc0d8 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/sqlite.h.in | 12 +++++++++++- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index fbd8198361..8dd0ff3390 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\scompiler\swarning\sassociated\swith\sUSE_PREAD64. -D 2015-02-21T00:56:05.294 +C Update\sdocument\son\ssqlite3_mprintf()\sand\srelated\sfunctions.\s\sDiscuss\sthe\n%w\sformat\sand\spoint\sout\sthat\sobscure\sANSI-C\sformats\sare\snot\ssupported.\nNo\schanges\sto\scode. +D 2015-02-21T15:42:57.800 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 6b9e7677829aa94b9f30949656e27312aefb9a46 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -232,7 +232,7 @@ F src/resolve.c f4d79e31ffa5820c2e3d1740baa5e9b190425f2b F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e F src/select.c e46cef4c224549b439384c88fc7f57ba064dad54 F src/shell.c 6276582ee4e9114e0bb0795772414caaf21c0f8e -F src/sqlite.h.in b02d8d19c5adc73bd02b225054103247aff64425 +F src/sqlite.h.in 86cddbfdb3155967858c1469108813bcc08eda21 F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h 17d487c3c91b0b8c584a32fbeb393f6f795eea7d F src/sqliteInt.h 57a405ae6d2ed10fff52de376d18f21e04d96609 @@ -1239,7 +1239,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 7560a9fa50236ecaa0617f1ab5bb5662f4a61c72 -R afd779aaccfbda112c52de91ea006a71 +P c299e55a661c04f71ab43cb8aed04f8ece6e0567 +R dda772aafb6dee5a528cc1c5d5a14dc2 U drh -Z 8991d0e22753a2d2a931885c01f739fa +Z 75f83919b9b483315b93f05f4ef8627c diff --git a/manifest.uuid b/manifest.uuid index 799d2f85ad..c46ad20405 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c299e55a661c04f71ab43cb8aed04f8ece6e0567 \ No newline at end of file +f8917ba4d917bc762b3b252466ab72a8a70dc0d8 \ No newline at end of file diff --git a/src/sqlite.h.in b/src/sqlite.h.in index 8a358dbb2f..ee910393e6 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -2232,6 +2232,10 @@ void sqlite3_free_table(char **result); ** ** These routines are work-alikes of the "printf()" family of functions ** from the standard C library. +** These routines understand most of the common K&R formatting options, +** plus some additional non-standard formats, detailed below. +** Note that some of the more obscure formatting options from recent +** C-library standards are omitted from this implementation. ** ** ^The sqlite3_mprintf() and sqlite3_vmprintf() routines write their ** results into memory obtained from [sqlite3_malloc()]. @@ -2264,7 +2268,7 @@ void sqlite3_free_table(char **result); ** These routines all implement some additional formatting ** options that are useful for constructing SQL statements. ** All of the usual printf() formatting options apply. In addition, there -** is are "%q", "%Q", and "%z" options. +** is are "%q", "%Q", "%w" and "%z" options. ** ** ^(The %q option works like %s in that it substitutes a nul-terminated ** string from the argument list. But %q also doubles every '\'' character. @@ -2317,6 +2321,12 @@ void sqlite3_free_table(char **result); ** The code above will render a correct SQL statement in the zSQL ** variable even if the zText variable is a NULL pointer. ** +** ^(The "%w" formatting option is like "%q" except that it expects to +** be contained within double-quotes instead of single quotes, and it +** escapes the double-quote character instead of the single-quote +** character.)^ The "%w" formatting option is intended for safely inserting +** table and column names into a constructed SQL statement. +** ** ^(The "%z" formatting option works like "%s" but with the ** addition that after the string has been read and copied into ** the result, [sqlite3_free()] is called on the input string.)^ From 36f65bafe5c571a3548435751939a99155b5f129 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 24 Feb 2015 16:05:54 +0000 Subject: [PATCH 50/62] Make sure partial automatic indexes are not based on terms in the ON clause of a LEFT JOIN. Fix for ticket [2326c258d02ead3]. FossilOrigin-Name: c0f4e308a508183b72ceda447dc3ac778cb85b9f --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/where.c | 1 + test/autoindex4.test | 21 +++++++++++++++++++++ 4 files changed, 30 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 8dd0ff3390..34750ae8f3 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Update\sdocument\son\ssqlite3_mprintf()\sand\srelated\sfunctions.\s\sDiscuss\sthe\n%w\sformat\sand\spoint\sout\sthat\sobscure\sANSI-C\sformats\sare\snot\ssupported.\nNo\schanges\sto\scode. -D 2015-02-21T15:42:57.800 +C Make\ssure\spartial\sautomatic\sindexes\sare\snot\sbased\son\sterms\sin\sthe\sON\sclause\nof\sa\sLEFT\sJOIN.\s\sFix\sfor\sticket\s[2326c258d02ead3]. +D 2015-02-24T16:05:54.976 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 6b9e7677829aa94b9f30949656e27312aefb9a46 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -306,7 +306,7 @@ F src/vtab.c 699f2b8d509cfe379c33dde33827875d5b030e01 F src/wal.c 39303f2c9db02a4e422cd8eb2c8760420c6a51fe F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4 F src/walker.c c253b95b4ee44b21c406e2a1052636c31ea27804 -F src/where.c d46de821bc604a4fd36fa3928c086950e91aafb1 +F src/where.c 59ab7da73b0de376d945c96c2867a1d550686717 F src/whereInt.h d3633e9b592103241b74b0ec76185f3e5b8b62e0 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2 @@ -350,7 +350,7 @@ F test/autoinc.test c58912526998a39e11f66b533e23cfabea7f25b7 F test/autoindex1.test 6ff78b94f43a59616c06c11c55b12935173506d7 F test/autoindex2.test af7e595c6864cc6ef5fc38d5db579a3e34940cb8 F test/autoindex3.test a3be0d1a53a7d2edff208a5e442312957047e972 -F test/autoindex4.test fc807f9efd158bec60f5dfdf34ebe46fb274612d +F test/autoindex4.test 364be4c1654267720aa537beba4ef0ca4d7f60d9 F test/autovacuum.test 941892505d2c0f410a0cb5970dfa1c7c4e5f6e74 F test/autovacuum_ioerr2.test 8a367b224183ad801e0e24dcb7d1501f45f244b4 F test/avtrans.test 0252654f4295ddda3b2cce0e894812259e655a85 @@ -1239,7 +1239,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P c299e55a661c04f71ab43cb8aed04f8ece6e0567 -R dda772aafb6dee5a528cc1c5d5a14dc2 +P f8917ba4d917bc762b3b252466ab72a8a70dc0d8 +R 3f565b8438472847d9367d99d4186ffd U drh -Z 75f83919b9b483315b93f05f4ef8627c +Z f1617e86199163d366d582f2564e1bac diff --git a/manifest.uuid b/manifest.uuid index c46ad20405..8ebe715cb4 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -f8917ba4d917bc762b3b252466ab72a8a70dc0d8 \ No newline at end of file +c0f4e308a508183b72ceda447dc3ac778cb85b9f \ No newline at end of file diff --git a/src/where.c b/src/where.c index 183a8cb667..aef1820e80 100644 --- a/src/where.c +++ b/src/where.c @@ -1614,6 +1614,7 @@ static void constructAutomaticIndex( for(pTerm=pWC->a; pTermprereq==0 && (pTerm->wtFlags & TERM_VIRTUAL)==0 + && !ExprHasProperty(pTerm->pExpr, EP_FromJoin) && sqlite3ExprIsTableConstant(pTerm->pExpr, pSrc->iCursor) ){ pPartial = sqlite3ExprAnd(pParse->db, pPartial, sqlite3ExprDup(pParse->db, pTerm->pExpr, 0)); diff --git a/test/autoindex4.test b/test/autoindex4.test index 6d0865bf72..8e32462df4 100644 --- a/test/autoindex4.test +++ b/test/autoindex4.test @@ -49,4 +49,25 @@ do_execsql_test autoindex4-2.0 { ORDER BY rowid; } {1 123 654 | 0 555 444 | 4 234 987 |} +# Ticket [2326c258d02ead33d] +# Two joins, one with and the other without an ORDER BY clause. +# The one without ORDER BY correctly returns two rows of result. +# The one with ORDER BY returns no rows. +# +do_execsql_test autoindex4-3.0 { + CREATE TABLE A(Name text); + CREATE TABLE Items(ItemName text , Name text); + INSERT INTO Items VALUES('Item1','Parent'); + INSERT INTO Items VALUES('Item2','Parent'); + CREATE TABLE B(Name text); + + SELECT Items.ItemName + FROM Items + LEFT JOIN A ON (A.Name = Items.ItemName and Items.ItemName = 'dummy') + LEFT JOIN B ON (B.Name = Items.ItemName) + WHERE Items.Name = 'Parent' + ORDER BY Items.ItemName; +} {Item1 Item2} + + finish_test From 077f06edfa988588b93442b646a55bfb58ec9d92 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 24 Feb 2015 16:48:59 +0000 Subject: [PATCH 51/62] This additional fix prevents a partial index from being qualified for use if the constraint that qualifies the partial index is part of the ON clause of a LEFT JOIN. FossilOrigin-Name: 1a1516e4da26dcee35e6fbb6604ce252faf3d116 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/where.c | 6 +++++- test/autoindex4.test | 10 ++++++++++ 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 34750ae8f3..07b1467343 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Make\ssure\spartial\sautomatic\sindexes\sare\snot\sbased\son\sterms\sin\sthe\sON\sclause\nof\sa\sLEFT\sJOIN.\s\sFix\sfor\sticket\s[2326c258d02ead3]. -D 2015-02-24T16:05:54.976 +C This\sadditional\sfix\sprevents\sa\spartial\sindex\sfrom\sbeing\squalified\sfor\suse\s\nif\sthe\sconstraint\sthat\squalifies\sthe\spartial\sindex\sis\spart\sof\sthe\sON\sclause\sof\na\sLEFT\sJOIN. +D 2015-02-24T16:48:59.496 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 6b9e7677829aa94b9f30949656e27312aefb9a46 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -306,7 +306,7 @@ F src/vtab.c 699f2b8d509cfe379c33dde33827875d5b030e01 F src/wal.c 39303f2c9db02a4e422cd8eb2c8760420c6a51fe F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4 F src/walker.c c253b95b4ee44b21c406e2a1052636c31ea27804 -F src/where.c 59ab7da73b0de376d945c96c2867a1d550686717 +F src/where.c 88509f19a64a36e1c22a1dbdac74ee1a62d99dc3 F src/whereInt.h d3633e9b592103241b74b0ec76185f3e5b8b62e0 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2 @@ -350,7 +350,7 @@ F test/autoinc.test c58912526998a39e11f66b533e23cfabea7f25b7 F test/autoindex1.test 6ff78b94f43a59616c06c11c55b12935173506d7 F test/autoindex2.test af7e595c6864cc6ef5fc38d5db579a3e34940cb8 F test/autoindex3.test a3be0d1a53a7d2edff208a5e442312957047e972 -F test/autoindex4.test 364be4c1654267720aa537beba4ef0ca4d7f60d9 +F test/autoindex4.test 49d3cd791a9baa16fb461d7ea3de80d019a819cf F test/autovacuum.test 941892505d2c0f410a0cb5970dfa1c7c4e5f6e74 F test/autovacuum_ioerr2.test 8a367b224183ad801e0e24dcb7d1501f45f244b4 F test/avtrans.test 0252654f4295ddda3b2cce0e894812259e655a85 @@ -1239,7 +1239,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P f8917ba4d917bc762b3b252466ab72a8a70dc0d8 -R 3f565b8438472847d9367d99d4186ffd +P c0f4e308a508183b72ceda447dc3ac778cb85b9f +R 4fd07aecba33e9248bb5425721691954 U drh -Z f1617e86199163d366d582f2564e1bac +Z 49115944492618e32f7d86cca0efe1da diff --git a/manifest.uuid b/manifest.uuid index 8ebe715cb4..36a5889cda 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c0f4e308a508183b72ceda447dc3ac778cb85b9f \ No newline at end of file +1a1516e4da26dcee35e6fbb6604ce252faf3d116 \ No newline at end of file diff --git a/src/where.c b/src/where.c index aef1820e80..f45da74794 100644 --- a/src/where.c +++ b/src/where.c @@ -4695,7 +4695,11 @@ static int whereUsablePartialIndex(int iTab, WhereClause *pWC, Expr *pWhere){ int i; WhereTerm *pTerm; for(i=0, pTerm=pWC->a; inTerm; i++, pTerm++){ - if( sqlite3ExprImpliesExpr(pTerm->pExpr, pWhere, iTab) ) return 1; + if( sqlite3ExprImpliesExpr(pTerm->pExpr, pWhere, iTab) + && !ExprHasProperty(pTerm->pExpr, EP_FromJoin) + ){ + return 1; + } } return 0; } diff --git a/test/autoindex4.test b/test/autoindex4.test index 8e32462df4..0e7a80df21 100644 --- a/test/autoindex4.test +++ b/test/autoindex4.test @@ -68,6 +68,16 @@ do_execsql_test autoindex4-3.0 { WHERE Items.Name = 'Parent' ORDER BY Items.ItemName; } {Item1 Item2} +do_execsql_test autoindex4-3.1 { + CREATE INDEX Items_x1 ON Items(ItemName,Name) WHERE ItemName = 'dummy'; + + SELECT Items.ItemName + FROM Items + LEFT JOIN A ON (A.Name = Items.ItemName and Items.ItemName = 'dummy') + LEFT JOIN B ON (B.Name = Items.ItemName) + WHERE Items.Name = 'Parent' + ORDER BY Items.ItemName; +} {Item1 Item2} finish_test From e006a866432d7448aeacec6254a18268e8ac9807 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 24 Feb 2015 18:39:00 +0000 Subject: [PATCH 52/62] More test cases to help ensure that partial indexes do not get used if their qualifing constraint is inside the ON clause of a LEFT JOIN. FossilOrigin-Name: c6399958a17e8b7c1798a9240fb06bffc774b332 --- manifest | 12 ++++++------ manifest.uuid | 2 +- test/index6.test | 28 ++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/manifest b/manifest index 07b1467343..04f8e1d71c 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C This\sadditional\sfix\sprevents\sa\spartial\sindex\sfrom\sbeing\squalified\sfor\suse\s\nif\sthe\sconstraint\sthat\squalifies\sthe\spartial\sindex\sis\spart\sof\sthe\sON\sclause\sof\na\sLEFT\sJOIN. -D 2015-02-24T16:48:59.496 +C More\stest\scases\sto\shelp\sensure\sthat\spartial\sindexes\sdo\snot\sget\sused\sif\stheir\nqualifing\sconstraint\sis\sinside\sthe\sON\sclause\sof\sa\sLEFT\sJOIN. +D 2015-02-24T18:39:00.173 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 6b9e7677829aa94b9f30949656e27312aefb9a46 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -652,7 +652,7 @@ F test/index2.test ee83c6b5e3173a3d7137140d945d9a5d4fdfb9d6 F test/index3.test 55a90cff99834305e8141df7afaef39674b57062 F test/index4.test ab92e736d5946840236cd61ac3191f91a7856bf6 F test/index5.test 25b0b451aceed4ac5f7d49f856f6de7257470b3e -F test/index6.test fb370966ac3cd0989053dd5385757b5c3e24ab6a +F test/index6.test c56852451b574ad5b2a1789e566e62e6ab244f42 F test/index7.test 917cf1e1c7439bb155abbeabec511b28945e157b F test/indexedby.test b2f22f3e693a53813aa3f50b812eb609ba6df1ec F test/indexfault.test 31d4ab9a7d2f6e9616933eb079722362a883eb1d @@ -1239,7 +1239,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P c0f4e308a508183b72ceda447dc3ac778cb85b9f -R 4fd07aecba33e9248bb5425721691954 +P 1a1516e4da26dcee35e6fbb6604ce252faf3d116 +R 65a9e61b66b400145ad4b4adbab491c4 U drh -Z 49115944492618e32f7d86cca0efe1da +Z f7c7ecf68414d2c1e5314c6ea356d3c1 diff --git a/manifest.uuid b/manifest.uuid index 36a5889cda..5b0e5ce53e 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -1a1516e4da26dcee35e6fbb6604ce252faf3d116 \ No newline at end of file +c6399958a17e8b7c1798a9240fb06bffc774b332 \ No newline at end of file diff --git a/test/index6.test b/test/index6.test index 68bdd06c14..8414b11baa 100644 --- a/test/index6.test +++ b/test/index6.test @@ -267,5 +267,33 @@ do_execsql_test index6-6.2 { PRAGMA integrity_check; } {ok} +# Test case for ticket [2326c258d02ead33d69faa63de8f4686b9b1b9d9] on +# 2015-02-24. Any use of a partial index qualifying constraint inside +# the ON clause of a LEFT JOIN was causing incorrect results for all +# versions of SQLite 3.8.0 through 3.8.8. +# +do_execsql_test index6-7.0 { + CREATE TABLE t7a(x); + CREATE TABLE t7b(y); + INSERT INTO t7a(x) VALUES(1); + CREATE INDEX t7ax ON t7a(x) WHERE x=99; + PRAGMA automatic_index=OFF; + SELECT * FROM t7a LEFT JOIN t7b ON (x=99) ORDER BY x; +} {1 {}} +do_execsql_test index6-7.1 { + INSERT INTO t7b(y) VALUES(2); + SELECT * FROM t7a JOIN t7b ON (x=99) ORDER BY x; +} {} +do_execsql_test index6-7.2 { + INSERT INTO t7a(x) VALUES(99); + SELECT * FROM t7a LEFT JOIN t7b ON (x=99) ORDER BY x; +} {1 {} 99 2} +do_execsql_test index6-7.3 { + SELECT * FROM t7a JOIN t7b ON (x=99) ORDER BY x; +} {99 2} +do_execsql_test index6-7.4 { + EXPLAIN QUERY PLAN + SELECT * FROM t7a JOIN t7b ON (x=99) ORDER BY x; +} {/USING COVERING INDEX t7ax/} finish_test From 2a45cb5c0ecfba41c673fc8184337543ea8d475f Mon Sep 17 00:00:00 2001 From: dan Date: Tue, 24 Feb 2015 20:10:49 +0000 Subject: [PATCH 53/62] Prevent partial indexes on the table on the left hand side of a LEFT JOIN from being incorrectly qualified by a constraint in the ON clause of the join. This relaxes the rule introduced by the previous commit (as the partial indexes on the table on the rhs of the LEFT JOIN may now be qualified by terms within the ON clause). FossilOrigin-Name: 1d6fb43a576d335d2717e94d28385178c23c81a1 --- manifest | 17 ++++++++--------- manifest.uuid | 2 +- src/where.c | 8 +++++--- test/index6.test | 31 +++++++++++++++++++++++++++++++ 4 files changed, 45 insertions(+), 13 deletions(-) diff --git a/manifest b/manifest index 1f4acd3fec..c6a94d0d59 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Make\ssure\spartial\sindexes\sare\snot\squalified\sincorrectly\sby\sa\sconstraint\sthat\nis\sinside\sthe\sON\sclause\sof\sa\sLEFT\sJOIN.\s\sFix\sfor\sticket\s[2326c258d02ead33]. -D 2015-02-24T20:04:59.149 +C Prevent\spartial\sindexes\son\sthe\stable\son\sthe\sleft\shand\sside\sof\sa\sLEFT\sJOIN\sfrom\sbeing\sincorrectly\squalified\sby\sa\sconstraint\sin\sthe\sON\sclause\sof\sthe\sjoin.\sThis\srelaxes\sthe\srule\sintroduced\sby\sthe\sprevious\scommit\s(as\sthe\spartial\sindexes\son\sthe\stable\son\sthe\srhs\sof\sthe\sLEFT\sJOIN\smay\snow\sbe\squalified\sby\sterms\swithin\sthe\sON\sclause). +D 2015-02-24T20:10:49.082 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 6b9e7677829aa94b9f30949656e27312aefb9a46 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -306,7 +306,7 @@ F src/vtab.c 699f2b8d509cfe379c33dde33827875d5b030e01 F src/wal.c 39303f2c9db02a4e422cd8eb2c8760420c6a51fe F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4 F src/walker.c c253b95b4ee44b21c406e2a1052636c31ea27804 -F src/where.c 88509f19a64a36e1c22a1dbdac74ee1a62d99dc3 +F src/where.c 294423cf9a3c46377c3e246338ff2a38365ad922 F src/whereInt.h d3633e9b592103241b74b0ec76185f3e5b8b62e0 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2 @@ -652,7 +652,7 @@ F test/index2.test ee83c6b5e3173a3d7137140d945d9a5d4fdfb9d6 F test/index3.test 55a90cff99834305e8141df7afaef39674b57062 F test/index4.test ab92e736d5946840236cd61ac3191f91a7856bf6 F test/index5.test 25b0b451aceed4ac5f7d49f856f6de7257470b3e -F test/index6.test c56852451b574ad5b2a1789e566e62e6ab244f42 +F test/index6.test 3ae54e53c53f2adcacda269237d8e52bdb05a481 F test/index7.test 917cf1e1c7439bb155abbeabec511b28945e157b F test/indexedby.test b2f22f3e693a53813aa3f50b812eb609ba6df1ec F test/indexfault.test 31d4ab9a7d2f6e9616933eb079722362a883eb1d @@ -1239,8 +1239,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P f8917ba4d917bc762b3b252466ab72a8a70dc0d8 c6399958a17e8b7c1798a9240fb06bffc774b332 -R 65a9e61b66b400145ad4b4adbab491c4 -T +closed c6399958a17e8b7c1798a9240fb06bffc774b332 -U drh -Z 128fd4816e28956dbfeb54d3b3932fdf +P 491cfe9b3f87f5fcc579f953745012cea8d64db7 +R ca86a79194d1da36938ef90c0f8f3a89 +U dan +Z 37d3633be74b06dd46fb3d2721885844 diff --git a/manifest.uuid b/manifest.uuid index af369a2ac7..cd9fd72c3a 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -491cfe9b3f87f5fcc579f953745012cea8d64db7 \ No newline at end of file +1d6fb43a576d335d2717e94d28385178c23c81a1 \ No newline at end of file diff --git a/src/where.c b/src/where.c index f45da74794..f40b051a56 100644 --- a/src/where.c +++ b/src/where.c @@ -1614,7 +1614,8 @@ static void constructAutomaticIndex( for(pTerm=pWC->a; pTermprereq==0 && (pTerm->wtFlags & TERM_VIRTUAL)==0 - && !ExprHasProperty(pTerm->pExpr, EP_FromJoin) + && (!ExprHasProperty(pTerm->pExpr, EP_FromJoin) + || pTerm->pExpr->iRightJoinTable==pSrc->iCursor) && sqlite3ExprIsTableConstant(pTerm->pExpr, pSrc->iCursor) ){ pPartial = sqlite3ExprAnd(pParse->db, pPartial, sqlite3ExprDup(pParse->db, pTerm->pExpr, 0)); @@ -4695,8 +4696,9 @@ static int whereUsablePartialIndex(int iTab, WhereClause *pWC, Expr *pWhere){ int i; WhereTerm *pTerm; for(i=0, pTerm=pWC->a; inTerm; i++, pTerm++){ - if( sqlite3ExprImpliesExpr(pTerm->pExpr, pWhere, iTab) - && !ExprHasProperty(pTerm->pExpr, EP_FromJoin) + Expr *pExpr = pTerm->pExpr; + if( sqlite3ExprImpliesExpr(pExpr, pWhere, iTab) + && (!ExprHasProperty(pExpr, EP_FromJoin) || pExpr->iRightJoinTable==iTab) ){ return 1; } diff --git a/test/index6.test b/test/index6.test index 8414b11baa..69fae49feb 100644 --- a/test/index6.test +++ b/test/index6.test @@ -296,4 +296,35 @@ do_execsql_test index6-7.4 { SELECT * FROM t7a JOIN t7b ON (x=99) ORDER BY x; } {/USING COVERING INDEX t7ax/} + +do_execsql_test index6-8.0 { + CREATE TABLE t8a(a,b); + CREATE TABLE t8b(x,y); + CREATE INDEX i8c ON t8b(y) WHERE x = 'value'; + + INSERT INTO t8a VALUES(1, 'one'); + INSERT INTO t8a VALUES(2, 'two'); + INSERT INTO t8a VALUES(3, 'three'); + + INSERT INTO t8b VALUES('value', 1); + INSERT INTO t8b VALUES('dummy', 2); + INSERT INTO t8b VALUES('value', 3); + INSERT INTO t8b VALUES('dummy', 4); +} {} + +do_eqp_test index6-8.1 { + SELECT * FROM t8a LEFT JOIN t8b ON (x = 'value' AND y = a) +} { + 0 0 0 {SCAN TABLE t8a} + 0 1 1 {SEARCH TABLE t8b USING INDEX i8c (y=?)} +} + +do_execsql_test index6-8.2 { + SELECT * FROM t8a LEFT JOIN t8b ON (x = 'value' AND y = a) +} { + 1 one value 1 + 2 two {} {} + 3 three value 3 +} + finish_test From 13cc90cfa208c8ca3f9b7ca27b11f977bda92d71 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 25 Feb 2015 00:24:41 +0000 Subject: [PATCH 54/62] Remove an always-false conditional from constructAutomaticIndex(). Put an assert() in its place to prove that the conditional is always false. FossilOrigin-Name: 3af300bf6f5bee0b51a4c1ac1dc3879771378bff --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/where.c | 11 +++++++---- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/manifest b/manifest index c6a94d0d59..b8fa723431 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Prevent\spartial\sindexes\son\sthe\stable\son\sthe\sleft\shand\sside\sof\sa\sLEFT\sJOIN\sfrom\sbeing\sincorrectly\squalified\sby\sa\sconstraint\sin\sthe\sON\sclause\sof\sthe\sjoin.\sThis\srelaxes\sthe\srule\sintroduced\sby\sthe\sprevious\scommit\s(as\sthe\spartial\sindexes\son\sthe\stable\son\sthe\srhs\sof\sthe\sLEFT\sJOIN\smay\snow\sbe\squalified\sby\sterms\swithin\sthe\sON\sclause). -D 2015-02-24T20:10:49.082 +C Remove\san\salways-false\sconditional\sfrom\sconstructAutomaticIndex().\s\sPut\san\nassert()\sin\sits\splace\sto\sprove\sthat\sthe\sconditional\sis\salways\sfalse. +D 2015-02-25T00:24:41.524 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 6b9e7677829aa94b9f30949656e27312aefb9a46 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -306,7 +306,7 @@ F src/vtab.c 699f2b8d509cfe379c33dde33827875d5b030e01 F src/wal.c 39303f2c9db02a4e422cd8eb2c8760420c6a51fe F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4 F src/walker.c c253b95b4ee44b21c406e2a1052636c31ea27804 -F src/where.c 294423cf9a3c46377c3e246338ff2a38365ad922 +F src/where.c a50d5082b0fecd2bcf1725cdd012732d9d1e9d5c F src/whereInt.h d3633e9b592103241b74b0ec76185f3e5b8b62e0 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2 @@ -1239,7 +1239,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 491cfe9b3f87f5fcc579f953745012cea8d64db7 -R ca86a79194d1da36938ef90c0f8f3a89 -U dan -Z 37d3633be74b06dd46fb3d2721885844 +P 1d6fb43a576d335d2717e94d28385178c23c81a1 +R 3a88db56d427fb7fb84c3827bb156d55 +U drh +Z d1736e186e6b8e2f484863856fdaa011 diff --git a/manifest.uuid b/manifest.uuid index cd9fd72c3a..bdbc030145 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -1d6fb43a576d335d2717e94d28385178c23c81a1 \ No newline at end of file +3af300bf6f5bee0b51a4c1ac1dc3879771378bff \ No newline at end of file diff --git a/src/where.c b/src/where.c index f40b051a56..d01945de7f 100644 --- a/src/where.c +++ b/src/where.c @@ -1612,13 +1612,16 @@ static void constructAutomaticIndex( pLoop = pLevel->pWLoop; idxCols = 0; for(pTerm=pWC->a; pTermpExpr; + assert( !ExprHasProperty(pExpr, EP_FromJoin) /* prereq always non-zero */ + || pExpr->iRightJoinTable!=pSrc->iCursor /* for the right-hand */ + || pLoop->prereq!=0 ); /* table of a LEFT JOIN */ if( pLoop->prereq==0 && (pTerm->wtFlags & TERM_VIRTUAL)==0 - && (!ExprHasProperty(pTerm->pExpr, EP_FromJoin) - || pTerm->pExpr->iRightJoinTable==pSrc->iCursor) - && sqlite3ExprIsTableConstant(pTerm->pExpr, pSrc->iCursor) ){ + && !ExprHasProperty(pExpr, EP_FromJoin) + && sqlite3ExprIsTableConstant(pExpr, pSrc->iCursor) ){ pPartial = sqlite3ExprAnd(pParse->db, pPartial, - sqlite3ExprDup(pParse->db, pTerm->pExpr, 0)); + sqlite3ExprDup(pParse->db, pExpr, 0)); } if( termCanDriveIndex(pTerm, pSrc, notReady) ){ int iCol = pTerm->u.leftColumn; From 8d8738eae07ae397e2fef22787d6080769022600 Mon Sep 17 00:00:00 2001 From: mistachkin Date: Wed, 25 Feb 2015 01:06:08 +0000 Subject: [PATCH 55/62] When cleaning with MSVC, prevent superfluous output regarding 'missing' files and directories. FossilOrigin-Name: 034c16bd24ddca363946a4b8751418469d890d2a --- Makefile.msc | 52 +++++++++++++++++++++++++-------------------------- manifest | 14 +++++++------- manifest.uuid | 2 +- 3 files changed, 34 insertions(+), 34 deletions(-) diff --git a/Makefile.msc b/Makefile.msc index 4621661ee5..1d491c432f 100644 --- a/Makefile.msc +++ b/Makefile.msc @@ -1536,32 +1536,32 @@ speedtest1.exe: $(TOP)\test\speedtest1.c $(SQLITE3C) $(TOP)\test\speedtest1.c $(SQLITE3C) clean: - del /Q *.lo *.ilk *.lib *.obj *.pdb sqlite3.exe libsqlite3.lib - del /Q *.cod *.da *.bb *.bbg gmon.out - del /Q sqlite3.h opcodes.c opcodes.h - del /Q lemon.* lempar.c parse.* - del /Q mkkeywordhash.* keywordhash.h - del /Q notasharedlib.* - -rmdir /Q/S .deps - -rmdir /Q/S .libs - -rmdir /Q/S quota2a - -rmdir /Q/S quota2b - -rmdir /Q/S quota2c - -rmdir /Q/S tsrc - del /Q .target_source - del /Q tclsqlite3.exe tclsqlite3.exp - del /Q testloadext.dll testloadext.exp - del /Q testfixture.exe testfixture.exp test.db - del /Q LogEst.exe fts3view.exe rollback-test.exe showdb.exe - del /Q showjournal.exe showstat4.exe showwal.exe speedtest1.exe - del /Q wordcount.exe - del /Q sqlite3.dll sqlite3.lib sqlite3.exp sqlite3.def - del /Q sqlite3.c sqlite3-*.c - del /Q sqlite3rc.h - del /Q shell.c sqlite3ext.h - del /Q sqlite3_analyzer.exe sqlite3_analyzer.exp sqlite3_analyzer.c - del /Q sqlite-*-output.vsix - del /Q mptester.exe + del /Q *.lo *.ilk *.lib *.obj *.pdb sqlite3.exe libsqlite3.lib 2>NUL + del /Q *.cod *.da *.bb *.bbg gmon.out 2>NUL + del /Q sqlite3.h 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 + -rmdir /Q/S .deps 2>NUL + -rmdir /Q/S .libs 2>NUL + -rmdir /Q/S quota2a 2>NUL + -rmdir /Q/S quota2b 2>NUL + -rmdir /Q/S quota2c 2>NUL + -rmdir /Q/S tsrc 2>NUL + del /Q .target_source 2>NUL + del /Q tclsqlite3.exe tclsqlite3.exp 2>NUL + del /Q testloadext.dll testloadext.exp 2>NUL + del /Q testfixture.exe testfixture.exp 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 wordcount.exe 2>NUL + del /Q sqlite3.dll sqlite3.lib sqlite3.exp 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 + del /Q sqlite3_analyzer.exe sqlite3_analyzer.exp sqlite3_analyzer.c 2>NUL + del /Q sqlite-*-output.vsix 2>NUL + del /Q mptester.exe 2>NUL # Dynamic link library section. # diff --git a/manifest b/manifest index b8fa723431..d3509b8688 100644 --- a/manifest +++ b/manifest @@ -1,9 +1,9 @@ -C Remove\san\salways-false\sconditional\sfrom\sconstructAutomaticIndex().\s\sPut\san\nassert()\sin\sits\splace\sto\sprove\sthat\sthe\sconditional\sis\salways\sfalse. -D 2015-02-25T00:24:41.524 +C When\scleaning\swith\sMSVC,\sprevent\ssuperfluous\soutput\sregarding\s'missing'\sfiles\sand\sdirectories. +D 2015-02-25T01:06:08.853 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 6b9e7677829aa94b9f30949656e27312aefb9a46 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 -F Makefile.msc fc6b0b233b5621f3e56298e4d6a0b3f6c936c520 +F Makefile.msc edbe2e2a9d27a4a56bd2891808a7c013bc322f6e F Makefile.vxworks e1b65dea203f054e71653415bd8f96dcaed47858 F README.md d58e3bebc0a4145e0f2a87994015fdb575a8e866 F VERSION d846487aff892625eb8e75960234e7285f0462fe @@ -1239,7 +1239,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 1d6fb43a576d335d2717e94d28385178c23c81a1 -R 3a88db56d427fb7fb84c3827bb156d55 -U drh -Z d1736e186e6b8e2f484863856fdaa011 +P 3af300bf6f5bee0b51a4c1ac1dc3879771378bff +R 8787792779793757c506c3a0c170c525 +U mistachkin +Z 74a7e954f31f0d389c5ddd5c11bb86cc diff --git a/manifest.uuid b/manifest.uuid index bdbc030145..004261669d 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -3af300bf6f5bee0b51a4c1ac1dc3879771378bff \ No newline at end of file +034c16bd24ddca363946a4b8751418469d890d2a \ No newline at end of file From fd34d6d37944cfe142140eb73fd393226812cd8b Mon Sep 17 00:00:00 2001 From: dan Date: Wed, 25 Feb 2015 10:54:53 +0000 Subject: [PATCH 56/62] Add support for linenoise to shell.c. FossilOrigin-Name: f7f2598c376a27a86acc21578779c03d0016cd30 --- manifest | 17 ++++++++++------- manifest.uuid | 2 +- src/shell.c | 52 ++++++++++++++++++++++++++++++++++----------------- 3 files changed, 46 insertions(+), 25 deletions(-) diff --git a/manifest b/manifest index d3509b8688..dc53d9cb05 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C When\scleaning\swith\sMSVC,\sprevent\ssuperfluous\soutput\sregarding\s'missing'\sfiles\sand\sdirectories. -D 2015-02-25T01:06:08.853 +C Add\ssupport\sfor\slinenoise\sto\sshell.c. +D 2015-02-25T10:54:53.924 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 6b9e7677829aa94b9f30949656e27312aefb9a46 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -231,7 +231,7 @@ F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c f4d79e31ffa5820c2e3d1740baa5e9b190425f2b F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e F src/select.c e46cef4c224549b439384c88fc7f57ba064dad54 -F src/shell.c 6276582ee4e9114e0bb0795772414caaf21c0f8e +F src/shell.c f06cca68a3f07e03d35d2f879375967169db6a61 F src/sqlite.h.in 86cddbfdb3155967858c1469108813bcc08eda21 F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h 17d487c3c91b0b8c584a32fbeb393f6f795eea7d @@ -1239,7 +1239,10 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 3af300bf6f5bee0b51a4c1ac1dc3879771378bff -R 8787792779793757c506c3a0c170c525 -U mistachkin -Z 74a7e954f31f0d389c5ddd5c11bb86cc +P 034c16bd24ddca363946a4b8751418469d890d2a +R 39a5a9d65bc63648e34cb80c3dc9dec4 +T *branch * linenoise +T *sym-linenoise * +T -sym-trunk * +U dan +Z 309f98e10b08754fd0af3602fd92a078 diff --git a/manifest.uuid b/manifest.uuid index 004261669d..e18b0b871d 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -034c16bd24ddca363946a4b8751418469d890d2a \ No newline at end of file +f7f2598c376a27a86acc21578779c03d0016cd30 \ No newline at end of file diff --git a/src/shell.c b/src/shell.c index e0d0b78b7d..4aaa2d90ec 100644 --- a/src/shell.c +++ b/src/shell.c @@ -59,18 +59,38 @@ # include # include #endif + #if HAVE_EDITLINE -# undef HAVE_READLINE -# define HAVE_READLINE 1 # include #endif -#if !HAVE_READLINE -# define add_history(X) -# define read_history(X) -# define write_history(X) -# define stifle_history(X) + +#if HAVE_EDITLINE || HAVE_READLINE + +# define shell_add_history(X) add_history(X) +# define shell_read_history(X) read_history(X) +# define shell_write_history(X) write_history(X) +# define shell_stifle_history(X) stifle_history(X) +# define shell_readline(X) readline(X) + +#elif HAVE_LINENOISE + +# include "linenoise.h" +# define shell_add_history(X) linenoiseHistoryAdd(X) +# define shell_read_history(X) linenoiseHistoryLoad(X) +# define shell_write_history(X) linenoiseHistorySave(X) +# define shell_stifle_history(X) linenoiseHistorySetMaxLen(X) +# define shell_readline(X) linenoise(X) + +#else + +# define shell_read_history(X) +# define shell_write_history(X) +# define shell_stifle_history(X) + +# define SHELL_USE_LOCAL_GETLINE 1 #endif + #if defined(_WIN32) || defined(WIN32) # include # include @@ -451,14 +471,14 @@ static char *one_input_line(FILE *in, char *zPrior, int isContinuation){ zResult = local_getline(zPrior, in); }else{ zPrompt = isContinuation ? continuePrompt : mainPrompt; -#if HAVE_READLINE - free(zPrior); - zResult = readline(zPrompt); - if( zResult && *zResult ) add_history(zResult); -#else +#if SHELL_USE_LOCAL_GETLINE printf("%s", zPrompt); fflush(stdout); zResult = local_getline(zPrior, stdin); +#else + free(zPrior); + zResult = shell_readline(zPrompt); + if( zResult && *zResult ) shell_add_history(zResult); #endif } return zResult; @@ -4636,13 +4656,11 @@ int main(int argc, char **argv){ sqlite3_snprintf(nHistory, zHistory,"%s/.sqlite_history", zHome); } } -#if HAVE_READLINE - if( zHistory ) read_history(zHistory); -#endif + if( zHistory ) shell_read_history(zHistory); rc = process_input(&data, 0); if( zHistory ){ - stifle_history(100); - write_history(zHistory); + shell_stifle_history(100); + shell_write_history(zHistory); free(zHistory); } }else{ From cbb3f33c56414d2e5f70af3099e2945420b51cee Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 25 Feb 2015 14:25:31 +0000 Subject: [PATCH 57/62] Make sure the sqlite3_mutex.id field is initialized in the Win32 mutex implementation, even when SQLITE_DEBUG is turned off. FossilOrigin-Name: 6d132e7a224ee68b5cefe9222944aac5760ffc20 --- manifest | 13 ++++++------- manifest.uuid | 2 +- src/mutex_w32.c | 4 ++-- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index d67728f0c0..e6e5711336 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\ssupport\sfor\sthe\slinenoise\scommand-line\sediting\slibrary\sin\sshell.c. -D 2015-02-25T13:48:10.884 +C Make\ssure\sthe\ssqlite3_mutex.id\sfield\sis\sinitialized\sin\sthe\sWin32\nmutex\simplementation,\seven\swhen\sSQLITE_DEBUG\sis\sturned\soff. +D 2015-02-25T14:25:31.047 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 6b9e7677829aa94b9f30949656e27312aefb9a46 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -208,7 +208,7 @@ F src/mutex.c 19bf9acba69ca2f367c3761080f8a9f0cf4670a8 F src/mutex.h 779d588e3b7756ec3ecf7d78cde1d84aba414f85 F src/mutex_noop.c 529bab0743c3321c940f32c3464de494fd38cfa9 F src/mutex_unix.c 5cf676464bd19e0a866297515d146e8bf1669dfb -F src/mutex_w32.c a6f0b84068db2cbd96a94f23c622aeb875c57dff +F src/mutex_w32.c 61660ada28d8308ad190f444c2170c4f2a590c2f F src/notify.c 9711a7575036f0d3040ba61bc6e217f13a9888e7 F src/os.c 8fd25588eeba74068d41102d26810e216999b6c8 F src/os.h 3e57a24e2794a94d3cf2342c6d9a884888cd96bf @@ -1239,8 +1239,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 034c16bd24ddca363946a4b8751418469d890d2a f7f2598c376a27a86acc21578779c03d0016cd30 -R 39a5a9d65bc63648e34cb80c3dc9dec4 -T +closed f7f2598c376a27a86acc21578779c03d0016cd30 +P 03bbb947192b0c28d960604eae12e5fc2fa6e74e +R 0ad5cee8f09a4692c3924d804df85893 U drh -Z c8318c1240f80cb8fe06db610b0ca5b1 +Z 3ea920f4ffaac12fb90626f34318b0eb diff --git a/manifest.uuid b/manifest.uuid index acb199a50a..cc37c0191d 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -03bbb947192b0c28d960604eae12e5fc2fa6e74e \ No newline at end of file +6d132e7a224ee68b5cefe9222944aac5760ffc20 \ No newline at end of file diff --git a/src/mutex_w32.c b/src/mutex_w32.c index 284355f578..6786614d8e 100644 --- a/src/mutex_w32.c +++ b/src/mutex_w32.c @@ -194,8 +194,8 @@ static sqlite3_mutex *winMutexAlloc(int iType){ case SQLITE_MUTEX_RECURSIVE: { p = sqlite3MallocZero( sizeof(*p) ); if( p ){ -#ifdef SQLITE_DEBUG p->id = iType; +#ifdef SQLITE_DEBUG #ifdef SQLITE_WIN32_MUTEX_TRACE_DYNAMIC p->trace = 1; #endif @@ -216,8 +216,8 @@ static sqlite3_mutex *winMutexAlloc(int iType){ } #endif p = &winMutex_staticMutexes[iType-2]; -#ifdef SQLITE_DEBUG p->id = iType; +#ifdef SQLITE_DEBUG #ifdef SQLITE_WIN32_MUTEX_TRACE_STATIC p->trace = 1; #endif From c941a4b3b641e7319241583334dda0f4e11caceb Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 26 Feb 2015 02:33:52 +0000 Subject: [PATCH 58/62] Simplifications to the description of the nByte parameter to sqlite3_prepare() and friends. FossilOrigin-Name: 4bee8295e36fb61f903210b6d052ee9b8fb3b6d0 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/sqlite.h.in | 18 ++++++++---------- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/manifest b/manifest index e6e5711336..54ad7184b2 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Make\ssure\sthe\ssqlite3_mutex.id\sfield\sis\sinitialized\sin\sthe\sWin32\nmutex\simplementation,\seven\swhen\sSQLITE_DEBUG\sis\sturned\soff. -D 2015-02-25T14:25:31.047 +C Simplifications\sto\sthe\sdescription\sof\sthe\snByte\sparameter\sto\ssqlite3_prepare()\nand\sfriends. +D 2015-02-26T02:33:52.248 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 6b9e7677829aa94b9f30949656e27312aefb9a46 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -232,7 +232,7 @@ F src/resolve.c f4d79e31ffa5820c2e3d1740baa5e9b190425f2b F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e F src/select.c e46cef4c224549b439384c88fc7f57ba064dad54 F src/shell.c f06cca68a3f07e03d35d2f879375967169db6a61 -F src/sqlite.h.in 86cddbfdb3155967858c1469108813bcc08eda21 +F src/sqlite.h.in 62d3997824038cc32335b04aaa18cc8f4c19e9be F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h 17d487c3c91b0b8c584a32fbeb393f6f795eea7d F src/sqliteInt.h 57a405ae6d2ed10fff52de376d18f21e04d96609 @@ -1239,7 +1239,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 03bbb947192b0c28d960604eae12e5fc2fa6e74e -R 0ad5cee8f09a4692c3924d804df85893 +P 6d132e7a224ee68b5cefe9222944aac5760ffc20 +R 32aba763c92a19bba8ed1b93e2ee7564 U drh -Z 3ea920f4ffaac12fb90626f34318b0eb +Z b332eede7bc32b2767cceb08a9880768 diff --git a/manifest.uuid b/manifest.uuid index cc37c0191d..07f7cba1c2 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -6d132e7a224ee68b5cefe9222944aac5760ffc20 \ No newline at end of file +4bee8295e36fb61f903210b6d052ee9b8fb3b6d0 \ No newline at end of file diff --git a/src/sqlite.h.in b/src/sqlite.h.in index ee910393e6..b7cac497e7 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -3182,16 +3182,14 @@ int sqlite3_limit(sqlite3*, int id, int newVal); ** interfaces use UTF-8, and sqlite3_prepare16() and sqlite3_prepare16_v2() ** use UTF-16. ** -** ^If the nByte argument is less than zero, then zSql is read up to the -** first zero terminator. ^If nByte is non-negative, then it is the maximum -** number of bytes read from zSql. ^When nByte is non-negative, the -** zSql string ends at either the first '\000' or '\u0000' character or -** the nByte-th byte, whichever comes first. If the caller knows -** that the supplied string is nul-terminated, then there is a small -** performance advantage to be gained by passing an nByte parameter that -** is equal to the number of bytes in the input string including -** the nul-terminator bytes as this saves SQLite from having to -** make a copy of the input string. +** ^If the nByte argument is negative, then zSql is read up to the +** first zero terminator. ^If nByte is positive, then it is the +** number of bytes read from zSql. ^If nByte is zero, then no prepared +** statement is generated. +** If the caller knows that the supplied string is nul-terminated, then +** there is a small performance advantage to passing an nByte parameter that +** is the number of bytes in the input string including +** the nul-terminator. ** ** ^If pzTail is not NULL then *pzTail is made to point to the first byte ** past the end of the first SQL statement in zSql. These routines only From 05f6c67cc180ea6770585c0d4bcc0aee77a6bad4 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 26 Feb 2015 16:32:33 +0000 Subject: [PATCH 59/62] Fix a real bug (in test code) that was introduced while trying to eliminate harmless compiler warnings from OpenBSD (see check-in [10321910990195878c]). FossilOrigin-Name: a62ba58c737656fae620d9cdaaae299104ac06f6 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/tclsqlite.c | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 54ad7184b2..98fbd897f7 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Simplifications\sto\sthe\sdescription\sof\sthe\snByte\sparameter\sto\ssqlite3_prepare()\nand\sfriends. -D 2015-02-26T02:33:52.248 +C Fix\sa\sreal\sbug\s(in\stest\scode)\sthat\swas\sintroduced\swhile\strying\sto\seliminate\nharmless\scompiler\swarnings\sfrom\sOpenBSD\s(see\scheck-in\s[10321910990195878c]). +D 2015-02-26T16:32:33.621 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 6b9e7677829aa94b9f30949656e27312aefb9a46 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -239,7 +239,7 @@ F src/sqliteInt.h 57a405ae6d2ed10fff52de376d18f21e04d96609 F src/sqliteLimit.h 164b0e6749d31e0daa1a4589a169d31c0dec7b3d F src/status.c 81712116e826b0089bb221b018929536b2b5406f F src/table.c e7a09215315a978057fb42c640f890160dbcc45e -F src/tclsqlite.c b8014393a96a9781bb635c8b1f52fc9b77a2bfcf +F src/tclsqlite.c b290774586f022e16e04ba8ed2f0b8edd86b5b77 F src/test1.c 90fbedce75330d48d99eadb7d5f4223e86969585 F src/test2.c 577961fe48961b2f2e5c8b56ee50c3f459d3359d F src/test3.c 64d2afdd68feac1bb5e2ffb8226c8c639f798622 @@ -1239,7 +1239,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 6d132e7a224ee68b5cefe9222944aac5760ffc20 -R 32aba763c92a19bba8ed1b93e2ee7564 +P 4bee8295e36fb61f903210b6d052ee9b8fb3b6d0 +R b2eab9c50d96affd3b5f18c0bbfa30e2 U drh -Z b332eede7bc32b2767cceb08a9880768 +Z aab122678a648eda2debfa9adc01f9ac diff --git a/manifest.uuid b/manifest.uuid index 07f7cba1c2..8c5dda702f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -4bee8295e36fb61f903210b6d052ee9b8fb3b6d0 \ No newline at end of file +a62ba58c737656fae620d9cdaaae299104ac06f6 \ No newline at end of file diff --git a/src/tclsqlite.c b/src/tclsqlite.c index b1d4dc413c..549a410b28 100644 --- a/src/tclsqlite.c +++ b/src/tclsqlite.c @@ -3429,7 +3429,7 @@ static void MD5DigestToBase10x8(unsigned char digest[16], char zDigest[50]){ for(i=j=0; i<16; i+=2){ x = digest[i]*256 + digest[i+1]; if( i>0 ) zDigest[j++] = '-'; - sqlite3_snprintf(16-j, &zDigest[j], "%05u", x); + sqlite3_snprintf(50-j, &zDigest[j], "%05u", x); j += 5; } zDigest[j] = 0; From 531b55ead0e2063575d1dcead08fa12d82a454c5 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 26 Feb 2015 16:40:41 +0000 Subject: [PATCH 60/62] Update a requirements mark to reflect a change of wording in the documentation. No changes to code. FossilOrigin-Name: 3038d0169bfc3f63d64c7fef20ab2323d032655f --- manifest | 12 ++++++------ manifest.uuid | 2 +- test/e_wal.test | 9 +++++---- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index 98fbd897f7..bb17e20589 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sreal\sbug\s(in\stest\scode)\sthat\swas\sintroduced\swhile\strying\sto\seliminate\nharmless\scompiler\swarnings\sfrom\sOpenBSD\s(see\scheck-in\s[10321910990195878c]). -D 2015-02-26T16:32:33.621 +C Update\sa\srequirements\smark\sto\sreflect\sa\schange\sof\swording\sin\sthe\sdocumentation.\nNo\schanges\sto\scode. +D 2015-02-26T16:40:41.460 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 6b9e7677829aa94b9f30949656e27312aefb9a46 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -479,7 +479,7 @@ F test/e_totalchanges.test b12ee5809d3e63aeb83238dd501a7bca7fd72c10 F test/e_update.test 312cb8f5ccfe41515a6bb092f8ea562a9bd54d52 F test/e_uri.test 5ae33760fb2039c61aa2d90886f1664664173585 F test/e_vacuum.test 5bfbdc21b65c0abf24398d0ba31dc88d93ca77a9 -F test/e_wal.test 0967f0b8f1dfda871dc7b9b5574198f1f4f7d69a +F test/e_wal.test ae9a593207a77d711443ee69ffe081fda9243625 F test/e_walauto.test ca70cf75c07a6cb1874ced101dd426da76625649 F test/e_walckpt.test 65e29b6631e51f210f83e4ff11571e647ba93608 F test/e_walhook.test da3ea8b3483d1af72190337bda50155a91a4b664 @@ -1239,7 +1239,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 4bee8295e36fb61f903210b6d052ee9b8fb3b6d0 -R b2eab9c50d96affd3b5f18c0bbfa30e2 +P a62ba58c737656fae620d9cdaaae299104ac06f6 +R 10478383687ae87f2012aeaa926b3297 U drh -Z aab122678a648eda2debfa9adc01f9ac +Z ebf66855f11c3f65a39c6b4bb93adf68 diff --git a/manifest.uuid b/manifest.uuid index 8c5dda702f..001a5cd348 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -a62ba58c737656fae620d9cdaaae299104ac06f6 \ No newline at end of file +3038d0169bfc3f63d64c7fef20ab2323d032655f \ No newline at end of file diff --git a/test/e_wal.test b/test/e_wal.test index a5e074f49b..77ac83a0ae 100644 --- a/test/e_wal.test +++ b/test/e_wal.test @@ -200,10 +200,11 @@ do_test 3.4.2 { db close -# EVIDENCE-OF: R-22428-28959 To prevent older versions of SQLite from -# trying to recover a WAL-mode database (and making matters worse) the -# database file format version numbers (bytes 18 and 19 in the database -# header) are increased from 1 to 2 in WAL mode. +# EVIDENCE-OF: R-45540-25505 To prevent older versions of SQLite (prior +# to version 3.7.0, 2010-07-22) from trying to recover a WAL-mode +# database (and making matters worse) the database file format version +# numbers (bytes 18 and 19 in the database header) are increased from 1 +# to 2 in WAL mode. # reset_db do_execsql_test 4.1.1 { CREATE TABLE t1(x, y) } From 38e40ee2e5e4960bd5c7247018da08b018f1b552 Mon Sep 17 00:00:00 2001 From: mistachkin Date: Thu, 26 Feb 2015 21:04:44 +0000 Subject: [PATCH 61/62] Fix potential memory leaks in the misc 'compress' extension. FossilOrigin-Name: 3bc34fd427d9d7819cd9740237b1f5d4180341fa --- ext/misc/compress.c | 11 +++++++++-- manifest | 14 +++++++------- manifest.uuid | 2 +- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/ext/misc/compress.c b/ext/misc/compress.c index a4059116c9..bf38d4c93c 100644 --- a/ext/misc/compress.c +++ b/ext/misc/compress.c @@ -38,6 +38,7 @@ static void compressFunc( unsigned int nIn; unsigned long int nOut; unsigned char x[8]; + int rc; int i, j; pIn = sqlite3_value_blob(argv[0]); @@ -50,8 +51,12 @@ static void compressFunc( for(i=0; i<4 && x[i]==0; i++){} for(j=0; i<=4; i++, j++) pOut[j] = x[i]; pOut[j-1] |= 0x80; - compress(&pOut[j], &nOut, pIn, nIn); - sqlite3_result_blob(context, pOut, nOut+j, sqlite3_free); + rc = compress(&pOut[j], &nOut, pIn, nIn); + if( rc==Z_OK ){ + sqlite3_result_blob(context, pOut, nOut+j, sqlite3_free); + }else{ + sqlite3_free(pOut); + } } /* @@ -82,6 +87,8 @@ static void uncompressFunc( rc = uncompress(pOut, &nOut, &pIn[i], nIn-i); if( rc==Z_OK ){ sqlite3_result_blob(context, pOut, nOut, sqlite3_free); + }else{ + sqlite3_free(pOut); } } diff --git a/manifest b/manifest index bb17e20589..c2419455e1 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Update\sa\srequirements\smark\sto\sreflect\sa\schange\sof\swording\sin\sthe\sdocumentation.\nNo\schanges\sto\scode. -D 2015-02-26T16:40:41.460 +C Fix\spotential\smemory\sleaks\sin\sthe\smisc\s'compress'\sextension. +D 2015-02-26T21:04:44.709 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 6b9e7677829aa94b9f30949656e27312aefb9a46 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -108,7 +108,7 @@ F ext/icu/icu.c d415ccf984defeb9df2c0e1afcfaa2f6dc05eacb F ext/icu/sqliteicu.h 728867a802baa5a96de7495e9689a8e01715ef37 F ext/misc/amatch.c 27b9b601fb1453084e18a3432ea0240d7af8decb F ext/misc/closure.c 636024302cde41b2bf0c542f81c40c624cfb7012 -F ext/misc/compress.c 76e45655f4046e756064ab10c62e18f2eb846b9f +F ext/misc/compress.c 122faa92d25033d6c3f07c39231de074ab3d2e83 F ext/misc/eval.c f971962e92ebb8b0a4e6b62949463ee454d88fa2 F ext/misc/fileio.c d4171c815d6543a9edef8308aab2951413cd8d0f F ext/misc/fuzzer.c e3e18f47252c151b5553d7e806f38e757d37c4cc @@ -1239,7 +1239,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P a62ba58c737656fae620d9cdaaae299104ac06f6 -R 10478383687ae87f2012aeaa926b3297 -U drh -Z ebf66855f11c3f65a39c6b4bb93adf68 +P 3038d0169bfc3f63d64c7fef20ab2323d032655f +R 92275b863621a447a1ee2bc5287be291 +U mistachkin +Z 13fe93e6bf28cbbfddb5268264090ce6 diff --git a/manifest.uuid b/manifest.uuid index 001a5cd348..a8a6350637 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -3038d0169bfc3f63d64c7fef20ab2323d032655f \ No newline at end of file +3bc34fd427d9d7819cd9740237b1f5d4180341fa \ No newline at end of file From 22ec13466cbc6ce4f3cc642e5c23c5d52dcace27 Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 27 Feb 2015 00:33:15 +0000 Subject: [PATCH 62/62] Add a couple of requirements marks. FossilOrigin-Name: d70b0fd4c94f2b70cf31c2ab9ef7a2fb2e71c182 --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/vdbeapi.c | 4 ++++ test/capi3.test | 14 +++++++++++++- 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index c2419455e1..b4667b6c06 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\spotential\smemory\sleaks\sin\sthe\smisc\s'compress'\sextension. -D 2015-02-26T21:04:44.709 +C Add\sa\scouple\sof\srequirements\smarks. +D 2015-02-27T00:33:15.390 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 6b9e7677829aa94b9f30949656e27312aefb9a46 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -296,7 +296,7 @@ F src/vacuum.c 9460b9de7b2d4e34b0d374894aa6c8a0632be8ec F src/vdbe.c ddfc977981cd6324668aa6b114045eb1c677421a F src/vdbe.h 6fc69d9c5e146302c56e163cb4b31d1ee64a18c3 F src/vdbeInt.h bb56fd199d8af1a2c1b9639ee2f70724b4338e3a -F src/vdbeapi.c 3d88089b10f71750b019a806224f0277d371a072 +F src/vdbeapi.c dac0d0d8009a8aa549cd77d9c29da44c0344f0c4 F src/vdbeaux.c 97911edb61074b871ec4aa2d6bb779071643dee5 F src/vdbeblob.c 4f2e8e075d238392df98c5e03a64342465b03f90 F src/vdbemem.c 31d8eabb0cd78bfeab4e5124c7363c3e9e54db9f @@ -386,7 +386,7 @@ F test/btreefault.test c2bcb542685eea44621275cfedbd8a13f65201e3 F test/busy.test 76b4887f8b9160ba903c1ac22e8ff406ad6ae2f0 F test/cache.test 13bc046b26210471ca6f2889aceb1ea52dc717de F test/capi2.test 011c16da245fdc0106a2785035de6b242c05e738 -F test/capi3.test f0718f4f90d0efdc980119bfbdf1d7f1541ee5ef +F test/capi3.test bf6f0308bbbba1e770dac13aa08e5c2ac61c7324 F test/capi3b.test efb2b9cfd127efa84433cd7a2d72ce0454ae0dc4 F test/capi3c.test fdc0d67a2cb8e8fc400d5b7735e330161ea057a2 F test/capi3d.test a82b6321c50a1cfc848e386fa2c851893606f68c @@ -1239,7 +1239,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 3038d0169bfc3f63d64c7fef20ab2323d032655f -R 92275b863621a447a1ee2bc5287be291 -U mistachkin -Z 13fe93e6bf28cbbfddb5268264090ce6 +P 3bc34fd427d9d7819cd9740237b1f5d4180341fa +R ea56360259f5f37b0ed4591b0dd003bd +U drh +Z c0882f7c7d1c49cd54726f112c10b39e diff --git a/manifest.uuid b/manifest.uuid index a8a6350637..1881ff1d28 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -3bc34fd427d9d7819cd9740237b1f5d4180341fa \ No newline at end of file +d70b0fd4c94f2b70cf31c2ab9ef7a2fb2e71c182 \ No newline at end of file diff --git a/src/vdbeapi.c b/src/vdbeapi.c index b29338eb3d..8c0038e4e8 100644 --- a/src/vdbeapi.c +++ b/src/vdbeapi.c @@ -170,6 +170,10 @@ const void *sqlite3_value_text16le(sqlite3_value *pVal){ return sqlite3ValueText(pVal, SQLITE_UTF16LE); } #endif /* SQLITE_OMIT_UTF16 */ +/* EVIDENCE-OF: R-12793-43283 Every value in SQLite has one of five +** fundamental datatypes: 64-bit signed integer 64-bit IEEE floating +** point number string BLOB NULL +*/ int sqlite3_value_type(sqlite3_value* pVal){ static const u8 aType[] = { SQLITE_BLOB, /* 0x00 */ diff --git a/test/capi3.test b/test/capi3.test index 9f3d6f6916..163bb19ada 100644 --- a/test/capi3.test +++ b/test/capi3.test @@ -452,9 +452,21 @@ proc check_data {STMT test types ints doubles strings} { # types do_test $test.1 { set types [list] - foreach i $idxlist {lappend types [sqlite3_column_type $STMT $i]} + foreach i $idxlist { + set x [sqlite3_column_type $STMT $i] + # EVIDENCE-OF: R-12793-43283 Every value in SQLite has one of five + # fundamental datatypes: 64-bit signed integer 64-bit IEEE floating + # point number string BLOB NULL + if {[lsearch {INTEGER FLOAT TEXT BLOB NULL} $x]<0} { + set types ERROR + break + } else { + lappend types $x + } + } set types } $types + # Integers do_test $test.2 {