From 39caccf83d7c8af6f5b2e1a747c4adebe2307031 Mon Sep 17 00:00:00 2001 From: dan Date: Tue, 1 Jul 2014 11:54:02 +0000 Subject: [PATCH 01/37] Ensure that all fields are loaded from the stat4 table for records that correspond to indexes on WITHOUT ROWID tables with composite primary keys. FossilOrigin-Name: 21981e35062cc6b30e9576786cbf55265a7a4d41 --- manifest | 18 +++++++++--------- manifest.uuid | 2 +- src/analyze.c | 25 ++++++++++++++++++------- src/where.c | 2 +- test/analyze9.test | 44 ++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 73 insertions(+), 18 deletions(-) diff --git a/manifest b/manifest index d5d65422e5..4b1417a454 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Bump\sthe\sversion\snumber\sto\s3.8.6. -D 2014-06-30T19:28:57.595 +C Ensure\sthat\sall\sfields\sare\sloaded\sfrom\sthe\sstat4\stable\sfor\srecords\sthat\scorrespond\sto\sindexes\son\sWITHOUT\sROWID\stables\swith\scomposite\sprimary\skeys. +D 2014-07-01T11:54:02.938 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 1732320ecac3fee229d560d7ef2afa34681d1815 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -161,7 +161,7 @@ F sqlite.pc.in 42b7bf0d02e08b9e77734a47798d1a55a9e0716b F sqlite3.1 3d8b83c91651f53472ca17599dae3457b8b89494 F sqlite3.pc.in 48fed132e7cb71ab676105d2a4dc77127d8c1f3a F src/alter.c b00900877f766f116f9e16116f1ccacdc21d82f1 -F src/analyze.c ec6e0691a6a23e0239dc733109b906ee04b89cc3 +F src/analyze.c 61bc3467bd7803158d460dd92f5ba5205371bdce F src/attach.c 3801129015ef59d76bf23c95ef9b0069d18a0c52 F src/auth.c 523da7fb4979469955d822ff9298352d6b31de34 F src/backup.c a729e63cf5cd1829507cb7b8e89f99b95141bb53 @@ -296,7 +296,7 @@ F src/vtab.c 21b932841e51ebd7d075e2d0ad1415dce8d2d5fd F src/wal.c 264df50a1b33124130b23180ded2e2c5663c652a F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4 F src/walker.c 11edb74d587bc87b33ca96a5173e3ec1b8389e45 -F src/where.c 6ff6f7e3b272fad66eea601af489777adea3cc1f +F src/where.c 3a451b00516b59f414c59f817508edce51c732f1 F src/whereInt.h 929c1349b5355fd44f22cee5c14d72b3329c58a6 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2 @@ -316,7 +316,7 @@ F test/analyze5.test 765c4e284aa69ca172772aa940946f55629bc8c4 F test/analyze6.test d31defa011a561b938b4608d3538c1b4e0b5e92c F test/analyze7.test bb1409afc9e8629e414387ef048b8e0e3e0bdc4f F test/analyze8.test 093d15c1c888eed5034304a98c992f7360130b88 -F test/analyze9.test 93619368fff2db833747a6dfa9b1146a82e5d4d2 +F test/analyze9.test 3129cc8a82c3d6c5dfd340143b18499219faebac F test/analyzeA.test 1a5c40079894847976d983ca39c707aaa44b6944 F test/analyzeB.test 8bf35ee0a548aea831bf56762cb8e7fdb1db083d F test/async.test 1d0e056ba1bb9729283a0f22718d3a25e82c277b @@ -1182,7 +1182,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 d09ca6d5efad3e4cfa93a4dc711e6ba6079d4b4b -R 0b9fd011a99704759c36a48aebd29593 -U drh -Z 99f7c1257c18120424d63d4c4b9a073c +P f925e9baafea625f63105f8013abb3807b418379 +R b0479b264ee66056e956ca8c9e5bfcd6 +U dan +Z 2688039829f2bbaff9c051901e2506da diff --git a/manifest.uuid b/manifest.uuid index 708593f343..ec2c1a4071 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -f925e9baafea625f63105f8013abb3807b418379 \ No newline at end of file +21981e35062cc6b30e9576786cbf55265a7a4d41 \ No newline at end of file diff --git a/src/analyze.c b/src/analyze.c index 364f3b7131..2330bdb342 100644 --- a/src/analyze.c +++ b/src/analyze.c @@ -1519,7 +1519,16 @@ static void initAvgEq(Index *pIdx){ IndexSample *aSample = pIdx->aSample; IndexSample *pFinal = &aSample[pIdx->nSample-1]; int iCol; - for(iCol=0; iColnKeyCol; iCol++){ + int nCol = 1; + if( pIdx->nSampleCol>1 ){ + /* If this is stat4 data, then calculate aAvgEq[] values for all + ** sample columns except the last. The last is always set to 1, as + ** once the trailing PK fields are considered all index keys are + ** unique. */ + nCol = pIdx->nSampleCol-1; + pIdx->aAvgEq[nCol] = 1; + } + for(iCol=0; iColaAvgEq[iCol] = avgEq; - if( pIdx->nSampleCol==1 ) break; } } } @@ -1601,7 +1609,6 @@ static int loadStatTbl( while( sqlite3_step(pStmt)==SQLITE_ROW ){ int nIdxCol = 1; /* Number of columns in stat4 records */ - int nAvgCol = 1; /* Number of entries in Index.aAvgEq */ char *zIndex; /* Index name */ Index *pIdx; /* Pointer to the index object */ @@ -1619,13 +1626,17 @@ static int loadStatTbl( ** loaded from the stat4 table. In this case ignore stat3 data. */ if( pIdx==0 || pIdx->nSample ) continue; if( bStat3==0 ){ - nIdxCol = pIdx->nKeyCol+1; - nAvgCol = pIdx->nKeyCol; + assert( !HasRowid(pIdx->pTable) || pIdx->nColumn==pIdx->nKeyCol+1 ); + if( !HasRowid(pIdx->pTable) && IsPrimaryKeyIndex(pIdx) ){ + nIdxCol = pIdx->nKeyCol; + }else{ + nIdxCol = pIdx->nColumn; + } } pIdx->nSampleCol = nIdxCol; nByte = sizeof(IndexSample) * nSample; nByte += sizeof(tRowcnt) * nIdxCol * 3 * nSample; - nByte += nAvgCol * sizeof(tRowcnt); /* Space for Index.aAvgEq[] */ + nByte += nIdxCol * sizeof(tRowcnt); /* Space for Index.aAvgEq[] */ pIdx->aSample = sqlite3DbMallocZero(db, nByte); if( pIdx->aSample==0 ){ @@ -1633,7 +1644,7 @@ static int loadStatTbl( return SQLITE_NOMEM; } pSpace = (tRowcnt*)&pIdx->aSample[nSample]; - pIdx->aAvgEq = pSpace; pSpace += nAvgCol; + pIdx->aAvgEq = pSpace; pSpace += nIdxCol; for(i=0; iaSample[i].anEq = pSpace; pSpace += nIdxCol; pIdx->aSample[i].anLt = pSpace; pSpace += nIdxCol; diff --git a/src/where.c b/src/where.c index a26a9ea9a1..e52f598e02 100644 --- a/src/where.c +++ b/src/where.c @@ -1959,7 +1959,7 @@ static void whereKeyStats( iUpper = i>=pIdx->nSample ? nRow0 : aSample[i].anLt[iCol]; iLower = aSample[i-1].anEq[iCol] + aSample[i-1].anLt[iCol]; } - aStat[1] = (pIdx->nKeyCol>iCol ? pIdx->aAvgEq[iCol] : 1); + aStat[1] = pIdx->aAvgEq[iCol]; if( iLower>=iUpper ){ iGap = 0; }else{ diff --git a/test/analyze9.test b/test/analyze9.test index d0d3b3524f..d8bdc768d3 100644 --- a/test/analyze9.test +++ b/test/analyze9.test @@ -1019,6 +1019,50 @@ foreach {tn where res} { do_eqp_test 22.2.$tn "SELECT * FROM t3 WHERE $where" $res } +proc int_to_char {i} { + set ret "" + set char [list a b c d e f g h i j] + foreach {div} {1000 100 10 1} { + append ret [lindex $char [expr ($i / $div) % 10]] + } + set ret +} +db func int_to_char int_to_char + +do_execsql_test 23.0 { + CREATE TABLE t4( + a COLLATE nocase, b, c, + d, e, f, + PRIMARY KEY(c, b, a) + ) WITHOUT ROWID; + CREATE INDEX i41 ON t4(e); + CREATE INDEX i42 ON t4(f); + + WITH data(a, b, c, d, e, f) AS ( + SELECT int_to_char(0), 'xyz', 'zyx', '*', 0, 0 + UNION ALL + SELECT + int_to_char(f+1), b, c, d, (e+1) % 2, f+1 + FROM data WHERE f<1024 + ) + INSERT INTO t4 SELECT a, b, c, d, e, f FROM data; + ANALYZE; +} {} + +do_eqp_test 23.1 { + SELECT * FROM t4 WHERE + (e=1 AND b='xyz' AND c='zyx' AND a<'AEA') AND f<300 +} { + 0 0 0 {SEARCH TABLE t4 USING INDEX i41 (e=? AND c=? AND b=? AND a Date: Tue, 1 Jul 2014 15:22:11 +0000 Subject: [PATCH 02/37] Add another test to verify that SQLite is using stat4 data for composite primary keys on WITHOUT ROWID tables. FossilOrigin-Name: 0df1fe72f8271abc86cd552027d938c910f90967 --- manifest | 12 ++++++------ manifest.uuid | 2 +- test/analyze9.test | 27 ++++++++++++++++++++++++++- 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 4b1417a454..7a52f87c5e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Ensure\sthat\sall\sfields\sare\sloaded\sfrom\sthe\sstat4\stable\sfor\srecords\sthat\scorrespond\sto\sindexes\son\sWITHOUT\sROWID\stables\swith\scomposite\sprimary\skeys. -D 2014-07-01T11:54:02.938 +C Add\sanother\stest\sto\sverify\sthat\sSQLite\sis\susing\sstat4\sdata\sfor\scomposite\sprimary\skeys\son\sWITHOUT\sROWID\stables. +D 2014-07-01T15:22:11.950 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 1732320ecac3fee229d560d7ef2afa34681d1815 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -316,7 +316,7 @@ F test/analyze5.test 765c4e284aa69ca172772aa940946f55629bc8c4 F test/analyze6.test d31defa011a561b938b4608d3538c1b4e0b5e92c F test/analyze7.test bb1409afc9e8629e414387ef048b8e0e3e0bdc4f F test/analyze8.test 093d15c1c888eed5034304a98c992f7360130b88 -F test/analyze9.test 3129cc8a82c3d6c5dfd340143b18499219faebac +F test/analyze9.test bd5aaf2a8fd2dd774b08251416897185531a8adf F test/analyzeA.test 1a5c40079894847976d983ca39c707aaa44b6944 F test/analyzeB.test 8bf35ee0a548aea831bf56762cb8e7fdb1db083d F test/async.test 1d0e056ba1bb9729283a0f22718d3a25e82c277b @@ -1182,7 +1182,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 f925e9baafea625f63105f8013abb3807b418379 -R b0479b264ee66056e956ca8c9e5bfcd6 +P 21981e35062cc6b30e9576786cbf55265a7a4d41 +R e4440e4e4a98b796b4fa8322644ff7eb U dan -Z 2688039829f2bbaff9c051901e2506da +Z 9cb18e75f66a8c4075f21fee1b6ab8d9 diff --git a/manifest.uuid b/manifest.uuid index ec2c1a4071..91d9eea5ec 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -21981e35062cc6b30e9576786cbf55265a7a4d41 \ No newline at end of file +0df1fe72f8271abc86cd552027d938c910f90967 \ No newline at end of file diff --git a/test/analyze9.test b/test/analyze9.test index d8bdc768d3..fc5a13f43f 100644 --- a/test/analyze9.test +++ b/test/analyze9.test @@ -1055,7 +1055,6 @@ do_eqp_test 23.1 { } { 0 0 0 {SEARCH TABLE t4 USING INDEX i41 (e=? AND c=? AND b=? AND a Date: Thu, 3 Jul 2014 12:18:22 +0000 Subject: [PATCH 03/37] Change fts3/4 so that the "unicode61" is included in builds by default. It may now be excluded by defining SQLITE_DISABLE_FTS3_UNICODE. FossilOrigin-Name: 0cc0230ae9cfc9760fd8ef2c25e82576b052dbeb --- ext/fts3/fts3.c | 8 ++++---- ext/fts3/fts3Int.h | 2 +- ext/fts3/fts3_unicode.c | 4 ++-- ext/fts3/fts3_unicode2.c | 4 ++-- manifest | 20 ++++++++++---------- manifest.uuid | 2 +- src/test_config.c | 2 +- 7 files changed, 21 insertions(+), 21 deletions(-) diff --git a/ext/fts3/fts3.c b/ext/fts3/fts3.c index 1676fd41e1..4f4b667430 100644 --- a/ext/fts3/fts3.c +++ b/ext/fts3/fts3.c @@ -3750,7 +3750,7 @@ static void hashDestroy(void *p){ */ void sqlite3Fts3SimpleTokenizerModule(sqlite3_tokenizer_module const**ppModule); void sqlite3Fts3PorterTokenizerModule(sqlite3_tokenizer_module const**ppModule); -#ifdef SQLITE_ENABLE_FTS4_UNICODE61 +#ifndef SQLITE_DISABLE_FTS3_UNICODE void sqlite3Fts3UnicodeTokenizer(sqlite3_tokenizer_module const**ppModule); #endif #ifdef SQLITE_ENABLE_ICU @@ -3768,7 +3768,7 @@ int sqlite3Fts3Init(sqlite3 *db){ Fts3Hash *pHash = 0; const sqlite3_tokenizer_module *pSimple = 0; const sqlite3_tokenizer_module *pPorter = 0; -#ifdef SQLITE_ENABLE_FTS4_UNICODE61 +#ifndef SQLITE_DISABLE_FTS3_UNICODE const sqlite3_tokenizer_module *pUnicode = 0; #endif @@ -3777,7 +3777,7 @@ int sqlite3Fts3Init(sqlite3 *db){ sqlite3Fts3IcuTokenizerModule(&pIcu); #endif -#ifdef SQLITE_ENABLE_FTS4_UNICODE61 +#ifndef SQLITE_DISABLE_FTS3_UNICODE sqlite3Fts3UnicodeTokenizer(&pUnicode); #endif @@ -3805,7 +3805,7 @@ int sqlite3Fts3Init(sqlite3 *db){ if( sqlite3Fts3HashInsert(pHash, "simple", 7, (void *)pSimple) || sqlite3Fts3HashInsert(pHash, "porter", 7, (void *)pPorter) -#ifdef SQLITE_ENABLE_FTS4_UNICODE61 +#ifndef SQLITE_DISABLE_FTS3_UNICODE || sqlite3Fts3HashInsert(pHash, "unicode61", 10, (void *)pUnicode) #endif #ifdef SQLITE_ENABLE_ICU diff --git a/ext/fts3/fts3Int.h b/ext/fts3/fts3Int.h index 1383102f4c..b2827b7352 100644 --- a/ext/fts3/fts3Int.h +++ b/ext/fts3/fts3Int.h @@ -585,7 +585,7 @@ int sqlite3Fts3MsrIncrRestart(Fts3MultiSegReader *pCsr); int sqlite3Fts3InitTok(sqlite3*, Fts3Hash *); /* fts3_unicode2.c (functions generated by parsing unicode text files) */ -#ifdef SQLITE_ENABLE_FTS4_UNICODE61 +#ifndef SQLITE_DISABLE_FTS3_UNICODE int sqlite3FtsUnicodeFold(int, int); int sqlite3FtsUnicodeIsalnum(int); int sqlite3FtsUnicodeIsdiacritic(int); diff --git a/ext/fts3/fts3_unicode.c b/ext/fts3/fts3_unicode.c index 188358eade..591cbb8dc9 100644 --- a/ext/fts3/fts3_unicode.c +++ b/ext/fts3/fts3_unicode.c @@ -13,7 +13,7 @@ ** Implementation of the "unicode" full-text-search tokenizer. */ -#ifdef SQLITE_ENABLE_FTS4_UNICODE61 +#ifndef SQLITE_DISABLE_FTS3_UNICODE #include "fts3Int.h" #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) @@ -390,4 +390,4 @@ void sqlite3Fts3UnicodeTokenizer(sqlite3_tokenizer_module const **ppModule){ } #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) */ -#endif /* ifndef SQLITE_ENABLE_FTS4_UNICODE61 */ +#endif /* ifndef SQLITE_DISABLE_FTS3_UNICODE */ diff --git a/ext/fts3/fts3_unicode2.c b/ext/fts3/fts3_unicode2.c index fba688ff9c..4837dbd272 100644 --- a/ext/fts3/fts3_unicode2.c +++ b/ext/fts3/fts3_unicode2.c @@ -15,7 +15,7 @@ ** DO NOT EDIT THIS MACHINE GENERATED FILE. */ -#if defined(SQLITE_ENABLE_FTS4_UNICODE61) +#ifndef SQLITE_DISABLE_FTS3_UNICODE #if defined(SQLITE_ENABLE_FTS3) || defined(SQLITE_ENABLE_FTS4) #include @@ -362,4 +362,4 @@ int sqlite3FtsUnicodeFold(int c, int bRemoveDiacritic){ return ret; } #endif /* defined(SQLITE_ENABLE_FTS3) || defined(SQLITE_ENABLE_FTS4) */ -#endif /* !defined(SQLITE_ENABLE_FTS4_UNICODE61) */ +#endif /* !defined(SQLITE_DISABLE_FTS3_UNICODE) */ diff --git a/manifest b/manifest index 7a52f87c5e..ee3d1132c1 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sanother\stest\sto\sverify\sthat\sSQLite\sis\susing\sstat4\sdata\sfor\scomposite\sprimary\skeys\son\sWITHOUT\sROWID\stables. -D 2014-07-01T15:22:11.950 +C Change\sfts3/4\sso\sthat\sthe\s"unicode61"\sis\sincluded\sin\sbuilds\sby\sdefault.\sIt\smay\snow\sbe\sexcluded\sby\sdefining\sSQLITE_DISABLE_FTS3_UNICODE. +D 2014-07-03T12:18:22.515 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 1732320ecac3fee229d560d7ef2afa34681d1815 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -78,9 +78,9 @@ 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 20bc65862cfcea0a39bb64a819f8fe92a8e144c1 +F ext/fts3/fts3.c 2f5e925bdb9d6d3e488c5a981af60cad4f9cdfe7 F ext/fts3/fts3.h 3a10a0af180d502cecc50df77b1b22df142817fe -F ext/fts3/fts3Int.h 16cddf2d7b0e5f3681615ae1d8ca0e45fca44918 +F ext/fts3/fts3Int.h 53d4eca1fb23eab00681fb028fb82eb5705c1e21 F ext/fts3/fts3_aux.c 5c211e17a64885faeb16b9ba7772f9d5445c2365 F ext/fts3/fts3_expr.c 351395fad6fcb16ecfc61db0861008a70101330c F ext/fts3/fts3_hash.c 29b986e43f4e9dd40110eafa377dc0d63c422c60 @@ -94,8 +94,8 @@ F ext/fts3/fts3_tokenize_vtab.c 011170fe9eba5ff062f1a31d3188e00267716706 F ext/fts3/fts3_tokenizer.c bbdc731bc91338050675c6d1da9ab82147391e16 F ext/fts3/fts3_tokenizer.h 64c6ef6c5272c51ebe60fc607a896e84288fcbc3 F ext/fts3/fts3_tokenizer1.c 5c98225a53705e5ee34824087478cf477bdb7004 -F ext/fts3/fts3_unicode.c 92391b4b4fb043564c6539ea9b8661e3bcba47b9 -F ext/fts3/fts3_unicode2.c 0113d3acf13429e6dc38e0647d1bc71211c31a4d +F ext/fts3/fts3_unicode.c 0f598fa4c96af1188e4d5f5e8e78e25500bd5922 +F ext/fts3/fts3_unicode2.c c8adda75aad0c6c252ef3dd555f811f437485044 F ext/fts3/fts3_write.c 8260388626516a7005d06a9dce94f9e55c6c2a41 F ext/fts3/fts3speed.tcl b54caf6a18d38174f1a6e84219950d85e98bb1e9 F ext/fts3/mkfts3amal.tcl 252ecb7fe6467854f2aa237bf2c390b74e71f100 @@ -245,7 +245,7 @@ F src/test_async.c 21e11293a2f72080eda70e1124e9102044531cd8 F src/test_autoext.c dea8a01a7153b9adc97bd26161e4226329546e12 F src/test_backup.c 3875e899222b651e18b662f86e0e50daa946344e F src/test_btree.c 2e9978eca99a9a4bfa8cae949efb00886860a64f -F src/test_config.c dabaa32868974e1ae39770cc17d7e066a9c38e6d +F src/test_config.c 42fb068a038c8684741522f551325228b1389e63 F src/test_demovfs.c 69b2085076654ebc18014cbc6386f04409c959a9 F src/test_devsym.c e7498904e72ba7491d142d5c83b476c4e76993bc F src/test_fs.c ced436e3d4b8e4681328409b8081051ce614e28f @@ -1182,7 +1182,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 21981e35062cc6b30e9576786cbf55265a7a4d41 -R e4440e4e4a98b796b4fa8322644ff7eb +P 0df1fe72f8271abc86cd552027d938c910f90967 +R ef308fba8a4f61e769b2e20d3673cd17 U dan -Z 9cb18e75f66a8c4075f21fee1b6ab8d9 +Z 86452bd7dda1f4219032eac6ac7bc6d3 diff --git a/manifest.uuid b/manifest.uuid index 91d9eea5ec..57da097497 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -0df1fe72f8271abc86cd552027d938c910f90967 \ No newline at end of file +0cc0230ae9cfc9760fd8ef2c25e82576b052dbeb \ No newline at end of file diff --git a/src/test_config.c b/src/test_config.c index bf8afd8e67..9ce7f6fdf6 100644 --- a/src/test_config.c +++ b/src/test_config.c @@ -330,7 +330,7 @@ static void set_options(Tcl_Interp *interp){ Tcl_SetVar2(interp, "sqlite_options", "fts3", "0", TCL_GLOBAL_ONLY); #endif -#if defined(SQLITE_ENABLE_FTS3) && defined(SQLITE_ENABLE_FTS4_UNICODE61) +#if defined(SQLITE_ENABLE_FTS3) && !defined(SQLITE_DISABLE_FTS3_UNICODE) Tcl_SetVar2(interp, "sqlite_options", "fts3_unicode", "1", TCL_GLOBAL_ONLY); #else Tcl_SetVar2(interp, "sqlite_options", "fts3_unicode", "0", TCL_GLOBAL_ONLY); From 42d3d37ad1378dde011c1fa6c21927aa62e60b64 Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 7 Jul 2014 16:07:43 +0000 Subject: [PATCH 04/37] Fix a division-by-zero error in the fts3view utility program. Add the fts3view utility program to the "main.mk" makefile. FossilOrigin-Name: 64f02699b4bd747e4c2f0debf72d37ec275137d8 --- ext/fts3/tool/fts3view.c | 2 +- main.mk | 4 ++++ manifest | 16 ++++++++-------- manifest.uuid | 2 +- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/ext/fts3/tool/fts3view.c b/ext/fts3/tool/fts3view.c index 479ae9868d..406eb91688 100644 --- a/ext/fts3/tool/fts3view.c +++ b/ext/fts3/tool/fts3view.c @@ -376,7 +376,7 @@ static void showSegmentStats(sqlite3 *db, const char *zTab){ sqlite3_finalize(pStmt); nLeaf = nSeg - nIdx; printf("Leaf segments larger than %5d bytes.... %9d %5.2f%%\n", - pgsz-45, n, n*100.0/nLeaf); + pgsz-45, n, nLeaf>0 ? n*100.0/nLeaf : 0.0); pStmt = prepare(db, "SELECT max(level%%1024) FROM '%q_segdir'", zTab); mxLevel = 0; diff --git a/main.mk b/main.mk index 62b6b22475..865f7a87c2 100644 --- a/main.mk +++ b/main.mk @@ -644,6 +644,10 @@ showwal$(EXE): $(TOP)/tool/showwal.c sqlite3.o $(TCC) -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION -o showwal$(EXE) \ $(TOP)/tool/showwal.c sqlite3.o $(THREADLIB) +fts3view$(EXE): $(TOP)/ext/fts3/tool/fts3view.c sqlite3.o + $(TCC) -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION -o fts3view$(EXE) \ + $(TOP)/ext/fts3/tool/fts3view.c sqlite3.o $(THREADLIB) + rollback-test$(EXE): $(TOP)/tool/rollback-test.c sqlite3.o $(TCC) -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION -o rollback-test$(EXE) \ $(TOP)/tool/rollback-test.c sqlite3.o $(THREADLIB) diff --git a/manifest b/manifest index ee3d1132c1..6f5d54f727 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Change\sfts3/4\sso\sthat\sthe\s"unicode61"\sis\sincluded\sin\sbuilds\sby\sdefault.\sIt\smay\snow\sbe\sexcluded\sby\sdefining\sSQLITE_DISABLE_FTS3_UNICODE. -D 2014-07-03T12:18:22.515 +C Fix\sa\sdivision-by-zero\serror\sin\sthe\sfts3view\sutility\sprogram.\s\sAdd\sthe\nfts3view\sutility\sprogram\sto\sthe\s"main.mk"\smakefile. +D 2014-07-07T16:07:43.091 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 1732320ecac3fee229d560d7ef2afa34681d1815 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -99,7 +99,7 @@ F ext/fts3/fts3_unicode2.c c8adda75aad0c6c252ef3dd555f811f437485044 F ext/fts3/fts3_write.c 8260388626516a7005d06a9dce94f9e55c6c2a41 F ext/fts3/fts3speed.tcl b54caf6a18d38174f1a6e84219950d85e98bb1e9 F ext/fts3/mkfts3amal.tcl 252ecb7fe6467854f2aa237bf2c390b74e71f100 -F ext/fts3/tool/fts3view.c 6cfc5b67a5f0e09c0d698f9fd012c784bfaa9197 +F ext/fts3/tool/fts3view.c e2bc4c5c549541b74e367039399ce47320fbae57 F ext/fts3/unicode/CaseFolding.txt 8c678ca52ecc95e16bc7afc2dbf6fc9ffa05db8c F ext/fts3/unicode/UnicodeData.txt cd07314edb62d49fde34debdaf92fa2aa69011e7 F ext/fts3/unicode/mkunicode.tcl dc6f268eb526710e2c6e496c372471d773d0c368 @@ -146,7 +146,7 @@ F ext/rtree/viewrtree.tcl eea6224b3553599ae665b239bd827e182b466024 F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 x F ltmain.sh 3ff0879076df340d2e23ae905484d8c15d5fdea8 F magic.txt 8273bf49ba3b0c8559cb2774495390c31fd61c60 -F main.mk 7850d834ca7f3c772e2b0087631868d5bfdeabb9 +F main.mk 0b5baabb84a5d212b40c244e9439329a542e1982 F mkopcodec.awk c2ff431854d702cdd2d779c9c0d1f58fa16fa4ea F mkopcodeh.awk c6b3fa301db6ef7ac916b14c60868aeaec1337b5 F mkso.sh fd21c06b063bb16a5d25deea1752c2da6ac3ed83 @@ -1182,7 +1182,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 0df1fe72f8271abc86cd552027d938c910f90967 -R ef308fba8a4f61e769b2e20d3673cd17 -U dan -Z 86452bd7dda1f4219032eac6ac7bc6d3 +P 0cc0230ae9cfc9760fd8ef2c25e82576b052dbeb +R 52eca07cc58a435942000a424a892b43 +U drh +Z 228c9cd7cbfc8e1485536ecff5b51496 diff --git a/manifest.uuid b/manifest.uuid index 57da097497..702645c1b6 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -0cc0230ae9cfc9760fd8ef2c25e82576b052dbeb \ No newline at end of file +64f02699b4bd747e4c2f0debf72d37ec275137d8 \ No newline at end of file From de54527fb2bb63dfab76236f729340a73c844178 Mon Sep 17 00:00:00 2001 From: mistachkin Date: Mon, 7 Jul 2014 17:57:50 +0000 Subject: [PATCH 05/37] Add the fts3view utility program to the MSVC makefile. FossilOrigin-Name: b04751bd59fed513ab615e7f368fe25c64b3607c --- Makefile.msc | 4 ++++ manifest | 14 +++++++------- manifest.uuid | 2 +- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/Makefile.msc b/Makefile.msc index 55d26e3053..f1fb591553 100644 --- a/Makefile.msc +++ b/Makefile.msc @@ -1447,6 +1447,10 @@ showwal.exe: $(TOP)\tool\showwal.c $(SQLITE3C) $(LTLINK) -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION -Fe$@ \ $(TOP)\tool\showwal.c $(SQLITE3C) +fts3view.exe: $(TOP)\ext\fts3\tool\fts3view.c $(SQLITE3C) + $(LTLINK) -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION -Fe$@ \ + $(TOP)\ext\fts3\tool\fts3view.c $(SQLITE3C) + rollback-test.exe: $(TOP)\tool\rollback-test.c $(SQLITE3C) $(LTLINK) -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION -Fe$@ \ $(TOP)\tool\rollback-test.c $(SQLITE3C) diff --git a/manifest b/manifest index 6f5d54f727..71d860ddc9 100644 --- a/manifest +++ b/manifest @@ -1,9 +1,9 @@ -C Fix\sa\sdivision-by-zero\serror\sin\sthe\sfts3view\sutility\sprogram.\s\sAdd\sthe\nfts3view\sutility\sprogram\sto\sthe\s"main.mk"\smakefile. -D 2014-07-07T16:07:43.091 +C Add\sthe\sfts3view\sutility\sprogram\sto\sthe\sMSVC\smakefile. +D 2014-07-07T17:57:50.539 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 1732320ecac3fee229d560d7ef2afa34681d1815 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 -F Makefile.msc ad60c4d8be35f98fdcca614088b84a91612b2b4c +F Makefile.msc 0fc63e099a4f71fdeef31496b1f4ad04ab419884 F Makefile.vxworks 034289efa9d591b04b1a73598623119c306cbba0 F README.md 64f270c43c38c46de749e419c22f0ae2f4499fe8 F VERSION 1c877615a9db323e3cd301e3d57d853f9d5c4a07 @@ -1182,7 +1182,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 0cc0230ae9cfc9760fd8ef2c25e82576b052dbeb -R 52eca07cc58a435942000a424a892b43 -U drh -Z 228c9cd7cbfc8e1485536ecff5b51496 +P 64f02699b4bd747e4c2f0debf72d37ec275137d8 +R c90797aa6cbf897903a4492efeae675d +U mistachkin +Z 28a255fbc95b5b8b8da59816ed21faba diff --git a/manifest.uuid b/manifest.uuid index 702645c1b6..f2f5008375 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -64f02699b4bd747e4c2f0debf72d37ec275137d8 \ No newline at end of file +b04751bd59fed513ab615e7f368fe25c64b3607c \ No newline at end of file From 166c3737793fe2b0c6fe36ab7f3a040c1e50ac3b Mon Sep 17 00:00:00 2001 From: mistachkin Date: Mon, 7 Jul 2014 18:03:38 +0000 Subject: [PATCH 06/37] Fix harmless compiler warnings in the fts3view utility program that can occur with MSVC. FossilOrigin-Name: 1cec1e030035e5253fb7ebbdfe5c1a3029e4e29b --- ext/fts3/tool/fts3view.c | 13 +++++++------ manifest | 12 ++++++------ manifest.uuid | 2 +- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/ext/fts3/tool/fts3view.c b/ext/fts3/tool/fts3view.c index 406eb91688..3dc1ba80fe 100644 --- a/ext/fts3/tool/fts3view.c +++ b/ext/fts3/tool/fts3view.c @@ -554,7 +554,7 @@ static void decodeSegment( sqlite3_int64 n; sqlite3_int64 iDocsz; int iHeight; - int i = 0; + sqlite3_int64 i = 0; int cnt = 0; char zTerm[1000]; @@ -576,12 +576,12 @@ static void decodeSegment( fprintf(stderr, "term to long\n"); exit(1); } - memcpy(zTerm+iPrefix, aData+i, nTerm); + memcpy(zTerm+iPrefix, aData+i, (size_t)nTerm); zTerm[iPrefix+nTerm] = 0; i += nTerm; if( iHeight==0 ){ i += getVarint(aData+i, &iDocsz); - printf("term: %-25s doclist %7lld bytes offset %d\n", zTerm, iDocsz, i); + printf("term: %-25s doclist %7lld bytes offset %lld\n", zTerm, iDocsz, i); i += iDocsz; }else{ printf("term: %-25s child %lld\n", zTerm, ++iChild); @@ -749,18 +749,19 @@ static void decodeDoclist( */ static void showDoclist(sqlite3 *db, const char *zTab){ const unsigned char *aData; - sqlite3_int64 offset, nData; + sqlite3_int64 offset; + int nData; sqlite3_stmt *pStmt; offset = atoi64(azExtra[1]); - nData = atoi64(azExtra[2]); + nData = atoi(azExtra[2]); pStmt = prepareToGetSegment(db, zTab, azExtra[0]); if( sqlite3_step(pStmt)!=SQLITE_ROW ){ sqlite3_finalize(pStmt); return; } aData = sqlite3_column_blob(pStmt, 0); - printf("Doclist at %s offset %lld of size %lld bytes:\n", + printf("Doclist at %s offset %lld of size %d bytes:\n", azExtra[0], offset, nData); if( findOption("raw", 0, 0)!=0 ){ printBlob(aData+offset, nData); diff --git a/manifest b/manifest index 71d860ddc9..2b4d4ab97f 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sthe\sfts3view\sutility\sprogram\sto\sthe\sMSVC\smakefile. -D 2014-07-07T17:57:50.539 +C Fix\sharmless\scompiler\swarnings\sin\sthe\sfts3view\sutility\sprogram\sthat\scan\soccur\swith\sMSVC. +D 2014-07-07T18:03:38.442 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 1732320ecac3fee229d560d7ef2afa34681d1815 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -99,7 +99,7 @@ F ext/fts3/fts3_unicode2.c c8adda75aad0c6c252ef3dd555f811f437485044 F ext/fts3/fts3_write.c 8260388626516a7005d06a9dce94f9e55c6c2a41 F ext/fts3/fts3speed.tcl b54caf6a18d38174f1a6e84219950d85e98bb1e9 F ext/fts3/mkfts3amal.tcl 252ecb7fe6467854f2aa237bf2c390b74e71f100 -F ext/fts3/tool/fts3view.c e2bc4c5c549541b74e367039399ce47320fbae57 +F ext/fts3/tool/fts3view.c 3986531f2fc0ceca0c89c31ec7d0589b6adb19d6 F ext/fts3/unicode/CaseFolding.txt 8c678ca52ecc95e16bc7afc2dbf6fc9ffa05db8c F ext/fts3/unicode/UnicodeData.txt cd07314edb62d49fde34debdaf92fa2aa69011e7 F ext/fts3/unicode/mkunicode.tcl dc6f268eb526710e2c6e496c372471d773d0c368 @@ -1182,7 +1182,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 64f02699b4bd747e4c2f0debf72d37ec275137d8 -R c90797aa6cbf897903a4492efeae675d +P b04751bd59fed513ab615e7f368fe25c64b3607c +R 30e3947db20694bb71560953bb8a13c2 U mistachkin -Z 28a255fbc95b5b8b8da59816ed21faba +Z 58c34cf56858b67c344e911b0fcd0cab diff --git a/manifest.uuid b/manifest.uuid index f2f5008375..afc22bde21 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -b04751bd59fed513ab615e7f368fe25c64b3607c \ No newline at end of file +1cec1e030035e5253fb7ebbdfe5c1a3029e4e29b \ No newline at end of file From 56f674c8a0802314ae398b9f6e93fe8a3b6a15f4 Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 18 Jul 2014 14:43:29 +0000 Subject: [PATCH 07/37] Improvements to the ".fullschema" command in the command-line shell. FossilOrigin-Name: fa80c64caa573297bf43cb5b11d9e7db58567200 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/shell.c | 43 ++++++++++++++++++++++++++++--------------- 3 files changed, 36 insertions(+), 23 deletions(-) diff --git a/manifest b/manifest index 2b4d4ab97f..baca280a3a 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sharmless\scompiler\swarnings\sin\sthe\sfts3view\sutility\sprogram\sthat\scan\soccur\swith\sMSVC. -D 2014-07-07T18:03:38.442 +C Improvements\sto\sthe\s".fullschema"\scommand\sin\sthe\scommand-line\sshell. +D 2014-07-18T14:43:29.403 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 1732320ecac3fee229d560d7ef2afa34681d1815 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -223,7 +223,7 @@ F src/random.c d10c1f85b6709ca97278428fd5db5bbb9c74eece F src/resolve.c 5fc110baeacf120a73fe34e103f052632ff11a02 F src/rowset.c a9c9aae3234b44a6d7c6f5a3cadf90dce1e627be F src/select.c 6762c62e11b504aa014edceab8886495165e3a77 -F src/shell.c 56de2dfa3f25def4bf03098f7e2256fbb42f6e3c +F src/shell.c 566aee8213372a2e81ba0eb34e9759f7b2574009 F src/sqlite.h.in a98eb3e8c86c934ea6f5bcfc6b69653dde2f4ed4 F src/sqlite3.rc 11094cc6a157a028b301a9f06b3d03089ea37c3e F src/sqlite3ext.h 886f5a34de171002ad46fae8c36a7d8051c190fc @@ -1182,7 +1182,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 b04751bd59fed513ab615e7f368fe25c64b3607c -R 30e3947db20694bb71560953bb8a13c2 -U mistachkin -Z 58c34cf56858b67c344e911b0fcd0cab +P 1cec1e030035e5253fb7ebbdfe5c1a3029e4e29b +R 3a5c863b5d4e43cf3d99c01f25a09c91 +U drh +Z f91dd8693f049cec144fbd0b43e0e92a diff --git a/manifest.uuid b/manifest.uuid index afc22bde21..984495a47c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -1cec1e030035e5253fb7ebbdfe5c1a3029e4e29b \ No newline at end of file +fa80c64caa573297bf43cb5b11d9e7db58567200 \ No newline at end of file diff --git a/src/shell.c b/src/shell.c index ff87d817b9..97167dc877 100644 --- a/src/shell.c +++ b/src/shell.c @@ -2416,6 +2416,7 @@ static int do_meta_command(char *zLine, struct callback_data *p){ if( c=='f' && strncmp(azArg[0], "fullschema", n)==0 ){ struct callback_data data; char *zErrMsg = 0; + int doStats = 0; if( nArg!=1 ){ fprintf(stderr, "Usage: .fullschema\n"); rc = 1; @@ -2434,21 +2435,33 @@ static int do_meta_command(char *zLine, struct callback_data *p){ "ORDER BY rowid", callback, &data, &zErrMsg ); - sqlite3_exec(p->db, "SELECT 'ANALYZE sqlite_master;'", - callback, &data, &zErrMsg); - data.mode = MODE_Insert; - data.zDestTable = "sqlite_stat1"; - shell_exec(p->db, "SELECT * FROM sqlite_stat1", - shell_callback, &data,&zErrMsg); - data.zDestTable = "sqlite_stat3"; - shell_exec(p->db, "SELECT * FROM sqlite_stat3", - shell_callback, &data,&zErrMsg); - data.zDestTable = "sqlite_stat4"; - shell_exec(p->db, "SELECT * FROM sqlite_stat4", - shell_callback, &data, &zErrMsg); - data.mode = MODE_Semi; - shell_exec(p->db, "SELECT 'ANALYZE sqlite_master;'", - shell_callback, &data, &zErrMsg); + if( rc==SQLITE_OK ){ + sqlite3_stmt *pStmt; + rc = sqlite3_prepare_v2(p->db, + "SELECT rowid FROM sqlite_master" + " WHERE name GLOB 'sqlite_stat[134]'", + -1, &pStmt, 0); + doStats = sqlite3_step(pStmt)==SQLITE_ROW; + sqlite3_finalize(pStmt); + } + if( doStats==0 ){ + fprintf(p->out, "/* No STAT tables available */\n"); + }else{ + fprintf(p->out, "ANALYZE sqlite_master;\n"); + sqlite3_exec(p->db, "SELECT 'ANALYZE sqlite_master'", + callback, &data, &zErrMsg); + data.mode = MODE_Insert; + data.zDestTable = "sqlite_stat1"; + shell_exec(p->db, "SELECT * FROM sqlite_stat1", + shell_callback, &data,&zErrMsg); + data.zDestTable = "sqlite_stat3"; + shell_exec(p->db, "SELECT * FROM sqlite_stat3", + shell_callback, &data,&zErrMsg); + data.zDestTable = "sqlite_stat4"; + shell_exec(p->db, "SELECT * FROM sqlite_stat4", + shell_callback, &data, &zErrMsg); + fprintf(p->out, "ANALYZE sqlite_master;\n"); + } }else if( c=='h' && strncmp(azArg[0], "headers", n)==0 ){ From 71607c77c88d70dab468db6cc267a29118163513 Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 18 Jul 2014 17:39:48 +0000 Subject: [PATCH 08/37] SQLite has long accepted some unadvertised and non-standard join syntax. Add a test to ensure that future versions continue to accept this non-standard syntax, to avoid breaking legacy applications that use the undefined syntax. FossilOrigin-Name: 824dde7fc48dbca6d6c956c4eb79bbfa2d139ee5 --- manifest | 12 ++++++------ manifest.uuid | 2 +- test/join.test | 11 +++++++++++ 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/manifest b/manifest index baca280a3a..f047a472d0 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Improvements\sto\sthe\s".fullschema"\scommand\sin\sthe\scommand-line\sshell. -D 2014-07-18T14:43:29.403 +C SQLite\shas\slong\saccepted\ssome\sunadvertised\sand\snon-standard\sjoin\ssyntax.\nAdd\sa\stest\sto\sensure\sthat\sfuture\sversions\scontinue\sto\saccept\sthis\snon-standard\nsyntax,\sto\savoid\sbreaking\slegacy\sapplications\sthat\suse\sthe\sundefined\ssyntax. +D 2014-07-18T17:39:48.053 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 1732320ecac3fee229d560d7ef2afa34681d1815 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -643,7 +643,7 @@ F test/ioerr3.test d3cec5e1a11ad6d27527d0d38573fbff14c71bdd F test/ioerr4.test f130fe9e71008577b342b8874d52984bd04ede2c F test/ioerr5.test 2edfa4fb0f896f733071303b42224df8bedd9da4 F test/ioerr6.test a395a6ab144b26a9e3e21059a1ab6a7149cca65b -F test/join.test 559b81eb56ae350246f9c25986aa52c81c725c7e +F test/join.test 52d4d49f86d0cf46926672878c4eaf0da399104a F test/join2.test f2171c265e57ee298a27e57e7051d22962f9f324 F test/join3.test 6f0c774ff1ba0489e6c88a3e77b9d3528fb4fda0 F test/join4.test 1a352e4e267114444c29266ce79e941af5885916 @@ -1182,7 +1182,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 1cec1e030035e5253fb7ebbdfe5c1a3029e4e29b -R 3a5c863b5d4e43cf3d99c01f25a09c91 +P fa80c64caa573297bf43cb5b11d9e7db58567200 +R 98a05e82af602a262cecfbef5a77de2c U drh -Z f91dd8693f049cec144fbd0b43e0e92a +Z 99ce618698b83450b2fdb30e802ca3fb diff --git a/manifest.uuid b/manifest.uuid index 984495a47c..e1252a9375 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -fa80c64caa573297bf43cb5b11d9e7db58567200 \ No newline at end of file +824dde7fc48dbca6d6c956c4eb79bbfa2d139ee5 \ No newline at end of file diff --git a/test/join.test b/test/join.test index 28d9ddf8b2..4c83fa6b3b 100644 --- a/test/join.test +++ b/test/join.test @@ -36,6 +36,17 @@ do_test join-1.2 { } } {1 2 3 2 3 4 3 4 5} +# A FROM clause of the form: ",
ON " is not +# allowed by the SQLite syntax diagram, nor by any other SQL database +# engine that we are aware of. Nevertheless, historic versions of +# SQLite have allowed it. We need to continue to support it moving +# forward to prevent breakage of legacy applications. Though, we will +# not advertise it as being supported. +# +do_execsql_test join-1.2.1 { + SELECT t1.rowid, t2.rowid, '|' FROM t1, t2 ON t1.a=t2.b; +} {1 1 | 2 2 | 3 3 |} + do_test join-1.3 { execsql2 { SELECT * FROM t1 NATURAL JOIN t2; From a6f5972c7529bc4b7f4c754278e2b5383126b6d0 Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 18 Jul 2014 19:06:39 +0000 Subject: [PATCH 09/37] Improved documentation for checkpoints and the busy handler. No changes to code. FossilOrigin-Name: ca92c0240681b199c4b8ecc557792b8aea71692d --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/sqlite.h.in | 44 ++++++++++++++++++++++++++++++++------------ 3 files changed, 39 insertions(+), 19 deletions(-) diff --git a/manifest b/manifest index f047a472d0..1ef6e6429f 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C SQLite\shas\slong\saccepted\ssome\sunadvertised\sand\snon-standard\sjoin\ssyntax.\nAdd\sa\stest\sto\sensure\sthat\sfuture\sversions\scontinue\sto\saccept\sthis\snon-standard\nsyntax,\sto\savoid\sbreaking\slegacy\sapplications\sthat\suse\sthe\sundefined\ssyntax. -D 2014-07-18T17:39:48.053 +C Improved\sdocumentation\sfor\scheckpoints\sand\sthe\sbusy\shandler.\s\sNo\schanges\nto\scode. +D 2014-07-18T19:06:39.261 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 1732320ecac3fee229d560d7ef2afa34681d1815 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -224,7 +224,7 @@ F src/resolve.c 5fc110baeacf120a73fe34e103f052632ff11a02 F src/rowset.c a9c9aae3234b44a6d7c6f5a3cadf90dce1e627be F src/select.c 6762c62e11b504aa014edceab8886495165e3a77 F src/shell.c 566aee8213372a2e81ba0eb34e9759f7b2574009 -F src/sqlite.h.in a98eb3e8c86c934ea6f5bcfc6b69653dde2f4ed4 +F src/sqlite.h.in fd8e3a36b0aded082dc93a4b89c1e85324b4cf75 F src/sqlite3.rc 11094cc6a157a028b301a9f06b3d03089ea37c3e F src/sqlite3ext.h 886f5a34de171002ad46fae8c36a7d8051c190fc F src/sqliteInt.h e88614d7371b80ff69dbbb5e4b9813ee93dfd890 @@ -1182,7 +1182,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 fa80c64caa573297bf43cb5b11d9e7db58567200 -R 98a05e82af602a262cecfbef5a77de2c +P 824dde7fc48dbca6d6c956c4eb79bbfa2d139ee5 +R e12aaadd86bb0f0252aac83b76e58ccc U drh -Z 99ce618698b83450b2fdb30e802ca3fb +Z 06586dc6d29c2abfb50a449af797bf0e diff --git a/manifest.uuid b/manifest.uuid index e1252a9375..38385b2f75 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -824dde7fc48dbca6d6c956c4eb79bbfa2d139ee5 \ No newline at end of file +ca92c0240681b199c4b8ecc557792b8aea71692d \ No newline at end of file diff --git a/src/sqlite.h.in b/src/sqlite.h.in index 21ab67a4c2..93cde78340 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -2032,9 +2032,13 @@ int sqlite3_complete16(const void *sql); /* ** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors ** -** ^This routine sets a callback function that might be invoked whenever -** an attempt is made to open a database table that another thread -** or process has locked. +** ^The sqlite3_busy_handler(D,X,P) routine sets a callback function X +** that might be invoked with argument P whenever +** an attempt is made to access a database table associated with +** [database connection] D when another thread +** or process has the table locked. +** The sqlite3_busy_handler() interface is used to implement +** [sqlite3_busy_timeout()] and [PRAGMA busy_timeout]. ** ** ^If the busy callback is NULL, then [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED] ** is returned immediately upon encountering the lock. ^If the busy callback @@ -2043,16 +2047,18 @@ int sqlite3_complete16(const void *sql); ** ^The first argument to the busy handler is a copy of the void* pointer which ** is the third argument to sqlite3_busy_handler(). ^The second argument to ** the busy handler callback is the number of times that the busy handler has -** been invoked for this locking event. ^If the +** been invoked for the same locking event. ^If the ** busy callback returns 0, then no additional attempts are made to -** access the database and [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED] is returned. +** access the database and [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED] is returned +** to the application. ** ^If the callback returns non-zero, then another attempt -** is made to open the database for reading and the cycle repeats. +** is made to access the database and the cycle repeats. ** ** The presence of a busy handler does not guarantee that it will be invoked ** when there is lock contention. ^If SQLite determines that invoking the busy ** handler could result in a deadlock, it will go ahead and return [SQLITE_BUSY] -** or [SQLITE_IOERR_BLOCKED] instead of invoking the busy handler. +** or [SQLITE_IOERR_BLOCKED] to the application instead of invoking the +** busy handler. ** Consider a scenario where one process is holding a read lock that ** it is trying to promote to a reserved lock and ** a second process is holding a reserved lock that it is trying @@ -2084,10 +2090,12 @@ int sqlite3_complete16(const void *sql); ** ^(There can only be a single busy handler defined for each ** [database connection]. Setting a new busy handler clears any ** previously set handler.)^ ^Note that calling [sqlite3_busy_timeout()] -** will also set or clear the busy handler. +** or evaluating [PRAGMA busy_timeout=N] will change the +** busy handler and thus clear any previously set busy handler. ** ** The busy callback should not take any actions which modify the -** database connection that invoked the busy handler. Any such actions +** database connection that invoked the busy handler. In other words, +** the busy handler is not reentrant. Any such actions ** result in undefined behavior. ** ** A busy handler must not close the database connection @@ -2112,6 +2120,8 @@ int sqlite3_busy_handler(sqlite3*, int(*)(void*,int), void*); ** [database connection] any any given moment. If another busy handler ** was defined (using [sqlite3_busy_handler()]) prior to calling ** this routine, that other busy handler is cleared.)^ +** +** See also: [PRAGMA busy_timeout] */ int sqlite3_busy_timeout(sqlite3*, int ms); @@ -7139,6 +7149,9 @@ void *sqlite3_wal_hook( ** ^The [wal_autocheckpoint pragma] can be used to invoke this interface ** from SQL. ** +** ^Checkpoints initiated by this mechanism are +** [sqlite3_wal_checkpoint_v2|PASSIVE]. +** ** ^Every new [database connection] defaults to having the auto-checkpoint ** enabled with a threshold of 1000 or [SQLITE_DEFAULT_WAL_AUTOCHECKPOINT] ** pages. The use of this interface @@ -7155,6 +7168,10 @@ int sqlite3_wal_autocheckpoint(sqlite3 *db, int N); ** empty string, then a checkpoint is run on all databases of ** connection D. ^If the database connection D is not in ** [WAL | write-ahead log mode] then this interface is a harmless no-op. +** ^The [sqlite3_wal_checkpoint(D,X)] interface initiates a +** [sqlite3_wal_checkpoint_v2|PASSIVE] checkpoint. +** Use the [sqlite3_wal_checkpoint_v2()] interface to get a FULL +** or RESET checkpoint. ** ** ^The [wal_checkpoint pragma] can be used to invoke this interface ** from SQL. ^The [sqlite3_wal_autocheckpoint()] interface and the @@ -7177,10 +7194,12 @@ int sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb); ** Checkpoint as many frames as possible without waiting for any database ** readers or writers to finish. Sync the db file if all frames in the log ** are checkpointed. This mode is the same as calling -** sqlite3_wal_checkpoint(). The busy-handler callback is never invoked. +** sqlite3_wal_checkpoint(). The [sqlite3_busy_handler|busy-handler callback] +** is never invoked. ** **
SQLITE_CHECKPOINT_FULL
-** This mode blocks (calls the busy-handler callback) until there is no +** This mode blocks (it invokes the +** [sqlite3_busy_handler|busy-handler callback]) until there is no ** database writer and all readers are reading from the most recent database ** snapshot. It then checkpoints all frames in the log file and syncs the ** database file. This call blocks database writers while it is running, @@ -7188,7 +7207,8 @@ int sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb); ** **
SQLITE_CHECKPOINT_RESTART
** This mode works the same way as SQLITE_CHECKPOINT_FULL, except after -** checkpointing the log file it blocks (calls the busy-handler callback) +** checkpointing the log file it blocks (calls the +** [sqlite3_busy_handler|busy-handler callback]) ** until all readers are reading from the database file only. This ensures ** that the next client to write to the database file restarts the log file ** from the beginning. This call blocks database writers while it is running, From 3a046c6c315788963ddd1f6e16358a5ab4f74ea2 Mon Sep 17 00:00:00 2001 From: mistachkin Date: Fri, 18 Jul 2014 21:02:54 +0000 Subject: [PATCH 10/37] Update clean targets with the recently added command-line tools. FossilOrigin-Name: 2beefa68c0c53f663321bebf0ac06f6c936be63f --- Makefile.in | 3 +++ Makefile.msc | 3 +++ main.mk | 10 +++++++++- manifest | 18 +++++++++--------- manifest.uuid | 2 +- 5 files changed, 25 insertions(+), 11 deletions(-) diff --git a/Makefile.in b/Makefile.in index b5768e83a6..cf17b02918 100644 --- a/Makefile.in +++ b/Makefile.in @@ -997,6 +997,9 @@ clean: rm -rf tsrc .target_source rm -f tclsqlite3$(TEXE) rm -f testfixture$(TEXE) test.db + rm -f LogEst$(TEXE) fts3view$(TEXE) rollback-test$(TEXE) showdb$(TEXE) + rm -f showjournal$(TEXE) showstat4$(TEXE) showwal$(TEXE) speedtest1$(TEXE) + rm -f wordcount$(TEXE) rm -f sqlite3.dll sqlite3.lib sqlite3.exp sqlite3.def rm -f sqlite3.c rm -f sqlite3rc.h diff --git a/Makefile.msc b/Makefile.msc index f1fb591553..3a9fa29740 100644 --- a/Makefile.msc +++ b/Makefile.msc @@ -1483,6 +1483,9 @@ clean: 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 diff --git a/main.mk b/main.mk index 865f7a87c2..718cf5cc4d 100644 --- a/main.mk +++ b/main.mk @@ -695,10 +695,18 @@ clean: rm -f fts3-testfixture fts3-testfixture.exe rm -f testfixture testfixture.exe rm -f threadtest3 threadtest3.exe + rm -f LogEst LogEst.exe + rm -f fts3view fts3view.exe + rm -f rollback-test rollback-test.exe + rm -f showdb showdb.exe + rm -f showjournal showjournal.exe + rm -f showstat4 showstat4.exe + rm -f showwal showwal.exe + rm -f speedtest1 speedtest1.exe + rm -f wordcount wordcount.exe rm -f sqlite3.c sqlite3-*.c fts?amal.c tclsqlite3.c rm -f sqlite3rc.h rm -f shell.c sqlite3ext.h rm -f sqlite3_analyzer sqlite3_analyzer.exe sqlite3_analyzer.c rm -f sqlite-*-output.vsix rm -f mptester mptester.exe - rm -f showdb diff --git a/manifest b/manifest index 1ef6e6429f..3fa4f049fa 100644 --- a/manifest +++ b/manifest @@ -1,9 +1,9 @@ -C Improved\sdocumentation\sfor\scheckpoints\sand\sthe\sbusy\shandler.\s\sNo\schanges\nto\scode. -D 2014-07-18T19:06:39.261 +C Update\sclean\stargets\swith\sthe\srecently\sadded\scommand-line\stools. +D 2014-07-18T21:02:54.697 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f -F Makefile.in 1732320ecac3fee229d560d7ef2afa34681d1815 +F Makefile.in 5eb79e334a5de69c87740edd56af6527dd219308 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 -F Makefile.msc 0fc63e099a4f71fdeef31496b1f4ad04ab419884 +F Makefile.msc 5b04e657cf08a9ac7fc47d876c5c8be962c47d6b F Makefile.vxworks 034289efa9d591b04b1a73598623119c306cbba0 F README.md 64f270c43c38c46de749e419c22f0ae2f4499fe8 F VERSION 1c877615a9db323e3cd301e3d57d853f9d5c4a07 @@ -146,7 +146,7 @@ F ext/rtree/viewrtree.tcl eea6224b3553599ae665b239bd827e182b466024 F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 x F ltmain.sh 3ff0879076df340d2e23ae905484d8c15d5fdea8 F magic.txt 8273bf49ba3b0c8559cb2774495390c31fd61c60 -F main.mk 0b5baabb84a5d212b40c244e9439329a542e1982 +F main.mk 036a65c9042b2f5013baf85c82629d700fe031c4 F mkopcodec.awk c2ff431854d702cdd2d779c9c0d1f58fa16fa4ea F mkopcodeh.awk c6b3fa301db6ef7ac916b14c60868aeaec1337b5 F mkso.sh fd21c06b063bb16a5d25deea1752c2da6ac3ed83 @@ -1182,7 +1182,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 824dde7fc48dbca6d6c956c4eb79bbfa2d139ee5 -R e12aaadd86bb0f0252aac83b76e58ccc -U drh -Z 06586dc6d29c2abfb50a449af797bf0e +P ca92c0240681b199c4b8ecc557792b8aea71692d +R 432f9d3a43bd2fc68603a985c53b9df5 +U mistachkin +Z 7459013a6be89cfe73225b448eb2a655 diff --git a/manifest.uuid b/manifest.uuid index 38385b2f75..e37705787e 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ca92c0240681b199c4b8ecc557792b8aea71692d \ No newline at end of file +2beefa68c0c53f663321bebf0ac06f6c936be63f \ No newline at end of file From 0461cc4795ddcc8fa9d63ef5c956a712bc73dea3 Mon Sep 17 00:00:00 2001 From: mistachkin Date: Fri, 18 Jul 2014 21:16:37 +0000 Subject: [PATCH 11/37] Fix harmless compiler warnings for MSVC in the showdb/showwal command line tools. FossilOrigin-Name: 6dc7b2f119eb92da17c9e914bdad30a9ceaebdb5 --- manifest | 17 ++++++++++------- manifest.uuid | 2 +- tool/showdb.c | 47 +++++++++++++++++++++++++---------------------- tool/showwal.c | 36 +++++++++++++++++++++--------------- 4 files changed, 57 insertions(+), 45 deletions(-) diff --git a/manifest b/manifest index 3fa4f049fa..685f9ad594 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Update\sclean\stargets\swith\sthe\srecently\sadded\scommand-line\stools. -D 2014-07-18T21:02:54.697 +C Fix\sharmless\scompiler\swarnings\sfor\sMSVC\sin\sthe\sshowdb/showwal\scommand\sline\stools. +D 2014-07-18T21:16:37.850 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5eb79e334a5de69c87740edd56af6527dd219308 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -1160,10 +1160,10 @@ F tool/opcodeDoc.awk b3a2a3d5d3075b8bd90b7afe24283efdd586659c F tool/pagesig.c ff0ca355fd3c2398e933da5e22439bbff89b803b F tool/restore_jrnl.tcl 6957a34f8f1f0f8285e07536225ec3b292a9024a F tool/rollback-test.c 9fc98427d1e23e84429d7e6d07d9094fbdec65a5 -F tool/showdb.c 213e0288501b2cf67c1b2c72a9e5b8acda4738b3 +F tool/showdb.c 3c78d10af9bb7ee667ceaa271e1d1ecbcdc3e69c F tool/showjournal.c 053eb1cc774710c6890b7dd6293300cc297b16a5 F tool/showstat4.c c39279d6bd37cb999b634f0064f6f86ad7af008f -F tool/showwal.c 3f7f7da5ec0cba51b1449a75f700493377da57b5 +F tool/showwal.c 6e98bc0fe0ae75f4b08e39d21ed90d7d78d307c0 F tool/soak1.tcl 8d407956e1a45b485a8e072470a3e629a27037fe F tool/space_used.tcl f714c41a59e326b8b9042f415b628b561bafa06b F tool/spaceanal.tcl 8e50b217c56a6a086a1b47eac9d09c5cd65b996f @@ -1182,7 +1182,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 ca92c0240681b199c4b8ecc557792b8aea71692d -R 432f9d3a43bd2fc68603a985c53b9df5 +P 2beefa68c0c53f663321bebf0ac06f6c936be63f +R 7c81b84c85a1fee51213cddde915664f +T *branch * toolWarnings +T *sym-toolWarnings * +T -sym-trunk * U mistachkin -Z 7459013a6be89cfe73225b448eb2a655 +Z 6dc51fde6dee7a6bda251af41648d319 diff --git a/manifest.uuid b/manifest.uuid index e37705787e..e189e09c49 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -2beefa68c0c53f663321bebf0ac06f6c936be63f \ No newline at end of file +6dc7b2f119eb92da17c9e914bdad30a9ceaebdb5 \ No newline at end of file diff --git a/tool/showdb.c b/tool/showdb.c index 8dd387365c..3324729184 100644 --- a/tool/showdb.c +++ b/tool/showdb.c @@ -9,6 +9,8 @@ #if !defined(_MSC_VER) #include +#else +#include #endif #include @@ -190,14 +192,14 @@ static void print_db_header(void){ /* ** Describe cell content. */ -static int describeContent( +static i64 describeContent( unsigned char *a, /* Cell content */ - int nLocal, /* Bytes in a[] */ + i64 nLocal, /* Bytes in a[] */ char *zDesc /* Write description here */ ){ - int nDesc = 0; - int n, i, j; - i64 x, v; + i64 nDesc = 0; + int n, j; + i64 i, x, v; const unsigned char *pData; const unsigned char *pLimit; char sep = ' '; @@ -237,7 +239,7 @@ static int describeContent( }else if( x==9 ){ sprintf(zDesc, "1"); }else if( x>=12 ){ - int size = (x-12)/2; + i64 size = (x-12)/2; if( (x&1)==0 ){ sprintf(zDesc, "blob(%d)", size); }else{ @@ -256,11 +258,11 @@ static int describeContent( ** Compute the local payload size given the total payload size and ** the page size. */ -static int localPayload(i64 nPayload, char cType){ - int maxLocal; - int minLocal; - int surplus; - int nLocal; +static i64 localPayload(i64 nPayload, char cType){ + i64 maxLocal; + i64 minLocal; + i64 surplus; + i64 nLocal; if( cType==13 ){ /* Table leaf */ maxLocal = pagesize-35; @@ -288,19 +290,19 @@ static int localPayload(i64 nPayload, char cType){ ** ** The return value is the local cell size. */ -static int describeCell( +static i64 describeCell( unsigned char cType, /* Page type */ unsigned char *a, /* Cell content */ int showCellContent, /* Show cell content if true */ char **pzDesc /* Store description here */ ){ int i; - int nDesc = 0; + i64 nDesc = 0; int n = 0; int leftChild; i64 nPayload; i64 rowid; - int nLocal; + i64 nLocal; static char zDesc[1000]; i = 0; if( cType<=5 ){ @@ -373,13 +375,14 @@ static void decodeCell( int szPgHdr, /* Size of the page header. 0 or 100 */ int ofst /* Cell begins at a[ofst] */ ){ - int i, j, k; + int i, j; int leftChild; + i64 k; i64 nPayload; i64 rowid; i64 nHdr; i64 iType; - int nLocal; + i64 nLocal; unsigned char *x = a + ofst; unsigned char *end; unsigned char cType = a[0]; @@ -452,7 +455,7 @@ static void decodeCell( } printf("%s\n", zTypeName); szCol[nCol] = sz; - ofstCol[nCol] = k; + ofstCol[nCol] = (int)k; typeCol[nCol] = (int)iType; k += sz; nCol++; @@ -585,13 +588,13 @@ static void decode_btree_page( for(i=0; i #include #include + +#if !defined(_MSC_VER) #include +#else +#include +#endif + #include #include @@ -273,14 +279,14 @@ static void print_wal_header(Cksum *pCksum){ /* ** Describe cell content. */ -static int describeContent( +static i64 describeContent( unsigned char *a, /* Cell content */ - int nLocal, /* Bytes in a[] */ + i64 nLocal, /* Bytes in a[] */ char *zDesc /* Write description here */ ){ int nDesc = 0; - int n, i, j; - i64 x, v; + int n, j; + i64 i, x, v; const unsigned char *pData; const unsigned char *pLimit; char sep = ' '; @@ -320,7 +326,7 @@ static int describeContent( }else if( x==9 ){ sprintf(zDesc, "1"); }else if( x>=12 ){ - int size = (x-12)/2; + i64 size = (x-12)/2; if( (x&1)==0 ){ sprintf(zDesc, "blob(%d)", size); }else{ @@ -339,11 +345,11 @@ static int describeContent( ** Compute the local payload size given the total payload size and ** the page size. */ -static int localPayload(i64 nPayload, char cType){ - int maxLocal; - int minLocal; - int surplus; - int nLocal; +static i64 localPayload(i64 nPayload, char cType){ + i64 maxLocal; + i64 minLocal; + i64 surplus; + i64 nLocal; if( cType==13 ){ /* Table leaf */ maxLocal = pagesize-35; @@ -370,19 +376,19 @@ static int localPayload(i64 nPayload, char cType){ ** ** The return value is the local cell size. */ -static int describeCell( +static i64 describeCell( unsigned char cType, /* Page type */ unsigned char *a, /* Cell content */ int showCellContent, /* Show cell content if true */ char **pzDesc /* Store description here */ ){ int i; - int nDesc = 0; + i64 nDesc = 0; int n = 0; int leftChild; i64 nPayload; i64 rowid; - int nLocal; + i64 nLocal; static char zDesc[1000]; i = 0; if( cType<=5 ){ @@ -479,13 +485,13 @@ static void decode_btree_page( for(i=0; i Date: Sat, 19 Jul 2014 15:30:01 +0000 Subject: [PATCH 12/37] Fix warnings caused by the previous commit. FossilOrigin-Name: 89634a419d0c1ef899d0591c7c6ab9290bf665d2 --- manifest | 17 +++++++---------- manifest.uuid | 2 +- tool/showdb.c | 12 ++++++------ tool/showwal.c | 4 ++-- 4 files changed, 16 insertions(+), 19 deletions(-) diff --git a/manifest b/manifest index 685f9ad594..f2ee7060d6 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sharmless\scompiler\swarnings\sfor\sMSVC\sin\sthe\sshowdb/showwal\scommand\sline\stools. -D 2014-07-18T21:16:37.850 +C Fix\swarnings\scaused\sby\sthe\sprevious\scommit. +D 2014-07-19T15:30:01.552 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5eb79e334a5de69c87740edd56af6527dd219308 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -1160,10 +1160,10 @@ F tool/opcodeDoc.awk b3a2a3d5d3075b8bd90b7afe24283efdd586659c F tool/pagesig.c ff0ca355fd3c2398e933da5e22439bbff89b803b F tool/restore_jrnl.tcl 6957a34f8f1f0f8285e07536225ec3b292a9024a F tool/rollback-test.c 9fc98427d1e23e84429d7e6d07d9094fbdec65a5 -F tool/showdb.c 3c78d10af9bb7ee667ceaa271e1d1ecbcdc3e69c +F tool/showdb.c d7d354c52f259c06d84938fc2be095656e761b78 F tool/showjournal.c 053eb1cc774710c6890b7dd6293300cc297b16a5 F tool/showstat4.c c39279d6bd37cb999b634f0064f6f86ad7af008f -F tool/showwal.c 6e98bc0fe0ae75f4b08e39d21ed90d7d78d307c0 +F tool/showwal.c 9c299ba842f1ac0364e95f9effbc3a5b3b2349f2 F tool/soak1.tcl 8d407956e1a45b485a8e072470a3e629a27037fe F tool/space_used.tcl f714c41a59e326b8b9042f415b628b561bafa06b F tool/spaceanal.tcl 8e50b217c56a6a086a1b47eac9d09c5cd65b996f @@ -1182,10 +1182,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 2beefa68c0c53f663321bebf0ac06f6c936be63f -R 7c81b84c85a1fee51213cddde915664f -T *branch * toolWarnings -T *sym-toolWarnings * -T -sym-trunk * +P 6dc7b2f119eb92da17c9e914bdad30a9ceaebdb5 +R 7b842e4424a0effae20a64ee9f307907 U mistachkin -Z 6dc51fde6dee7a6bda251af41648d319 +Z c9d7c6fd91ebbbad7eb3b3a8b17ddccd diff --git a/manifest.uuid b/manifest.uuid index e189e09c49..9e2002f2da 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -6dc7b2f119eb92da17c9e914bdad30a9ceaebdb5 \ No newline at end of file +89634a419d0c1ef899d0591c7c6ab9290bf665d2 \ No newline at end of file diff --git a/tool/showdb.c b/tool/showdb.c index 3324729184..1618bdb2fd 100644 --- a/tool/showdb.c +++ b/tool/showdb.c @@ -241,9 +241,9 @@ static i64 describeContent( }else if( x>=12 ){ i64 size = (x-12)/2; if( (x&1)==0 ){ - sprintf(zDesc, "blob(%d)", size); + sprintf(zDesc, "blob(%lld)", size); }else{ - sprintf(zDesc, "txt(%d)", size); + sprintf(zDesc, "txt(%lld)", size); } pData += size; } @@ -403,10 +403,10 @@ static void decodeCell( printBytes(a, x, i); nLocal = localPayload(nPayload, cType); if( nLocal==nPayload ){ - printf("payload-size: %d\n", (int)nPayload); + printf("payload-size: %lld\n", nPayload); }else{ - printf("payload-size: %d (%d local, %d overflow)\n", - (int)nPayload, nLocal, (int)(nPayload-nLocal)); + printf("payload-size: %lld (%lld local, %lld overflow)\n", + nPayload, nLocal, nPayload-nLocal); } x += i; }else{ @@ -509,7 +509,7 @@ static void decodeCell( } if( j=12 ){ i64 size = (x-12)/2; if( (x&1)==0 ){ - sprintf(zDesc, "blob(%d)", size); + sprintf(zDesc, "blob(%lld)", size); }else{ - sprintf(zDesc, "txt(%d)", size); + sprintf(zDesc, "txt(%lld)", size); } pData += size; } From ef60703e8f808b733bb83de3bccfde64a868dcd5 Mon Sep 17 00:00:00 2001 From: mistachkin Date: Sat, 19 Jul 2014 15:40:39 +0000 Subject: [PATCH 13/37] Fix warnings related to having a 64-bit size_t. FossilOrigin-Name: 29ac9336dba2b62d13315cecfc5c4a74cc54087a --- manifest | 14 +++++++------- manifest.uuid | 2 +- tool/showdb.c | 8 ++++---- tool/showwal.c | 8 ++++---- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/manifest b/manifest index f2ee7060d6..8160c09155 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\swarnings\scaused\sby\sthe\sprevious\scommit. -D 2014-07-19T15:30:01.552 +C Fix\swarnings\srelated\sto\shaving\sa\s64-bit\ssize_t. +D 2014-07-19T15:40:39.591 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5eb79e334a5de69c87740edd56af6527dd219308 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -1160,10 +1160,10 @@ F tool/opcodeDoc.awk b3a2a3d5d3075b8bd90b7afe24283efdd586659c F tool/pagesig.c ff0ca355fd3c2398e933da5e22439bbff89b803b F tool/restore_jrnl.tcl 6957a34f8f1f0f8285e07536225ec3b292a9024a F tool/rollback-test.c 9fc98427d1e23e84429d7e6d07d9094fbdec65a5 -F tool/showdb.c d7d354c52f259c06d84938fc2be095656e761b78 +F tool/showdb.c b9ee6b6c81a094bf33badbf7e9da34cdbc0cce25 F tool/showjournal.c 053eb1cc774710c6890b7dd6293300cc297b16a5 F tool/showstat4.c c39279d6bd37cb999b634f0064f6f86ad7af008f -F tool/showwal.c 9c299ba842f1ac0364e95f9effbc3a5b3b2349f2 +F tool/showwal.c 3209120269cdf9380f091459e47b776b4f81dfd3 F tool/soak1.tcl 8d407956e1a45b485a8e072470a3e629a27037fe F tool/space_used.tcl f714c41a59e326b8b9042f415b628b561bafa06b F tool/spaceanal.tcl 8e50b217c56a6a086a1b47eac9d09c5cd65b996f @@ -1182,7 +1182,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 6dc7b2f119eb92da17c9e914bdad30a9ceaebdb5 -R 7b842e4424a0effae20a64ee9f307907 +P 89634a419d0c1ef899d0591c7c6ab9290bf665d2 +R 7c73c160afe9efe974113734dfcd1ed9 U mistachkin -Z c9d7c6fd91ebbbad7eb3b3a8b17ddccd +Z 6a0ee89ac8bea8d9e5f887e8d36032b1 diff --git a/manifest.uuid b/manifest.uuid index 9e2002f2da..6eee24a63a 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -89634a419d0c1ef899d0591c7c6ab9290bf665d2 \ No newline at end of file +29ac9336dba2b62d13315cecfc5c4a74cc54087a \ No newline at end of file diff --git a/tool/showdb.c b/tool/showdb.c index 1618bdb2fd..1a51e9d1a2 100644 --- a/tool/showdb.c +++ b/tool/showdb.c @@ -143,7 +143,7 @@ static void print_decode_line( int val = aData[ofst]; char zBuf[100]; sprintf(zBuf, " %03x: %02x", ofst, aData[ofst]); - i = strlen(zBuf); + i = (int)strlen(zBuf); for(j=1; j<4; j++){ if( j>=nByte ){ sprintf(&zBuf[i], " "); @@ -151,7 +151,7 @@ static void print_decode_line( sprintf(&zBuf[i], " %02x", aData[ofst+j]); val = val*256 + aData[ofst+j]; } - i += strlen(&zBuf[i]); + i += (int)strlen(&zBuf[i]); } sprintf(&zBuf[i], " %9d", val); printf("%s %s\n", zBuf, zMsg); @@ -247,7 +247,7 @@ static i64 describeContent( } pData += size; } - j = strlen(zDesc); + j = (int)strlen(zDesc); zDesc += j; nDesc += j; } @@ -598,7 +598,7 @@ static void decode_btree_page( zMap[cofst] = '['; zMap[cofst+n-1] = ']'; sprintf(zBuf, "%d", i); - j = strlen(zBuf); + j = (int)strlen(zBuf); if( j<=n-2 ) memcpy(&zMap[cofst+1], zBuf, j); } if( cellToDecode==(-2) ){ diff --git a/tool/showwal.c b/tool/showwal.c index 8353b8dfc4..6dc1de173f 100644 --- a/tool/showwal.c +++ b/tool/showwal.c @@ -178,7 +178,7 @@ static void print_decode_line( int val = aData[ofst]; char zBuf[100]; sprintf(zBuf, " %03x: %02x", ofst, aData[ofst]); - i = strlen(zBuf); + i = (int)strlen(zBuf); for(j=1; j<4; j++){ if( j>=nByte ){ sprintf(&zBuf[i], " "); @@ -186,7 +186,7 @@ static void print_decode_line( sprintf(&zBuf[i], " %02x", aData[ofst+j]); val = val*256 + aData[ofst+j]; } - i += strlen(&zBuf[i]); + i += (int)strlen(&zBuf[i]); } if( asHex ){ sprintf(&zBuf[i], " 0x%08x", val); @@ -334,7 +334,7 @@ static i64 describeContent( } pData += size; } - j = strlen(zDesc); + j = (int)strlen(zDesc); zDesc += j; nDesc += j; } @@ -495,7 +495,7 @@ static void decode_btree_page( zMap[cofst] = '['; zMap[cofst+n-1] = ']'; sprintf(zBuf, "%d", i); - j = strlen(zBuf); + j = (int)strlen(zBuf); if( j<=n-2 ) memcpy(&zMap[cofst+1], zBuf, j); } printf(" %03x: cell[%d] %s\n", cofst, i, zDesc); From 86ac612e8a8c10504bd4e2864beb23017f7fe94b Mon Sep 17 00:00:00 2001 From: mistachkin Date: Sat, 19 Jul 2014 15:44:29 +0000 Subject: [PATCH 14/37] Fix some harmess compiler warnings in the FTS3 Unicode module. FossilOrigin-Name: c01caea5d6ad7a570628b85fb3056ac955ff03dd --- ext/fts3/fts3_unicode.c | 10 +++++----- manifest | 12 ++++++------ manifest.uuid | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/ext/fts3/fts3_unicode.c b/ext/fts3/fts3_unicode.c index 591cbb8dc9..57e7a4d3c9 100644 --- a/ext/fts3/fts3_unicode.c +++ b/ext/fts3/fts3_unicode.c @@ -231,7 +231,7 @@ static int unicodeCreate( for(i=0; rc==SQLITE_OK && ibRemoveDiacritic = 1; @@ -363,11 +363,11 @@ static int unicodeNext( ); /* Set the output variables and return. */ - pCsr->iOff = (z - pCsr->aInput); + pCsr->iOff = (int)(z - pCsr->aInput); *paToken = pCsr->zToken; - *pnToken = zOut - pCsr->zToken; - *piStart = (zStart - pCsr->aInput); - *piEnd = (zEnd - pCsr->aInput); + *pnToken = (int)(zOut - pCsr->zToken); + *piStart = (int)(zStart - pCsr->aInput); + *piEnd = (int)(zEnd - pCsr->aInput); *piPos = pCsr->iToken++; return SQLITE_OK; } diff --git a/manifest b/manifest index 8160c09155..59d0b2b601 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\swarnings\srelated\sto\shaving\sa\s64-bit\ssize_t. -D 2014-07-19T15:40:39.591 +C Fix\ssome\sharmess\scompiler\swarnings\sin\sthe\sFTS3\sUnicode\smodule. +D 2014-07-19T15:44:29.116 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5eb79e334a5de69c87740edd56af6527dd219308 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -94,7 +94,7 @@ F ext/fts3/fts3_tokenize_vtab.c 011170fe9eba5ff062f1a31d3188e00267716706 F ext/fts3/fts3_tokenizer.c bbdc731bc91338050675c6d1da9ab82147391e16 F ext/fts3/fts3_tokenizer.h 64c6ef6c5272c51ebe60fc607a896e84288fcbc3 F ext/fts3/fts3_tokenizer1.c 5c98225a53705e5ee34824087478cf477bdb7004 -F ext/fts3/fts3_unicode.c 0f598fa4c96af1188e4d5f5e8e78e25500bd5922 +F ext/fts3/fts3_unicode.c e80eef8a11f2020dc9c1eb95c5b405b9012f2fbe F ext/fts3/fts3_unicode2.c c8adda75aad0c6c252ef3dd555f811f437485044 F ext/fts3/fts3_write.c 8260388626516a7005d06a9dce94f9e55c6c2a41 F ext/fts3/fts3speed.tcl b54caf6a18d38174f1a6e84219950d85e98bb1e9 @@ -1182,7 +1182,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 89634a419d0c1ef899d0591c7c6ab9290bf665d2 -R 7c73c160afe9efe974113734dfcd1ed9 +P 29ac9336dba2b62d13315cecfc5c4a74cc54087a +R 4ac50ab96ea64a1527703075acfe4ff2 U mistachkin -Z 6a0ee89ac8bea8d9e5f887e8d36032b1 +Z ef640c9ada5ada1862dacc56c6ab494a diff --git a/manifest.uuid b/manifest.uuid index 6eee24a63a..e4b4c3f479 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -29ac9336dba2b62d13315cecfc5c4a74cc54087a \ No newline at end of file +c01caea5d6ad7a570628b85fb3056ac955ff03dd \ No newline at end of file From 857745c089741831310cbd2071b226dcd4b18bfa Mon Sep 17 00:00:00 2001 From: dan Date: Sat, 19 Jul 2014 17:57:10 +0000 Subject: [PATCH 15/37] Update the sqlite3_stmt_busy() function so that it correctly returns true for "ROLLBACK" statements that have been stepped but not yet reset. FossilOrigin-Name: 61cee3c0678f5abd9131a29ab946a5e71f55643e --- manifest | 19 +++++++++---------- manifest.uuid | 2 +- src/vdbeapi.c | 2 +- src/vdbeaux.c | 2 +- test/capi3d.test | 37 +++++++++++++++++++++++++++++++++++++ 5 files changed, 49 insertions(+), 13 deletions(-) diff --git a/manifest b/manifest index 52a708bbe8..9c16ebe0d5 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sharmless\scompiler\swarnings\sin\sthe\sshowdb\sand\sshowwal\stools\sand\sin\nthe\sunicode\stokenizer\sof\sFTS3. -D 2014-07-19T17:49:40.535 +C Update\sthe\ssqlite3_stmt_busy()\sfunction\sso\sthat\sit\scorrectly\sreturns\strue\sfor\s"ROLLBACK"\sstatements\sthat\shave\sbeen\sstepped\sbut\snot\syet\sreset. +D 2014-07-19T17:57:10.785 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5eb79e334a5de69c87740edd56af6527dd219308 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -286,8 +286,8 @@ F src/vacuum.c 3728d74919d4fb1356f9e9a13e27773db60b7179 F src/vdbe.c 9bfe6becfc094382ae213656fbe511055ad83a54 F src/vdbe.h c63fad052c9e7388d551e556e119c0bcf6bebdf8 F src/vdbeInt.h 5df5e9afe9b7839cd17256220fc4f7af84b8b1cd -F src/vdbeapi.c 0ed6053f947edd0b30f64ce5aeb811872a3450a4 -F src/vdbeaux.c 8ce7dcdbb8c59e5c2194518ce3099b254ae94c15 +F src/vdbeapi.c 24e40422382beb774daab11fe9fe9d37e8a04949 +F src/vdbeaux.c 8d32b5a68670ccc6c64904924e6a0dddbc3a2fc5 F src/vdbeblob.c 9205ce9d3b064d9600f8418a897fc88b5687d9ac F src/vdbemem.c d90a1e8acf8b63dc9d14cbbea12bfec6cec31394 F src/vdbesort.c 44441d73b08b3a638dcdb725afffb87c6574ad27 @@ -372,7 +372,7 @@ F test/capi2.test 011c16da245fdc0106a2785035de6b242c05e738 F test/capi3.test 71bcf2fbd36a9732f617766dfd752552c8e491b5 F test/capi3b.test efb2b9cfd127efa84433cd7a2d72ce0454ae0dc4 F test/capi3c.test a21869e4d50d5dbb7e566e328fc0bc7c2efa6a32 -F test/capi3d.test 6d0fc0a86d73f42dd19a7d8b7761ab9bc02277d0 +F test/capi3d.test c84af0c49267f9c3fbf4c1c46aa647646023811e F test/capi3e.test 3d49c01ef2a1a55f41d73cba2b23b5059ec460fe F test/cast.test 4c275cbdc8202d6f9c54a3596701719868ac7dc3 F test/check.test 5831ddb6f2c687782eaf2e1a07b6e17f24c4f763 @@ -1182,8 +1182,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 2beefa68c0c53f663321bebf0ac06f6c936be63f c01caea5d6ad7a570628b85fb3056ac955ff03dd -R 4ac50ab96ea64a1527703075acfe4ff2 -T +closed c01caea5d6ad7a570628b85fb3056ac955ff03dd -U drh -Z cd2aeeb09b327b0fcacfc59206b5ba8f +P 574cc8eb1448cff67390f2e16cc9b7c3ddd4658b +R 3e17c7c287ebc0f7c8d4dc519939fd8f +U dan +Z 2190a4b1d8dc0a3facc078eb683578eb diff --git a/manifest.uuid b/manifest.uuid index 1773fd5e15..5e45c34d1e 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -574cc8eb1448cff67390f2e16cc9b7c3ddd4658b \ No newline at end of file +61cee3c0678f5abd9131a29ab946a5e71f55643e \ No newline at end of file diff --git a/src/vdbeapi.c b/src/vdbeapi.c index 5d7a0b0608..5e5bb81366 100644 --- a/src/vdbeapi.c +++ b/src/vdbeapi.c @@ -1323,7 +1323,7 @@ int sqlite3_stmt_readonly(sqlite3_stmt *pStmt){ */ int sqlite3_stmt_busy(sqlite3_stmt *pStmt){ Vdbe *v = (Vdbe*)pStmt; - return v!=0 && v->pc>0 && v->magic==VDBE_MAGIC_RUN; + return v!=0 && v->pc>=0 && v->magic==VDBE_MAGIC_RUN; } /* diff --git a/src/vdbeaux.c b/src/vdbeaux.c index de61b55c83..92652de5a7 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -2143,7 +2143,7 @@ static void checkActiveVdbeCnt(sqlite3 *db){ int nRead = 0; p = db->pVdbe; while( p ){ - if( p->magic==VDBE_MAGIC_RUN && p->pc>=0 ){ + if( sqlite3_stmt_busy((sqlite3_stmt*)p) ){ cnt++; if( p->readOnly==0 ) nWrite++; if( p->bIsReader ) nRead++; diff --git a/test/capi3d.test b/test/capi3d.test index ed3765b051..fb8abe86d2 100644 --- a/test/capi3d.test +++ b/test/capi3d.test @@ -144,4 +144,41 @@ do_test capi3d-3.99 { sqlite3_stmt_busy 0 } {0} +#-------------------------------------------------------------------------- +# Test the sqlite3_stmt_busy() function with ROLLBACK statements. +# +reset_db + +do_execsql_test capi3d-4.1 { + CREATE TABLE t4(x,y); + BEGIN; +} + +do_test capi3d-4.2.1 { + breakpoint + set ::s1 [sqlite3_prepare_v2 db "ROLLBACK" -1 notused] + sqlite3_step $::s1 +} {SQLITE_DONE} + +do_test capi3d-4.2.2 { + sqlite3_stmt_busy $::s1 +} {1} + +do_catchsql_test capi3d-4.2.3 { + VACUUM +} {1 {cannot VACUUM - SQL statements in progress}} + +do_test capi3d-4.2.4 { + sqlite3_reset $::s1 +} {SQLITE_OK} + +do_catchsql_test capi3d-4.2.5 { + VACUUM +} {0 {}} + +do_test capi3d-4.2.6 { + sqlite3_finalize $::s1 +} {SQLITE_OK} + + finish_test From a7ab6d8165fb25e0e55d72577181399fa2c9692a Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 21 Jul 2014 15:44:39 +0000 Subject: [PATCH 16/37] Allow the SQLITE_MAX_ATTACHED compile-time option to be larger than 62. The default limit on the number of attached databases remains 10. FossilOrigin-Name: 1a817ae2f35fa0396148dda2782cd4f919bf5c6f --- manifest | 22 +++++++++++----------- manifest.uuid | 2 +- src/build.c | 34 +++++++++++++++++++++++----------- src/main.c | 4 ++-- src/sqliteInt.h | 15 ++++++++++++++- src/vdbe.c | 22 +++++++++++----------- src/vdbeaux.c | 22 ++++++++++------------ 7 files changed, 72 insertions(+), 49 deletions(-) diff --git a/manifest b/manifest index 9c16ebe0d5..6b6e2f6d22 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Update\sthe\ssqlite3_stmt_busy()\sfunction\sso\sthat\sit\scorrectly\sreturns\strue\sfor\s"ROLLBACK"\sstatements\sthat\shave\sbeen\sstepped\sbut\snot\syet\sreset. -D 2014-07-19T17:57:10.785 +C Allow\sthe\sSQLITE_MAX_ATTACHED\scompile-time\soption\sto\sbe\slarger\sthan\s62.\s\sThe\ndefault\slimit\son\sthe\snumber\sof\sattached\sdatabases\sremains\s10. +D 2014-07-21T15:44:39.054 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5eb79e334a5de69c87740edd56af6527dd219308 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -170,7 +170,7 @@ F src/btmutex.c 976f45a12e37293e32cae0281b15a21d48a8aaa7 F src/btree.c 70c60a3807b2072982f184d9614e020d2953f89c F src/btree.h 4245a349bfe09611d7ff887dbc3a80cee8b7955a F src/btreeInt.h cf180d86b2e9e418f638d65baa425c4c69c0e0e3 -F src/build.c 927e39b6aaf872c7b28f154f6acfeb9a05a72442 +F src/build.c 48f400fa14fd6add244b954ce7e223ce7ccacf0b F src/callback.c 174e3c8656bc29f91d710ab61550d16eea34be98 F src/complete.c dc1d136c0feee03c2f7550bafc0d29075e36deac F src/ctime.c 0231df905e2c4abba4483ee18ffc05adc321df2a @@ -189,7 +189,7 @@ F src/journal.c b4124532212b6952f42eb2c12fa3c25701d8ba8d F src/legacy.c 0df0b1550b9cc1f58229644735e317ac89131f12 F src/lempar.c cdf0a000315332fc9b50b62f3b5e22e080a0952b F src/loadext.c 867c7b330b740c6c917af9956b13b81d0a048303 -F src/main.c 7c2c3cafdd6313c8f9319ebec1565782e624372e +F src/main.c bba87834413394f43b1a211c38c282c7d4092d1d F src/malloc.c 0203ebce9152c6a0e5de520140b8ba65187350be F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645 F src/mem1.c c0c990fcaddff810ea277b4fb5d9138603dd5d4b @@ -227,7 +227,7 @@ F src/shell.c 566aee8213372a2e81ba0eb34e9759f7b2574009 F src/sqlite.h.in fd8e3a36b0aded082dc93a4b89c1e85324b4cf75 F src/sqlite3.rc 11094cc6a157a028b301a9f06b3d03089ea37c3e F src/sqlite3ext.h 886f5a34de171002ad46fae8c36a7d8051c190fc -F src/sqliteInt.h e88614d7371b80ff69dbbb5e4b9813ee93dfd890 +F src/sqliteInt.h 5dbcdcf81cb15e77df16f88699a15f7af491c580 F src/sqliteLimit.h 164b0e6749d31e0daa1a4589a169d31c0dec7b3d F src/status.c 7ac05a5c7017d0b9f0b4bcd701228b784f987158 F src/table.c 2cd62736f845d82200acfa1287e33feb3c15d62e @@ -283,11 +283,11 @@ F src/update.c 01564b3c430f6c7b0a35afaf7aba7987206fa3a5 F src/utf.c a0314e637768a030e6e84a957d0c4f6ba910cc05 F src/util.c 049fe1d3c0e2209c1bee107aec2fcff6285f909f F src/vacuum.c 3728d74919d4fb1356f9e9a13e27773db60b7179 -F src/vdbe.c 9bfe6becfc094382ae213656fbe511055ad83a54 +F src/vdbe.c 514adcc9478e461d01b9b064565d2c99604ed537 F src/vdbe.h c63fad052c9e7388d551e556e119c0bcf6bebdf8 F src/vdbeInt.h 5df5e9afe9b7839cd17256220fc4f7af84b8b1cd F src/vdbeapi.c 24e40422382beb774daab11fe9fe9d37e8a04949 -F src/vdbeaux.c 8d32b5a68670ccc6c64904924e6a0dddbc3a2fc5 +F src/vdbeaux.c 1ffe0bbc3a2c8aedd95622de9be6b6d07b3d3c6b F src/vdbeblob.c 9205ce9d3b064d9600f8418a897fc88b5687d9ac F src/vdbemem.c d90a1e8acf8b63dc9d14cbbea12bfec6cec31394 F src/vdbesort.c 44441d73b08b3a638dcdb725afffb87c6574ad27 @@ -1182,7 +1182,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 574cc8eb1448cff67390f2e16cc9b7c3ddd4658b -R 3e17c7c287ebc0f7c8d4dc519939fd8f -U dan -Z 2190a4b1d8dc0a3facc078eb683578eb +P 61cee3c0678f5abd9131a29ab946a5e71f55643e +R 03bc11d876fd7682716b5fcb2f08b30c +U drh +Z 1b802be3c637c9b3363a3a4e9caf7d2a diff --git a/manifest.uuid b/manifest.uuid index 5e45c34d1e..e7fd3c7be7 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -61cee3c0678f5abd9131a29ab946a5e71f55643e \ No newline at end of file +1a817ae2f35fa0396148dda2782cd4f919bf5c6f \ No newline at end of file diff --git a/src/build.c b/src/build.c index 677ba326c6..27c9671da6 100644 --- a/src/build.c +++ b/src/build.c @@ -113,6 +113,19 @@ static void codeTableLocks(Parse *pParse){ #define codeTableLocks(x) #endif +/* +** Return TRUE if the given yDbMask object is empty - if it contains no +** 1 bits. This routine is used by the DbMaskAllZero() and DbMaskNotZero() +** macros when SQLITE_MAX_ATTACHED is greater than 30. +*/ +#if SQLITE_MAX_ATTACHED>30 +int sqlite3DbMaskAllZero(yDbMask m){ + int i; + for(i=0; imallocFailed==0 && (pParse->cookieMask || pParse->pConstExpr) ){ - yDbMask mask; + if( db->mallocFailed==0 + && (DbMaskNonZero(pParse->cookieMask) || pParse->pConstExpr) + ){ int iDb, i; assert( sqlite3VdbeGetOp(v, 0)->opcode==OP_Init ); sqlite3VdbeJumpHere(v, 0); - for(iDb=0, mask=1; iDbnDb; mask<<=1, iDb++){ - if( (mask & pParse->cookieMask)==0 ) continue; + for(iDb=0; iDbnDb; iDb++){ + if( DbMaskTest(pParse->cookieMask, iDb)==0 ) continue; sqlite3VdbeUsesBtree(v, iDb); sqlite3VdbeAddOp4Int(v, OP_Transaction, /* Opcode */ iDb, /* P1 */ - (mask & pParse->writeMask)!=0, /* P2 */ + DbMaskTest(pParse->writeMask,iDb), /* P2 */ pParse->cookieValue[iDb], /* P3 */ db->aDb[iDb].pSchema->iGeneration /* P4 */ ); @@ -216,7 +230,7 @@ void sqlite3FinishCoding(Parse *pParse){ pParse->nMem = 0; pParse->nSet = 0; pParse->nVar = 0; - pParse->cookieMask = 0; + DbMaskZero(pParse->cookieMask); } /* @@ -3843,15 +3857,13 @@ int sqlite3OpenTempDatabase(Parse *pParse){ void sqlite3CodeVerifySchema(Parse *pParse, int iDb){ Parse *pToplevel = sqlite3ParseToplevel(pParse); sqlite3 *db = pToplevel->db; - yDbMask mask; assert( iDb>=0 && iDbnDb ); assert( db->aDb[iDb].pBt!=0 || iDb==1 ); assert( iDbcookieMask & mask)==0 ){ - pToplevel->cookieMask |= mask; + if( DbMaskTest(pToplevel->cookieMask, iDb)==0 ){ + DbMaskSet(pToplevel->cookieMask, iDb); pToplevel->cookieValue[iDb] = db->aDb[iDb].pSchema->schema_cookie; if( !OMIT_TEMPDB && iDb==1 ){ sqlite3OpenTempDatabase(pToplevel); @@ -3890,7 +3902,7 @@ void sqlite3CodeVerifyNamedSchema(Parse *pParse, const char *zDb){ void sqlite3BeginWriteOperation(Parse *pParse, int setStatement, int iDb){ Parse *pToplevel = sqlite3ParseToplevel(pParse); sqlite3CodeVerifySchema(pParse, iDb); - pToplevel->writeMask |= ((yDbMask)1)<writeMask, iDb); pToplevel->isMultiWrite |= setStatement; } diff --git a/src/main.c b/src/main.c index 564c012472..c1d59976a6 100644 --- a/src/main.c +++ b/src/main.c @@ -2101,8 +2101,8 @@ static const int aHardLimit[] = { #if SQLITE_MAX_FUNCTION_ARG<0 || SQLITE_MAX_FUNCTION_ARG>1000 # error SQLITE_MAX_FUNCTION_ARG must be between 0 and 1000 #endif -#if SQLITE_MAX_ATTACHED<0 || SQLITE_MAX_ATTACHED>62 -# error SQLITE_MAX_ATTACHED must be between 0 and 62 +#if SQLITE_MAX_ATTACHED<0 +# error SQLITE_MAX_ATTACHED must be greater than 0 #endif #if SQLITE_MAX_LIKE_PATTERN_LENGTH<1 # error SQLITE_MAX_LIKE_PATTERN_LENGTH must be at least 1 diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 7e347c4ee2..8f256d52fc 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -2392,9 +2392,19 @@ struct TriggerPrg { ** The yDbMask datatype for the bitmask of all attached databases. */ #if SQLITE_MAX_ATTACHED>30 - typedef sqlite3_uint64 yDbMask; + typedef unsigned char yDbMask[(SQLITE_MAX_ATTACHED+9)/8]; +# define DbMaskTest(M,I) (((M)[(I)/8]&(1<<((I)&7)))!=0) +# define DbMaskZero(M) memset((M),0,sizeof(M)) +# define DbMaskSet(M,I) (M)[(I)/8]|=(1<<((I)&7)) +# define DbMaskAllZero(M) sqlite3DbMaskAllZero(M) +# define DbMaskNonZero(M) (sqlite3DbMaskAllZero(M)==0) #else typedef unsigned int yDbMask; +# define DbMaskTest(M,I) (((M)&(((yDbMask)1)<<(I)))!=0) +# define DbMaskZero(M) (M)=0 +# define DbMaskSet(M,I) (M)|=(((yDbMask)1)<<(I)) +# define DbMaskAllZero(M) (M)==0 +# define DbMaskNonZero(M) (M)!=0 #endif /* @@ -3067,6 +3077,9 @@ void sqlite3CreateView(Parse*,Token*,Token*,Token*,Select*,int,int); # define sqlite3ViewGetColumnNames(A,B) 0 #endif +#if SQLITE_MAX_ATTACHED>30 + int sqlite3DbMaskAllZero(yDbMask); +#endif void sqlite3DropTable(Parse*, SrcList*, int, int); void sqlite3CodeDropTable(Parse*, Table*, int, int); void sqlite3DeleteTable(sqlite3*, Table*); diff --git a/src/vdbe.c b/src/vdbe.c index 11aa035026..ecea3782d4 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -3034,7 +3034,7 @@ case OP_Transaction: { assert( p->bIsReader ); assert( p->readOnly==0 || pOp->p2==0 ); assert( pOp->p1>=0 && pOp->p1nDb ); - assert( (p->btreeMask & (((yDbMask)1)<p1))!=0 ); + assert( DbMaskTest(p->btreeMask, pOp->p1) ); if( pOp->p2 && (db->flags & SQLITE_QueryOnly)!=0 ){ rc = SQLITE_READONLY; goto abort_due_to_error; @@ -3129,7 +3129,7 @@ case OP_ReadCookie: { /* out2-prerelease */ assert( pOp->p3=0 && iDbnDb ); assert( db->aDb[iDb].pBt!=0 ); - assert( (p->btreeMask & (((yDbMask)1)<btreeMask, iDb) ); sqlite3BtreeGetMeta(db->aDb[iDb].pBt, iCookie, (u32 *)&iMeta); pOut->u.i = iMeta; @@ -3150,7 +3150,7 @@ case OP_SetCookie: { /* in3 */ Db *pDb; assert( pOp->p2p1>=0 && pOp->p1nDb ); - assert( (p->btreeMask & (((yDbMask)1)<p1))!=0 ); + assert( DbMaskTest(p->btreeMask, pOp->p1) ); assert( p->readOnly==0 ); pDb = &db->aDb[pOp->p1]; assert( pDb->pBt!=0 ); @@ -3253,7 +3253,7 @@ case OP_OpenWrite: { p2 = pOp->p2; iDb = pOp->p3; assert( iDb>=0 && iDbnDb ); - assert( (p->btreeMask & (((yDbMask)1)<btreeMask, iDb) ); pDb = &db->aDb[iDb]; pX = pDb->pBt; assert( pX!=0 ); @@ -4844,7 +4844,7 @@ case OP_Destroy: { /* out2-prerelease */ }else{ iDb = pOp->p3; assert( iCnt==1 ); - assert( (p->btreeMask & (((yDbMask)1)<btreeMask, iDb) ); iMoved = 0; /* Not needed. Only to silence a warning. */ rc = sqlite3BtreeDropTable(db->aDb[iDb].pBt, pOp->p1, &iMoved); pOut->flags = MEM_Int; @@ -4884,7 +4884,7 @@ case OP_Clear: { nChange = 0; assert( p->readOnly==0 ); - assert( (p->btreeMask & (((yDbMask)1)<p2))!=0 ); + assert( DbMaskTest(p->btreeMask, pOp->p2) ); rc = sqlite3BtreeClearTable( db->aDb[pOp->p2].pBt, pOp->p1, (pOp->p3 ? &nChange : 0) ); @@ -4954,7 +4954,7 @@ case OP_CreateTable: { /* out2-prerelease */ pgno = 0; assert( pOp->p1>=0 && pOp->p1nDb ); - assert( (p->btreeMask & (((yDbMask)1)<p1))!=0 ); + assert( DbMaskTest(p->btreeMask, pOp->p1) ); assert( p->readOnly==0 ); pDb = &db->aDb[pOp->p1]; assert( pDb->pBt!=0 ); @@ -5119,7 +5119,7 @@ case OP_IntegrityCk: { } aRoot[j] = 0; assert( pOp->p5nDb ); - assert( (p->btreeMask & (((yDbMask)1)<p5))!=0 ); + assert( DbMaskTest(p->btreeMask, pOp->p5) ); z = sqlite3BtreeIntegrityCheck(db->aDb[pOp->p5].pBt, aRoot, nRoot, (int)pnErr->u.i, &nErr); sqlite3DbFree(db, aRoot); @@ -5779,7 +5779,7 @@ case OP_IncrVacuum: { /* jump */ Btree *pBt; assert( pOp->p1>=0 && pOp->p1nDb ); - assert( (p->btreeMask & (((yDbMask)1)<p1))!=0 ); + assert( DbMaskTest(p->btreeMask, pOp->p1) ); assert( p->readOnly==0 ); pBt = db->aDb[pOp->p1].pBt; rc = sqlite3BtreeIncrVacuum(pBt); @@ -5831,7 +5831,7 @@ case OP_TableLock: { if( isWriteLock || 0==(db->flags&SQLITE_ReadUncommitted) ){ int p1 = pOp->p1; assert( p1>=0 && p1nDb ); - assert( (p->btreeMask & (((yDbMask)1)<btreeMask, p1) ); assert( isWriteLock==0 || isWriteLock==1 ); rc = sqlite3BtreeLockTable(db->aDb[p1].pBt, pOp->p2, isWriteLock); if( (rc&0xFF)==SQLITE_LOCKED ){ @@ -6281,7 +6281,7 @@ case OP_Init: { /* jump */ if( zTrace ){ int i; for(i=0; inDb; i++){ - if( (MASKBIT(i) & p->btreeMask)==0 ) continue; + if( DbMaskTest(p->btreeMask, i)==0 ) continue; sqlite3_file_control(db, db->aDb[i].zName, SQLITE_FCNTL_TRACE, zTrace); } } diff --git a/src/vdbeaux.c b/src/vdbeaux.c index 92652de5a7..ac945df59e 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -499,7 +499,7 @@ static void resolveP2Values(Vdbe *p, int *pMaxFuncArgs){ pParse->aLabel = 0; pParse->nLabel = 0; *pMaxFuncArgs = nMaxArgs; - assert( p->bIsReader!=0 || p->btreeMask==0 ); + assert( p->bIsReader!=0 || DbMaskAllZero(p->btreeMask) ); } /* @@ -526,7 +526,7 @@ VdbeOp *sqlite3VdbeTakeOpArray(Vdbe *p, int *pnOp, int *pnMaxArg){ assert( aOp && !p->db->mallocFailed ); /* Check that sqlite3VdbeUsesBtree() was not called on this VM */ - assert( p->btreeMask==0 ); + assert( DbMaskAllZero(p->btreeMask) ); resolveP2Values(p, pnMaxArg); *pnOp = p->nOp; @@ -1111,9 +1111,9 @@ static char *displayP4(Op *pOp, char *zTemp, int nTemp){ void sqlite3VdbeUsesBtree(Vdbe *p, int i){ assert( i>=0 && idb->nDb && i<(int)sizeof(yDbMask)*8 ); assert( i<(int)sizeof(p->btreeMask)*8 ); - p->btreeMask |= ((yDbMask)1)<btreeMask, i); if( i!=1 && sqlite3BtreeSharable(p->db->aDb[i].pBt) ){ - p->lockMask |= ((yDbMask)1)<lockMask, i); } } @@ -1141,16 +1141,15 @@ void sqlite3VdbeUsesBtree(Vdbe *p, int i){ */ void sqlite3VdbeEnter(Vdbe *p){ int i; - yDbMask mask; sqlite3 *db; Db *aDb; int nDb; - if( p->lockMask==0 ) return; /* The common case */ + if( DbMaskAllZero(p->lockMask) ) return; /* The common case */ db = p->db; aDb = db->aDb; nDb = db->nDb; - for(i=0, mask=1; ilockMask)!=0 && ALWAYS(aDb[i].pBt!=0) ){ + for(i=0; ilockMask,i) && ALWAYS(aDb[i].pBt!=0) ){ sqlite3BtreeEnter(aDb[i].pBt); } } @@ -1163,16 +1162,15 @@ void sqlite3VdbeEnter(Vdbe *p){ */ void sqlite3VdbeLeave(Vdbe *p){ int i; - yDbMask mask; sqlite3 *db; Db *aDb; int nDb; - if( p->lockMask==0 ) return; /* The common case */ + if( DbMaskAllZero(p->lockMask) ) return; /* The common case */ db = p->db; aDb = db->aDb; nDb = db->nDb; - for(i=0, mask=1; ilockMask)!=0 && ALWAYS(aDb[i].pBt!=0) ){ + for(i=0; ilockMask,i) && ALWAYS(aDb[i].pBt!=0) ){ sqlite3BtreeLeave(aDb[i].pBt); } } From 215c0c82fa08e224a747ac22ac0c34318fe422ff Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 21 Jul 2014 20:07:17 +0000 Subject: [PATCH 17/37] Limit the maximum SQLITE_MAX_ATTACHED to 127, since a signed character is sometimes used to store the database index. FossilOrigin-Name: f1c76c7c4c7d16855db60d16e23ecdf8d7ca862a --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/main.c | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 6b6e2f6d22..907c781f6f 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Allow\sthe\sSQLITE_MAX_ATTACHED\scompile-time\soption\sto\sbe\slarger\sthan\s62.\s\sThe\ndefault\slimit\son\sthe\snumber\sof\sattached\sdatabases\sremains\s10. -D 2014-07-21T15:44:39.054 +C Limit\sthe\smaximum\sSQLITE_MAX_ATTACHED\sto\s127,\ssince\sa\ssigned\scharacter\nis\ssometimes\sused\sto\sstore\sthe\sdatabase\sindex. +D 2014-07-21T20:07:17.299 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5eb79e334a5de69c87740edd56af6527dd219308 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -189,7 +189,7 @@ F src/journal.c b4124532212b6952f42eb2c12fa3c25701d8ba8d F src/legacy.c 0df0b1550b9cc1f58229644735e317ac89131f12 F src/lempar.c cdf0a000315332fc9b50b62f3b5e22e080a0952b F src/loadext.c 867c7b330b740c6c917af9956b13b81d0a048303 -F src/main.c bba87834413394f43b1a211c38c282c7d4092d1d +F src/main.c d0fa35a8582923730ab2113d34dddc061f59d211 F src/malloc.c 0203ebce9152c6a0e5de520140b8ba65187350be F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645 F src/mem1.c c0c990fcaddff810ea277b4fb5d9138603dd5d4b @@ -1182,7 +1182,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 61cee3c0678f5abd9131a29ab946a5e71f55643e -R 03bc11d876fd7682716b5fcb2f08b30c +P 1a817ae2f35fa0396148dda2782cd4f919bf5c6f +R 848516fae6f90d131f9449e42d77b0c0 U drh -Z 1b802be3c637c9b3363a3a4e9caf7d2a +Z 0a273a2cc8050e8888f6349db4185a5f diff --git a/manifest.uuid b/manifest.uuid index e7fd3c7be7..f108a708b4 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -1a817ae2f35fa0396148dda2782cd4f919bf5c6f \ No newline at end of file +f1c76c7c4c7d16855db60d16e23ecdf8d7ca862a \ No newline at end of file diff --git a/src/main.c b/src/main.c index c1d59976a6..1e05dd8486 100644 --- a/src/main.c +++ b/src/main.c @@ -2101,8 +2101,8 @@ static const int aHardLimit[] = { #if SQLITE_MAX_FUNCTION_ARG<0 || SQLITE_MAX_FUNCTION_ARG>1000 # error SQLITE_MAX_FUNCTION_ARG must be between 0 and 1000 #endif -#if SQLITE_MAX_ATTACHED<0 -# error SQLITE_MAX_ATTACHED must be greater than 0 +#if SQLITE_MAX_ATTACHED<0 || SQLITE_MAX_ATTACHED>127 +# error SQLITE_MAX_ATTACHED must be between 0 and 127 #endif #if SQLITE_MAX_LIKE_PATTERN_LENGTH<1 # error SQLITE_MAX_LIKE_PATTERN_LENGTH must be at least 1 From 53ad7e48ab72d07728e4db6875c12561f3748d98 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 22 Jul 2014 00:40:45 +0000 Subject: [PATCH 18/37] For the OR-optimization, avoid generating OP_OpenRead opcodes that reopen exactly the same index. FossilOrigin-Name: b67a6e33f23ce5f5d9a545fa9d6700a7ed636901 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/sqliteInt.h | 1 + src/where.c | 19 +++++++++++++++++-- 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index 907c781f6f..df25ada5a5 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Limit\sthe\smaximum\sSQLITE_MAX_ATTACHED\sto\s127,\ssince\sa\ssigned\scharacter\nis\ssometimes\sused\sto\sstore\sthe\sdatabase\sindex. -D 2014-07-21T20:07:17.299 +C For\sthe\sOR-optimization,\savoid\sgenerating\sOP_OpenRead\sopcodes\sthat\sreopen\nexactly\sthe\ssame\sindex. +D 2014-07-22T00:40:45.480 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5eb79e334a5de69c87740edd56af6527dd219308 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -227,7 +227,7 @@ F src/shell.c 566aee8213372a2e81ba0eb34e9759f7b2574009 F src/sqlite.h.in fd8e3a36b0aded082dc93a4b89c1e85324b4cf75 F src/sqlite3.rc 11094cc6a157a028b301a9f06b3d03089ea37c3e F src/sqlite3ext.h 886f5a34de171002ad46fae8c36a7d8051c190fc -F src/sqliteInt.h 5dbcdcf81cb15e77df16f88699a15f7af491c580 +F src/sqliteInt.h 0991b31a98c6ce072d255954af617baf50735eb1 F src/sqliteLimit.h 164b0e6749d31e0daa1a4589a169d31c0dec7b3d F src/status.c 7ac05a5c7017d0b9f0b4bcd701228b784f987158 F src/table.c 2cd62736f845d82200acfa1287e33feb3c15d62e @@ -296,7 +296,7 @@ F src/vtab.c 21b932841e51ebd7d075e2d0ad1415dce8d2d5fd F src/wal.c 264df50a1b33124130b23180ded2e2c5663c652a F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4 F src/walker.c 11edb74d587bc87b33ca96a5173e3ec1b8389e45 -F src/where.c 3a451b00516b59f414c59f817508edce51c732f1 +F src/where.c 4f8dce8f4e50b3b3675e8af7811e48526d6b4be2 F src/whereInt.h 929c1349b5355fd44f22cee5c14d72b3329c58a6 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2 @@ -1182,7 +1182,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 1a817ae2f35fa0396148dda2782cd4f919bf5c6f -R 848516fae6f90d131f9449e42d77b0c0 +P f1c76c7c4c7d16855db60d16e23ecdf8d7ca862a +R ff4e333e5c258e291fb4ff256a0eb1e1 U drh -Z 0a273a2cc8050e8888f6349db4185a5f +Z 9049ac2491ab8361811966ab022cf8d0 diff --git a/manifest.uuid b/manifest.uuid index f108a708b4..9e127a138a 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -f1c76c7c4c7d16855db60d16e23ecdf8d7ca862a \ No newline at end of file +b67a6e33f23ce5f5d9a545fa9d6700a7ed636901 \ No newline at end of file diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 8f256d52fc..6b0e031b30 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -2136,6 +2136,7 @@ struct SrcList { #define WHERE_DISTINCTBY 0x0200 /* pOrderby is really a DISTINCT clause */ #define WHERE_WANT_DISTINCT 0x0400 /* All output needs to be distinct */ #define WHERE_SORTBYGROUP 0x0800 /* Support sqlite3WhereIsSorted() */ +#define WHERE_OR_INDEX_OPEN 0x1000 /* OP_OpenRead for the OR index exists */ /* Allowed return values from sqlite3WhereIsDistinct() */ diff --git a/src/where.c b/src/where.c index e52f598e02..84a8d9a03f 100644 --- a/src/where.c +++ b/src/where.c @@ -3422,6 +3422,7 @@ static Bitmask codeOneLoopStart( int iRetInit; /* Address of regReturn init */ int untestedTerms = 0; /* Some terms not completely tested */ int ii; /* Loop counter */ + int subWctrlFlags; /* wctrlFlags for sub-queries */ Expr *pAndExpr = 0; /* An ".. AND (...)" expression */ Table *pTab = pTabItem->pTab; @@ -3517,6 +3518,8 @@ static Bitmask codeOneLoopStart( ** eliminating duplicates from other WHERE clauses, the action for each ** sub-WHERE clause is to to invoke the main loop body as a subroutine. */ + subWctrlFlags = WHERE_OMIT_OPEN_CLOSE | WHERE_AND_ONLY | + WHERE_FORCE_TABLE | WHERE_ONETABLE_ONLY; for(ii=0; iinTerm; ii++){ WhereTerm *pOrTerm = &pOrWc->a[ii]; if( pOrTerm->leftCursor==iCur || (pOrTerm->eOperator & WO_AND)!=0 ){ @@ -3529,8 +3532,7 @@ static Bitmask codeOneLoopStart( } /* Loop through table entries that match term pOrTerm. */ pSubWInfo = sqlite3WhereBegin(pParse, pOrTab, pOrExpr, 0, 0, - WHERE_OMIT_OPEN_CLOSE | WHERE_AND_ONLY | - WHERE_FORCE_TABLE | WHERE_ONETABLE_ONLY, iCovCur); + subWctrlFlags, iCovCur); assert( pSubWInfo || pParse->nErr || db->mallocFailed ); if( pSubWInfo ){ WhereLoop *pSubLoop; @@ -3621,6 +3623,7 @@ static Bitmask codeOneLoopStart( ){ assert( pSubWInfo->a[0].iIdxCur==iCovCur ); pCov = pSubLoop->u.btree.pIndex; + subWctrlFlags |= WHERE_OR_INDEX_OPEN; }else{ pCov = 0; } @@ -6212,6 +6215,18 @@ WhereInfo *sqlite3WhereBegin( pWInfo->aiCurOnePass[1] = iIndexCur; }else if( iIdxCur && (wctrlFlags & WHERE_ONETABLE_ONLY)!=0 ){ iIndexCur = iIdxCur; + if( (wctrlFlags & WHERE_OR_INDEX_OPEN)!=0 ){ + /* For 2nd and subsequent subqueries for processing OR terms, + ** try to reuse the previous OP_OpenRead, if there is one. The + ** WHERE_OR_INDEX_OPEN bit will only be set if there is a prior + ** OP_OpenRead opcode on cursor iIndexCur, so the while() loop + ** below is guaranteed to terminate. + */ + VdbeOp *pOp = sqlite3VdbeGetOp(v, -1); + while( pOp->opcode!=OP_OpenRead || pOp->p1!=iIndexCur ) pOp--; + assert( pOp->p3==iDb ); + if( pOp->p2==pIx->tnum ) op = 0; + } }else{ iIndexCur = pParse->nTab++; } From 83a305f20e69101b7439d0e20d00c72aacbcfdca Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 22 Jul 2014 12:05:32 +0000 Subject: [PATCH 19/37] Enhance the comment on whereLoopAddBtree(). No changes to code. FossilOrigin-Name: b22dd165da227a52d88b17a91e80a1701dce61ad --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/where.c | 8 ++++++++ 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/manifest b/manifest index df25ada5a5..0b57ed3d1b 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C For\sthe\sOR-optimization,\savoid\sgenerating\sOP_OpenRead\sopcodes\sthat\sreopen\nexactly\sthe\ssame\sindex. -D 2014-07-22T00:40:45.480 +C Enhance\sthe\scomment\son\swhereLoopAddBtree().\s\sNo\schanges\sto\scode. +D 2014-07-22T12:05:32.008 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5eb79e334a5de69c87740edd56af6527dd219308 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -296,7 +296,7 @@ F src/vtab.c 21b932841e51ebd7d075e2d0ad1415dce8d2d5fd F src/wal.c 264df50a1b33124130b23180ded2e2c5663c652a F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4 F src/walker.c 11edb74d587bc87b33ca96a5173e3ec1b8389e45 -F src/where.c 4f8dce8f4e50b3b3675e8af7811e48526d6b4be2 +F src/where.c 00c4b52d973f5176297ab3b633c8f5d8f9475af6 F src/whereInt.h 929c1349b5355fd44f22cee5c14d72b3329c58a6 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2 @@ -1182,7 +1182,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 f1c76c7c4c7d16855db60d16e23ecdf8d7ca862a -R ff4e333e5c258e291fb4ff256a0eb1e1 +P b67a6e33f23ce5f5d9a545fa9d6700a7ed636901 +R 7e3c00e4bb7f0f9e6e95bc158e12c00a U drh -Z 9049ac2491ab8361811966ab022cf8d0 +Z bea5212013e532ea4358a5003d399c52 diff --git a/manifest.uuid b/manifest.uuid index 9e127a138a..6d720e3002 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -b67a6e33f23ce5f5d9a545fa9d6700a7ed636901 \ No newline at end of file +b22dd165da227a52d88b17a91e80a1701dce61ad \ No newline at end of file diff --git a/src/where.c b/src/where.c index 84a8d9a03f..753284bc32 100644 --- a/src/where.c +++ b/src/where.c @@ -4577,6 +4577,14 @@ static int whereUsablePartialIndex(int iTab, WhereClause *pWC, Expr *pWhere){ ** Normally, nSeek is 1. nSeek values greater than 1 come about if the ** WHERE clause includes "x IN (....)" terms used in place of "x=?". Or when ** implicit "x IN (SELECT x FROM tbl)" terms are added for skip-scans. +** +** The estimated values (nRow, nVisit, nSeek) often contain a large amount +** of uncertainty. For this reason, scoring is designed to pick plans that +** "do the least harm" if the estimates are inaccurate. For example, a +** log(nRow) factor is omitted from a non-covering index scan in order to +** bias the scoring in favor of using an index, since the worst-case +** performance of using an index is far better than the worst-case performance +** of a full table scan. */ static int whereLoopAddBtree( WhereLoopBuilder *pBuilder, /* WHERE clause information */ From 358406fc573b047a95150319a417e93a967e5107 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 22 Jul 2014 14:42:16 +0000 Subject: [PATCH 20/37] Expire prepared statements after running ANALYZE. FossilOrigin-Name: b083a961f8ac3a6158e822574d73cd63e3103b09 --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/analyze.c | 3 +++ src/where.c | 1 - test/analyze6.test | 2 +- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index 0b57ed3d1b..5a933c3991 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Enhance\sthe\scomment\son\swhereLoopAddBtree().\s\sNo\schanges\sto\scode. -D 2014-07-22T12:05:32.008 +C Expire\sprepared\sstatements\safter\srunning\sANALYZE. +D 2014-07-22T14:42:16.806 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5eb79e334a5de69c87740edd56af6527dd219308 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -161,7 +161,7 @@ F sqlite.pc.in 42b7bf0d02e08b9e77734a47798d1a55a9e0716b F sqlite3.1 3d8b83c91651f53472ca17599dae3457b8b89494 F sqlite3.pc.in 48fed132e7cb71ab676105d2a4dc77127d8c1f3a F src/alter.c b00900877f766f116f9e16116f1ccacdc21d82f1 -F src/analyze.c 61bc3467bd7803158d460dd92f5ba5205371bdce +F src/analyze.c 9f4e473c83a582d696ce57dc8cb7a40ad1314d02 F src/attach.c 3801129015ef59d76bf23c95ef9b0069d18a0c52 F src/auth.c 523da7fb4979469955d822ff9298352d6b31de34 F src/backup.c a729e63cf5cd1829507cb7b8e89f99b95141bb53 @@ -296,7 +296,7 @@ F src/vtab.c 21b932841e51ebd7d075e2d0ad1415dce8d2d5fd F src/wal.c 264df50a1b33124130b23180ded2e2c5663c652a F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4 F src/walker.c 11edb74d587bc87b33ca96a5173e3ec1b8389e45 -F src/where.c 00c4b52d973f5176297ab3b633c8f5d8f9475af6 +F src/where.c 52edd7f5df58d8f73230e5f9883ce867ca2f4a7d F src/whereInt.h 929c1349b5355fd44f22cee5c14d72b3329c58a6 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2 @@ -313,7 +313,7 @@ F test/analyze.test 1772936d66471c65221e437b6d1999c3a03166c4 F test/analyze3.test bf41f0f680dd1e0d44eed5e769531e93a5320275 F test/analyze4.test eff2df19b8dd84529966420f29ea52edc6b56213 F test/analyze5.test 765c4e284aa69ca172772aa940946f55629bc8c4 -F test/analyze6.test d31defa011a561b938b4608d3538c1b4e0b5e92c +F test/analyze6.test f1c552ce39cca4ec922a7e4e0e5d0203d6b3281f F test/analyze7.test bb1409afc9e8629e414387ef048b8e0e3e0bdc4f F test/analyze8.test 093d15c1c888eed5034304a98c992f7360130b88 F test/analyze9.test bd5aaf2a8fd2dd774b08251416897185531a8adf @@ -1182,7 +1182,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 b67a6e33f23ce5f5d9a545fa9d6700a7ed636901 -R 7e3c00e4bb7f0f9e6e95bc158e12c00a +P b22dd165da227a52d88b17a91e80a1701dce61ad +R 9fe107c1276b2eda80832b2d6848bc6f U drh -Z bea5212013e532ea4358a5003d399c52 +Z 54d8743399e09513763a4a3a09f86610 diff --git a/manifest.uuid b/manifest.uuid index 6d720e3002..300e0983ce 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -b22dd165da227a52d88b17a91e80a1701dce61ad \ No newline at end of file +b083a961f8ac3a6158e822574d73cd63e3103b09 \ No newline at end of file diff --git a/src/analyze.c b/src/analyze.c index 2330bdb342..7d2bed8c7f 100644 --- a/src/analyze.c +++ b/src/analyze.c @@ -1320,6 +1320,7 @@ void sqlite3Analyze(Parse *pParse, Token *pName1, Token *pName2){ Table *pTab; Index *pIdx; Token *pTableName; + Vdbe *v; /* Read the database schema. If an error occurs, leave an error message ** and code in pParse and return NULL. */ @@ -1367,6 +1368,8 @@ void sqlite3Analyze(Parse *pParse, Token *pName1, Token *pName2){ } } } + v = sqlite3GetVdbe(pParse); + if( v ) sqlite3VdbeAddOp0(v, OP_Expire); } /* diff --git a/src/where.c b/src/where.c index 753284bc32..4ecf02f0c1 100644 --- a/src/where.c +++ b/src/where.c @@ -4426,7 +4426,6 @@ static int whereLoopAddBtreeIndex( }else{ rc = whereInScanEst(pParse, pBuilder, pExpr->x.pList, &nOut); } - assert( rc!=SQLITE_OK || nOut>0 ); if( rc==SQLITE_NOTFOUND ) rc = SQLITE_OK; if( rc!=SQLITE_OK ) break; /* Jump out of the pTerm loop */ if( nOut ){ diff --git a/test/analyze6.test b/test/analyze6.test index f77f05324a..31ace8eda5 100644 --- a/test/analyze6.test +++ b/test/analyze6.test @@ -91,7 +91,7 @@ do_test analyze6-2.3 { } {0 0 0 {SEARCH TABLE t201 USING INTEGER PRIMARY KEY (rowid=?)}} do_test analyze6-2.4 { execsql { - INSERT INTO t201 VALUES(1,2,3); + INSERT INTO t201 VALUES(1,2,3),(2,3,4),(3,4,5); ANALYZE t201; } eqp {SELECT * FROM t201 WHERE z=5} From 25df48d967207568584016d7d922f01e77f36cef Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 22 Jul 2014 14:58:12 +0000 Subject: [PATCH 21/37] Enhance the sqlite_stat1.stat parsing to allow additional text parameters at the end. Unrecognized parameters are silently ignored. FossilOrigin-Name: ca2a5a2c770fa94cd8db1b1b241ede058a7c58e2 --- manifest | 17 ++--- manifest.uuid | 2 +- src/analyze.c | 7 +- src/vdbe.c | 9 +-- test/analyze9.test | 2 - test/analyzeC.test | 167 +++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 187 insertions(+), 17 deletions(-) create mode 100644 test/analyzeC.test diff --git a/manifest b/manifest index 5a933c3991..de21246669 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Expire\sprepared\sstatements\safter\srunning\sANALYZE. -D 2014-07-22T14:42:16.806 +C Enhance\sthe\ssqlite_stat1.stat\sparsing\sto\sallow\sadditional\stext\sparameters\nat\sthe\send.\s\sUnrecognized\sparameters\sare\ssilently\signored. +D 2014-07-22T14:58:12.596 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5eb79e334a5de69c87740edd56af6527dd219308 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -161,7 +161,7 @@ F sqlite.pc.in 42b7bf0d02e08b9e77734a47798d1a55a9e0716b F sqlite3.1 3d8b83c91651f53472ca17599dae3457b8b89494 F sqlite3.pc.in 48fed132e7cb71ab676105d2a4dc77127d8c1f3a F src/alter.c b00900877f766f116f9e16116f1ccacdc21d82f1 -F src/analyze.c 9f4e473c83a582d696ce57dc8cb7a40ad1314d02 +F src/analyze.c 56799121c72753f40d56f3c17c66c3961af6acb7 F src/attach.c 3801129015ef59d76bf23c95ef9b0069d18a0c52 F src/auth.c 523da7fb4979469955d822ff9298352d6b31de34 F src/backup.c a729e63cf5cd1829507cb7b8e89f99b95141bb53 @@ -283,7 +283,7 @@ F src/update.c 01564b3c430f6c7b0a35afaf7aba7987206fa3a5 F src/utf.c a0314e637768a030e6e84a957d0c4f6ba910cc05 F src/util.c 049fe1d3c0e2209c1bee107aec2fcff6285f909f F src/vacuum.c 3728d74919d4fb1356f9e9a13e27773db60b7179 -F src/vdbe.c 514adcc9478e461d01b9b064565d2c99604ed537 +F src/vdbe.c 2f3f0582dfacce292d3d6f22d129fe1abe3ddd00 F src/vdbe.h c63fad052c9e7388d551e556e119c0bcf6bebdf8 F src/vdbeInt.h 5df5e9afe9b7839cd17256220fc4f7af84b8b1cd F src/vdbeapi.c 24e40422382beb774daab11fe9fe9d37e8a04949 @@ -316,9 +316,10 @@ F test/analyze5.test 765c4e284aa69ca172772aa940946f55629bc8c4 F test/analyze6.test f1c552ce39cca4ec922a7e4e0e5d0203d6b3281f F test/analyze7.test bb1409afc9e8629e414387ef048b8e0e3e0bdc4f F test/analyze8.test 093d15c1c888eed5034304a98c992f7360130b88 -F test/analyze9.test bd5aaf2a8fd2dd774b08251416897185531a8adf +F test/analyze9.test 3ef1b471247308e710a794b6e50a6ab536c5604b F test/analyzeA.test 1a5c40079894847976d983ca39c707aaa44b6944 F test/analyzeB.test 8bf35ee0a548aea831bf56762cb8e7fdb1db083d +F test/analyzeC.test 555a6cc388b9818b6eda6df816f01ce0a75d3a93 F test/async.test 1d0e056ba1bb9729283a0f22718d3a25e82c277b F test/async2.test c0a9bd20816d7d6a2ceca7b8c03d3d69c28ffb8b F test/async3.test d73a062002376d7edc1fe3edff493edbec1fc2f7 @@ -1182,7 +1183,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 b22dd165da227a52d88b17a91e80a1701dce61ad -R 9fe107c1276b2eda80832b2d6848bc6f +P b083a961f8ac3a6158e822574d73cd63e3103b09 +R 5b14cb35846d5c4a5d2461874ff76990 U drh -Z 54d8743399e09513763a4a3a09f86610 +Z 267c7ac0e4de2238ef8d9515f94ccafd diff --git a/manifest.uuid b/manifest.uuid index 300e0983ce..cc3037dca8 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -b083a961f8ac3a6158e822574d73cd63e3103b09 \ No newline at end of file +ca2a5a2c770fa94cd8db1b1b241ede058a7c58e2 \ No newline at end of file diff --git a/src/analyze.c b/src/analyze.c index 7d2bed8c7f..97305f0dc1 100644 --- a/src/analyze.c +++ b/src/analyze.c @@ -1428,14 +1428,16 @@ static void decodeIntArray( #else if( pIndex ) #endif - { - if( strcmp(z, "unordered")==0 ){ + while( z[0] ){ + if( sqlite3_strglob("unordered*", z)==0 ){ pIndex->bUnordered = 1; }else if( sqlite3_strglob("sz=[0-9]*", z)==0 ){ int v32 = 0; sqlite3GetInt32(z+3, &v32); pIndex->szIdxRow = sqlite3LogEst(v32); } + while( z[0]!=0 && z[0]!=' ' ) z++; + while( z[0]==' ' ) z++; } } @@ -1476,6 +1478,7 @@ static int analysisLoader(void *pData, int argc, char **argv, char **NotUsed){ z = argv[2]; if( pIndex ){ + pIndex->bUnordered = 0; decodeIntArray((char*)z, pIndex->nKeyCol+1, 0, pIndex->aiRowLogEst, pIndex); if( pIndex->pPartIdxWhere==0 ) pTable->nRowLogEst = pIndex->aiRowLogEst[0]; }else{ diff --git a/src/vdbe.c b/src/vdbe.c index ecea3782d4..86cf8b0484 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -5794,12 +5794,13 @@ case OP_IncrVacuum: { /* jump */ /* Opcode: Expire P1 * * * * ** -** Cause precompiled statements to become expired. An expired statement -** fails with an error code of SQLITE_SCHEMA if it is ever executed -** (via sqlite3_step()). +** Cause precompiled statements to expire. When an expired statement +** is executed using sqlite3_step() it will either automatically +** reprepare itself (if it was originally created using sqlite3_prepare_v2()) +** or it will fail with SQLITE_SCHEMA. ** ** If P1 is 0, then all SQL statements become expired. If P1 is non-zero, -** then only the currently executing statement is affected. +** then only the currently executing statement is expired. */ case OP_Expire: { if( !pOp->p1 ){ diff --git a/test/analyze9.test b/test/analyze9.test index fc5a13f43f..0d72658df6 100644 --- a/test/analyze9.test +++ b/test/analyze9.test @@ -1089,5 +1089,3 @@ foreach {tn where eqp} { } finish_test - - diff --git a/test/analyzeC.test b/test/analyzeC.test new file mode 100644 index 0000000000..02faa9c7e9 --- /dev/null +++ b/test/analyzeC.test @@ -0,0 +1,167 @@ +# 2014-07-22 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# This file contains automated tests used to verify that the text terms +# at the end of sqlite_stat1.stat are processed correctly. +# +# (1) "unordered" means that the index cannot be used for ORDER BY +# or for range queries +# +# (2) "sz=NNN" sets the relative size of the index entries +# +# (3) All other fields are silently ignored +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix analyzeC + +# Baseline case. Range queries work OK. Indexes can be used for +# ORDER BY. +# +do_execsql_test 1.0 { + CREATE TABLE t1(a,b,c); + INSERT INTO t1(a,b,c) + VALUES(1,2,3),(7,8,9),(4,5,6),(10,11,12),(4,8,12),(1,11,111); + CREATE INDEX t1a ON t1(a); + CREATE INDEX t1b ON t1(b); + ANALYZE; + DELETE FROM sqlite_stat1; + INSERT INTO sqlite_stat1(tbl,idx,stat) + VALUES('t1','t1a','12345 2'),('t1','t1b','12345 4'); + ANALYZE sqlite_master; + SELECT *, '#' FROM t1 WHERE a BETWEEN 3 AND 8 ORDER BY c; +} {4 5 6 # 7 8 9 # 4 8 12 #} +do_execsql_test 1.1 { + EXPLAIN QUERY PLAN + SELECT *, '#' FROM t1 WHERE a BETWEEN 3 AND 8 ORDER BY c; +} {/.* USING INDEX t1a .a>. AND a<...*/} +do_execsql_test 1.2 { + SELECT c FROM t1 ORDER BY a; +} {3 111 6 12 9 12} +do_execsql_test 1.3 { + EXPLAIN QUERY PLAN + SELECT c FROM t1 ORDER BY a; +} {/.*SCAN TABLE t1 USING INDEX t1a.*/} +do_execsql_test 1.3x { + EXPLAIN QUERY PLAN + SELECT c FROM t1 ORDER BY a; +} {~/.*B-TREE FOR ORDER BY.*/} + +# Now mark the t1a index as "unordered". Range queries and ORDER BY no +# longer use the index, but equality queries do. +# +do_execsql_test 2.0 { + UPDATE sqlite_stat1 SET stat='12345 2 unordered' WHERE idx='t1a'; + ANALYZE sqlite_master; + SELECT *, '#' FROM t1 WHERE a BETWEEN 3 AND 8 ORDER BY c; +} {4 5 6 # 7 8 9 # 4 8 12 #} +do_execsql_test 2.1 { + EXPLAIN QUERY PLAN + SELECT *, '#' FROM t1 WHERE a BETWEEN 3 AND 8 ORDER BY c; +} {~/.*USING INDEX.*/} +do_execsql_test 2.2 { + SELECT c FROM t1 ORDER BY a; +} {3 111 6 12 9 12} +do_execsql_test 2.3 { + EXPLAIN QUERY PLAN + SELECT c FROM t1 ORDER BY a; +} {~/.*USING INDEX.*/} +do_execsql_test 2.3x { + EXPLAIN QUERY PLAN + SELECT c FROM t1 ORDER BY a; +} {/.*B-TREE FOR ORDER BY.*/} + +# Ignore extraneous text parameters in the sqlite_stat1.stat field. +# +do_execsql_test 3.0 { + UPDATE sqlite_stat1 SET stat='12345 2 whatever=5 unordered xyzzy=11' + WHERE idx='t1a'; + ANALYZE sqlite_master; + SELECT *, '#' FROM t1 WHERE a BETWEEN 3 AND 8 ORDER BY c; +} {4 5 6 # 7 8 9 # 4 8 12 #} +do_execsql_test 3.1 { + EXPLAIN QUERY PLAN + SELECT *, '#' FROM t1 WHERE a BETWEEN 3 AND 8 ORDER BY c; +} {~/.*USING INDEX.*/} +do_execsql_test 3.2 { + SELECT c FROM t1 ORDER BY a; +} {3 111 6 12 9 12} +do_execsql_test 3.3 { + EXPLAIN QUERY PLAN + SELECT c FROM t1 ORDER BY a; +} {~/.*USING INDEX.*/} +do_execsql_test 3.3x { + EXPLAIN QUERY PLAN + SELECT c FROM t1 ORDER BY a; +} {/.*B-TREE FOR ORDER BY.*/} + +# The sz=NNN parameter determines which index to scan +# +do_execsql_test 4.0 { + DROP INDEX t1a; + CREATE INDEX t1ab ON t1(a,b); + CREATE INDEX t1ca ON t1(c,a); + DELETE FROM sqlite_stat1; + INSERT INTO sqlite_stat1(tbl,idx,stat) + VALUES('t1','t1ab','12345 3 2 sz=10'),('t1','t1ca','12345 3 2 sz=20'); + ANALYZE sqlite_master; + SELECT count(a) FROM t1; +} {6} +do_execsql_test 4.1 { + EXPLAIN QUERY PLAN + SELECT count(a) FROM t1; +} {/.*INDEX t1ab.*/} +do_execsql_test 4.2 { + DELETE FROM sqlite_stat1; + INSERT INTO sqlite_stat1(tbl,idx,stat) + VALUES('t1','t1ab','12345 3 2 sz=20'),('t1','t1ca','12345 3 2 sz=10'); + ANALYZE sqlite_master; + SELECT count(a) FROM t1; +} {6} +do_execsql_test 4.3 { + EXPLAIN QUERY PLAN + SELECT count(a) FROM t1; +} {/.*INDEX t1ca.*/} + + +# The sz=NNN parameter works even if there is other extraneous text +# in the sqlite_stat1.stat column. +# +do_execsql_test 5.0 { + DELETE FROM sqlite_stat1; + INSERT INTO sqlite_stat1(tbl,idx,stat) + VALUES('t1','t1ab','12345 3 2 x=5 sz=10 y=10'), + ('t1','t1ca','12345 3 2 whatever sz=20 junk'); + ANALYZE sqlite_master; + SELECT count(a) FROM t1; +} {6} +do_execsql_test 5.1 { + EXPLAIN QUERY PLAN + SELECT count(a) FROM t1; +} {/.*INDEX t1ab.*/} +do_execsql_test 5.2 { + DELETE FROM sqlite_stat1; + INSERT INTO sqlite_stat1(tbl,idx,stat) + VALUES('t1','t1ca','12345 3 2 x=5 sz=10 y=10'), + ('t1','t1ab','12345 3 2 whatever sz=20 junk'); + ANALYZE sqlite_master; + SELECT count(a) FROM t1; +} {6} +do_execsql_test 5.3 { + EXPLAIN QUERY PLAN + SELECT count(a) FROM t1; +} {/.*INDEX t1ca.*/} + + + + +finish_test From d08b27988c9467740a89951e100462f7d57f226c Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 22 Jul 2014 15:33:31 +0000 Subject: [PATCH 22/37] Correction: The maximum SQLITE_MAX_ATTACHED value to avoid overflowing a signed 8-bit integer is 125, not 127. FossilOrigin-Name: 48e378029528dac33d29866016128d236a7995d9 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/main.c | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index de21246669..8bed619c3d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Enhance\sthe\ssqlite_stat1.stat\sparsing\sto\sallow\sadditional\stext\sparameters\nat\sthe\send.\s\sUnrecognized\sparameters\sare\ssilently\signored. -D 2014-07-22T14:58:12.596 +C Correction:\s\sThe\smaximum\sSQLITE_MAX_ATTACHED\svalue\sto\savoid\soverflowing\sa\nsigned\s8-bit\sinteger\sis\s125,\snot\s127. +D 2014-07-22T15:33:31.603 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5eb79e334a5de69c87740edd56af6527dd219308 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -189,7 +189,7 @@ F src/journal.c b4124532212b6952f42eb2c12fa3c25701d8ba8d F src/legacy.c 0df0b1550b9cc1f58229644735e317ac89131f12 F src/lempar.c cdf0a000315332fc9b50b62f3b5e22e080a0952b F src/loadext.c 867c7b330b740c6c917af9956b13b81d0a048303 -F src/main.c d0fa35a8582923730ab2113d34dddc061f59d211 +F src/main.c 1a420efa9a34e8603c4807886408cba5546b87f9 F src/malloc.c 0203ebce9152c6a0e5de520140b8ba65187350be F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645 F src/mem1.c c0c990fcaddff810ea277b4fb5d9138603dd5d4b @@ -1183,7 +1183,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 b083a961f8ac3a6158e822574d73cd63e3103b09 -R 5b14cb35846d5c4a5d2461874ff76990 +P ca2a5a2c770fa94cd8db1b1b241ede058a7c58e2 +R c3cff698f37a9f53c6d75b84d0e942cf U drh -Z 267c7ac0e4de2238ef8d9515f94ccafd +Z 54df2fe47e5bf7bb724052e4ddee7e12 diff --git a/manifest.uuid b/manifest.uuid index cc3037dca8..29f2036f2d 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ca2a5a2c770fa94cd8db1b1b241ede058a7c58e2 \ No newline at end of file +48e378029528dac33d29866016128d236a7995d9 \ No newline at end of file diff --git a/src/main.c b/src/main.c index 1e05dd8486..5e976e3397 100644 --- a/src/main.c +++ b/src/main.c @@ -2101,8 +2101,8 @@ static const int aHardLimit[] = { #if SQLITE_MAX_FUNCTION_ARG<0 || SQLITE_MAX_FUNCTION_ARG>1000 # error SQLITE_MAX_FUNCTION_ARG must be between 0 and 1000 #endif -#if SQLITE_MAX_ATTACHED<0 || SQLITE_MAX_ATTACHED>127 -# error SQLITE_MAX_ATTACHED must be between 0 and 127 +#if SQLITE_MAX_ATTACHED<0 || SQLITE_MAX_ATTACHED>125 +# error SQLITE_MAX_ATTACHED must be between 0 and 125 #endif #if SQLITE_MAX_LIKE_PATTERN_LENGTH<1 # error SQLITE_MAX_LIKE_PATTERN_LENGTH must be at least 1 From f5d87f77e2a3d1b34cb67539ea0c172cb811120a Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 22 Jul 2014 16:00:49 +0000 Subject: [PATCH 23/37] Fix the index name for the shadow tables in the spellfix1 extension so that multiple instances of the spellfix1 virtual table can each have their own index. FossilOrigin-Name: 438c348a40383796a710499e4e1b7a6b08f75778 --- ext/misc/spellfix.c | 4 ++-- manifest | 12 ++++++------ manifest.uuid | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/ext/misc/spellfix.c b/ext/misc/spellfix.c index a62d24c592..2e6743e4f7 100644 --- a/ext/misc/spellfix.c +++ b/ext/misc/spellfix.c @@ -1893,7 +1893,7 @@ static int spellfix1Init( char **pzErr ){ spellfix1_vtab *pNew = 0; - const char *zModule = argv[0]; + /* const char *zModule = argv[0]; // not used */ const char *zDbName = argv[1]; const char *zTableName = argv[2]; int nDbName; @@ -1947,7 +1947,7 @@ static int spellfix1Init( spellfix1DbExec(&rc, db, "CREATE INDEX IF NOT EXISTS \"%w\".\"%w_vocab_index_langid_k2\" " "ON \"%w_vocab\"(langid,k2);", - zDbName, zModule, zTableName + zDbName, zTableName, zTableName ); } for(i=3; rc==SQLITE_OK && i Date: Tue, 22 Jul 2014 19:14:42 +0000 Subject: [PATCH 24/37] The optimization of check-in [b67a6e33f2] does not work (it generates incorrect VDBE code) if an OR term is AND-ed with a constant expression. So back that optimization out and add a test case to make sure it does not get added back in. FossilOrigin-Name: eed754fe93644f4df082eac0c0a7ffc5c78ccd10 --- manifest | 17 +++++++++-------- manifest.uuid | 2 +- src/sqliteInt.h | 1 - src/where.c | 19 ++----------------- test/where2.test | 8 ++++++++ 5 files changed, 20 insertions(+), 27 deletions(-) diff --git a/manifest b/manifest index cdf41d31ba..39a7dab1e8 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sthe\sindex\sname\sfor\sthe\sshadow\stables\sin\sthe\sspellfix1\sextension\sso\sthat\nmultiple\sinstances\sof\sthe\sspellfix1\svirtual\stable\scan\seach\shave\stheir\sown\nindex. -D 2014-07-22T16:00:49.088 +C The\soptimization\sof\scheck-in\s[b67a6e33f2]\sdoes\snot\swork\s(it\sgenerates\nincorrect\sVDBE\scode)\sif\san\sOR\sterm\sis\sAND-ed\swith\sa\sconstant\sexpression.\nSo\sback\sthat\soptimization\sout\sand\sadd\sa\stest\scase\sto\smake\ssure\sit\sdoes\snot\nget\sadded\sback\sin. +D 2014-07-22T19:14:42.618 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5eb79e334a5de69c87740edd56af6527dd219308 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -227,7 +227,7 @@ F src/shell.c 566aee8213372a2e81ba0eb34e9759f7b2574009 F src/sqlite.h.in fd8e3a36b0aded082dc93a4b89c1e85324b4cf75 F src/sqlite3.rc 11094cc6a157a028b301a9f06b3d03089ea37c3e F src/sqlite3ext.h 886f5a34de171002ad46fae8c36a7d8051c190fc -F src/sqliteInt.h 0991b31a98c6ce072d255954af617baf50735eb1 +F src/sqliteInt.h 5dbcdcf81cb15e77df16f88699a15f7af491c580 F src/sqliteLimit.h 164b0e6749d31e0daa1a4589a169d31c0dec7b3d F src/status.c 7ac05a5c7017d0b9f0b4bcd701228b784f987158 F src/table.c 2cd62736f845d82200acfa1287e33feb3c15d62e @@ -296,7 +296,7 @@ F src/vtab.c 21b932841e51ebd7d075e2d0ad1415dce8d2d5fd F src/wal.c 264df50a1b33124130b23180ded2e2c5663c652a F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4 F src/walker.c 11edb74d587bc87b33ca96a5173e3ec1b8389e45 -F src/where.c 52edd7f5df58d8f73230e5f9883ce867ca2f4a7d +F src/where.c 4e7e6bc639a938eb35c433bdca2aad80478fece4 F src/whereInt.h 929c1349b5355fd44f22cee5c14d72b3329c58a6 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2 @@ -1097,7 +1097,7 @@ F test/walshared.test 0befc811dcf0b287efae21612304d15576e35417 F test/walslow.test e7be6d9888f83aa5d3d3c7c08aa9b5c28b93609a F test/walthread.test de8dbaf6d9e41481c460ba31ca61e163d7348f8e F test/where.test 28b64e93428961b07b0d486778d63fd672948f6b -F test/where2.test 455a2eb2666e66c1e84e2cb5815173a85e6237db +F test/where2.test 23fdb5d8e756554aad4ca7ae03de9dd8367a2c6e F test/where3.test 1ad55ba900bd7747f98b6082e65bd3e442c5004e F test/where4.test d8420ceeb8323a41ceff1f1841fc528e824e1ecf F test/where5.test fdf66f96d29a064b63eb543e28da4dfdccd81ad2 @@ -1183,7 +1183,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 48e378029528dac33d29866016128d236a7995d9 -R ef5e99a62dffbd3ce7a7196840380036 +P 438c348a40383796a710499e4e1b7a6b08f75778 +Q -b67a6e33f23ce5f5d9a545fa9d6700a7ed636901 +R 086bb10698e6defd83e7aae53f79809b U drh -Z f16a3660aabbbb2778203c851a571a70 +Z 6c73d4c61d83e0b2dc5ff58e1c82716d diff --git a/manifest.uuid b/manifest.uuid index e6d3a6b9d4..730f453e7f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -438c348a40383796a710499e4e1b7a6b08f75778 \ No newline at end of file +eed754fe93644f4df082eac0c0a7ffc5c78ccd10 \ No newline at end of file diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 6b0e031b30..8f256d52fc 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -2136,7 +2136,6 @@ struct SrcList { #define WHERE_DISTINCTBY 0x0200 /* pOrderby is really a DISTINCT clause */ #define WHERE_WANT_DISTINCT 0x0400 /* All output needs to be distinct */ #define WHERE_SORTBYGROUP 0x0800 /* Support sqlite3WhereIsSorted() */ -#define WHERE_OR_INDEX_OPEN 0x1000 /* OP_OpenRead for the OR index exists */ /* Allowed return values from sqlite3WhereIsDistinct() */ diff --git a/src/where.c b/src/where.c index 4ecf02f0c1..284f141ff9 100644 --- a/src/where.c +++ b/src/where.c @@ -3422,7 +3422,6 @@ static Bitmask codeOneLoopStart( int iRetInit; /* Address of regReturn init */ int untestedTerms = 0; /* Some terms not completely tested */ int ii; /* Loop counter */ - int subWctrlFlags; /* wctrlFlags for sub-queries */ Expr *pAndExpr = 0; /* An ".. AND (...)" expression */ Table *pTab = pTabItem->pTab; @@ -3518,8 +3517,6 @@ static Bitmask codeOneLoopStart( ** eliminating duplicates from other WHERE clauses, the action for each ** sub-WHERE clause is to to invoke the main loop body as a subroutine. */ - subWctrlFlags = WHERE_OMIT_OPEN_CLOSE | WHERE_AND_ONLY | - WHERE_FORCE_TABLE | WHERE_ONETABLE_ONLY; for(ii=0; iinTerm; ii++){ WhereTerm *pOrTerm = &pOrWc->a[ii]; if( pOrTerm->leftCursor==iCur || (pOrTerm->eOperator & WO_AND)!=0 ){ @@ -3532,7 +3529,8 @@ static Bitmask codeOneLoopStart( } /* Loop through table entries that match term pOrTerm. */ pSubWInfo = sqlite3WhereBegin(pParse, pOrTab, pOrExpr, 0, 0, - subWctrlFlags, iCovCur); + WHERE_OMIT_OPEN_CLOSE | WHERE_AND_ONLY | + WHERE_FORCE_TABLE | WHERE_ONETABLE_ONLY, iCovCur); assert( pSubWInfo || pParse->nErr || db->mallocFailed ); if( pSubWInfo ){ WhereLoop *pSubLoop; @@ -3623,7 +3621,6 @@ static Bitmask codeOneLoopStart( ){ assert( pSubWInfo->a[0].iIdxCur==iCovCur ); pCov = pSubLoop->u.btree.pIndex; - subWctrlFlags |= WHERE_OR_INDEX_OPEN; }else{ pCov = 0; } @@ -6222,18 +6219,6 @@ WhereInfo *sqlite3WhereBegin( pWInfo->aiCurOnePass[1] = iIndexCur; }else if( iIdxCur && (wctrlFlags & WHERE_ONETABLE_ONLY)!=0 ){ iIndexCur = iIdxCur; - if( (wctrlFlags & WHERE_OR_INDEX_OPEN)!=0 ){ - /* For 2nd and subsequent subqueries for processing OR terms, - ** try to reuse the previous OP_OpenRead, if there is one. The - ** WHERE_OR_INDEX_OPEN bit will only be set if there is a prior - ** OP_OpenRead opcode on cursor iIndexCur, so the while() loop - ** below is guaranteed to terminate. - */ - VdbeOp *pOp = sqlite3VdbeGetOp(v, -1); - while( pOp->opcode!=OP_OpenRead || pOp->p1!=iIndexCur ) pOp--; - assert( pOp->p3==iDb ); - if( pOp->p2==pIx->tnum ) op = 0; - } }else{ iIndexCur = pParse->nTab++; } diff --git a/test/where2.test b/test/where2.test index d9b2b23de9..367eb0dfea 100644 --- a/test/where2.test +++ b/test/where2.test @@ -751,5 +751,13 @@ do_execsql_test where2-12.1 { } {/.*SEARCH TABLE t12 AS b .*SEARCH TABLE t12 AS b .*/} } +# Verify that all necessary OP_OpenRead opcodes occur in the OR optimization. +# +do_execsql_test where2-13.1 { + CREATE TABLE t13(a,b); + CREATE INDEX t13a ON t13(a); + INSERT INTO t13 VALUES(4,5); + SELECT * FROM t13 WHERE (1=2 AND a=3) OR a=4; +} {4 5} finish_test From 3526319b483fac1aba4dd19c93ebd61aa2663b97 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 22 Jul 2014 20:02:19 +0000 Subject: [PATCH 25/37] Add the OP_ReopenIdx opcode that works like OP_OpenRead except that it becomes a no-op if the cursor is already open on the same index. Update the OR-optimization logic to make use of OP_ReopenIdx in order to avoid unnecessary cursor open requests sent to the B-Tree layer. FossilOrigin-Name: 77f412caf0192d3e7fecb377d6d72123d8b64424 --- manifest | 19 +++++++++---------- manifest.uuid | 2 +- src/sqliteInt.h | 1 + src/vdbe.c | 33 +++++++++++++++++++++++++++++++-- src/vdbeInt.h | 1 + src/where.c | 8 ++++++-- 6 files changed, 49 insertions(+), 15 deletions(-) diff --git a/manifest b/manifest index 39a7dab1e8..4ac400af64 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C The\soptimization\sof\scheck-in\s[b67a6e33f2]\sdoes\snot\swork\s(it\sgenerates\nincorrect\sVDBE\scode)\sif\san\sOR\sterm\sis\sAND-ed\swith\sa\sconstant\sexpression.\nSo\sback\sthat\soptimization\sout\sand\sadd\sa\stest\scase\sto\smake\ssure\sit\sdoes\snot\nget\sadded\sback\sin. -D 2014-07-22T19:14:42.618 +C Add\sthe\sOP_ReopenIdx\sopcode\sthat\sworks\slike\sOP_OpenRead\sexcept\sthat\sit\sbecomes\na\sno-op\sif\sthe\scursor\sis\salready\sopen\son\sthe\ssame\sindex.\s\sUpdate\sthe\nOR-optimization\slogic\sto\smake\suse\sof\sOP_ReopenIdx\sin\sorder\sto\savoid\nunnecessary\scursor\sopen\srequests\ssent\sto\sthe\sB-Tree\slayer. +D 2014-07-22T20:02:19.743 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5eb79e334a5de69c87740edd56af6527dd219308 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -227,7 +227,7 @@ F src/shell.c 566aee8213372a2e81ba0eb34e9759f7b2574009 F src/sqlite.h.in fd8e3a36b0aded082dc93a4b89c1e85324b4cf75 F src/sqlite3.rc 11094cc6a157a028b301a9f06b3d03089ea37c3e F src/sqlite3ext.h 886f5a34de171002ad46fae8c36a7d8051c190fc -F src/sqliteInt.h 5dbcdcf81cb15e77df16f88699a15f7af491c580 +F src/sqliteInt.h b72a09326d7cbd8375ec3d9a04ea5e0cf476beb3 F src/sqliteLimit.h 164b0e6749d31e0daa1a4589a169d31c0dec7b3d F src/status.c 7ac05a5c7017d0b9f0b4bcd701228b784f987158 F src/table.c 2cd62736f845d82200acfa1287e33feb3c15d62e @@ -283,9 +283,9 @@ F src/update.c 01564b3c430f6c7b0a35afaf7aba7987206fa3a5 F src/utf.c a0314e637768a030e6e84a957d0c4f6ba910cc05 F src/util.c 049fe1d3c0e2209c1bee107aec2fcff6285f909f F src/vacuum.c 3728d74919d4fb1356f9e9a13e27773db60b7179 -F src/vdbe.c 2f3f0582dfacce292d3d6f22d129fe1abe3ddd00 +F src/vdbe.c fa74c6563486022920db4d73897bd9b837c7441d F src/vdbe.h c63fad052c9e7388d551e556e119c0bcf6bebdf8 -F src/vdbeInt.h 5df5e9afe9b7839cd17256220fc4f7af84b8b1cd +F src/vdbeInt.h f41a7cf5a40e7abd994d5fe3a04589ae3e1154e7 F src/vdbeapi.c 24e40422382beb774daab11fe9fe9d37e8a04949 F src/vdbeaux.c 1ffe0bbc3a2c8aedd95622de9be6b6d07b3d3c6b F src/vdbeblob.c 9205ce9d3b064d9600f8418a897fc88b5687d9ac @@ -296,7 +296,7 @@ F src/vtab.c 21b932841e51ebd7d075e2d0ad1415dce8d2d5fd F src/wal.c 264df50a1b33124130b23180ded2e2c5663c652a F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4 F src/walker.c 11edb74d587bc87b33ca96a5173e3ec1b8389e45 -F src/where.c 4e7e6bc639a938eb35c433bdca2aad80478fece4 +F src/where.c 0ffd586e04cd069ed6ce7f820194ccaa6cbd669e F src/whereInt.h 929c1349b5355fd44f22cee5c14d72b3329c58a6 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2 @@ -1183,8 +1183,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 438c348a40383796a710499e4e1b7a6b08f75778 -Q -b67a6e33f23ce5f5d9a545fa9d6700a7ed636901 -R 086bb10698e6defd83e7aae53f79809b +P eed754fe93644f4df082eac0c0a7ffc5c78ccd10 +R 09dedf30e4922c66cabf472458c9ab58 U drh -Z 6c73d4c61d83e0b2dc5ff58e1c82716d +Z 96627cd265c0a3b75631b3111ef23fd4 diff --git a/manifest.uuid b/manifest.uuid index 730f453e7f..6783218a06 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -eed754fe93644f4df082eac0c0a7ffc5c78ccd10 \ No newline at end of file +77f412caf0192d3e7fecb377d6d72123d8b64424 \ No newline at end of file diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 8f256d52fc..7edc04ca42 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -2136,6 +2136,7 @@ struct SrcList { #define WHERE_DISTINCTBY 0x0200 /* pOrderby is really a DISTINCT clause */ #define WHERE_WANT_DISTINCT 0x0400 /* All output needs to be distinct */ #define WHERE_SORTBYGROUP 0x0800 /* Support sqlite3WhereIsSorted() */ +#define WHERE_REOPEN_IDX 0x1000 /* Try to use OP_ReopenIdx */ /* Allowed return values from sqlite3WhereIsDistinct() */ diff --git a/src/vdbe.c b/src/vdbe.c index 86cf8b0484..093669a82d 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -3205,7 +3205,21 @@ case OP_SetCookie: { /* in3 */ ** sequence of the index being opened. Otherwise, if P4 is an integer ** value, it is set to the number of columns in the table. ** -** See also OpenWrite. +** See also: OpenWrite, ReopenIdx +*/ +/* Opcode: ReopenIdx P1 P2 P3 P4 P5 +** Synopsis: root=P2 iDb=P3 +** +** The ReopenIdx opcode works exactly like ReadOpen except that it first +** checks to see if the cursor on P1 is already open with a root page +** number of P2 and if it is this opcode becomes a no-op. In other words, +** if the cursor is already open, do not reopen it. +** +** The ReopenIdx opcode may only be used with P5==0 and with P4 being +** a P4_KEYINFO object. Furthermore, the P3 value must be the same as +** every other ReopenIdx or OpenRead for the same cursor number. +** +** See the OpenRead opcode documentation for additional information. */ /* Opcode: OpenWrite P1 P2 P3 P4 P5 ** Synopsis: root=P2 iDb=P3 @@ -3227,6 +3241,19 @@ case OP_SetCookie: { /* in3 */ ** ** See also OpenRead. */ +case OP_ReopenIdx: { + VdbeCursor *pCur; + + assert( pOp->p5==0 ); + assert( pOp->p4type==P4_KEYINFO ); + pCur = p->apCsr[pOp->p1]; + if( pCur && pCur->pgnoRoot==pOp->p2 ){ + assert( pCur->iDb==pOp->p3 ); /* Guaranteed by the code generator */ + break; + } + /* If the cursor is not currently open or is open on a different + ** index, then fall through into OP_OpenRead to force a reopen */ +} case OP_OpenRead: case OP_OpenWrite: { int nField; @@ -3241,7 +3268,8 @@ case OP_OpenWrite: { assert( (pOp->p5&(OPFLAG_P2ISREG|OPFLAG_BULKCSR))==pOp->p5 ); assert( pOp->opcode==OP_OpenWrite || pOp->p5==0 ); assert( p->bIsReader ); - assert( pOp->opcode==OP_OpenRead || p->readOnly==0 ); + assert( pOp->opcode==OP_OpenRead || pOp->opcode==OP_ReopenIdx + || p->readOnly==0 ); if( p->expired ){ rc = SQLITE_ABORT; @@ -3298,6 +3326,7 @@ case OP_OpenWrite: { if( pCur==0 ) goto no_mem; pCur->nullRow = 1; pCur->isOrdered = 1; + pCur->pgnoRoot = p2; rc = sqlite3BtreeCursor(pX, p2, wrFlag, pKeyInfo, pCur->pCursor); pCur->pKeyInfo = pKeyInfo; assert( OPFLAG_BULKCSR==BTREE_BULKLOAD ); diff --git a/src/vdbeInt.h b/src/vdbeInt.h index d629802a64..f541aa7170 100644 --- a/src/vdbeInt.h +++ b/src/vdbeInt.h @@ -76,6 +76,7 @@ struct VdbeCursor { Bool useRandomRowid:1;/* Generate new record numbers semi-randomly */ Bool isTable:1; /* True if a table requiring integer keys */ Bool isOrdered:1; /* True if the underlying table is BTREE_UNORDERED */ + Pgno pgnoRoot; /* Root page of the open btree cursor */ sqlite3_vtab_cursor *pVtabCursor; /* The cursor for a virtual table */ i64 seqCount; /* Sequence counter */ i64 movetoTarget; /* Argument to the deferred sqlite3BtreeMoveto() */ diff --git a/src/where.c b/src/where.c index 284f141ff9..ff18d5d4e2 100644 --- a/src/where.c +++ b/src/where.c @@ -3422,6 +3422,7 @@ static Bitmask codeOneLoopStart( int iRetInit; /* Address of regReturn init */ int untestedTerms = 0; /* Some terms not completely tested */ int ii; /* Loop counter */ + u16 wctrlFlags; /* Flags for sub-WHERE clause */ Expr *pAndExpr = 0; /* An ".. AND (...)" expression */ Table *pTab = pTabItem->pTab; @@ -3517,6 +3518,8 @@ static Bitmask codeOneLoopStart( ** eliminating duplicates from other WHERE clauses, the action for each ** sub-WHERE clause is to to invoke the main loop body as a subroutine. */ + wctrlFlags = WHERE_OMIT_OPEN_CLOSE | WHERE_AND_ONLY | + WHERE_FORCE_TABLE | WHERE_ONETABLE_ONLY; for(ii=0; iinTerm; ii++){ WhereTerm *pOrTerm = &pOrWc->a[ii]; if( pOrTerm->leftCursor==iCur || (pOrTerm->eOperator & WO_AND)!=0 ){ @@ -3529,8 +3532,7 @@ static Bitmask codeOneLoopStart( } /* Loop through table entries that match term pOrTerm. */ pSubWInfo = sqlite3WhereBegin(pParse, pOrTab, pOrExpr, 0, 0, - WHERE_OMIT_OPEN_CLOSE | WHERE_AND_ONLY | - WHERE_FORCE_TABLE | WHERE_ONETABLE_ONLY, iCovCur); + wctrlFlags, iCovCur); assert( pSubWInfo || pParse->nErr || db->mallocFailed ); if( pSubWInfo ){ WhereLoop *pSubLoop; @@ -3621,6 +3623,7 @@ static Bitmask codeOneLoopStart( ){ assert( pSubWInfo->a[0].iIdxCur==iCovCur ); pCov = pSubLoop->u.btree.pIndex; + wctrlFlags |= WHERE_REOPEN_IDX; }else{ pCov = 0; } @@ -6219,6 +6222,7 @@ WhereInfo *sqlite3WhereBegin( pWInfo->aiCurOnePass[1] = iIndexCur; }else if( iIdxCur && (wctrlFlags & WHERE_ONETABLE_ONLY)!=0 ){ iIndexCur = iIdxCur; + if( wctrlFlags & WHERE_REOPEN_IDX ) op = OP_ReopenIdx; }else{ iIndexCur = pParse->nTab++; } From 0f65cce82580619ba3498e3b2ef7bd338d73b6e5 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 22 Jul 2014 22:46:54 +0000 Subject: [PATCH 26/37] When running ANALYZE, it is not necessary to check the right-most key column for changes since that column will always change if none of the previous columns have. FossilOrigin-Name: 48f40861db4fbd10725a2b8b606d44fe16d5bd27 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/analyze.c | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index 4ac400af64..f57975f5d3 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sthe\sOP_ReopenIdx\sopcode\sthat\sworks\slike\sOP_OpenRead\sexcept\sthat\sit\sbecomes\na\sno-op\sif\sthe\scursor\sis\salready\sopen\son\sthe\ssame\sindex.\s\sUpdate\sthe\nOR-optimization\slogic\sto\smake\suse\sof\sOP_ReopenIdx\sin\sorder\sto\savoid\nunnecessary\scursor\sopen\srequests\ssent\sto\sthe\sB-Tree\slayer. -D 2014-07-22T20:02:19.743 +C When\srunning\sANALYZE,\sit\sis\snot\snecessary\sto\scheck\sthe\sright-most\skey\scolumn\nfor\schanges\ssince\sthat\scolumn\swill\salways\schange\sif\snone\sof\sthe\sprevious\ncolumns\shave. +D 2014-07-22T22:46:54.689 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5eb79e334a5de69c87740edd56af6527dd219308 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -161,7 +161,7 @@ F sqlite.pc.in 42b7bf0d02e08b9e77734a47798d1a55a9e0716b F sqlite3.1 3d8b83c91651f53472ca17599dae3457b8b89494 F sqlite3.pc.in 48fed132e7cb71ab676105d2a4dc77127d8c1f3a F src/alter.c b00900877f766f116f9e16116f1ccacdc21d82f1 -F src/analyze.c 56799121c72753f40d56f3c17c66c3961af6acb7 +F src/analyze.c ab1e44158c25490bfda557f3d690217b2bb509e2 F src/attach.c 3801129015ef59d76bf23c95ef9b0069d18a0c52 F src/auth.c 523da7fb4979469955d822ff9298352d6b31de34 F src/backup.c a729e63cf5cd1829507cb7b8e89f99b95141bb53 @@ -1183,7 +1183,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 eed754fe93644f4df082eac0c0a7ffc5c78ccd10 -R 09dedf30e4922c66cabf472458c9ab58 +P 77f412caf0192d3e7fecb377d6d72123d8b64424 +R e38e472b4e4b7503ed49bdb3ca667f5c U drh -Z 96627cd265c0a3b75631b3111ef23fd4 +Z e390ae6bf708e4580525fb01df14fd1e diff --git a/manifest.uuid b/manifest.uuid index 6783218a06..691fcc01d6 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -77f412caf0192d3e7fecb377d6d72123d8b64424 \ No newline at end of file +48f40861db4fbd10725a2b8b606d44fe16d5bd27 \ No newline at end of file diff --git a/src/analyze.c b/src/analyze.c index 97305f0dc1..c614350ae3 100644 --- a/src/analyze.c +++ b/src/analyze.c @@ -1109,7 +1109,7 @@ static void analyzeOneTable( ** goto chng_addr_N */ addrNextRow = sqlite3VdbeCurrentAddr(v); - for(i=0; iazColl[i]); sqlite3VdbeAddOp2(v, OP_Integer, i, regChng); sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, i, regTemp); @@ -1118,7 +1118,7 @@ static void analyzeOneTable( sqlite3VdbeChangeP5(v, SQLITE_NULLEQ); VdbeCoverage(v); } - sqlite3VdbeAddOp2(v, OP_Integer, nCol, regChng); + sqlite3VdbeAddOp2(v, OP_Integer, nCol-1, regChng); aGotoChng[nCol] = sqlite3VdbeAddOp0(v, OP_Goto); /* @@ -1129,7 +1129,7 @@ static void analyzeOneTable( ** ... */ sqlite3VdbeJumpHere(v, addrGotoChng0); - for(i=0; i Date: Wed, 23 Jul 2014 01:26:51 +0000 Subject: [PATCH 27/37] Add support for parsing C-style hexadecimal literals. FossilOrigin-Name: 34a1f38b7a23c64f5c6e5b34c19a20480be53961 --- manifest | 17 +++++----- manifest.uuid | 2 +- src/tokenize.c | 6 ++++ src/util.c | 84 ++++++++++++++++++++++++++++++++++++++------------ 4 files changed, 81 insertions(+), 28 deletions(-) diff --git a/manifest b/manifest index f57975f5d3..1ebf10efcd 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C When\srunning\sANALYZE,\sit\sis\snot\snecessary\sto\scheck\sthe\sright-most\skey\scolumn\nfor\schanges\ssince\sthat\scolumn\swill\salways\schange\sif\snone\sof\sthe\sprevious\ncolumns\shave. -D 2014-07-22T22:46:54.689 +C Add\ssupport\sfor\sparsing\sC-style\shexadecimal\sliterals. +D 2014-07-23T01:26:51.616 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5eb79e334a5de69c87740edd56af6527dd219308 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -277,11 +277,11 @@ F src/test_thread.c 1e133a40b50e9c035b00174035b846e7eef481cb F src/test_vfs.c f84075a388527892ff184988f43b69ce69b8083c F src/test_vfstrace.c bab9594adc976cbe696ff3970728830b4c5ed698 F src/test_wsd.c 41cadfd9d97fe8e3e4e44f61a4a8ccd6f7ca8fe9 -F src/tokenize.c 6da2de6e12218ccb0aea5184b56727d011f4bee7 +F src/tokenize.c ae45399d6252b4d736af43bee1576ce7bff86aec F src/trigger.c 66f3470b03b52b395e839155786966e3e037fddb F src/update.c 01564b3c430f6c7b0a35afaf7aba7987206fa3a5 F src/utf.c a0314e637768a030e6e84a957d0c4f6ba910cc05 -F src/util.c 049fe1d3c0e2209c1bee107aec2fcff6285f909f +F src/util.c 9d87de90e59d78e69ab944f34a03a4228b05de6e F src/vacuum.c 3728d74919d4fb1356f9e9a13e27773db60b7179 F src/vdbe.c fa74c6563486022920db4d73897bd9b837c7441d F src/vdbe.h c63fad052c9e7388d551e556e119c0bcf6bebdf8 @@ -1183,7 +1183,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 77f412caf0192d3e7fecb377d6d72123d8b64424 -R e38e472b4e4b7503ed49bdb3ca667f5c +P 48f40861db4fbd10725a2b8b606d44fe16d5bd27 +R bc60c63a2067ce5c2bcc7a7ef85e26f4 +T *branch * hex-literal +T *sym-hex-literal * +T -sym-trunk * U drh -Z e390ae6bf708e4580525fb01df14fd1e +Z 425e58328b59810233115ebd1d9053d0 diff --git a/manifest.uuid b/manifest.uuid index 691fcc01d6..6e3e9df36d 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -48f40861db4fbd10725a2b8b606d44fe16d5bd27 \ No newline at end of file +34a1f38b7a23c64f5c6e5b34c19a20480be53961 \ No newline at end of file diff --git a/src/tokenize.c b/src/tokenize.c index 87553e25b0..4017c3b816 100644 --- a/src/tokenize.c +++ b/src/tokenize.c @@ -270,6 +270,12 @@ int sqlite3GetToken(const unsigned char *z, int *tokenType){ testcase( z[0]=='6' ); testcase( z[0]=='7' ); testcase( z[0]=='8' ); testcase( z[0]=='9' ); *tokenType = TK_INTEGER; +#ifndef SQLITE_OMIT_HEX_INTEGER + if( z[0]=='0' && (z[1]=='x' || z[1]=='X') && sqlite3Isxdigit(z[2]) ){ + for(i=3; sqlite3Isxdigit(z[i]); i++){} + return i; + } +#endif for(i=0; sqlite3Isdigit(z[i]); i++){} #ifndef SQLITE_OMIT_FLOATING_POINT if( z[i]=='.' ){ diff --git a/src/util.c b/src/util.c index 4fe07a862a..1686d4342d 100644 --- a/src/util.c +++ b/src/util.c @@ -255,6 +255,22 @@ int sqlite3_strnicmp(const char *zLeft, const char *zRight, int N){ return N<0 ? 0 : UpperToLower[*a] - UpperToLower[*b]; } +/* +** Translate a single byte of Hex into an integer. +** This routine only works if h really is a valid hexadecimal +** character: 0..9a..fA..F +*/ +u8 sqlite3HexToInt(int h){ + assert( (h>='0' && h<='9') || (h>='a' && h<='f') || (h>='A' && h<='F') ); +#ifdef SQLITE_ASCII + h += 9*(1&(h>>6)); +#endif +#ifdef SQLITE_EBCDIC + h += 9*(1&~(h>>4)); +#endif + return (u8)(h & 0xf); +} + /* ** The string z[] is an text representation of a real number. ** Convert this string to a double and write it into *pResult. @@ -318,6 +334,20 @@ int sqlite3AtoF(const char *z, double *pResult, int length, u8 enc){ }else if( *z=='+' ){ z+=incr; } +#ifndef SQLITE_OMIT_HEX_INTEGER + else if( *z==0 + && &z[incr*2]=zEnd && nonNum==0; + } +#endif /* skip leading zeroes */ while( z16*incr || nonNum; + } +#endif } zStart = zNum; while( zNum=0 && c<=9; i++){ v = v*10 + c; } @@ -1029,24 +1091,6 @@ void sqlite3Put4byte(unsigned char *p, u32 v){ p[3] = (u8)v; } - - -/* -** Translate a single byte of Hex into an integer. -** This routine only works if h really is a valid hexadecimal -** character: 0..9a..fA..F -*/ -u8 sqlite3HexToInt(int h){ - assert( (h>='0' && h<='9') || (h>='a' && h<='f') || (h>='A' && h<='F') ); -#ifdef SQLITE_ASCII - h += 9*(1&(h>>6)); -#endif -#ifdef SQLITE_EBCDIC - h += 9*(1&~(h>>4)); -#endif - return (u8)(h & 0xf); -} - #if !defined(SQLITE_OMIT_BLOB_LITERAL) || defined(SQLITE_HAS_CODEC) /* ** Convert a BLOB literal of the form "x'hhhhhh'" into its binary From fce4da1b737b34432ca06432dd6d71101a89f00a Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 23 Jul 2014 01:56:32 +0000 Subject: [PATCH 28/37] Test cases for hex literals. FossilOrigin-Name: 19054339c47448bcdfd1f7be35daa3826c409077 --- manifest | 16 +++-- manifest.uuid | 2 +- src/util.c | 2 +- test/hexlit.test | 150 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 159 insertions(+), 11 deletions(-) create mode 100644 test/hexlit.test diff --git a/manifest b/manifest index 1ebf10efcd..133cabf19e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\ssupport\sfor\sparsing\sC-style\shexadecimal\sliterals. -D 2014-07-23T01:26:51.616 +C Test\scases\sfor\shex\sliterals. +D 2014-07-23T01:56:32.016 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5eb79e334a5de69c87740edd56af6527dd219308 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -281,7 +281,7 @@ F src/tokenize.c ae45399d6252b4d736af43bee1576ce7bff86aec F src/trigger.c 66f3470b03b52b395e839155786966e3e037fddb F src/update.c 01564b3c430f6c7b0a35afaf7aba7987206fa3a5 F src/utf.c a0314e637768a030e6e84a957d0c4f6ba910cc05 -F src/util.c 9d87de90e59d78e69ab944f34a03a4228b05de6e +F src/util.c eff2c1e5a49a3c64af0fe9f2fb32cada3436a167 F src/vacuum.c 3728d74919d4fb1356f9e9a13e27773db60b7179 F src/vdbe.c fa74c6563486022920db4d73897bd9b837c7441d F src/vdbe.h c63fad052c9e7388d551e556e119c0bcf6bebdf8 @@ -601,6 +601,7 @@ F test/fuzz_malloc.test 328f70aaca63adf29b4c6f06505ed0cf57ca7c26 F test/fuzzer1.test d4c52aaf3ef923da293a2653cfab33d02f718a36 F test/fuzzerfault.test 8792cd77fd5bce765b05d0c8e01b9edcf8af8536 F test/genesis.tcl 1e2e2e8e5cc4058549a154ff1892fe5c9de19f98 +F test/hexlit.test c7f30348053065b75c189356ffcaf3d09824d57f F test/hook.test 162d7cef7a2d2b04839fe14402934e6a1b79442f F test/icu.test 70df4faca133254c042d02ae342c0a141f2663f4 F test/in.test 047c4671328e9032ab95666a67021adbbd36e98e @@ -1183,10 +1184,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 48f40861db4fbd10725a2b8b606d44fe16d5bd27 -R bc60c63a2067ce5c2bcc7a7ef85e26f4 -T *branch * hex-literal -T *sym-hex-literal * -T -sym-trunk * +P 34a1f38b7a23c64f5c6e5b34c19a20480be53961 +R 31f7dbbcb963767edb50861a2259f157 U drh -Z 425e58328b59810233115ebd1d9053d0 +Z fe6debea68030ad6a2bb2c17bc2c014e diff --git a/manifest.uuid b/manifest.uuid index 6e3e9df36d..8a951ec1f6 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -34a1f38b7a23c64f5c6e5b34c19a20480be53961 \ No newline at end of file +19054339c47448bcdfd1f7be35daa3826c409077 \ No newline at end of file diff --git a/src/util.c b/src/util.c index 1686d4342d..f7f3f58b2b 100644 --- a/src/util.c +++ b/src/util.c @@ -335,7 +335,7 @@ int sqlite3AtoF(const char *z, double *pResult, int length, u8 enc){ z+=incr; } #ifndef SQLITE_OMIT_HEX_INTEGER - else if( *z==0 + else if( *z=='0' && &z[incr*2] Date: Wed, 23 Jul 2014 01:59:47 +0000 Subject: [PATCH 29/37] Reformatting a few test cases for clarity. FossilOrigin-Name: 7e1bbacb11a4689b69856450125cae3d045307af --- manifest | 12 ++++++------ manifest.uuid | 2 +- test/hexlit.test | 8 ++++---- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index 133cabf19e..7608ebf7fa 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Test\scases\sfor\shex\sliterals. -D 2014-07-23T01:56:32.016 +C Reformatting\sa\sfew\stest\scases\sfor\sclarity. +D 2014-07-23T01:59:47.721 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5eb79e334a5de69c87740edd56af6527dd219308 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -601,7 +601,7 @@ F test/fuzz_malloc.test 328f70aaca63adf29b4c6f06505ed0cf57ca7c26 F test/fuzzer1.test d4c52aaf3ef923da293a2653cfab33d02f718a36 F test/fuzzerfault.test 8792cd77fd5bce765b05d0c8e01b9edcf8af8536 F test/genesis.tcl 1e2e2e8e5cc4058549a154ff1892fe5c9de19f98 -F test/hexlit.test c7f30348053065b75c189356ffcaf3d09824d57f +F test/hexlit.test 499de0bfdfd16e8d406f3a4104d275c1a473b2d5 F test/hook.test 162d7cef7a2d2b04839fe14402934e6a1b79442f F test/icu.test 70df4faca133254c042d02ae342c0a141f2663f4 F test/in.test 047c4671328e9032ab95666a67021adbbd36e98e @@ -1184,7 +1184,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 34a1f38b7a23c64f5c6e5b34c19a20480be53961 -R 31f7dbbcb963767edb50861a2259f157 +P 19054339c47448bcdfd1f7be35daa3826c409077 +R 52ea51dcf5a265235552cc5fcbffc473 U drh -Z fe6debea68030ad6a2bb2c17bc2c014e +Z 7e4424638caf7e83118206706ce53455 diff --git a/manifest.uuid b/manifest.uuid index 8a951ec1f6..fc8e55fbc5 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -19054339c47448bcdfd1f7be35daa3826c409077 \ No newline at end of file +7e1bbacb11a4689b69856450125cae3d045307af \ No newline at end of file diff --git a/test/hexlit.test b/test/hexlit.test index 79bd7e4e6e..bfb4682571 100644 --- a/test/hexlit.test +++ b/test/hexlit.test @@ -142,9 +142,9 @@ hexlit2 327 0x1000000000000000000000000000 3.245186e+32 hexlit2 328 0x10000000000000000000000000000 5.192297e+33 hexlit2 329 0x100000000000000000000000000000 8.307675e+34 -hexlit2 400 0x7fffffffffffffff 9.223372e+18 -hexlit2 401 0x8000000000000000 -9.223372e+18 -hexlit2 402 0xffffffffffffffff -1.000000e+00 -hexlit2 403 0x10000000000000000 1.844674e+19 +hexlit2 400 0x07fffffffffffffff 9.223372e+18 +hexlit2 401 0x08000000000000000 -9.223372e+18 +hexlit2 402 0x0ffffffffffffffff -1.000000e+00 +hexlit2 403 0x10000000000000000 1.844674e+19 finish_test From 5ec659cfcb030f8aa47eac97edf74046605c3bfb Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 23 Jul 2014 02:07:11 +0000 Subject: [PATCH 30/37] Casting hex literals directly from string to float always results in a positive number. FossilOrigin-Name: 4b86ccdf4f4eb4339a5706e10ad24f01b6c3939e --- manifest | 12 ++++++------ manifest.uuid | 2 +- test/hexlit.test | 10 +++++----- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/manifest b/manifest index 7608ebf7fa..656415a599 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Reformatting\sa\sfew\stest\scases\sfor\sclarity. -D 2014-07-23T01:59:47.721 +C Casting\shex\sliterals\sdirectly\sfrom\sstring\sto\sfloat\salways\sresults\sin\sa\npositive\snumber. +D 2014-07-23T02:07:11.054 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5eb79e334a5de69c87740edd56af6527dd219308 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -601,7 +601,7 @@ F test/fuzz_malloc.test 328f70aaca63adf29b4c6f06505ed0cf57ca7c26 F test/fuzzer1.test d4c52aaf3ef923da293a2653cfab33d02f718a36 F test/fuzzerfault.test 8792cd77fd5bce765b05d0c8e01b9edcf8af8536 F test/genesis.tcl 1e2e2e8e5cc4058549a154ff1892fe5c9de19f98 -F test/hexlit.test 499de0bfdfd16e8d406f3a4104d275c1a473b2d5 +F test/hexlit.test 58b653845b60da52161b5f451db9a89c569187d1 F test/hook.test 162d7cef7a2d2b04839fe14402934e6a1b79442f F test/icu.test 70df4faca133254c042d02ae342c0a141f2663f4 F test/in.test 047c4671328e9032ab95666a67021adbbd36e98e @@ -1184,7 +1184,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 19054339c47448bcdfd1f7be35daa3826c409077 -R 52ea51dcf5a265235552cc5fcbffc473 +P 7e1bbacb11a4689b69856450125cae3d045307af +R 8a73a1b568b990d7d0a1847902994baf U drh -Z 7e4424638caf7e83118206706ce53455 +Z d9d4d7765f779882d47568941cd5db2a diff --git a/manifest.uuid b/manifest.uuid index fc8e55fbc5..4442ea274c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -7e1bbacb11a4689b69856450125cae3d045307af \ No newline at end of file +4b86ccdf4f4eb4339a5706e10ad24f01b6c3939e \ No newline at end of file diff --git a/test/hexlit.test b/test/hexlit.test index bfb4682571..39ddf96e0b 100644 --- a/test/hexlit.test +++ b/test/hexlit.test @@ -108,7 +108,7 @@ hexlit1 219 0x00f 15 hexlit1 220 0x00F 15 proc hexlit2 {tnum hex ans} { - do_execsql_test hexlit-$tnum "SELECT printf('%7e',CAST($hex AS real))" $ans + do_execsql_test hexlit-$tnum "SELECT printf('%7e',CAST('$hex' AS real))" $ans } hexlit2 300 0x1 1.000000e+00 @@ -142,9 +142,9 @@ hexlit2 327 0x1000000000000000000000000000 3.245186e+32 hexlit2 328 0x10000000000000000000000000000 5.192297e+33 hexlit2 329 0x100000000000000000000000000000 8.307675e+34 -hexlit2 400 0x07fffffffffffffff 9.223372e+18 -hexlit2 401 0x08000000000000000 -9.223372e+18 -hexlit2 402 0x0ffffffffffffffff -1.000000e+00 -hexlit2 403 0x10000000000000000 1.844674e+19 +hexlit2 400 0x07fffffffffffffff 9.223372e+18 +hexlit2 401 0x08000000000000000 9.223372e+18 +hexlit2 402 0x0ffffffffffffffff 1.844674e+19 +hexlit2 403 0x10000000000000000 1.844674e+19 finish_test From 9296c18a509e32dac34e0ac9560946cee7f560e0 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 23 Jul 2014 13:40:49 +0000 Subject: [PATCH 31/37] Change the hex literal processing so that only the SQL parser understands hex literals. Casting and coercing string literals into numeric values does not understand hexadecimal integers. This preserves backwards compatibility. Also: Throw an error on any hex literal that is too big to fit into 64 bits. FossilOrigin-Name: 6c6f0de59bf96b79c8ace8c9bfe48c7a6a306a50 --- manifest | 22 +++++------ manifest.uuid | 2 +- src/expr.c | 8 +++- src/main.c | 2 +- src/pragma.c | 6 +-- src/sqliteInt.h | 2 + src/util.c | 100 +++++++++++++++++++++++++---------------------- test/hexlit.test | 52 +++++++----------------- 8 files changed, 93 insertions(+), 101 deletions(-) diff --git a/manifest b/manifest index 656415a599..8a6aa1f099 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Casting\shex\sliterals\sdirectly\sfrom\sstring\sto\sfloat\salways\sresults\sin\sa\npositive\snumber. -D 2014-07-23T02:07:11.054 +C Change\sthe\shex\sliteral\sprocessing\sso\sthat\sonly\sthe\sSQL\sparser\sunderstands\nhex\sliterals.\s\sCasting\sand\scoercing\sstring\sliterals\sinto\snumeric\svalues\sdoes\nnot\sunderstand\shexadecimal\sintegers.\s\sThis\spreserves\sbackwards\scompatibility.\nAlso:\s\sThrow\san\serror\son\sany\shex\sliteral\sthat\sis\stoo\sbig\sto\sfit\sinto\s64\sbits. +D 2014-07-23T13:40:49.410 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5eb79e334a5de69c87740edd56af6527dd219308 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -176,7 +176,7 @@ F src/complete.c dc1d136c0feee03c2f7550bafc0d29075e36deac F src/ctime.c 0231df905e2c4abba4483ee18ffc05adc321df2a F src/date.c 593c744b2623971e45affd0bde347631bdfa4625 F src/delete.c bcf8f72126cea80fc3d5bc5494cf19b3f8935aaf -F src/expr.c 40d06d1543b1355aa02efa9666178f7642a96ed6 +F src/expr.c b1ffac76b69ae005ca38eba6dcdefa5d65eb5c95 F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb F src/fkey.c a549cff9fe8b736cdae21650ea0af6de29b77619 F src/func.c 3bc223ea36cd29a91c481485343d0ee4257ab8dc @@ -189,7 +189,7 @@ F src/journal.c b4124532212b6952f42eb2c12fa3c25701d8ba8d F src/legacy.c 0df0b1550b9cc1f58229644735e317ac89131f12 F src/lempar.c cdf0a000315332fc9b50b62f3b5e22e080a0952b F src/loadext.c 867c7b330b740c6c917af9956b13b81d0a048303 -F src/main.c 1a420efa9a34e8603c4807886408cba5546b87f9 +F src/main.c cfdb2aa5d248ff1af60227cc3f6d485ba86f92dc F src/malloc.c 0203ebce9152c6a0e5de520140b8ba65187350be F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645 F src/mem1.c c0c990fcaddff810ea277b4fb5d9138603dd5d4b @@ -216,7 +216,7 @@ F src/parse.y 22d6a074e5f5a7258947a1dc55a9bf946b765dd0 F src/pcache.c d8eafac28290d4bb80332005435db44991d07fc2 F src/pcache.h a5e4f5d9f5d592051d91212c5949517971ae6222 F src/pcache1.c 102e6f5a2fbc646154463eb856d1fd716867b64c -F src/pragma.c 810ef31ccfaa233201dcf100637a9777cc24e897 +F src/pragma.c e17c5ea1cb9eb9d93c41bbb7c3a17e747d5e0335 F src/prepare.c 677521ab7132615a8a26107a1d1c3132f44ae337 F src/printf.c af06f66927919730f03479fed6ae9854f73419f4 F src/random.c d10c1f85b6709ca97278428fd5db5bbb9c74eece @@ -227,7 +227,7 @@ F src/shell.c 566aee8213372a2e81ba0eb34e9759f7b2574009 F src/sqlite.h.in fd8e3a36b0aded082dc93a4b89c1e85324b4cf75 F src/sqlite3.rc 11094cc6a157a028b301a9f06b3d03089ea37c3e F src/sqlite3ext.h 886f5a34de171002ad46fae8c36a7d8051c190fc -F src/sqliteInt.h b72a09326d7cbd8375ec3d9a04ea5e0cf476beb3 +F src/sqliteInt.h 783e77ab498ac05a3fab396dfc1c2d6c2083dced F src/sqliteLimit.h 164b0e6749d31e0daa1a4589a169d31c0dec7b3d F src/status.c 7ac05a5c7017d0b9f0b4bcd701228b784f987158 F src/table.c 2cd62736f845d82200acfa1287e33feb3c15d62e @@ -281,7 +281,7 @@ F src/tokenize.c ae45399d6252b4d736af43bee1576ce7bff86aec F src/trigger.c 66f3470b03b52b395e839155786966e3e037fddb F src/update.c 01564b3c430f6c7b0a35afaf7aba7987206fa3a5 F src/utf.c a0314e637768a030e6e84a957d0c4f6ba910cc05 -F src/util.c eff2c1e5a49a3c64af0fe9f2fb32cada3436a167 +F src/util.c 3076bdd51cdbf60a6e2e57fada745be37133c73e F src/vacuum.c 3728d74919d4fb1356f9e9a13e27773db60b7179 F src/vdbe.c fa74c6563486022920db4d73897bd9b837c7441d F src/vdbe.h c63fad052c9e7388d551e556e119c0bcf6bebdf8 @@ -601,7 +601,7 @@ F test/fuzz_malloc.test 328f70aaca63adf29b4c6f06505ed0cf57ca7c26 F test/fuzzer1.test d4c52aaf3ef923da293a2653cfab33d02f718a36 F test/fuzzerfault.test 8792cd77fd5bce765b05d0c8e01b9edcf8af8536 F test/genesis.tcl 1e2e2e8e5cc4058549a154ff1892fe5c9de19f98 -F test/hexlit.test 58b653845b60da52161b5f451db9a89c569187d1 +F test/hexlit.test 1dc49cfd1c8938a8f028e392775bc3e61623ec46 F test/hook.test 162d7cef7a2d2b04839fe14402934e6a1b79442f F test/icu.test 70df4faca133254c042d02ae342c0a141f2663f4 F test/in.test 047c4671328e9032ab95666a67021adbbd36e98e @@ -1184,7 +1184,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 7e1bbacb11a4689b69856450125cae3d045307af -R 8a73a1b568b990d7d0a1847902994baf +P 4b86ccdf4f4eb4339a5706e10ad24f01b6c3939e +R a36ec645688e0ae2f526ebda77270f17 U drh -Z d9d4d7765f779882d47568941cd5db2a +Z 32ccd1ec50cb642ea84793b61793e5b3 diff --git a/manifest.uuid b/manifest.uuid index 4442ea274c..f47a66e629 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -4b86ccdf4f4eb4339a5706e10ad24f01b6c3939e \ No newline at end of file +6c6f0de59bf96b79c8ace8c9bfe48c7a6a306a50 \ No newline at end of file diff --git a/src/expr.c b/src/expr.c index 803d93f30d..a60c0cba43 100644 --- a/src/expr.c +++ b/src/expr.c @@ -2075,7 +2075,7 @@ static void codeInteger(Parse *pParse, Expr *pExpr, int negFlag, int iMem){ i64 value; const char *z = pExpr->u.zToken; assert( z!=0 ); - c = sqlite3Atoi64(z, &value, sqlite3Strlen30(z), SQLITE_UTF8); + c = sqlite3DecOrHexToI64(z, &value); if( c==0 || (c==2 && negFlag) ){ char *zV; if( negFlag ){ value = c==2 ? SMALLEST_INT64 : -value; } @@ -2085,7 +2085,11 @@ static void codeInteger(Parse *pParse, Expr *pExpr, int negFlag, int iMem){ #ifdef SQLITE_OMIT_FLOATING_POINT sqlite3ErrorMsg(pParse, "oversized integer: %s%s", negFlag ? "-" : "", z); #else - codeReal(v, z, negFlag, iMem); + if( sqlite3_strnicmp(z,"0x",2)==0 ){ + sqlite3ErrorMsg(pParse, "hex literal too big: %s", z); + }else{ + codeReal(v, z, negFlag, iMem); + } #endif } } diff --git a/src/main.c b/src/main.c index 5e976e3397..904e0a4fc1 100644 --- a/src/main.c +++ b/src/main.c @@ -3409,7 +3409,7 @@ sqlite3_int64 sqlite3_uri_int64( ){ const char *z = sqlite3_uri_parameter(zFilename, zParam); sqlite3_int64 v; - if( z && sqlite3Atoi64(z, &v, sqlite3Strlen30(z), SQLITE_UTF8)==SQLITE_OK ){ + if( z && sqlite3DecOrHexToI64(z, &v)==SQLITE_OK ){ bDflt = v; } return bDflt; diff --git a/src/pragma.c b/src/pragma.c index 4c69ceb4fd..709662c989 100644 --- a/src/pragma.c +++ b/src/pragma.c @@ -1048,7 +1048,7 @@ void sqlite3Pragma( Pager *pPager = sqlite3BtreePager(pDb->pBt); i64 iLimit = -2; if( zRight ){ - sqlite3Atoi64(zRight, &iLimit, sqlite3Strlen30(zRight), SQLITE_UTF8); + sqlite3DecOrHexToI64(zRight, &iLimit); if( iLimit<-1 ) iLimit = -1; } iLimit = sqlite3PagerJournalSizeLimit(pPager, iLimit); @@ -1176,7 +1176,7 @@ void sqlite3Pragma( assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); if( zRight ){ int ii; - sqlite3Atoi64(zRight, &sz, sqlite3Strlen30(zRight), SQLITE_UTF8); + sqlite3DecOrHexToI64(zRight, &sz); if( sz<0 ) sz = sqlite3GlobalConfig.szMmap; if( pId2->n==0 ) db->szMmap = sz; for(ii=db->nDb-1; ii>=0; ii--){ @@ -2219,7 +2219,7 @@ void sqlite3Pragma( */ case PragTyp_SOFT_HEAP_LIMIT: { sqlite3_int64 N; - if( zRight && sqlite3Atoi64(zRight, &N, 1000000, SQLITE_UTF8)==SQLITE_OK ){ + if( zRight && sqlite3DecOrHexToI64(zRight, &N)==SQLITE_OK ){ sqlite3_soft_heap_limit64(N); } returnSingleInt(pParse, "soft_heap_limit", sqlite3_soft_heap_limit64(-1)); diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 7edc04ca42..0bbf9945ce 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -3331,9 +3331,11 @@ char sqlite3CompareAffinity(Expr *pExpr, char aff2); int sqlite3IndexAffinityOk(Expr *pExpr, char idx_affinity); char sqlite3ExprAffinity(Expr *pExpr); int sqlite3Atoi64(const char*, i64*, int, u8); +int sqlite3DecOrHexToI64(const char*, i64*); void sqlite3Error(sqlite3*, int, const char*,...); void *sqlite3HexToBlob(sqlite3*, const char *z, int n); u8 sqlite3HexToInt(int h); +int sqlite3HexToI64(const char*,i64*); int sqlite3TwoPartName(Parse *, Token *, Token *, Token **); #if defined(SQLITE_TEST) diff --git a/src/util.c b/src/util.c index f7f3f58b2b..619af7f758 100644 --- a/src/util.c +++ b/src/util.c @@ -255,22 +255,6 @@ int sqlite3_strnicmp(const char *zLeft, const char *zRight, int N){ return N<0 ? 0 : UpperToLower[*a] - UpperToLower[*b]; } -/* -** Translate a single byte of Hex into an integer. -** This routine only works if h really is a valid hexadecimal -** character: 0..9a..fA..F -*/ -u8 sqlite3HexToInt(int h){ - assert( (h>='0' && h<='9') || (h>='a' && h<='f') || (h>='A' && h<='F') ); -#ifdef SQLITE_ASCII - h += 9*(1&(h>>6)); -#endif -#ifdef SQLITE_EBCDIC - h += 9*(1&~(h>>4)); -#endif - return (u8)(h & 0xf); -} - /* ** The string z[] is an text representation of a real number. ** Convert this string to a double and write it into *pResult. @@ -334,20 +318,6 @@ int sqlite3AtoF(const char *z, double *pResult, int length, u8 enc){ }else if( *z=='+' ){ z+=incr; } -#ifndef SQLITE_OMIT_HEX_INTEGER - else if( *z=='0' - && &z[incr*2]=zEnd && nonNum==0; - } -#endif /* skip leading zeroes */ while( z16*incr || nonNum; - } -#endif } zStart = zNum; while( zNum='0' && h<='9') || (h>='a' && h<='f') || (h>='A' && h<='F') ); +#ifdef SQLITE_ASCII + h += 9*(1&(h>>6)); +#endif +#ifdef SQLITE_EBCDIC + h += 9*(1&~(h>>4)); +#endif + return (u8)(h & 0xf); +} + #if !defined(SQLITE_OMIT_BLOB_LITERAL) || defined(SQLITE_HAS_CODEC) /* ** Convert a BLOB literal of the form "x'hhhhhh'" into its binary diff --git a/test/hexlit.test b/test/hexlit.test index 39ddf96e0b..41133aba0f 100644 --- a/test/hexlit.test +++ b/test/hexlit.test @@ -107,44 +107,22 @@ hexlit1 218 0x00E 14 hexlit1 219 0x00f 15 hexlit1 220 0x00F 15 -proc hexlit2 {tnum hex ans} { - do_execsql_test hexlit-$tnum "SELECT printf('%7e',CAST('$hex' AS real))" $ans -} +# String literals that look like hex do not get cast or coerced. +# +do_execsql_test hexlit-300 { + CREATE TABLE t1(x INT, y REAL); + INSERT INTO t1 VALUES('1234','4567'),('0x1234','0x4567'); + SELECT typeof(x), x, typeof(y), y, '#' FROM t1 ORDER BY rowid; +} {integer 1234 real 4567.0 # text 0x1234 text 0x4567 #} +do_execsql_test hexlit-301 { + SELECT CAST('0x1234' AS INTEGER); +} {0} -hexlit2 300 0x1 1.000000e+00 -hexlit2 301 0x10 1.600000e+01 -hexlit2 302 0x100 2.560000e+02 -hexlit2 303 0x1000 4.096000e+03 -hexlit2 304 0x10000 6.553600e+04 -hexlit2 305 0x100000 1.048576e+06 -hexlit2 306 0x1000000 1.677722e+07 -hexlit2 307 0x10000000 2.684355e+08 -hexlit2 308 0x100000000 4.294967e+09 -hexlit2 309 0x1000000000 6.871948e+10 -hexlit2 310 0x10000000000 1.099512e+12 -hexlit2 311 0x100000000000 1.759219e+13 -hexlit2 312 0x1000000000000 2.814750e+14 -hexlit2 313 0x10000000000000 4.503600e+15 -hexlit2 314 0x100000000000000 7.205759e+16 -hexlit2 315 0x1000000000000000 1.152922e+18 -hexlit2 316 0x10000000000000000 1.844674e+19 -hexlit2 317 0x100000000000000000 2.951479e+20 -hexlit2 318 0x1000000000000000000 4.722366e+21 -hexlit2 319 0x10000000000000000000 7.555786e+22 -hexlit2 320 0x100000000000000000000 1.208926e+24 -hexlit2 321 0x1000000000000000000000 1.934281e+25 -hexlit2 322 0x10000000000000000000000 3.094850e+26 -hexlit2 323 0x100000000000000000000000 4.951760e+27 -hexlit2 324 0x1000000000000000000000000 7.922816e+28 -hexlit2 325 0x10000000000000000000000000 1.267651e+30 -hexlit2 326 0x100000000000000000000000000 2.028241e+31 -hexlit2 327 0x1000000000000000000000000000 3.245186e+32 -hexlit2 328 0x10000000000000000000000000000 5.192297e+33 -hexlit2 329 0x100000000000000000000000000000 8.307675e+34 +# Oversized hex literals are rejected +# +do_catchsql_test hexlist-400 { + SELECT 0x10000000000000000; +} {1 {hex literal too big: 0x10000000000000000}} -hexlit2 400 0x07fffffffffffffff 9.223372e+18 -hexlit2 401 0x08000000000000000 9.223372e+18 -hexlit2 402 0x0ffffffffffffffff 1.844674e+19 -hexlit2 403 0x10000000000000000 1.844674e+19 finish_test From 1b7ddc59158b4676e4382a5b39a0b40697c5f91d Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 23 Jul 2014 14:52:05 +0000 Subject: [PATCH 32/37] Remove a surplus function prototype. #ifdef code that is not used when hex integers are omitted at compile time. FossilOrigin-Name: a5b383e077e4b277a65920f7cc202f32f07aa9ee --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/expr.c | 5 ++++- src/sqliteInt.h | 1 - 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index 8a6aa1f099..70612a16ab 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Change\sthe\shex\sliteral\sprocessing\sso\sthat\sonly\sthe\sSQL\sparser\sunderstands\nhex\sliterals.\s\sCasting\sand\scoercing\sstring\sliterals\sinto\snumeric\svalues\sdoes\nnot\sunderstand\shexadecimal\sintegers.\s\sThis\spreserves\sbackwards\scompatibility.\nAlso:\s\sThrow\san\serror\son\sany\shex\sliteral\sthat\sis\stoo\sbig\sto\sfit\sinto\s64\sbits. -D 2014-07-23T13:40:49.410 +C Remove\sa\ssurplus\sfunction\sprototype.\s\s#ifdef\scode\sthat\sis\snot\sused\swhen\nhex\sintegers\sare\somitted\sat\scompile\stime. +D 2014-07-23T14:52:05.196 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5eb79e334a5de69c87740edd56af6527dd219308 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -176,7 +176,7 @@ F src/complete.c dc1d136c0feee03c2f7550bafc0d29075e36deac F src/ctime.c 0231df905e2c4abba4483ee18ffc05adc321df2a F src/date.c 593c744b2623971e45affd0bde347631bdfa4625 F src/delete.c bcf8f72126cea80fc3d5bc5494cf19b3f8935aaf -F src/expr.c b1ffac76b69ae005ca38eba6dcdefa5d65eb5c95 +F src/expr.c b989d07fc7c8780fff77365a4fc59881223e340c F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb F src/fkey.c a549cff9fe8b736cdae21650ea0af6de29b77619 F src/func.c 3bc223ea36cd29a91c481485343d0ee4257ab8dc @@ -227,7 +227,7 @@ F src/shell.c 566aee8213372a2e81ba0eb34e9759f7b2574009 F src/sqlite.h.in fd8e3a36b0aded082dc93a4b89c1e85324b4cf75 F src/sqlite3.rc 11094cc6a157a028b301a9f06b3d03089ea37c3e F src/sqlite3ext.h 886f5a34de171002ad46fae8c36a7d8051c190fc -F src/sqliteInt.h 783e77ab498ac05a3fab396dfc1c2d6c2083dced +F src/sqliteInt.h e8ff8fdb515774d330af4a4800e032ed00cc9adb F src/sqliteLimit.h 164b0e6749d31e0daa1a4589a169d31c0dec7b3d F src/status.c 7ac05a5c7017d0b9f0b4bcd701228b784f987158 F src/table.c 2cd62736f845d82200acfa1287e33feb3c15d62e @@ -1184,7 +1184,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 4b86ccdf4f4eb4339a5706e10ad24f01b6c3939e -R a36ec645688e0ae2f526ebda77270f17 +P 6c6f0de59bf96b79c8ace8c9bfe48c7a6a306a50 +R 9da9b225ebea231badb4246df3d3d1b3 U drh -Z 32ccd1ec50cb642ea84793b61793e5b3 +Z 6e030ade89af7e36cbcb367d7755ee7b diff --git a/manifest.uuid b/manifest.uuid index f47a66e629..af55c0e7ef 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -6c6f0de59bf96b79c8ace8c9bfe48c7a6a306a50 \ No newline at end of file +a5b383e077e4b277a65920f7cc202f32f07aa9ee \ No newline at end of file diff --git a/src/expr.c b/src/expr.c index a60c0cba43..72286dfdf9 100644 --- a/src/expr.c +++ b/src/expr.c @@ -2085,9 +2085,12 @@ static void codeInteger(Parse *pParse, Expr *pExpr, int negFlag, int iMem){ #ifdef SQLITE_OMIT_FLOATING_POINT sqlite3ErrorMsg(pParse, "oversized integer: %s%s", negFlag ? "-" : "", z); #else +#ifndef SQLITE_OMIT_HEX_INTEGER if( sqlite3_strnicmp(z,"0x",2)==0 ){ sqlite3ErrorMsg(pParse, "hex literal too big: %s", z); - }else{ + }else +#endif + { codeReal(v, z, negFlag, iMem); } #endif diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 0bbf9945ce..ca075307eb 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -3335,7 +3335,6 @@ int sqlite3DecOrHexToI64(const char*, i64*); void sqlite3Error(sqlite3*, int, const char*,...); void *sqlite3HexToBlob(sqlite3*, const char *z, int n); u8 sqlite3HexToInt(int h); -int sqlite3HexToI64(const char*,i64*); int sqlite3TwoPartName(Parse *, Token *, Token *, Token **); #if defined(SQLITE_TEST) From 11d451eb8a8b01610106b0792be64cfad5b85a45 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 23 Jul 2014 15:51:29 +0000 Subject: [PATCH 33/37] Updated documentation on sqlite3_temp_directory. No changes to code. FossilOrigin-Name: e6225a7bf77a700b318563b1a854b4b3a9e031e1 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/sqlite.h.in | 12 ++++++++++++ 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/manifest b/manifest index f57975f5d3..449ddf282d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C When\srunning\sANALYZE,\sit\sis\snot\snecessary\sto\scheck\sthe\sright-most\skey\scolumn\nfor\schanges\ssince\sthat\scolumn\swill\salways\schange\sif\snone\sof\sthe\sprevious\ncolumns\shave. -D 2014-07-22T22:46:54.689 +C Updated\sdocumentation\son\ssqlite3_temp_directory.\s\sNo\schanges\sto\scode. +D 2014-07-23T15:51:29.276 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5eb79e334a5de69c87740edd56af6527dd219308 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -224,7 +224,7 @@ F src/resolve.c 5fc110baeacf120a73fe34e103f052632ff11a02 F src/rowset.c a9c9aae3234b44a6d7c6f5a3cadf90dce1e627be F src/select.c 6762c62e11b504aa014edceab8886495165e3a77 F src/shell.c 566aee8213372a2e81ba0eb34e9759f7b2574009 -F src/sqlite.h.in fd8e3a36b0aded082dc93a4b89c1e85324b4cf75 +F src/sqlite.h.in ac4451c9da2771d2f4d702ef89722407242906d9 F src/sqlite3.rc 11094cc6a157a028b301a9f06b3d03089ea37c3e F src/sqlite3ext.h 886f5a34de171002ad46fae8c36a7d8051c190fc F src/sqliteInt.h b72a09326d7cbd8375ec3d9a04ea5e0cf476beb3 @@ -1183,7 +1183,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 77f412caf0192d3e7fecb377d6d72123d8b64424 -R e38e472b4e4b7503ed49bdb3ca667f5c +P 48f40861db4fbd10725a2b8b606d44fe16d5bd27 +R c881f4a63c48850e8a9fb96aa00a5db1 U drh -Z e390ae6bf708e4580525fb01df14fd1e +Z cd8aaf55159956edb23d2b840f6a6165 diff --git a/manifest.uuid b/manifest.uuid index 691fcc01d6..470adaeeca 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -48f40861db4fbd10725a2b8b606d44fe16d5bd27 \ No newline at end of file +e6225a7bf77a700b318563b1a854b4b3a9e031e1 \ No newline at end of file diff --git a/src/sqlite.h.in b/src/sqlite.h.in index 93cde78340..67113dc418 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -4711,6 +4711,13 @@ int sqlite3_sleep(int); ** is a NULL pointer, then SQLite performs a search for an appropriate ** temporary file directory. ** +** Applications are strongly discouraged from using this global variable. +** It is required to set a temporary folder on Windows Runtime (WinRT). +** But for all other platforms, it is highly recommended that applications +** neither read nor write this variable. This global variable is a relic +** that exists for backwards compatibility of legacy applications and should +** be avoided in new projects. +** ** It is not safe to read or modify this variable in more than one ** thread at a time. It is not safe to read or modify this variable ** if a [database connection] is being used at the same time in a separate @@ -4729,6 +4736,11 @@ int sqlite3_sleep(int); ** Hence, if this variable is modified directly, either it should be ** made NULL or made to point to memory obtained from [sqlite3_malloc] ** or else the use of the [temp_store_directory pragma] should be avoided. +** Except when requested by the [temp_store_directory pragma], SQLite +** does not free the memory that sqlite3_temp_directory points to. If +** the application wants that memory to be freed, it must do +** so itself, taking care to only do so after all [database connection] +** objects have been destroyed. ** ** Note to Windows Runtime users: The temporary directory must be set ** prior to calling [sqlite3_open] or [sqlite3_open_v2]. Otherwise, various From 3b9fab1cb9239e1ed0c17d695a45d467c826aa80 Mon Sep 17 00:00:00 2001 From: mistachkin Date: Wed, 23 Jul 2014 19:04:25 +0000 Subject: [PATCH 34/37] Enhancements to the hex literal tests. FossilOrigin-Name: a3cc027fa7ca41da23ecd0770a075a48416af020 --- manifest | 14 +++++++------- manifest.uuid | 2 +- test/hexlit.test | 28 +++++++--------------------- 3 files changed, 15 insertions(+), 29 deletions(-) diff --git a/manifest b/manifest index 70612a16ab..eafe791868 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Remove\sa\ssurplus\sfunction\sprototype.\s\s#ifdef\scode\sthat\sis\snot\sused\swhen\nhex\sintegers\sare\somitted\sat\scompile\stime. -D 2014-07-23T14:52:05.196 +C Enhancements\sto\sthe\shex\sliteral\stests. +D 2014-07-23T19:04:25.426 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5eb79e334a5de69c87740edd56af6527dd219308 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -601,7 +601,7 @@ F test/fuzz_malloc.test 328f70aaca63adf29b4c6f06505ed0cf57ca7c26 F test/fuzzer1.test d4c52aaf3ef923da293a2653cfab33d02f718a36 F test/fuzzerfault.test 8792cd77fd5bce765b05d0c8e01b9edcf8af8536 F test/genesis.tcl 1e2e2e8e5cc4058549a154ff1892fe5c9de19f98 -F test/hexlit.test 1dc49cfd1c8938a8f028e392775bc3e61623ec46 +F test/hexlit.test f9ecde8145bfc2341573473256c74ae37a200497 F test/hook.test 162d7cef7a2d2b04839fe14402934e6a1b79442f F test/icu.test 70df4faca133254c042d02ae342c0a141f2663f4 F test/in.test 047c4671328e9032ab95666a67021adbbd36e98e @@ -1184,7 +1184,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 6c6f0de59bf96b79c8ace8c9bfe48c7a6a306a50 -R 9da9b225ebea231badb4246df3d3d1b3 -U drh -Z 6e030ade89af7e36cbcb367d7755ee7b +P a5b383e077e4b277a65920f7cc202f32f07aa9ee +R 623c41f29572bef99f944ba802bce57d +U mistachkin +Z 3da04c4e52c1109f378a2e2e3819b02f diff --git a/manifest.uuid b/manifest.uuid index af55c0e7ef..af3d91e158 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -a5b383e077e4b277a65920f7cc202f32f07aa9ee \ No newline at end of file +a3cc027fa7ca41da23ecd0770a075a48416af020 \ No newline at end of file diff --git a/test/hexlit.test b/test/hexlit.test index 41133aba0f..10909e6f4c 100644 --- a/test/hexlit.test +++ b/test/hexlit.test @@ -84,28 +84,14 @@ hexlit1 160 0X1000000000000000 1152921504606846976 hexlit1 161 0x2000000000000000 2305843009213693952 hexlit1 162 0X4000000000000000 4611686018427387904 hexlit1 163 0x8000000000000000 -9223372036854775808 +hexlit1 164 0XFFFFFFFFFFFFFFFF -1 -hexlit1 200 0x001 1 -hexlit1 201 0X002 2 -hexlit1 202 0x003 3 -hexlit1 203 0X004 4 -hexlit1 204 0x005 5 -hexlit1 205 0X006 6 -hexlit1 206 0x007 7 -hexlit1 207 0X008 8 -hexlit1 208 0x009 9 -hexlit1 209 0x00a 10 -hexlit1 210 0x00A 10 -hexlit1 211 0x00b 11 -hexlit1 212 0x00B 11 -hexlit1 213 0x00c 12 -hexlit1 214 0x00C 12 -hexlit1 215 0x00d 13 -hexlit1 216 0x00D 13 -hexlit1 217 0x00e 14 -hexlit1 218 0x00E 14 -hexlit1 219 0x00f 15 -hexlit1 220 0x00F 15 +for {set n 1} {$n < 0x10} {incr n} { + hexlit1 200.$n.1 0X[format %03X $n] $n + hexlit1 200.$n.2 0x[format %03X $n] $n + hexlit1 200.$n.3 0X[format %03x $n] $n + hexlit1 200.$n.4 0x[format %03x $n] $n +} # String literals that look like hex do not get cast or coerced. # From dbd9486d5bada969d2d5abd89edb158eee1d0ec0 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 23 Jul 2014 23:57:42 +0000 Subject: [PATCH 35/37] Add experimental "costmult" logic. Only enabled when compiled with -DSQLITE_ENABLE_COSTMULT. FossilOrigin-Name: 729ece40885ed7f52c5981364833fc62281a388b --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/analyze.c | 12 +++++++++--- src/sqliteInt.h | 3 +++ src/where.c | 15 ++++++++++++++- 5 files changed, 35 insertions(+), 13 deletions(-) diff --git a/manifest b/manifest index 449ddf282d..5b3d8c340d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Updated\sdocumentation\son\ssqlite3_temp_directory.\s\sNo\schanges\sto\scode. -D 2014-07-23T15:51:29.276 +C Add\sexperimental\s"costmult"\slogic.\s\sOnly\senabled\swhen\scompiled\swith\n-DSQLITE_ENABLE_COSTMULT. +D 2014-07-23T23:57:42.403 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5eb79e334a5de69c87740edd56af6527dd219308 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -161,7 +161,7 @@ F sqlite.pc.in 42b7bf0d02e08b9e77734a47798d1a55a9e0716b F sqlite3.1 3d8b83c91651f53472ca17599dae3457b8b89494 F sqlite3.pc.in 48fed132e7cb71ab676105d2a4dc77127d8c1f3a F src/alter.c b00900877f766f116f9e16116f1ccacdc21d82f1 -F src/analyze.c ab1e44158c25490bfda557f3d690217b2bb509e2 +F src/analyze.c 1c9831015e8c575796a97692d1493ba720d16f27 F src/attach.c 3801129015ef59d76bf23c95ef9b0069d18a0c52 F src/auth.c 523da7fb4979469955d822ff9298352d6b31de34 F src/backup.c a729e63cf5cd1829507cb7b8e89f99b95141bb53 @@ -227,7 +227,7 @@ F src/shell.c 566aee8213372a2e81ba0eb34e9759f7b2574009 F src/sqlite.h.in ac4451c9da2771d2f4d702ef89722407242906d9 F src/sqlite3.rc 11094cc6a157a028b301a9f06b3d03089ea37c3e F src/sqlite3ext.h 886f5a34de171002ad46fae8c36a7d8051c190fc -F src/sqliteInt.h b72a09326d7cbd8375ec3d9a04ea5e0cf476beb3 +F src/sqliteInt.h deee99a62cd9fe4f4d094dad45ce7e85c475603e F src/sqliteLimit.h 164b0e6749d31e0daa1a4589a169d31c0dec7b3d F src/status.c 7ac05a5c7017d0b9f0b4bcd701228b784f987158 F src/table.c 2cd62736f845d82200acfa1287e33feb3c15d62e @@ -296,7 +296,7 @@ F src/vtab.c 21b932841e51ebd7d075e2d0ad1415dce8d2d5fd F src/wal.c 264df50a1b33124130b23180ded2e2c5663c652a F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4 F src/walker.c 11edb74d587bc87b33ca96a5173e3ec1b8389e45 -F src/where.c 0ffd586e04cd069ed6ce7f820194ccaa6cbd669e +F src/where.c 9454af8e5e18d6e91e5169eadfb61878e2cb42b1 F src/whereInt.h 929c1349b5355fd44f22cee5c14d72b3329c58a6 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2 @@ -1183,7 +1183,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 48f40861db4fbd10725a2b8b606d44fe16d5bd27 -R c881f4a63c48850e8a9fb96aa00a5db1 +P e6225a7bf77a700b318563b1a854b4b3a9e031e1 +R 07ca3465b9cbcf38e018d96848d50309 U drh -Z cd8aaf55159956edb23d2b840f6a6165 +Z 5f4178ba82b72065a3c11af477d1e9bb diff --git a/manifest.uuid b/manifest.uuid index 470adaeeca..ee7e54f8b2 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -e6225a7bf77a700b318563b1a854b4b3a9e031e1 \ No newline at end of file +729ece40885ed7f52c5981364833fc62281a388b \ No newline at end of file diff --git a/src/analyze.c b/src/analyze.c index c614350ae3..3a6823c107 100644 --- a/src/analyze.c +++ b/src/analyze.c @@ -1432,10 +1432,13 @@ static void decodeIntArray( if( sqlite3_strglob("unordered*", z)==0 ){ pIndex->bUnordered = 1; }else if( sqlite3_strglob("sz=[0-9]*", z)==0 ){ - int v32 = 0; - sqlite3GetInt32(z+3, &v32); - pIndex->szIdxRow = sqlite3LogEst(v32); + pIndex->szIdxRow = sqlite3LogEst(sqlite3Atoi(z+3)); } +#ifdef SQLITE_ENABLE_COSTMULT + else if( sqlite3_strglob("costmult=[0-9]*",z)==0 ){ + pIndex->pTable->costMult = sqlite3LogEst(sqlite3Atoi(z+9)); + } +#endif while( z[0]!=0 && z[0]!=' ' ) z++; while( z[0]==' ' ) z++; } @@ -1484,6 +1487,9 @@ static int analysisLoader(void *pData, int argc, char **argv, char **NotUsed){ }else{ Index fakeIdx; fakeIdx.szIdxRow = pTable->szTabRow; +#ifdef SQLITE_ENABLE_COSTMULT + fakeIdx.pTable = pTable; +#endif decodeIntArray((char*)z, 1, 0, &pTable->nRowLogEst, &fakeIdx); pTable->szTabRow = fakeIdx.szIdxRow; } diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 7edc04ca42..03f443f47c 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -1477,6 +1477,9 @@ struct Table { i16 nCol; /* Number of columns in this table */ u16 nRef; /* Number of pointers to this Table */ LogEst szTabRow; /* Estimated size of each table row in bytes */ +#ifdef SQLITE_ENABLE_COSTMULT + LogEst costMult; /* Cost multiplier for using this table */ +#endif u8 tabFlags; /* Mask of TF_* values */ u8 keyConf; /* What to do in case of uniqueness conflict on iPKey */ #ifndef SQLITE_OMIT_ALTERTABLE diff --git a/src/where.c b/src/where.c index ff18d5d4e2..3901dd468f 100644 --- a/src/where.c +++ b/src/where.c @@ -4230,6 +4230,16 @@ static void whereLoopOutputAdjust(WhereClause *pWC, WhereLoop *pLoop){ } } +/* +** Adjust the cost C by the costMult facter T. This only occurs if +** compiled with -DSQLITE_ENABLE_COSTMULT +*/ +#ifdef SQLITE_ENABLE_COSTMULT +# define ApplyCostMultiplier(C,T) C += T +#else +# define ApplyCostMultiplier(C,T) +#endif + /* ** We have so far matched pBuilder->pNew->u.btree.nEq terms of the ** index pIndex. Try to match one more. @@ -4457,6 +4467,7 @@ static int whereLoopAddBtreeIndex( if( (pNew->wsFlags & (WHERE_IDX_ONLY|WHERE_IPK))==0 ){ pNew->rRun = sqlite3LogEstAdd(pNew->rRun, pNew->nOut + 16); } + ApplyCostMultiplier(pNew->rRun, pProbe->pTable->costMult); nOutUnadjusted = pNew->nOut; pNew->rRun += nInMul + nIn; @@ -4671,6 +4682,7 @@ static int whereLoopAddBtree( ** approximately 7*N*log2(N) where N is the number of rows in ** the table being indexed. */ pNew->rSetup = rLogSize + rSize + 28; assert( 28==sqlite3LogEst(7) ); + ApplyCostMultiplier(pNew->rSetup, pTab->costMult); /* TUNING: Each index lookup yields 20 rows in the table. This ** is more than the usual guess of 10 rows, since we have no way ** of knowning how selective the index will ultimately be. It would @@ -4712,6 +4724,7 @@ static int whereLoopAddBtree( pNew->iSortIdx = b ? iSortIdx : 0; /* TUNING: Cost of full table scan is (N*3.0). */ pNew->rRun = rSize + 16; + ApplyCostMultiplier(pNew->rRun, pTab->costMult); whereLoopOutputAdjust(pWC, pNew); rc = whereLoopInsert(pBuilder, pNew); pNew->nOut = rSize; @@ -4747,7 +4760,7 @@ static int whereLoopAddBtree( if( m!=0 ){ pNew->rRun = sqlite3LogEstAdd(pNew->rRun, rSize+16); } - + ApplyCostMultiplier(pNew->rRun, pTab->costMult); whereLoopOutputAdjust(pWC, pNew); rc = whereLoopInsert(pBuilder, pNew); pNew->nOut = rSize; From 6976c2123b6498e6e5744a8be4caa4fa62de8906 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 24 Jul 2014 12:09:47 +0000 Subject: [PATCH 36/37] In the command-line shell, in CSV output mode, terminate rows with CRNL but do not expand NL characters in data into CRNL. Provide the extra -newline command-line option and the extra argument to .separator to designate an alternative newline character sequence for CSV output. FossilOrigin-Name: 16c8ce10e1530731441e6c4538691b71564684ed --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/shell.c | 49 ++++++++++++++++++++++++++++++++++++------------ test/shell1.test | 9 ++++++--- test/shell5.test | 11 +++++++---- 5 files changed, 59 insertions(+), 28 deletions(-) diff --git a/manifest b/manifest index 5b3d8c340d..3bd01efe72 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sexperimental\s"costmult"\slogic.\s\sOnly\senabled\swhen\scompiled\swith\n-DSQLITE_ENABLE_COSTMULT. -D 2014-07-23T23:57:42.403 +C In\sthe\scommand-line\sshell,\sin\sCSV\soutput\smode,\sterminate\srows\swith\sCRNL\sbut\ndo\snot\sexpand\sNL\scharacters\sin\sdata\sinto\sCRNL.\s\sProvide\sthe\sextra\s-newline\ncommand-line\soption\sand\sthe\sextra\sargument\sto\s.separator\sto\sdesignate\san\nalternative\snewline\scharacter\ssequence\sfor\sCSV\soutput. +D 2014-07-24T12:09:47.370 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5eb79e334a5de69c87740edd56af6527dd219308 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -223,7 +223,7 @@ F src/random.c d10c1f85b6709ca97278428fd5db5bbb9c74eece F src/resolve.c 5fc110baeacf120a73fe34e103f052632ff11a02 F src/rowset.c a9c9aae3234b44a6d7c6f5a3cadf90dce1e627be F src/select.c 6762c62e11b504aa014edceab8886495165e3a77 -F src/shell.c 566aee8213372a2e81ba0eb34e9759f7b2574009 +F src/shell.c cca6ea15719f2a3f41b8a1e0030d0b67a8aae3ca F src/sqlite.h.in ac4451c9da2771d2f4d702ef89722407242906d9 F src/sqlite3.rc 11094cc6a157a028b301a9f06b3d03089ea37c3e F src/sqlite3ext.h 886f5a34de171002ad46fae8c36a7d8051c190fc @@ -819,11 +819,11 @@ F test/shared9.test 5f2a8f79b4d6c7d107a01ffa1ed05ae7e6333e21 F test/sharedA.test 0cdf1a76dfa00e6beee66af5b534b1e8df2720f5 F test/shared_err.test 0079c05c97d88cfa03989b7c20a8b266983087aa F test/sharedlock.test 5ede3c37439067c43b0198f580fd374ebf15d304 -F test/shell1.test fb080d67c81e8a80a79ea04b36f127209b5bd112 +F test/shell1.test d60946b5fde4d85fe06db7331dfe89011f564350 F test/shell2.test c57da3a381c099b02c813ba156298d5c2f5c93a3 F test/shell3.test 5e8545ec72c4413a0e8d4c6be56496e3c257ca29 F test/shell4.test 8a9c08976291e6c6c808b4d718f4a8b299f339f5 -F test/shell5.test ef0c52952a4a96dc1d9ec3b1fa81ec897ca48154 +F test/shell5.test 15a419cc1df21c892ed64f5596ae7a501f2816f2 F test/shortread1.test bb591ef20f0fd9ed26d0d12e80eee6d7ac8897a3 F test/show_speedtest1_rtree.tcl 32e6c5f073d7426148a6936a0408f4b5b169aba5 F test/shrink.test 8c70f62b6e8eb4d54533de6d65bd06b1b9a17868 @@ -1183,7 +1183,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 e6225a7bf77a700b318563b1a854b4b3a9e031e1 -R 07ca3465b9cbcf38e018d96848d50309 +P 729ece40885ed7f52c5981364833fc62281a388b +R d4352ef214ae9bc2c731800627aed3f1 U drh -Z 5f4178ba82b72065a3c11af477d1e9bb +Z ddfb7b81152d55231f21f3e3700ae2bf diff --git a/manifest.uuid b/manifest.uuid index ee7e54f8b2..c78547e7f5 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -729ece40885ed7f52c5981364833fc62281a388b \ No newline at end of file +16c8ce10e1530731441e6c4538691b71564684ed \ No newline at end of file diff --git a/src/shell.c b/src/shell.c index 97167dc877..ea92b07e37 100644 --- a/src/shell.c +++ b/src/shell.c @@ -64,6 +64,7 @@ #if defined(_WIN32) || defined(WIN32) # include +# include #define isatty(h) _isatty(h) #ifndef access # define access(f,m) _access((f),(m)) @@ -458,6 +459,7 @@ struct callback_data { int showHeader; /* True to show column names in List or Column mode */ char *zDestTable; /* Name of destination table when MODE_Insert */ char separator[20]; /* Separator character for MODE_List */ + char newline[20]; /* Record separator in MODE_Csv */ int colWidth[100]; /* Requested width of each column when in column mode*/ int actualWidth[100]; /* Actual width of each column */ char nullvalue[20]; /* The text to print when a NULL comes back from @@ -659,7 +661,8 @@ static const char needCsvQuote[] = { /* ** Output a single term of CSV. Actually, p->separator is used for ** the separator, which may or may not be a comma. p->nullvalue is -** the null value. Strings are quoted if necessary. +** the null value. Strings are quoted if necessary. The separator +** is only issued if bSep is true. */ static void output_csv(struct callback_data *p, const char *z, int bSep){ FILE *out = p->out; @@ -855,17 +858,26 @@ static int shell_callback(void *pArg, int nArg, char **azArg, char **azCol, int break; } case MODE_Csv: { +#if defined(WIN32) || defined(_WIN32) + fflush(p->out); + _setmode(_fileno(p->out), _O_BINARY); +#endif if( p->cnt++==0 && p->showHeader ){ for(i=0; iout,"\n"); + fprintf(p->out,"%s",p->newline); } - if( azArg==0 ) break; - for(i=0; i0 ){ + for(i=0; iout,"%s",p->newline); } - fprintf(p->out,"\n"); +#if defined(WIN32) || defined(_WIN32) + fflush(p->out); + _setmode(_fileno(p->out), _O_TEXT); +#endif break; } case MODE_Insert: { @@ -1619,7 +1631,8 @@ static char zHelp[] = ".schema ?TABLE? Show the CREATE statements\n" " If TABLE specified, only show tables matching\n" " LIKE pattern TABLE.\n" - ".separator STRING Change separator used by output mode and .import\n" + ".separator STRING ?NL? Change separator used by output mode and .import\n" + " NL is the end-of-line mark for CSV\n" ".shell CMD ARGS... Run CMD ARGS... in a system shell\n" ".show Show the current values for various settings\n" ".stats on|off Turn stats on or off\n" @@ -2751,6 +2764,7 @@ static int do_meta_command(char *zLine, struct callback_data *p){ }else if( c2=='c' && strncmp(azArg[1],"csv",n2)==0 ){ p->mode = MODE_Csv; sqlite3_snprintf(sizeof(p->separator), p->separator, ","); + sqlite3_snprintf(sizeof(p->newline), p->newline, "\r\n"); }else if( c2=='t' && strncmp(azArg[1],"tabs",n2)==0 ){ p->mode = MODE_List; sqlite3_snprintf(sizeof(p->separator), p->separator, "\t"); @@ -3029,13 +3043,16 @@ static int do_meta_command(char *zLine, struct callback_data *p){ #endif if( c=='s' && strncmp(azArg[0], "separator", n)==0 ){ - if( nArg==2 ){ - sqlite3_snprintf(sizeof(p->separator), p->separator, - "%.*s", (int)sizeof(p->separator)-1, azArg[1]); - }else{ - fprintf(stderr, "Usage: .separator STRING\n"); + if( nArg<2 || nArg>3 ){ + fprintf(stderr, "Usage: .separator SEPARATOR ?NEWLINE?\n"); rc = 1; } + if( nArg>=2 ){ + sqlite3_snprintf(sizeof(p->separator), p->separator, azArg[1]); + } + if( nArg>=3 ){ + sqlite3_snprintf(sizeof(p->newline), p->newline, azArg[2]); + } }else if( c=='s' @@ -3076,6 +3093,8 @@ static int do_meta_command(char *zLine, struct callback_data *p){ strlen30(p->outfile) ? p->outfile : "stdout"); fprintf(p->out,"%9.9s: ", "separator"); output_c_string(p->out, p->separator); + fprintf(p->out," "); + output_c_string(p->out, p->newline); fprintf(p->out, "\n"); fprintf(p->out,"%9.9s: %s\n","stats", p->statsOn ? "on" : "off"); fprintf(p->out,"%9.9s: ","width"); @@ -3692,6 +3711,7 @@ static const char zOptions[] = #ifdef SQLITE_ENABLE_MULTIPLEX " -multiplex enable the multiplexor VFS\n" #endif + " -newline SEP set newline character(s) for CSV\n" " -nullvalue TEXT set text string for NULL values. Default ''\n" " -separator SEP set output field separator. Default: '|'\n" " -stats print memory stats before each finalize\n" @@ -3721,6 +3741,7 @@ static void main_init(struct callback_data *data) { memset(data, 0, sizeof(*data)); data->mode = MODE_List; memcpy(data->separator,"|", 2); + memcpy(data->newline,"\r\n", 3); data->showHeader = 0; sqlite3_config(SQLITE_CONFIG_URI, 1); sqlite3_config(SQLITE_CONFIG_LOG, shellLog, data); @@ -3813,6 +3834,7 @@ int main(int argc, char **argv){ if( z[1]=='-' ) z++; if( strcmp(z,"-separator")==0 || strcmp(z,"-nullvalue")==0 + || strcmp(z,"-newline")==0 || strcmp(z,"-cmd")==0 ){ (void)cmdline_option_value(argc, argv, ++i); @@ -3922,6 +3944,9 @@ int main(int argc, char **argv){ }else if( strcmp(z,"-separator")==0 ){ sqlite3_snprintf(sizeof(data.separator), data.separator, "%s",cmdline_option_value(argc,argv,++i)); + }else if( strcmp(z,"-newline")==0 ){ + sqlite3_snprintf(sizeof(data.newline), data.newline, + "%s",cmdline_option_value(argc,argv,++i)); }else if( strcmp(z,"-nullvalue")==0 ){ sqlite3_snprintf(sizeof(data.nullvalue), data.nullvalue, "%s",cmdline_option_value(argc,argv,++i)); diff --git a/test/shell1.test b/test/shell1.test index e6fb0c28d2..ab382e74cb 100644 --- a/test/shell1.test +++ b/test/shell1.test @@ -588,14 +588,17 @@ db eval {DROP VIEW v1; DROP VIEW v2; DROP TABLE t1;} # .separator STRING Change separator used by output mode and .import do_test shell1-3.22.1 { catchcmd "test.db" ".separator" -} {1 {Usage: .separator STRING}} +} {1 {Usage: .separator SEPARATOR ?NEWLINE?}} do_test shell1-3.22.2 { catchcmd "test.db" ".separator FOO" } {0 {}} do_test shell1-3.22.3 { + catchcmd "test.db" ".separator ABC XYZ" +} {0 {}} +do_test shell1-3.22.4 { # too many arguments - catchcmd "test.db" ".separator FOO BAD" -} {1 {Usage: .separator STRING}} + catchcmd "test.db" ".separator FOO BAD BAD2" +} {1 {Usage: .separator SEPARATOR ?NEWLINE?}} # .show Show the current values for various settings do_test shell1-3.23.1 { diff --git a/test/shell5.test b/test/shell5.test index 6e9dd20639..8d740cb980 100644 --- a/test/shell5.test +++ b/test/shell5.test @@ -55,14 +55,17 @@ do_test shell5-1.1.3 { # .separator STRING Change separator used by output mode and .import do_test shell5-1.2.1 { catchcmd "test.db" ".separator" -} {1 {Usage: .separator STRING}} +} {1 {Usage: .separator SEPARATOR ?NEWLINE?}} do_test shell5-1.2.2 { - catchcmd "test.db" ".separator FOO" + catchcmd "test.db" ".separator ONE" } {0 {}} do_test shell5-1.2.3 { + catchcmd "test.db" ".separator ONE TWO" +} {0 {}} +do_test shell5-1.2.4 { # too many arguments - catchcmd "test.db" ".separator FOO BAD" -} {1 {Usage: .separator STRING}} + catchcmd "test.db" ".separator ONE TWO THREE" +} {1 {Usage: .separator SEPARATOR ?NEWLINE?}} # separator should default to "|" do_test shell5-1.3.1 { From ba5b09319e2f79707bcc55a84a5f059ea0949334 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 24 Jul 2014 12:39:59 +0000 Subject: [PATCH 37/37] Add the readfile(FILENAME) and writefile(FILENAME,CONTENT) SQL functions to the command-line shell. FossilOrigin-Name: fb1048cb2b613a0dbfe625a5df05e9dcd736a433 --- manifest | 13 +++++----- manifest.uuid | 2 +- src/shell.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 987d285913..c9c66de972 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\ssupport\sfor\shexadecimal\sinteger\sliterals\sin\sthe\sparser. -D 2014-07-24T12:19:41.241 +C Add\sthe\sreadfile(FILENAME)\sand\swritefile(FILENAME,CONTENT)\sSQL\sfunctions\sto\nthe\scommand-line\sshell. +D 2014-07-24T12:39:59.049 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5eb79e334a5de69c87740edd56af6527dd219308 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -223,7 +223,7 @@ F src/random.c d10c1f85b6709ca97278428fd5db5bbb9c74eece F src/resolve.c 5fc110baeacf120a73fe34e103f052632ff11a02 F src/rowset.c a9c9aae3234b44a6d7c6f5a3cadf90dce1e627be F src/select.c 6762c62e11b504aa014edceab8886495165e3a77 -F src/shell.c cca6ea15719f2a3f41b8a1e0030d0b67a8aae3ca +F src/shell.c 191129c3f7a9cf241aea90ff6a6be3e74d3767f0 F src/sqlite.h.in ac4451c9da2771d2f4d702ef89722407242906d9 F src/sqlite3.rc 11094cc6a157a028b301a9f06b3d03089ea37c3e F src/sqlite3ext.h 886f5a34de171002ad46fae8c36a7d8051c190fc @@ -1184,8 +1184,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 16c8ce10e1530731441e6c4538691b71564684ed a3cc027fa7ca41da23ecd0770a075a48416af020 -R 800080a0f835a3b88d7f1d5c8ee5f8c1 -T +closed a3cc027fa7ca41da23ecd0770a075a48416af020 +P f8f79f28785db716b10c3bc9d6652b98253fd125 +R 3cb7c1591be4171f813333f040f9142c U drh -Z c1345ae836570db977d9f440b563b830 +Z d6bf09c8f21a2381ecdf6b5a91f85057 diff --git a/manifest.uuid b/manifest.uuid index 566e373026..c704a64b44 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -f8f79f28785db716b10c3bc9d6652b98253fd125 \ No newline at end of file +fb1048cb2b613a0dbfe625a5df05e9dcd736a433 \ No newline at end of file diff --git a/src/shell.c b/src/shell.c index ea92b07e37..371efa024e 100644 --- a/src/shell.c +++ b/src/shell.c @@ -1650,6 +1650,69 @@ static char zHelp[] = /* Forward reference */ static int process_input(struct callback_data *p, FILE *in); +/* +** Implementation of the "readfile(X)" SQL function. The entire content +** of the file named X is read and returned as a BLOB. NULL is returned +** if the file does not exist or is unreadable. +*/ +static void readfileFunc( + sqlite3_context *context, + int argc, + sqlite3_value **argv +){ + const char *zName; + FILE *in; + long nIn; + void *pBuf; + + zName = (const char*)sqlite3_value_text(argv[0]); + if( zName==0 ) return; + in = fopen(zName, "rb"); + if( in==0 ) return; + fseek(in, 0, SEEK_END); + nIn = ftell(in); + rewind(in); + pBuf = sqlite3_malloc( nIn ); + if( pBuf && 1==fread(pBuf, nIn, 1, in) ){ + sqlite3_result_blob(context, pBuf, nIn, sqlite3_free); + }else{ + sqlite3_free(pBuf); + } + fclose(in); +} + +/* +** Implementation of the "writefile(X,Y)" SQL function. The argument Y +** is written into file X. The number of bytes written is returned. Or +** NULL is returned if something goes wrong, such as being unable to open +** file X for writing. +*/ +static void writefileFunc( + sqlite3_context *context, + int argc, + sqlite3_value **argv +){ + FILE *out; + const char *z; + int n; + sqlite3_int64 rc; + const char *zFile; + + zFile = (const char*)sqlite3_value_text(argv[0]); + if( zFile==0 ) return; + out = fopen(zFile, "wb"); + if( out==0 ) return; + z = (const char*)sqlite3_value_blob(argv[1]); + if( z==0 ){ + n = 0; + rc = 0; + }else{ + n = sqlite3_value_bytes(argv[1]); + rc = fwrite(z, 1, n, out); + } + fclose(out); + sqlite3_result_int64(context, rc); +} /* ** Make sure the database is open. If it is not, then open it. If @@ -1673,6 +1736,10 @@ static void open_db(struct callback_data *p, int keepAlive){ #ifndef SQLITE_OMIT_LOAD_EXTENSION sqlite3_enable_load_extension(p->db, 1); #endif + sqlite3_create_function(db, "readfile", 1, SQLITE_UTF8, 0, + readfileFunc, 0, 0); + sqlite3_create_function(db, "writefile", 2, SQLITE_UTF8, 0, + writefileFunc, 0, 0); } }