From c435cf75a57292833696920189f416e923e4a85d Mon Sep 17 00:00:00 2001 From: drh Date: Sat, 21 Mar 2015 16:36:03 +0000 Subject: [PATCH 001/181] Fix the blocking WAL lock so that it works and so that it compiles on a Mac. FossilOrigin-Name: 67d69d21de32816894be53e4b446656d4174eb0d --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/os_unix.c | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/manifest b/manifest index 75771530bb..1277a25997 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Remove\san\sunreachable\sbranch\sfrom\sthe\sOP_VCreate\sopcode\s(merge\saccidental\sfork\sin\strunk). -D 2015-03-21T12:25:23.115 +C Fix\sthe\sblocking\sWAL\slock\sso\sthat\sit\sworks\sand\sso\sthat\sit\scompiles\son\sa\sMac. +D 2015-03-21T16:36:03.990 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -214,7 +214,7 @@ F src/os.c 8fd25588eeba74068d41102d26810e216999b6c8 F src/os.h 3e57a24e2794a94d3cf2342c6d9a884888cd96bf F src/os_common.h 92815ed65f805560b66166e3583470ff94478f04 F src/os_setup.h c9d4553b5aaa6f73391448b265b89bed0b890faa -F src/os_unix.c cc903ecc6ebda90ef703d043ddaa7f33de0cab0f +F src/os_unix.c e68c8e77e47ce38865ebf8e1a0e877ac955f469c F src/os_win.c 8223e7db5b7c4a81d8b161098ac3959400434cdb F src/os_win.h eb7a47aa17b26b77eb97e4823f20a00b8bda12ca F src/pager.c 4120a49ecd37697e28f5ed807f470b9c0b88410c @@ -1246,7 +1246,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 e3e234649616f20610abce9ae9da1c572d3a4377 5fca41a3811766b48f5f23d5d49cc4e6e79fa867 -R f330fb6722b7e402dae00a81353077df -U dan -Z 1c256b7cca05bea8c4676944e04ddeb4 +P 2fbfec62fc03d42ee240dfefaa0aeb59a3f04d88 +R 5a3409f8ffa9923877231407f3215215 +U drh +Z 15a1523db948e8ebecc44c81b8244965 diff --git a/manifest.uuid b/manifest.uuid index d71396b19d..a82805b710 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -2fbfec62fc03d42ee240dfefaa0aeb59a3f04d88 \ No newline at end of file +67d69d21de32816894be53e4b446656d4174eb0d \ No newline at end of file diff --git a/src/os_unix.c b/src/os_unix.c index 16cb935dec..d0924a511b 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -3782,6 +3782,10 @@ static int unixGetTempname(int nBuf, char *zBuf); static int unixFileControl(sqlite3_file *id, int op, void *pArg){ unixFile *pFile = (unixFile*)id; switch( op ){ + case SQLITE_FCNTL_WAL_BLOCK: { + pFile->ctrlFlags |= UNIXFILE_BLOCK; + return SQLITE_OK; + } case SQLITE_FCNTL_LOCKSTATE: { *(int*)pArg = pFile->eFileLock; return SQLITE_OK; @@ -7228,10 +7232,6 @@ static int proxyTransformUnixFile(unixFile *pFile, const char *path) { */ static int proxyFileControl(sqlite3_file *id, int op, void *pArg){ switch( op ){ - case SQLITE_FCNTL_WAL_BLOCK: { - id->ctrlFlags |= UNIXFILE_BLOCK; - return SQLITE_OK; - } case SQLITE_FCNTL_GET_LOCKPROXYFILE: { unixFile *pFile = (unixFile*)id; if( pFile->pMethod == &proxyIoMethods ){ From d2f99333cfb8a2589c8ea56e62a668ce881bbd6f Mon Sep 17 00:00:00 2001 From: dan Date: Sat, 21 Mar 2015 16:40:24 +0000 Subject: [PATCH 002/181] Change walblock.test to block an external process for 10 seconds, not 5. 5 seconds is not long enough to tell the difference between a blocking lock and a series of retries. FossilOrigin-Name: 717335fcdb15430ed977cbc98d30345b71728b66 --- manifest | 14 +++++++------- manifest.uuid | 2 +- test/walblock.test | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index 1277a25997..227d2396bf 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sthe\sblocking\sWAL\slock\sso\sthat\sit\sworks\sand\sso\sthat\sit\scompiles\son\sa\sMac. -D 2015-03-21T16:36:03.990 +C Change\swalblock.test\sto\sblock\san\sexternal\sprocess\sfor\s10\sseconds,\snot\s5.\s5\sseconds\sis\snot\slong\senough\sto\stell\sthe\sdifference\sbetween\sa\sblocking\slock\sand\sa\sseries\sof\sretries. +D 2015-03-21T16:40:24.176 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -1142,7 +1142,7 @@ F test/wal9.test 378e76a9ad09cd9bee06c172ad3547b0129a6750 F test/wal_common.tcl a98f17fba96206122eff624db0ab13ec377be4fe F test/walbak.test b9f68e39646375c2b877be906babcc15d38b4877 F test/walbig.test f437473a16cfb314867c6b5d1dbcd519e73e3434 -F test/walblock.test f1290524714232c109fb0b14db28f14d81c3ddd0 +F test/walblock.test ffc761cd467a93ccd8cd998a23be2f21b95a83b1 F test/walcksum.test 9afeb96240296c08c72fc524d199c912cfe34daa F test/walcrash.test 451d79e528add5c42764cea74aa2750754171b25 F test/walcrash2.test a0edab4e5390f03b99a790de89aad15d6ec70b36 @@ -1246,7 +1246,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 2fbfec62fc03d42ee240dfefaa0aeb59a3f04d88 -R 5a3409f8ffa9923877231407f3215215 -U drh -Z 15a1523db948e8ebecc44c81b8244965 +P 67d69d21de32816894be53e4b446656d4174eb0d +R fd1744ba13eb7ca730963f1f28c9bbe1 +U dan +Z 766817d70f1d0d42f94e17731574ace5 diff --git a/manifest.uuid b/manifest.uuid index a82805b710..183e639eed 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -67d69d21de32816894be53e4b446656d4174eb0d \ No newline at end of file +717335fcdb15430ed977cbc98d30345b71728b66 \ No newline at end of file diff --git a/test/walblock.test b/test/walblock.test index 9a85ea4acc..0b0b2241e6 100644 --- a/test/walblock.test +++ b/test/walblock.test @@ -92,9 +92,9 @@ proc barrier_callback {method args} { set ::out "" testfixture $::C { db eval { SELECT * FROM t1 } } {set ::out} - do_test "1.2.2.(blocking 5 seconds)" { + do_test "1.2.2.(blocking 10 seconds)" { set ::continue 0 - after 5000 {set ::continue 1} + after 10000 {set ::continue 1} vwait ::continue set ::out } {} From e10d87f65a8642957fd302a5522f90062620bf71 Mon Sep 17 00:00:00 2001 From: dan Date: Sat, 21 Mar 2015 19:35:09 +0000 Subject: [PATCH 003/181] Avoid a segfault if NULL is passed as the first argument to SQL scalar function fts3_tokenizer(). FossilOrigin-Name: 6d0989695b486275824c14d5f88357267c1e8104 --- ext/fts3/fts3_tokenizer.c | 6 ++++-- manifest | 14 +++++++------- manifest.uuid | 2 +- test/fts3atoken.test | 10 ++++++++++ 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/ext/fts3/fts3_tokenizer.c b/ext/fts3/fts3_tokenizer.c index 8bb8b178ba..2b985f5f33 100644 --- a/ext/fts3/fts3_tokenizer.c +++ b/ext/fts3/fts3_tokenizer.c @@ -69,7 +69,7 @@ static void scalarFunc( if( argc==2 ){ void *pOld; int n = sqlite3_value_bytes(argv[1]); - if( n!=sizeof(pPtr) ){ + if( zName==0 || n!=sizeof(pPtr) ){ sqlite3_result_error(context, "argument type mismatch", -1); return; } @@ -80,7 +80,9 @@ static void scalarFunc( return; } }else{ - pPtr = sqlite3Fts3HashFind(pHash, zName, nName); + if( zName ){ + pPtr = sqlite3Fts3HashFind(pHash, zName, nName); + } if( !pPtr ){ char *zErr = sqlite3_mprintf("unknown tokenizer: %s", zName); sqlite3_result_error(context, zErr, -1); diff --git a/manifest b/manifest index 227d2396bf..c02318a20e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Change\swalblock.test\sto\sblock\san\sexternal\sprocess\sfor\s10\sseconds,\snot\s5.\s5\sseconds\sis\snot\slong\senough\sto\stell\sthe\sdifference\sbetween\sa\sblocking\slock\sand\sa\sseries\sof\sretries. -D 2015-03-21T16:40:24.176 +C Avoid\sa\ssegfault\sif\sNULL\sis\spassed\sas\sthe\sfirst\sargument\sto\sSQL\sscalar\sfunction\sfts3_tokenizer(). +D 2015-03-21T19:35:09.439 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -91,7 +91,7 @@ F ext/fts3/fts3_snippet.c 52c2dcf410b1f9af5a44d81a2cf8c68ed1cb5283 F ext/fts3/fts3_term.c a521f75132f9a495bdca1bdd45949b3191c52763 F ext/fts3/fts3_test.c 8a3a78c4458b2d7c631fcf4b152a5cd656fa7038 F ext/fts3/fts3_tokenize_vtab.c becc661223db7898b213f9e8a23d75bac02408c9 -F ext/fts3/fts3_tokenizer.c 0f9e6e01de1e1fe2e79074e3cf70ed1b1ea848b7 +F ext/fts3/fts3_tokenizer.c b7e586baeb8d0a061cf01a0f7081d88f3935eecf F ext/fts3/fts3_tokenizer.h 64c6ef6c5272c51ebe60fc607a896e84288fcbc3 F ext/fts3/fts3_tokenizer1.c 5c98225a53705e5ee34824087478cf477bdb7004 F ext/fts3/fts3_unicode.c a93f5edc0aff44ef8b06d7cb55b52026541ca145 @@ -564,7 +564,7 @@ F test/fts3al.test 07d64326e79bbdbab20ee87fc3328fbf01641c9f F test/fts3am.test 218aa6ba0dfc50c7c16b2022aac5c6be593d08d8 F test/fts3an.test a49ccadc07a2f7d646ec1b81bc09da2d85a85b18 F test/fts3ao.test 3e4e3d5e75c076520341d0bdf4eb17c00e8cbde2 -F test/fts3atoken.test 95c721d71acb141eb754701b15a8e60bb6eb4263 +F test/fts3atoken.test e3a126365131a6db52efc20a9a6053cd44e5f289 F test/fts3auto.test b981fea19b132b4e6878f50d7c1f369b28f68eb9 F test/fts3aux1.test f8f287a4a73f381f8fa15b6a70f36245f903d221 F test/fts3aux2.test 7ae2b2c13aefdf4169279a27a5f51780ce57f6ba @@ -1246,7 +1246,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 67d69d21de32816894be53e4b446656d4174eb0d -R fd1744ba13eb7ca730963f1f28c9bbe1 +P 717335fcdb15430ed977cbc98d30345b71728b66 +R 9a44cfc186a78e5b971a0e9f8c3b76c2 U dan -Z 766817d70f1d0d42f94e17731574ace5 +Z 068927d1dd3aa367e2b9f4f743992531 diff --git a/manifest.uuid b/manifest.uuid index 183e639eed..98bf637961 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -717335fcdb15430ed977cbc98d30345b71728b66 \ No newline at end of file +6d0989695b486275824c14d5f88357267c1e8104 \ No newline at end of file diff --git a/test/fts3atoken.test b/test/fts3atoken.test index 904a9a3fc3..88e3d4f72b 100644 --- a/test/fts3atoken.test +++ b/test/fts3atoken.test @@ -203,5 +203,15 @@ do_catchsql_test 6.1.3 { CREATE VIRTUAL TABLE t3 USING fts4(tokenize=" "); } {1 {unknown tokenizer: }} +do_catchsql_test 6.2.1 { + SELECT fts3_tokenizer(NULL); +} {1 {unknown tokenizer: }} +do_catchsql_test 6.2.2 { + SELECT fts3_tokenizer(NULL, X'1234567812345678'); +} {1 {argument type mismatch}} +do_catchsql_test 6.2.3 { + SELECT fts3_tokenizer(NULL, X'12345678'); +} {1 {argument type mismatch}} + finish_test From 3858cb44b64efd781481e377a045ba50dba94894 Mon Sep 17 00:00:00 2001 From: drh Date: Sat, 21 Mar 2015 20:50:58 +0000 Subject: [PATCH 004/181] Add a missing "int" on a constant declaration. FossilOrigin-Name: 235157de5113ac4c750e36a498e2a1f1cf461751 --- ext/fts3/fts3.c | 2 +- manifest | 14 +++++++------- manifest.uuid | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/ext/fts3/fts3.c b/ext/fts3/fts3.c index 3c2e5adc01..c92463204c 100644 --- a/ext/fts3/fts3.c +++ b/ext/fts3/fts3.c @@ -910,7 +910,7 @@ static char *fts3WriteExprList(Fts3Table *p, const char *zFunc, int *pRc){ ** This function is used when parsing the "prefix=" FTS4 parameter. */ static int fts3GobbleInt(const char **pp, int *pnOut){ - const MAX_NPREFIX = 10000000; + const int MAX_NPREFIX = 10000000; const char *p; /* Iterator pointer */ int nInt = 0; /* Output value */ diff --git a/manifest b/manifest index c02318a20e..ec5a2a710e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Avoid\sa\ssegfault\sif\sNULL\sis\spassed\sas\sthe\sfirst\sargument\sto\sSQL\sscalar\sfunction\sfts3_tokenizer(). -D 2015-03-21T19:35:09.439 +C Add\sa\smissing\s"int"\son\sa\sconstant\sdeclaration. +D 2015-03-21T20:50:58.948 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -78,7 +78,7 @@ F ext/fts3/README.content fdc666a70d5257a64fee209f97cf89e0e6e32b51 F ext/fts3/README.syntax a19711dc5458c20734b8e485e75fb1981ec2427a F ext/fts3/README.tokenizers e0a8b81383ea60d0334d274fadf305ea14a8c314 F ext/fts3/README.txt 8c18f41574404623b76917b9da66fcb0ab38328d -F ext/fts3/fts3.c e2c7e61d676ce7b9383d1078c9774a2f22947d57 +F ext/fts3/fts3.c 2a1cf23133d0c75ce296d17440c44115f8413ec7 F ext/fts3/fts3.h 3a10a0af180d502cecc50df77b1b22df142817fe F ext/fts3/fts3Int.h 394858c12a17740f7a1f6bd372c4606d4425a8d1 F ext/fts3/fts3_aux.c 5c211e17a64885faeb16b9ba7772f9d5445c2365 @@ -1246,7 +1246,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 717335fcdb15430ed977cbc98d30345b71728b66 -R 9a44cfc186a78e5b971a0e9f8c3b76c2 -U dan -Z 068927d1dd3aa367e2b9f4f743992531 +P 6d0989695b486275824c14d5f88357267c1e8104 +R f4c5c38b537072acd0ef8cbe1e26c753 +U drh +Z c60ff55e80e06532c78f97fe504967fd diff --git a/manifest.uuid b/manifest.uuid index 98bf637961..7d077b0af4 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -6d0989695b486275824c14d5f88357267c1e8104 \ No newline at end of file +235157de5113ac4c750e36a498e2a1f1cf461751 \ No newline at end of file From 5ac936529c2a828acb809525c15af87ebdba6944 Mon Sep 17 00:00:00 2001 From: drh Date: Sat, 21 Mar 2015 20:59:43 +0000 Subject: [PATCH 005/181] Do not invoke a C preprocessor macro with an empty argument, as (reportedly) some versions of GCC are unable to deal with that. FossilOrigin-Name: de9da317d4df3efefe9a1a48f954af8a19e7d098 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/os_unix.c | 36 ++++++++++++++++++------------------ 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/manifest b/manifest index ec5a2a710e..4a0ca3ea20 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sa\smissing\s"int"\son\sa\sconstant\sdeclaration. -D 2015-03-21T20:50:58.948 +C Do\snot\sinvoke\sa\sC\spreprocessor\smacro\swith\san\sempty\sargument,\sas\s(reportedly)\nsome\sversions\sof\sGCC\sare\sunable\sto\sdeal\swith\sthat. +D 2015-03-21T20:59:43.779 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -214,7 +214,7 @@ F src/os.c 8fd25588eeba74068d41102d26810e216999b6c8 F src/os.h 3e57a24e2794a94d3cf2342c6d9a884888cd96bf F src/os_common.h 92815ed65f805560b66166e3583470ff94478f04 F src/os_setup.h c9d4553b5aaa6f73391448b265b89bed0b890faa -F src/os_unix.c e68c8e77e47ce38865ebf8e1a0e877ac955f469c +F src/os_unix.c a4dadbc2da41599e99093e91e276c38c17a73b89 F src/os_win.c 8223e7db5b7c4a81d8b161098ac3959400434cdb F src/os_win.h eb7a47aa17b26b77eb97e4823f20a00b8bda12ca F src/pager.c 4120a49ecd37697e28f5ed807f470b9c0b88410c @@ -1246,7 +1246,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 6d0989695b486275824c14d5f88357267c1e8104 -R f4c5c38b537072acd0ef8cbe1e26c753 +P 235157de5113ac4c750e36a498e2a1f1cf461751 +R 4027cff60803cc3b440b57484c5f02d8 U drh -Z c60ff55e80e06532c78f97fe504967fd +Z 5a82a26aab899b185210ad558ba95050 diff --git a/manifest.uuid b/manifest.uuid index 7d077b0af4..9a937f472e 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -235157de5113ac4c750e36a498e2a1f1cf461751 \ No newline at end of file +de9da317d4df3efefe9a1a48f954af8a19e7d098 \ No newline at end of file diff --git a/src/os_unix.c b/src/os_unix.c index d0924a511b..a9c883a935 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -1536,7 +1536,7 @@ static int unixLock(sqlite3_file *id, int eFileLock){ OSTRACE(("LOCK %d %s was %s(%s,%d) pid=%d (unix)\n", pFile->h, azFileLock(eFileLock), azFileLock(pFile->eFileLock), azFileLock(pFile->pInode->eFileLock), pFile->pInode->nShared, - osGetpid())); + osGetpid(0))); /* If there is already a lock of this type or more restrictive on the ** unixFile, do nothing. Don't use the end_lock: exit path, as @@ -1744,7 +1744,7 @@ static int posixUnlock(sqlite3_file *id, int eFileLock, int handleNFSUnlock){ assert( pFile ); OSTRACE(("UNLOCK %d %d was %d(%d,%d) pid=%d (unix)\n", pFile->h, eFileLock, pFile->eFileLock, pFile->pInode->eFileLock, pFile->pInode->nShared, - osGetpid())); + osGetpid(0))); assert( eFileLock<=SHARED_LOCK ); if( pFile->eFileLock<=eFileLock ){ @@ -2171,7 +2171,7 @@ static int dotlockUnlock(sqlite3_file *id, int eFileLock) { assert( pFile ); OSTRACE(("UNLOCK %d %d was %d pid=%d (dotlock)\n", pFile->h, eFileLock, - pFile->eFileLock, osGetpid())); + pFile->eFileLock, osGetpid(0))); assert( eFileLock<=SHARED_LOCK ); /* no-op if possible */ @@ -2389,7 +2389,7 @@ static int flockUnlock(sqlite3_file *id, int eFileLock) { assert( pFile ); OSTRACE(("UNLOCK %d %d was %d pid=%d (flock)\n", pFile->h, eFileLock, - pFile->eFileLock, osGetpid())); + pFile->eFileLock, osGetpid(0))); assert( eFileLock<=SHARED_LOCK ); /* no-op if possible */ @@ -2557,7 +2557,7 @@ static int semXUnlock(sqlite3_file *id, int eFileLock) { assert( pFile ); assert( pSem ); OSTRACE(("UNLOCK %d %d was %d pid=%d (sem)\n", pFile->h, eFileLock, - pFile->eFileLock, osGetpid())); + pFile->eFileLock, osGetpid(0))); assert( eFileLock<=SHARED_LOCK ); /* no-op if possible */ @@ -2771,7 +2771,7 @@ static int afpLock(sqlite3_file *id, int eFileLock){ assert( pFile ); OSTRACE(("LOCK %d %s was %s(%s,%d) pid=%d (afp)\n", pFile->h, azFileLock(eFileLock), azFileLock(pFile->eFileLock), - azFileLock(pInode->eFileLock), pInode->nShared , osGetpid())); + azFileLock(pInode->eFileLock), pInode->nShared , osGetpid(0))); /* If there is already a lock of this type or more restrictive on the ** unixFile, do nothing. Don't use the afp_end_lock: exit path, as @@ -2957,7 +2957,7 @@ static int afpUnlock(sqlite3_file *id, int eFileLock) { assert( pFile ); OSTRACE(("UNLOCK %d %d was %d(%d,%d) pid=%d (afp)\n", pFile->h, eFileLock, pFile->eFileLock, pFile->pInode->eFileLock, pFile->pInode->nShared, - osGetpid())); + osGetpid(0))); assert( eFileLock<=SHARED_LOCK ); if( pFile->eFileLock<=eFileLock ){ @@ -4636,7 +4636,7 @@ static int unixShmLock( } sqlite3_mutex_leave(pShmNode->mutex); OSTRACE(("SHM-LOCK shmid-%d, pid-%d got %03x,%03x\n", - p->id, osGetpid(), p->sharedMask, p->exclMask)); + p->id, osGetpid(0), p->sharedMask, p->exclMask)); return rc; } @@ -5731,8 +5731,8 @@ static int unixOpen( ** the same instant might all reset the PRNG. But multiple resets ** are harmless. */ - if( randomnessPid!=osGetpid() ){ - randomnessPid = osGetpid(); + if( randomnessPid!=osGetpid(0) ){ + randomnessPid = osGetpid(0); sqlite3_randomness(0,0); } @@ -6123,7 +6123,7 @@ static int unixRandomness(sqlite3_vfs *NotUsed, int nBuf, char *zBuf){ ** tests repeatable. */ memset(zBuf, 0, nBuf); - randomnessPid = osGetpid(); + randomnessPid = osGetpid(0); #if !defined(SQLITE_TEST) { int fd, got; @@ -6444,7 +6444,7 @@ static int proxyGetLockPath(const char *dbPath, char *lPath, size_t maxLen){ { if( !confstr(_CS_DARWIN_USER_TEMP_DIR, lPath, maxLen) ){ OSTRACE(("GETLOCKPATH failed %s errno=%d pid=%d\n", - lPath, errno, osGetpid())); + lPath, errno, osGetpid(0))); return SQLITE_IOERR_LOCK; } len = strlcat(lPath, "sqliteplocks", maxLen); @@ -6466,7 +6466,7 @@ static int proxyGetLockPath(const char *dbPath, char *lPath, size_t maxLen){ } lPath[i+len]='\0'; strlcat(lPath, ":auto:", maxLen); - OSTRACE(("GETLOCKPATH proxy lock path=%s pid=%d\n", lPath, osGetpid())); + OSTRACE(("GETLOCKPATH proxy lock path=%s pid=%d\n", lPath, osGetpid(0))); return SQLITE_OK; } @@ -6493,7 +6493,7 @@ static int proxyCreateLockPath(const char *lockPath){ if( err!=EEXIST ) { OSTRACE(("CREATELOCKPATH FAILED creating %s, " "'%s' proxy lock path=%s pid=%d\n", - buf, strerror(err), lockPath, osGetpid())); + buf, strerror(err), lockPath, osGetpid(0))); return err; } } @@ -6502,7 +6502,7 @@ static int proxyCreateLockPath(const char *lockPath){ } buf[i] = lockPath[i]; } - OSTRACE(("CREATELOCKPATH proxy lock path=%s pid=%d\n", lockPath, osGetpid())); + OSTRACE(("CREATELOCKPATH proxy lock path=%s pid=%d\n", lockPath, osGetpid(0))); return 0; } @@ -6808,7 +6808,7 @@ static int proxyTakeConch(unixFile *pFile){ OSTRACE(("TAKECONCH %d for %s pid=%d\n", conchFile->h, (pCtx->lockProxyPath ? pCtx->lockProxyPath : ":auto:"), - osGetpid())); + osGetpid(0))); rc = proxyGetHostID(myHostID, &pError); if( (rc&0xff)==SQLITE_IOERR ){ @@ -7018,7 +7018,7 @@ static int proxyReleaseConch(unixFile *pFile){ conchFile = pCtx->conchFile; OSTRACE(("RELEASECONCH %d for %s pid=%d\n", conchFile->h, (pCtx->lockProxyPath ? pCtx->lockProxyPath : ":auto:"), - osGetpid())); + osGetpid(0))); if( pCtx->conchHeld>0 ){ rc = conchFile->pMethod->xUnlock((sqlite3_file*)conchFile, NO_LOCK); } @@ -7160,7 +7160,7 @@ static int proxyTransformUnixFile(unixFile *pFile, const char *path) { } OSTRACE(("TRANSPROXY %d for %s pid=%d\n", pFile->h, - (lockPath ? lockPath : ":auto:"), osGetpid())); + (lockPath ? lockPath : ":auto:"), osGetpid(0))); pCtx = sqlite3_malloc( sizeof(*pCtx) ); if( pCtx==0 ){ From 082be63b1772e3f752a694de8e51c4b963b95dbf Mon Sep 17 00:00:00 2001 From: mistachkin Date: Sat, 21 Mar 2015 22:13:47 +0000 Subject: [PATCH 006/181] Increase the debugging level for the debug configuration in the MSVC batch build tool. FossilOrigin-Name: 041484ff91fd4615368ccb2257ab50acc2cd4fea --- manifest | 14 +++++++------- manifest.uuid | 2 +- tool/build-all-msvc.bat | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 4a0ca3ea20..9bcf1897b9 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Do\snot\sinvoke\sa\sC\spreprocessor\smacro\swith\san\sempty\sargument,\sas\s(reportedly)\nsome\sversions\sof\sGCC\sare\sunable\sto\sdeal\swith\sthat. -D 2015-03-21T20:59:43.779 +C Increase\sthe\sdebugging\slevel\sfor\sthe\sdebug\sconfiguration\sin\sthe\sMSVC\sbatch\sbuild\stool. +D 2015-03-21T22:13:47.750 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -1194,7 +1194,7 @@ F test/without_rowid6.test db0dbf03c49030aa3c1ba5f618620334bd2baf5f F test/wordcount.c 9915e06cb33d8ca8109b8700791afe80d305afda F test/zeroblob.test caaecfb4f908f7bc086ed238668049f96774d688 F test/zerodamage.test cf6748bad89553cc1632be51a6f54e487e4039ac -F tool/build-all-msvc.bat 62785b25bf7ea82dc016b3233a896151c786cfbb x +F tool/build-all-msvc.bat 6e2c65d4c694ad3bdcbf8d813d18336c378ef642 x F tool/build-shell.sh 950f47c6174f1eea171319438b93ba67ff5bf367 F tool/checkSpacing.c 810e51703529a204fc4e1eb060e9ab663e3c06d2 F tool/diffdb.c 7524b1b5df217c20cd0431f6789851a4e0cb191b @@ -1246,7 +1246,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 235157de5113ac4c750e36a498e2a1f1cf461751 -R 4027cff60803cc3b440b57484c5f02d8 -U drh -Z 5a82a26aab899b185210ad558ba95050 +P de9da317d4df3efefe9a1a48f954af8a19e7d098 +R 2dc59230e8af71c6a1b496cc05325870 +U mistachkin +Z bebf96c7eb7dba0d54e717c5ef7df7e1 diff --git a/manifest.uuid b/manifest.uuid index 9a937f472e..c20999f107 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -de9da317d4df3efefe9a1a48f954af8a19e7d098 \ No newline at end of file +041484ff91fd4615368ccb2257ab50acc2cd4fea \ No newline at end of file diff --git a/tool/build-all-msvc.bat b/tool/build-all-msvc.bat index 2ae202620a..1751fb4d12 100755 --- a/tool/build-all-msvc.bat +++ b/tool/build-all-msvc.bat @@ -321,7 +321,7 @@ FOR %%P IN (%PLATFORMS%) DO ( %_AECHO% Building the %%B configuration for platform %%P with name %%D... IF /I "%%B" == "Debug" ( - SET DEBUG=2 + SET DEBUG=3 SET MEMDEBUG=1 ) ELSE ( CALL :fn_UnsetVariable DEBUG From 774f42b6c62f938119248bc28a8426bcd3e7a416 Mon Sep 17 00:00:00 2001 From: mistachkin Date: Sat, 21 Mar 2015 22:23:46 +0000 Subject: [PATCH 007/181] Add more comments to the MSVC batch build tool. FossilOrigin-Name: 03522da37821958c647d49bf8189a5affa3f6720 --- manifest | 12 ++++++------ manifest.uuid | 2 +- tool/build-all-msvc.bat | 11 +++++++++++ 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/manifest b/manifest index 9bcf1897b9..9b298f9b65 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Increase\sthe\sdebugging\slevel\sfor\sthe\sdebug\sconfiguration\sin\sthe\sMSVC\sbatch\sbuild\stool. -D 2015-03-21T22:13:47.750 +C Add\smore\scomments\sto\sthe\sMSVC\sbatch\sbuild\stool. +D 2015-03-21T22:23:46.412 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -1194,7 +1194,7 @@ F test/without_rowid6.test db0dbf03c49030aa3c1ba5f618620334bd2baf5f F test/wordcount.c 9915e06cb33d8ca8109b8700791afe80d305afda F test/zeroblob.test caaecfb4f908f7bc086ed238668049f96774d688 F test/zerodamage.test cf6748bad89553cc1632be51a6f54e487e4039ac -F tool/build-all-msvc.bat 6e2c65d4c694ad3bdcbf8d813d18336c378ef642 x +F tool/build-all-msvc.bat 72e05bc8deca39a547884485c086b915f50a91ed x F tool/build-shell.sh 950f47c6174f1eea171319438b93ba67ff5bf367 F tool/checkSpacing.c 810e51703529a204fc4e1eb060e9ab663e3c06d2 F tool/diffdb.c 7524b1b5df217c20cd0431f6789851a4e0cb191b @@ -1246,7 +1246,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 de9da317d4df3efefe9a1a48f954af8a19e7d098 -R 2dc59230e8af71c6a1b496cc05325870 +P 041484ff91fd4615368ccb2257ab50acc2cd4fea +R b4cd923d8d74f09bebb5c4ffebc6ac77 U mistachkin -Z bebf96c7eb7dba0d54e717c5ef7df7e1 +Z 35bbc2e7e7719fcfdf895530fad162a8 diff --git a/manifest.uuid b/manifest.uuid index c20999f107..fa6b8b4a5b 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -041484ff91fd4615368ccb2257ab50acc2cd4fea \ No newline at end of file +03522da37821958c647d49bf8189a5affa3f6720 \ No newline at end of file diff --git a/tool/build-all-msvc.bat b/tool/build-all-msvc.bat index 1751fb4d12..728183629b 100755 --- a/tool/build-all-msvc.bat +++ b/tool/build-all-msvc.bat @@ -321,7 +321,18 @@ FOR %%P IN (%PLATFORMS%) DO ( %_AECHO% Building the %%B configuration for platform %%P with name %%D... IF /I "%%B" == "Debug" ( + REM + REM NOTE: Using this level for the DEBUG environment variable should + REM disable all compiler optimizations and prevent use of the + REM NDEBUG define. Additionally, both SQLITE_ENABLE_API_ARMOR + REM and SQLITE_DEBUG defines should be enabled. + REM SET DEBUG=3 + + REM + REM NOTE: Setting this to non-zero should enable the SQLITE_MEMDEBUG + REM define. + REM SET MEMDEBUG=1 ) ELSE ( CALL :fn_UnsetVariable DEBUG From d425864d3359806fa5096103bda390917a28ea0b Mon Sep 17 00:00:00 2001 From: mistachkin Date: Sat, 21 Mar 2015 23:38:59 +0000 Subject: [PATCH 008/181] Fix harmless compiler warnings with MSVC when assert() and SQLITE_MEMDEBUG are both enabled. FossilOrigin-Name: 9513dbd4860c8dd391f831982d09aff227d16f5c --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/malloc.c | 16 ++++++++-------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/manifest b/manifest index 9b298f9b65..3552ab570d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\smore\scomments\sto\sthe\sMSVC\sbatch\sbuild\stool. -D 2015-03-21T22:23:46.412 +C Fix\sharmless\scompiler\swarnings\swith\sMSVC\swhen\sassert()\sand\sSQLITE_MEMDEBUG\sare\sboth\senabled. +D 2015-03-21T23:38:59.970 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -196,7 +196,7 @@ F src/legacy.c ba1863ea58c4c840335a84ec276fc2b25e22bc4e F src/lempar.c 7274c97d24bb46631e504332ccd3bd1b37841770 F src/loadext.c 86bd4e2fccd520b748cba52492ab60c4a770f660 F src/main.c fa997fa27d95febc16d57095299384b667a7f762 -F src/malloc.c 740db54387204c9a2eb67c6d98e68b08e9ef4eab +F src/malloc.c 13f3f1cdc0c9990c79cefaf0ceba24da983ce8cd F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645 F src/mem1.c abe6ee469b6c5a35c7f22bfeb9c9bac664a1c987 F src/mem2.c f1940d9e91948dd6a908fbb9ce3835c36b5d83c3 @@ -1246,7 +1246,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 041484ff91fd4615368ccb2257ab50acc2cd4fea -R b4cd923d8d74f09bebb5c4ffebc6ac77 +P 03522da37821958c647d49bf8189a5affa3f6720 +R ec24cc7ca49e734053f58e4e5ed37882 U mistachkin -Z 35bbc2e7e7719fcfdf895530fad162a8 +Z e2c3eeafcd54988dc26d14970176c977 diff --git a/manifest.uuid b/manifest.uuid index fa6b8b4a5b..73b0fff7f2 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -03522da37821958c647d49bf8189a5affa3f6720 \ No newline at end of file +9513dbd4860c8dd391f831982d09aff227d16f5c \ No newline at end of file diff --git a/src/malloc.c b/src/malloc.c index 4960f91e02..8046fb2089 100644 --- a/src/malloc.c +++ b/src/malloc.c @@ -414,7 +414,7 @@ void sqlite3ScratchFree(void *p){ }else{ /* Release memory back to the heap */ assert( sqlite3MemdebugHasType(p, MEMTYPE_SCRATCH) ); - assert( sqlite3MemdebugNoType(p, ~MEMTYPE_SCRATCH) ); + assert( sqlite3MemdebugNoType(p, (u8)~MEMTYPE_SCRATCH) ); sqlite3MemdebugSetType(p, MEMTYPE_HEAP); if( sqlite3GlobalConfig.bMemstat ){ int iSize = sqlite3MallocSize(p); @@ -452,7 +452,7 @@ int sqlite3MallocSize(void *p){ } int sqlite3DbMallocSize(sqlite3 *db, void *p){ if( db==0 ){ - assert( sqlite3MemdebugNoType(p, ~MEMTYPE_HEAP) ); + assert( sqlite3MemdebugNoType(p, (u8)~MEMTYPE_HEAP) ); assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) ); return sqlite3MallocSize(p); }else{ @@ -461,13 +461,13 @@ int sqlite3DbMallocSize(sqlite3 *db, void *p){ return db->lookaside.sz; }else{ assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) ); - assert( sqlite3MemdebugNoType(p, ~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) ); + assert( sqlite3MemdebugNoType(p, (u8)~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) ); return sqlite3GlobalConfig.m.xSize(p); } } } sqlite3_uint64 sqlite3_msize(void *p){ - assert( sqlite3MemdebugNoType(p, ~MEMTYPE_HEAP) ); + assert( sqlite3MemdebugNoType(p, (u8)~MEMTYPE_HEAP) ); assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) ); return (sqlite3_uint64)sqlite3GlobalConfig.m.xSize(p); } @@ -478,7 +478,7 @@ sqlite3_uint64 sqlite3_msize(void *p){ void sqlite3_free(void *p){ if( p==0 ) return; /* IMP: R-49053-54554 */ assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) ); - assert( sqlite3MemdebugNoType(p, ~MEMTYPE_HEAP) ); + assert( sqlite3MemdebugNoType(p, (u8)~MEMTYPE_HEAP) ); if( sqlite3GlobalConfig.bMemstat ){ sqlite3_mutex_enter(mem0.mutex); sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, -sqlite3MallocSize(p)); @@ -523,7 +523,7 @@ void sqlite3DbFree(sqlite3 *db, void *p){ } } assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) ); - assert( sqlite3MemdebugNoType(p, ~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) ); + assert( sqlite3MemdebugNoType(p, (u8)~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) ); assert( db!=0 || sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) ); sqlite3MemdebugSetType(p, MEMTYPE_HEAP); sqlite3_free(p); @@ -536,7 +536,7 @@ void *sqlite3Realloc(void *pOld, u64 nBytes){ int nOld, nNew, nDiff; void *pNew; assert( sqlite3MemdebugHasType(pOld, MEMTYPE_HEAP) ); - assert( sqlite3MemdebugNoType(pOld, ~MEMTYPE_HEAP) ); + assert( sqlite3MemdebugNoType(pOld, (u8)~MEMTYPE_HEAP) ); if( pOld==0 ){ return sqlite3Malloc(nBytes); /* IMP: R-04300-56712 */ } @@ -703,7 +703,7 @@ void *sqlite3DbRealloc(sqlite3 *db, void *p, u64 n){ } }else{ assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) ); - assert( sqlite3MemdebugNoType(p, ~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) ); + assert( sqlite3MemdebugNoType(p, (u8)~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) ); sqlite3MemdebugSetType(p, MEMTYPE_HEAP); pNew = sqlite3_realloc64(p, n); if( !pNew ){ From 74893a4cdb556804dc4a31615be90fc8a69b3686 Mon Sep 17 00:00:00 2001 From: drh Date: Sun, 22 Mar 2015 10:23:17 +0000 Subject: [PATCH 009/181] Fix a potential NULL pointer dereference following a syntax error. FossilOrigin-Name: 8d27e3e16a9be79fe227e833f4770ebe09a9d90b --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/expr.c | 1 + test/misc1.test | 10 +++++++++- 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index 3552ab570d..012f08e737 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sharmless\scompiler\swarnings\swith\sMSVC\swhen\sassert()\sand\sSQLITE_MEMDEBUG\sare\sboth\senabled. -D 2015-03-21T23:38:59.970 +C Fix\sa\spotential\sNULL\spointer\sdereference\sfollowing\sa\ssyntax\serror. +D 2015-03-22T10:23:17.264 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -182,7 +182,7 @@ F src/complete.c 198a0066ba60ab06fc00fba1998d870a4d575463 F src/ctime.c 98f89724adc891a1a4c655bee04e33e716e05887 F src/date.c e4d50b3283696836ec1036b695ead9a19e37a5ac F src/delete.c 37964e6c1d73ff49cbea9ff690c9605fb15f600e -F src/expr.c eb4d795abca1e876726aecc7aeb95ceb29e73fe7 +F src/expr.c d09dac67d53c78880ba31d56e8ba2be3a6490553 F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb F src/fkey.c e0444b61bed271a76840cbe6182df93a9baa3f12 F src/func.c 1414c24c873c48796ad45942257a179a423ba42f @@ -741,7 +741,7 @@ F test/minmax.test 42fbad0e81afaa6e0de41c960329f2b2c3526efd F test/minmax2.test b44bae787fc7b227597b01b0ca5575c7cb54d3bc F test/minmax3.test cc1e8b010136db0d01a6f2a29ba5a9f321034354 F test/minmax4.test 936941484ebdceb8adec7c86b6cd9b6e5e897c1f -F test/misc1.test 4864f2834b203cad7f688df8a5f725e4bab08029 +F test/misc1.test f3f59b3941c84a10860c06c07e86ad367a74ec92 F test/misc2.test 00d7de54eda90e237fc9a38b9e5ccc769ebf6d4d F test/misc3.test cf3dda47d5dda3e53fc5804a100d3c82be736c9d F test/misc4.test 9c078510fbfff05a9869a0b6d8b86a623ad2c4f6 @@ -1246,7 +1246,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 03522da37821958c647d49bf8189a5affa3f6720 -R ec24cc7ca49e734053f58e4e5ed37882 -U mistachkin -Z e2c3eeafcd54988dc26d14970176c977 +P 9513dbd4860c8dd391f831982d09aff227d16f5c +R e779bfe0488c17857ae1dcf614dd348f +U drh +Z ca73f5b3867dd7a4dfc248e6290c5b53 diff --git a/manifest.uuid b/manifest.uuid index 73b0fff7f2..223b936105 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -9513dbd4860c8dd391f831982d09aff227d16f5c \ No newline at end of file +8d27e3e16a9be79fe227e833f4770ebe09a9d90b \ No newline at end of file diff --git a/src/expr.c b/src/expr.c index fe09b4b50b..e6ac0f6796 100644 --- a/src/expr.c +++ b/src/expr.c @@ -397,6 +397,7 @@ static void exprSetHeight(Expr *p){ ** Expr.flags. */ void sqlite3ExprSetHeightAndFlags(Parse *pParse, Expr *p){ + if( pParse->nErr ) return; exprSetHeight(p); sqlite3ExprCheckHeight(pParse, p->nHeight); } diff --git a/test/misc1.test b/test/misc1.test index d18223e67b..0f4881fb61 100644 --- a/test/misc1.test +++ b/test/misc1.test @@ -13,7 +13,6 @@ # This file implements tests for miscellanous features that were # left out of other test files. # -# $Id: misc1.test,v 1.42 2007/11/05 14:58:23 drh Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl @@ -631,4 +630,13 @@ do_execsql_test misc1-20.1 { SELECT rowid, quote(x) FROM t0; } {1 ''} +# 2015-03-22: NULL pointer dereference after a syntax error +# +do_catchsql_test misc1-21.1 { + select''like''like''like#0; +} {1 {near "#0": syntax error}} +do_catchsql_test misc1-21.2 { + VALUES(0,0x0MATCH#0; +} {1 {near ";": syntax error}} + finish_test From af89fe66eae40a520e370e634da59aefe688d06f Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 23 Mar 2015 17:25:18 +0000 Subject: [PATCH 010/181] Add the sqlite3_status64() interface. Make the new interface and the legacy sqlite3_status() both atomic and threadsafe. Check threadsafety using assert()s. FossilOrigin-Name: 1ce8e8fa4b866aafa12b1da0eb4d02321af9293e --- manifest | 25 +++++++------- manifest.uuid | 2 +- src/malloc.c | 33 +++++++++++-------- src/pcache1.c | 19 ++++++++--- src/sqlite.h.in | 23 +++++++------ src/sqliteInt.h | 9 ++++-- src/status.c | 86 +++++++++++++++++++++++++++++++++++++++++-------- src/tokenize.c | 2 ++ 8 files changed, 144 insertions(+), 55 deletions(-) diff --git a/manifest b/manifest index 012f08e737..362bf302a3 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\spotential\sNULL\spointer\sdereference\sfollowing\sa\ssyntax\serror. -D 2015-03-22T10:23:17.264 +C Add\sthe\ssqlite3_status64()\sinterface.\s\sMake\sthe\snew\sinterface\sand\sthe\slegacy\nsqlite3_status()\sboth\satomic\sand\sthreadsafe.\s\sCheck\sthreadsafety\susing\nassert()s. +D 2015-03-23T17:25:18.212 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -196,7 +196,7 @@ F src/legacy.c ba1863ea58c4c840335a84ec276fc2b25e22bc4e F src/lempar.c 7274c97d24bb46631e504332ccd3bd1b37841770 F src/loadext.c 86bd4e2fccd520b748cba52492ab60c4a770f660 F src/main.c fa997fa27d95febc16d57095299384b667a7f762 -F src/malloc.c 13f3f1cdc0c9990c79cefaf0ceba24da983ce8cd +F src/malloc.c e818a0db9ac0898f9dc74002f3a5baca32232d05 F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645 F src/mem1.c abe6ee469b6c5a35c7f22bfeb9c9bac664a1c987 F src/mem2.c f1940d9e91948dd6a908fbb9ce3835c36b5d83c3 @@ -222,7 +222,7 @@ F src/pager.h c3476e7c89cdf1c6914e50a11f3714e30b4e0a77 F src/parse.y 1299c66e7b1707322ccd8af43a359b8fb0d46d72 F src/pcache.c 10539fb959849ad6efff80050541cab3d25089d4 F src/pcache.h b44658c9c932d203510279439d891a2a83e12ba8 -F src/pcache1.c 1e77432b40b7d3288327d9cdf399dcdfd2b6d3bf +F src/pcache1.c 69d137620a305f814398bd29a0c998038c0695e9 F src/pragma.c ac4f3f856b4234e85f55b0f069698a4766011100 F src/pragma.h 09c89bca58e9a44de2116cc8272b8d454657129f F src/prepare.c 173a5a499138451b2561614ecb87d78f9f4644b9 @@ -232,12 +232,12 @@ F src/resolve.c f4d79e31ffa5820c2e3d1740baa5e9b190425f2b F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e F src/select.c 72ffb62e2879956302140e9f6e6ae88aee36b0e5 F src/shell.c 9c1589c8271c04c02d23cdbc2c07bb40752fa9eb -F src/sqlite.h.in c7c9111477b76c82c46bf851b619df4dd35cc095 +F src/sqlite.h.in df180ecc3215e4b87dbd536507869511bec88841 F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h 17d487c3c91b0b8c584a32fbeb393f6f795eea7d -F src/sqliteInt.h f2300529f3592323a98fd7acccec63d0e9082dc5 +F src/sqliteInt.h de9d20aa5757925a3cd26283d9e34a6ef49904fd F src/sqliteLimit.h 216557999cb45f2e3578ed53ebefe228d779cb46 -F src/status.c 81712116e826b0089bb221b018929536b2b5406f +F src/status.c 35d02aaf02600dfeade53d2adf2455186dfd741e F src/table.c e7a09215315a978057fb42c640f890160dbcc45e F src/tclsqlite.c fa72a7c5278662357c105ba7925c1d0972506ff9 F src/test1.c 90fbedce75330d48d99eadb7d5f4223e86969585 @@ -287,7 +287,7 @@ F src/test_vfs.c b7e6831e6fcf04c5090accff30640ec5c9630739 F src/test_vfstrace.c bab9594adc976cbe696ff3970728830b4c5ed698 F src/test_wsd.c 41cadfd9d97fe8e3e4e44f61a4a8ccd6f7ca8fe9 F src/threads.c 6bbcc9fe50c917864d48287b4792d46d6e873481 -F src/tokenize.c 05e52378c46efbc1fd63cbbbf7f3c555f840f4bf +F src/tokenize.c a8d270b06e5f709930f7b67cf70a847969cb5bf3 F src/trigger.c 25571661fdeae8c7f975ff40ffec205520a3f92f F src/update.c 3c4ecc282accf12d39edb8d524cf089645e55a13 F src/utf.c fc6b889ba0779b7722634cdeaa25f1930d93820c @@ -1246,7 +1246,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 9513dbd4860c8dd391f831982d09aff227d16f5c -R e779bfe0488c17857ae1dcf614dd348f +P 8d27e3e16a9be79fe227e833f4770ebe09a9d90b +R 2bfdb46ae6ff687a8efb07761e076d30 +T *branch * status64 +T *sym-status64 * +T -sym-trunk * U drh -Z ca73f5b3867dd7a4dfc248e6290c5b53 +Z 89310d97b168ea333a94dce0bcc0bc9f diff --git a/manifest.uuid b/manifest.uuid index 223b936105..e93a4dbdf2 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -8d27e3e16a9be79fe227e833f4770ebe09a9d90b \ No newline at end of file +1ce8e8fa4b866aafa12b1da0eb4d02321af9293e \ No newline at end of file diff --git a/src/malloc.c b/src/malloc.c index 8046fb2089..264d046ec8 100644 --- a/src/malloc.c +++ b/src/malloc.c @@ -75,6 +75,13 @@ static SQLITE_WSD struct Mem0Global { #define mem0 GLOBAL(struct Mem0Global, mem0) +/* +** Return the memory allocator mutex. sqlite3_status() needs it. +*/ +sqlite3_mutex *sqlite3MallocMutex(void){ + return mem0.mutex; +} + /* ** This routine runs when the memory allocator sees that the ** total memory allocation is about to exceed the soft heap @@ -97,7 +104,7 @@ static int sqlite3MemoryAlarm( void *pArg, sqlite3_int64 iThreshold ){ - int nUsed; + sqlite3_int64 nUsed; sqlite3_mutex_enter(mem0.mutex); mem0.alarmCallback = xCallback; mem0.alarmArg = pArg; @@ -266,7 +273,7 @@ static int mallocWithAlarm(int n, void **pp){ nFull = sqlite3GlobalConfig.m.xRoundup(n); sqlite3StatusSet(SQLITE_STATUS_MALLOC_SIZE, n); if( mem0.alarmCallback!=0 ){ - int nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED); + sqlite3_int64 nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED); if( nUsed >= mem0.alarmThreshold - nFull ){ mem0.nearlyFull = 1; sqlite3MallocAlarm(nFull); @@ -283,8 +290,8 @@ static int mallocWithAlarm(int n, void **pp){ #endif if( p ){ nFull = sqlite3MallocSize(p); - sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, nFull); - sqlite3StatusAdd(SQLITE_STATUS_MALLOC_COUNT, 1); + sqlite3StatusUp(SQLITE_STATUS_MEMORY_USED, nFull); + sqlite3StatusUp(SQLITE_STATUS_MALLOC_COUNT, 1); } *pp = p; return nFull; @@ -361,14 +368,14 @@ void *sqlite3ScratchMalloc(int n){ p = mem0.pScratchFree; mem0.pScratchFree = mem0.pScratchFree->pNext; mem0.nScratchFree--; - sqlite3StatusAdd(SQLITE_STATUS_SCRATCH_USED, 1); + sqlite3StatusUp(SQLITE_STATUS_SCRATCH_USED, 1); sqlite3_mutex_leave(mem0.mutex); }else{ sqlite3_mutex_leave(mem0.mutex); p = sqlite3Malloc(n); if( sqlite3GlobalConfig.bMemstat && p ){ sqlite3_mutex_enter(mem0.mutex); - sqlite3StatusAdd(SQLITE_STATUS_SCRATCH_OVERFLOW, sqlite3MallocSize(p)); + sqlite3StatusUp(SQLITE_STATUS_SCRATCH_OVERFLOW, sqlite3MallocSize(p)); sqlite3_mutex_leave(mem0.mutex); } sqlite3MemdebugSetType(p, MEMTYPE_SCRATCH); @@ -409,7 +416,7 @@ void sqlite3ScratchFree(void *p){ mem0.pScratchFree = pSlot; mem0.nScratchFree++; assert( mem0.nScratchFree <= (u32)sqlite3GlobalConfig.nScratch ); - sqlite3StatusAdd(SQLITE_STATUS_SCRATCH_USED, -1); + sqlite3StatusDown(SQLITE_STATUS_SCRATCH_USED, 1); sqlite3_mutex_leave(mem0.mutex); }else{ /* Release memory back to the heap */ @@ -419,9 +426,9 @@ void sqlite3ScratchFree(void *p){ if( sqlite3GlobalConfig.bMemstat ){ int iSize = sqlite3MallocSize(p); sqlite3_mutex_enter(mem0.mutex); - sqlite3StatusAdd(SQLITE_STATUS_SCRATCH_OVERFLOW, -iSize); - sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, -iSize); - sqlite3StatusAdd(SQLITE_STATUS_MALLOC_COUNT, -1); + sqlite3StatusDown(SQLITE_STATUS_SCRATCH_OVERFLOW, iSize); + sqlite3StatusDown(SQLITE_STATUS_MEMORY_USED, iSize); + sqlite3StatusDown(SQLITE_STATUS_MALLOC_COUNT, 1); sqlite3GlobalConfig.m.xFree(p); sqlite3_mutex_leave(mem0.mutex); }else{ @@ -481,8 +488,8 @@ void sqlite3_free(void *p){ assert( sqlite3MemdebugNoType(p, (u8)~MEMTYPE_HEAP) ); if( sqlite3GlobalConfig.bMemstat ){ sqlite3_mutex_enter(mem0.mutex); - sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, -sqlite3MallocSize(p)); - sqlite3StatusAdd(SQLITE_STATUS_MALLOC_COUNT, -1); + sqlite3StatusDown(SQLITE_STATUS_MEMORY_USED, sqlite3MallocSize(p)); + sqlite3StatusDown(SQLITE_STATUS_MALLOC_COUNT, 1); sqlite3GlobalConfig.m.xFree(p); sqlite3_mutex_leave(mem0.mutex); }else{ @@ -570,7 +577,7 @@ void *sqlite3Realloc(void *pOld, u64 nBytes){ } if( pNew ){ nNew = sqlite3MallocSize(pNew); - sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, nNew-nOld); + sqlite3StatusUp(SQLITE_STATUS_MEMORY_USED, nNew-nOld); } sqlite3_mutex_leave(mem0.mutex); }else{ diff --git a/src/pcache1.c b/src/pcache1.c index f5f7893714..a8755a3141 100644 --- a/src/pcache1.c +++ b/src/pcache1.c @@ -195,7 +195,6 @@ void sqlite3PCacheBufferSetup(void *pBuf, int sz, int n){ static void *pcache1Alloc(int nByte){ void *p = 0; assert( sqlite3_mutex_notheld(pcache1.grp.mutex) ); - sqlite3StatusSet(SQLITE_STATUS_PAGECACHE_SIZE, nByte); if( nByte<=pcache1.szSlot ){ sqlite3_mutex_enter(pcache1.mutex); p = (PgHdr1 *)pcache1.pFree; @@ -204,7 +203,8 @@ static void *pcache1Alloc(int nByte){ pcache1.nFreeSlot--; pcache1.bUnderPressure = pcache1.nFreeSlot=0 ); - sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_USED, 1); + sqlite3StatusSet(SQLITE_STATUS_PAGECACHE_SIZE, nByte); + sqlite3StatusUp(SQLITE_STATUS_PAGECACHE_USED, 1); } sqlite3_mutex_leave(pcache1.mutex); } @@ -217,7 +217,8 @@ static void *pcache1Alloc(int nByte){ if( p ){ int sz = sqlite3MallocSize(p); sqlite3_mutex_enter(pcache1.mutex); - sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_OVERFLOW, sz); + sqlite3StatusSet(SQLITE_STATUS_PAGECACHE_SIZE, nByte); + sqlite3StatusUp(SQLITE_STATUS_PAGECACHE_OVERFLOW, sz); sqlite3_mutex_leave(pcache1.mutex); } #endif @@ -235,7 +236,7 @@ static int pcache1Free(void *p){ if( p>=pcache1.pStart && ppNext = pcache1.pFree; pcache1.pFree = pSlot; @@ -249,7 +250,7 @@ static int pcache1Free(void *p){ nFreed = sqlite3MallocSize(p); #ifndef SQLITE_DISABLE_PAGECACHE_OVERFLOW_STATS sqlite3_mutex_enter(pcache1.mutex); - sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_OVERFLOW, -nFreed); + sqlite3StatusDown(SQLITE_STATUS_PAGECACHE_OVERFLOW, nFreed); sqlite3_mutex_leave(pcache1.mutex); #endif sqlite3_free(p); @@ -986,6 +987,14 @@ void sqlite3PCacheSetDefault(void){ */ int sqlite3HeaderSizePcache1(void){ return ROUND8(sizeof(PgHdr1)); } +/* +** Return the global mutex used by this PCACHE implementation. The +** sqlite3_status() routine needs access to this mutex. +*/ +sqlite3_mutex *sqlite3Pcache1Mutex(void){ + return pcache1.mutex; +} + #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT /* ** This function is called to free superfluous dynamically allocated memory diff --git a/src/sqlite.h.in b/src/sqlite.h.in index 9e48620c66..8419392cfa 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -1550,7 +1550,7 @@ struct sqlite3_mem_methods { **
  • [sqlite3_memory_used()] **
  • [sqlite3_memory_highwater()] **
  • [sqlite3_soft_heap_limit64()] -**
  • [sqlite3_status()] +**
  • [sqlite3_status64()] ** )^ ** ^Memory allocation statistics are enabled by default unless SQLite is ** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory @@ -6305,7 +6305,7 @@ int sqlite3_test_control(int op, ...); /* ** CAPI3REF: SQLite Runtime Status ** -** ^This interface is used to retrieve runtime status information +** ^These interfaces are used to retrieve runtime status information ** about the performance of SQLite, and optionally to reset various ** highwater marks. ^The first argument is an integer code for ** the specific parameter to measure. ^(Recognized integer codes @@ -6319,19 +6319,22 @@ int sqlite3_test_control(int op, ...); ** ^(Other parameters record only the highwater mark and not the current ** value. For these latter parameters nothing is written into *pCurrent.)^ ** -** ^The sqlite3_status() routine returns SQLITE_OK on success and a -** non-zero [error code] on failure. +** ^The sqlite3_status() and sqlite3_status64() routines return +** SQLITE_OK on success and a non-zero [error code] on failure. ** -** This routine is threadsafe but is not atomic. This routine can be -** called while other threads are running the same or different SQLite -** interfaces. However the values returned in *pCurrent and -** *pHighwater reflect the status of SQLite at different points in time -** and it is possible that another thread might change the parameter -** in between the times when *pCurrent and *pHighwater are written. +** If either the current value or the highwater mark is too large to +** be represented by a 32-bit integer, then the values returned by +** sqlite3_status() are undefined. ** ** See also: [sqlite3_db_status()] */ int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag); +int sqlite3_status64( + int op, + sqlite3_int64 *pCurrent, + sqlite3_int64 *pHighwater, + int resetFlag +); /* diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 9e174d6f4c..78945c1dde 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -3097,10 +3097,15 @@ const sqlite3_mem_methods *sqlite3MemGetMemsys5(void); int sqlite3MutexEnd(void); #endif -int sqlite3StatusValue(int); -void sqlite3StatusAdd(int, int); +sqlite3_int64 sqlite3StatusValue(int); +void sqlite3StatusUp(int, int); +void sqlite3StatusDown(int, int); void sqlite3StatusSet(int, int); +/* Access to mutexes used by sqlite3_status() */ +sqlite3_mutex *sqlite3Pcache1Mutex(void); +sqlite3_mutex *sqlite3MallocMutex(void); + #ifndef SQLITE_OMIT_FLOATING_POINT int sqlite3IsNaN(double); #else diff --git a/src/status.c b/src/status.c index 4c2eabb661..0f6328318a 100644 --- a/src/status.c +++ b/src/status.c @@ -21,10 +21,27 @@ */ typedef struct sqlite3StatType sqlite3StatType; static SQLITE_WSD struct sqlite3StatType { - int nowValue[10]; /* Current value */ - int mxValue[10]; /* Maximum value */ + sqlite3_int64 nowValue[10]; /* Current value */ + sqlite3_int64 mxValue[10]; /* Maximum value */ } sqlite3Stat = { {0,}, {0,} }; +/* +** Elements of sqlite3Stat[] are protected by either the memory allocator +** mutex, or by the pcache1 mutex. The following array determines which. +*/ +static const char statMutex[] = { + 0, /* SQLITE_STATUS_MEMORY_USED */ + 1, /* SQLITE_STATUS_PAGECACHE_USED */ + 1, /* SQLITE_STATUS_PAGECACHE_OVERFLOW */ + 0, /* SQLITE_STATUS_SCRATCH_USED */ + 0, /* SQLITE_STATUS_SCRATCH_OVERFLOW */ + 0, /* SQLITE_STATUS_MALLOC_SIZE */ + 0, /* SQLITE_STATUS_PARSER_STACK */ + 1, /* SQLITE_STATUS_PAGECACHE_SIZE */ + 0, /* SQLITE_STATUS_SCRATCH_SIZE */ + 0, /* SQLITE_STATUS_MALLOC_COUNT */ +}; + /* The "wsdStat" macro will resolve to the status information ** state vector. If writable static data is unsupported on the target, @@ -41,33 +58,60 @@ static SQLITE_WSD struct sqlite3StatType { #endif /* -** Return the current value of a status parameter. +** Return the current value of a status parameter. The caller must +** be holding the appropriate mutex. */ -int sqlite3StatusValue(int op){ +sqlite3_int64 sqlite3StatusValue(int op){ wsdStatInit; assert( op>=0 && op=0 && op=0 && op=0 && opwsdStat.mxValue[op] ){ wsdStat.mxValue[op] = wsdStat.nowValue[op]; } } +void sqlite3StatusDown(int op, int N){ + wsdStatInit; + assert( N>=0 ); + assert( op>=0 && op=0 && op=0 && op=0 && opwsdStat.mxValue[op] ){ wsdStat.mxValue[op] = wsdStat.nowValue[op]; @@ -76,26 +120,42 @@ void sqlite3StatusSet(int op, int X){ /* ** Query status information. -** -** This implementation assumes that reading or writing an aligned -** 32-bit integer is an atomic operation. If that assumption is not true, -** then this routine is not threadsafe. */ -int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag){ +int sqlite3_status64( + int op, + sqlite3_int64 *pCurrent, + sqlite3_int64 *pHighwater, + int resetFlag +){ wsdStatInit; + sqlite3_mutex *pMutex; if( op<0 || op>=ArraySize(wsdStat.nowValue) ){ return SQLITE_MISUSE_BKPT; } #ifdef SQLITE_ENABLE_API_ARMOR if( pCurrent==0 || pHighwater==0 ) return SQLITE_MISUSE_BKPT; #endif + pMutex = statMutex[op] ? sqlite3Pcache1Mutex() : sqlite3MallocMutex(); + sqlite3_mutex_enter(pMutex); *pCurrent = wsdStat.nowValue[op]; *pHighwater = wsdStat.mxValue[op]; if( resetFlag ){ wsdStat.mxValue[op] = wsdStat.nowValue[op]; } + sqlite3_mutex_leave(pMutex); return SQLITE_OK; } +int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag){ + sqlite3_int64 iCur, iHwtr; + int rc; +#ifdef SQLITE_ENABLE_API_ARMOR + if( pCurrent==0 || pHighwater==0 ) return SQLITE_MISUSE_BKPT; +#endif + rc = sqlite3_status64(op, &iCur, &iHwtr, resetFlag); + *pCurrent = (int)iCur; + *pHighwater = (int)iHwtr; + return rc; +} /* ** Query status information for a single database connection diff --git a/src/tokenize.c b/src/tokenize.c index 6fb5a35c3d..5068742f31 100644 --- a/src/tokenize.c +++ b/src/tokenize.c @@ -459,9 +459,11 @@ abort_parse: sqlite3Parser(pEngine, 0, pParse->sLastToken, pParse); } #ifdef YYTRACKMAXSTACKDEPTH + sqlite3_mutex_enter(sqlite3MallocMutex()); sqlite3StatusSet(SQLITE_STATUS_PARSER_STACK, sqlite3ParserStackPeak(pEngine) ); + sqlite3_mutex_leave(sqlite3MallocMutex()); #endif /* YYDEBUG */ sqlite3ParserFree(pEngine, sqlite3_free); db->lookaside.bEnabled = enableLookaside; From 2b4905c81fc1ee72c85f8bab318cc72735a34419 Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 23 Mar 2015 18:52:56 +0000 Subject: [PATCH 011/181] Add the SQLITE_PTRSIZE macro. Use it to help sqlite3_status() run faster on 32-bit systems. FossilOrigin-Name: c742bd6047bc6d0319a5a8c31d97f6b9229507f6 --- manifest | 19 ++++++++----------- manifest.uuid | 2 +- src/main.c | 5 +++++ src/sqliteInt.h | 14 ++++++++++++++ src/status.c | 11 +++++++++-- 5 files changed, 37 insertions(+), 14 deletions(-) diff --git a/manifest b/manifest index 362bf302a3..014d5df5b4 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sthe\ssqlite3_status64()\sinterface.\s\sMake\sthe\snew\sinterface\sand\sthe\slegacy\nsqlite3_status()\sboth\satomic\sand\sthreadsafe.\s\sCheck\sthreadsafety\susing\nassert()s. -D 2015-03-23T17:25:18.212 +C Add\sthe\sSQLITE_PTRSIZE\smacro.\s\sUse\sit\sto\shelp\ssqlite3_status()\srun\sfaster\non\s32-bit\ssystems. +D 2015-03-23T18:52:56.780 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -195,7 +195,7 @@ F src/journal.c b4124532212b6952f42eb2c12fa3c25701d8ba8d F src/legacy.c ba1863ea58c4c840335a84ec276fc2b25e22bc4e F src/lempar.c 7274c97d24bb46631e504332ccd3bd1b37841770 F src/loadext.c 86bd4e2fccd520b748cba52492ab60c4a770f660 -F src/main.c fa997fa27d95febc16d57095299384b667a7f762 +F src/main.c 569d45ba9eb4fbdd631d53f440bcdb4a35ab1505 F src/malloc.c e818a0db9ac0898f9dc74002f3a5baca32232d05 F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645 F src/mem1.c abe6ee469b6c5a35c7f22bfeb9c9bac664a1c987 @@ -235,9 +235,9 @@ F src/shell.c 9c1589c8271c04c02d23cdbc2c07bb40752fa9eb F src/sqlite.h.in df180ecc3215e4b87dbd536507869511bec88841 F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h 17d487c3c91b0b8c584a32fbeb393f6f795eea7d -F src/sqliteInt.h de9d20aa5757925a3cd26283d9e34a6ef49904fd +F src/sqliteInt.h e22a2bfbeed55ed3addff5e0ef34366e93ad0874 F src/sqliteLimit.h 216557999cb45f2e3578ed53ebefe228d779cb46 -F src/status.c 35d02aaf02600dfeade53d2adf2455186dfd741e +F src/status.c 8ccd03e35ac98e44b3df51cbc94a81119c6ab0dd F src/table.c e7a09215315a978057fb42c640f890160dbcc45e F src/tclsqlite.c fa72a7c5278662357c105ba7925c1d0972506ff9 F src/test1.c 90fbedce75330d48d99eadb7d5f4223e86969585 @@ -1246,10 +1246,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 8d27e3e16a9be79fe227e833f4770ebe09a9d90b -R 2bfdb46ae6ff687a8efb07761e076d30 -T *branch * status64 -T *sym-status64 * -T -sym-trunk * +P 1ce8e8fa4b866aafa12b1da0eb4d02321af9293e +R 0b9a82d5d161d745ba0c858230f2a6bc U drh -Z 89310d97b168ea333a94dce0bcc0bc9f +Z e9a2419ecec514dae3eef3cef6e74ea6 diff --git a/manifest.uuid b/manifest.uuid index e93a4dbdf2..db394d0c85 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -1ce8e8fa4b866aafa12b1da0eb4d02321af9293e \ No newline at end of file +c742bd6047bc6d0319a5a8c31d97f6b9229507f6 \ No newline at end of file diff --git a/src/main.c b/src/main.c index 092cbf8415..6967131143 100644 --- a/src/main.c +++ b/src/main.c @@ -128,6 +128,11 @@ int sqlite3_initialize(void){ } #endif + /* If the following assert() fails on some obscure processor/compiler + ** combination, the work-around is to set the correct pointer + ** size at compile-time using -DSQLITE_PTRSIZE=n compile-time option */ + assert( SQLITE_PTRSIZE==sizeof(char*) ); + /* If SQLite is already completely initialized, then this call ** to sqlite3_initialize() should be a no-op. But the initialization ** must be complete. So isInit must not be set until the very end diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 78945c1dde..2b1d7ebc6e 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -594,6 +594,20 @@ typedef INT8_TYPE i8; /* 1-byte signed integer */ */ typedef INT16_TYPE LogEst; +/* +** Set the SQLITE_PTRSIZE macro to the number of bytes in a pointer +*/ +#ifndef SQLITE_PTRSIZE +# if defined(__SIZEOF_POINTER__) +# define SQLITE_PTRSIZE __SIZEOF_POINTER__ +# elif defined(i386) || defined(__i386__) || defined(_M_IX86) || \ + defined(_M_ARM) || defined(__arm__) || defined(__x86) +# define SQLITE_PTRSIZE 4 +# else +# define SQLITE_PTRSIZE 8 +# endif +#endif + /* ** Macros to determine whether the machine is big or little endian, ** and whether or not that determination is run-time or compile-time. diff --git a/src/status.c b/src/status.c index 0f6328318a..739249ec22 100644 --- a/src/status.c +++ b/src/status.c @@ -21,8 +21,13 @@ */ typedef struct sqlite3StatType sqlite3StatType; static SQLITE_WSD struct sqlite3StatType { +#if SQLITE_PTRSIZE>4 sqlite3_int64 nowValue[10]; /* Current value */ sqlite3_int64 mxValue[10]; /* Maximum value */ +#else + u32 nowValue[10]; /* Current value */ + u32 mxValue[10]; /* Maximum value */ +#endif } sqlite3Stat = { {0,}, {0,} }; /* @@ -152,8 +157,10 @@ int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag){ if( pCurrent==0 || pHighwater==0 ) return SQLITE_MISUSE_BKPT; #endif rc = sqlite3_status64(op, &iCur, &iHwtr, resetFlag); - *pCurrent = (int)iCur; - *pHighwater = (int)iHwtr; + if( rc==0 ){ + *pCurrent = (int)iCur; + *pHighwater = (int)iHwtr; + } return rc; } From 062cf27d0014afc0ec0b00dee2a821111a0ef121 Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 23 Mar 2015 19:03:51 +0000 Subject: [PATCH 012/181] Fix datetype size asserts in btree.c. FossilOrigin-Name: ff4812d0e8e6322ca8b6992925fd4ef4aee463e6 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/btree.c | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 012f08e737..8ca7814754 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\spotential\sNULL\spointer\sdereference\sfollowing\sa\ssyntax\serror. -D 2015-03-22T10:23:17.264 +C Fix\sdatetype\ssize\sasserts\sin\sbtree.c. +D 2015-03-23T19:03:51.368 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -173,7 +173,7 @@ F src/auth.c b56c78ebe40a2110fd361379f7e8162d23f92240 F src/backup.c ff743689c4d6c5cb55ad42ed9d174b2b3e71f1e3 F src/bitvec.c 19a4ba637bd85f8f63fc8c9bae5ade9fb05ec1cb F src/btmutex.c 45a968cc85afed9b5e6cf55bf1f42f8d18107f79 -F src/btree.c d4d52fb14e863cff9dbc7c746e9048ec0967a555 +F src/btree.c 3e320cac836546c905bd90007074d887980aa70e F src/btree.h 969adc948e89e449220ff0ff724c94bb2a52e9f1 F src/btreeInt.h 2bfefc01875d8da066504c233ec259fcb3b2ef72 F src/build.c 0419bba592c22f6d00e6d57a2ca7136720d02c1a @@ -1246,7 +1246,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 9513dbd4860c8dd391f831982d09aff227d16f5c -R e779bfe0488c17857ae1dcf614dd348f +P 8d27e3e16a9be79fe227e833f4770ebe09a9d90b +R b5413ce9e25a08fe53ff3be92a646869 U drh -Z ca73f5b3867dd7a4dfc248e6290c5b53 +Z 5fbc203b6eb85f868f3432b74d400822 diff --git a/manifest.uuid b/manifest.uuid index 223b936105..16d4f53715 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -8d27e3e16a9be79fe227e833f4770ebe09a9d90b \ No newline at end of file +ff4812d0e8e6322ca8b6992925fd4ef4aee463e6 \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index 1d82a2b625..ac0c877317 100644 --- a/src/btree.c +++ b/src/btree.c @@ -2017,8 +2017,8 @@ int sqlite3BtreeOpen( ** the right size. This is to guard against size changes that result ** when compiling on a different architecture. */ - assert( sizeof(i64)==8 || sizeof(i64)==4 ); - assert( sizeof(u64)==8 || sizeof(u64)==4 ); + assert( sizeof(i64)==8 ); + assert( sizeof(u64)==8 ); assert( sizeof(u32)==4 ); assert( sizeof(u16)==2 ); assert( sizeof(Pgno)==4 ); From 2493870d9c15769e5dbeaacd30809728e4571bbf Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 23 Mar 2015 19:16:30 +0000 Subject: [PATCH 013/181] Fix a non-C89 variable declaration that causes problems for MSVC. FossilOrigin-Name: 3de085eab2fbe491f2242b340851e8af8f61ad13 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/status.c | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 014d5df5b4..4799c31f3a 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sthe\sSQLITE_PTRSIZE\smacro.\s\sUse\sit\sto\shelp\ssqlite3_status()\srun\sfaster\non\s32-bit\ssystems. -D 2015-03-23T18:52:56.780 +C Fix\sa\snon-C89\svariable\sdeclaration\sthat\scauses\sproblems\sfor\sMSVC. +D 2015-03-23T19:16:30.885 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -237,7 +237,7 @@ F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h 17d487c3c91b0b8c584a32fbeb393f6f795eea7d F src/sqliteInt.h e22a2bfbeed55ed3addff5e0ef34366e93ad0874 F src/sqliteLimit.h 216557999cb45f2e3578ed53ebefe228d779cb46 -F src/status.c 8ccd03e35ac98e44b3df51cbc94a81119c6ab0dd +F src/status.c 2e5c86866ff2f30988ce10ddbaa7ba2eaf6d4146 F src/table.c e7a09215315a978057fb42c640f890160dbcc45e F src/tclsqlite.c fa72a7c5278662357c105ba7925c1d0972506ff9 F src/test1.c 90fbedce75330d48d99eadb7d5f4223e86969585 @@ -1246,7 +1246,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 1ce8e8fa4b866aafa12b1da0eb4d02321af9293e -R 0b9a82d5d161d745ba0c858230f2a6bc +P c742bd6047bc6d0319a5a8c31d97f6b9229507f6 +R 7eaa072c7f96e653ea839c906764b0b8 U drh -Z e9a2419ecec514dae3eef3cef6e74ea6 +Z 211fd8daf94b9f843731a45e101ebe58 diff --git a/manifest.uuid b/manifest.uuid index db394d0c85..c73dc87d68 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c742bd6047bc6d0319a5a8c31d97f6b9229507f6 \ No newline at end of file +3de085eab2fbe491f2242b340851e8af8f61ad13 \ No newline at end of file diff --git a/src/status.c b/src/status.c index 739249ec22..aa27f70efc 100644 --- a/src/status.c +++ b/src/status.c @@ -132,8 +132,8 @@ int sqlite3_status64( sqlite3_int64 *pHighwater, int resetFlag ){ - wsdStatInit; sqlite3_mutex *pMutex; + wsdStatInit; if( op<0 || op>=ArraySize(wsdStat.nowValue) ){ return SQLITE_MISUSE_BKPT; } From ada3f2b14f1f9e9625f8e8f0e6b5a367bc0c9773 Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 23 Mar 2015 21:32:50 +0000 Subject: [PATCH 014/181] Disable loadable extensions in the command-line shell on VxWorks user-space. FossilOrigin-Name: 0ee2d38deb35aefc55395e86984a9a773caf6218 --- manifest | 13 ++++++------- manifest.uuid | 2 +- src/shell.c | 2 +- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 53a9cfe78a..9bc4020219 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Track\stotal\smemory\susage\susing\sa\s64-bit\sinteger\son\s64-bit\ssystems.\s\sAdd\nthe\ssqlite3_status64()\sinterface.\s\sMake\sthe\ssqlite3_status()\sand\nsqlite3_status64()\sinterfaces\satomic\susing\smutexes\sand\sverify\scorrect\nmutex\soperation\susing\sassert()\sstatements. -D 2015-03-23T19:55:21.641 +C Disable\sloadable\sextensions\sin\sthe\scommand-line\sshell\son\sVxWorks\suser-space. +D 2015-03-23T21:32:50.879 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -231,7 +231,7 @@ F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c f4d79e31ffa5820c2e3d1740baa5e9b190425f2b F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e F src/select.c 72ffb62e2879956302140e9f6e6ae88aee36b0e5 -F src/shell.c 9c1589c8271c04c02d23cdbc2c07bb40752fa9eb +F src/shell.c 3ae1e53878d2804fe77b8c8f1f6ca287a0e5d80e F src/sqlite.h.in df180ecc3215e4b87dbd536507869511bec88841 F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h 17d487c3c91b0b8c584a32fbeb393f6f795eea7d @@ -1246,8 +1246,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 ff4812d0e8e6322ca8b6992925fd4ef4aee463e6 3de085eab2fbe491f2242b340851e8af8f61ad13 -R fa228592c968c6dd60a3ff76053c22f4 -T +closed 3de085eab2fbe491f2242b340851e8af8f61ad13 +P 6fc4e79a2350295a15ac464593ad39d904953041 +R f88d42f63f5075e0fafdf77b9c8623bb U drh -Z 5ddc58556d6343081a340eb577f95e29 +Z b5778fea5ecdfe311fd40aa2979f5026 diff --git a/manifest.uuid b/manifest.uuid index dc77af1006..4f62d697cb 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -6fc4e79a2350295a15ac464593ad39d904953041 \ No newline at end of file +0ee2d38deb35aefc55395e86984a9a773caf6218 \ No newline at end of file diff --git a/src/shell.c b/src/shell.c index d5a8a3fe95..b31ea16333 100644 --- a/src/shell.c +++ b/src/shell.c @@ -27,7 +27,7 @@ /* ** No support for loadable extensions in VxWorks. */ -#if defined(_WRS_KERNEL) && !SQLITE_OMIT_LOAD_EXTENSION +#if (defined(__RTP__) || defined(_WRS_KERNEL)) && !SQLITE_OMIT_LOAD_EXTENSION # define SQLITE_OMIT_LOAD_EXTENSION 1 #endif From 086723a4a8a5490b46603554445a6e6d0e1c03e8 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 24 Mar 2015 12:51:52 +0000 Subject: [PATCH 015/181] Replace the Vdbe.inVtabMethod field with the sqlite3.nVDestroy counter. FossilOrigin-Name: 9faefb96272967e731e83ef516a8c1e1b876391b --- manifest | 21 ++++++++++++--------- manifest.uuid | 2 +- src/sqliteInt.h | 1 + src/vdbe.c | 25 +++---------------------- src/vdbeInt.h | 9 --------- src/vdbeaux.c | 2 -- 6 files changed, 17 insertions(+), 43 deletions(-) diff --git a/manifest b/manifest index 9bc4020219..5c9a4c0330 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Disable\sloadable\sextensions\sin\sthe\scommand-line\sshell\son\sVxWorks\suser-space. -D 2015-03-23T21:32:50.879 +C Replace\sthe\sVdbe.inVtabMethod\sfield\swith\sthe\ssqlite3.nVDestroy\scounter. +D 2015-03-24T12:51:52.656 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -235,7 +235,7 @@ F src/shell.c 3ae1e53878d2804fe77b8c8f1f6ca287a0e5d80e F src/sqlite.h.in df180ecc3215e4b87dbd536507869511bec88841 F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h 17d487c3c91b0b8c584a32fbeb393f6f795eea7d -F src/sqliteInt.h e22a2bfbeed55ed3addff5e0ef34366e93ad0874 +F src/sqliteInt.h bedf15914c09bfb5fe3ec4e3f211a4a6fc42cd33 F src/sqliteLimit.h 216557999cb45f2e3578ed53ebefe228d779cb46 F src/status.c 2e5c86866ff2f30988ce10ddbaa7ba2eaf6d4146 F src/table.c e7a09215315a978057fb42c640f890160dbcc45e @@ -293,11 +293,11 @@ F src/update.c 3c4ecc282accf12d39edb8d524cf089645e55a13 F src/utf.c fc6b889ba0779b7722634cdeaa25f1930d93820c F src/util.c 98a7627ca48ad3265b6940915a1d08355eb3fc7e F src/vacuum.c 9460b9de7b2d4e34b0d374894aa6c8a0632be8ec -F src/vdbe.c bd793ed436edccaf264ec969ac92c9b5f4b41d64 +F src/vdbe.c 884faa91c44023891d0992311fd0feed0df060fc F src/vdbe.h 6fc69d9c5e146302c56e163cb4b31d1ee64a18c3 -F src/vdbeInt.h bb56fd199d8af1a2c1b9639ee2f70724b4338e3a +F src/vdbeInt.h 9cbaa84f53ddd2d09a0cf61a94337a3a035d08a0 F src/vdbeapi.c 583d56b129dd27f12bed518270de9ebe521e6a75 -F src/vdbeaux.c 23390670e64f011f3fed8f38a2f25aaccacb74d2 +F src/vdbeaux.c d62823d72b8f69a3e64deb03c30e959af285e488 F src/vdbeblob.c 4f2e8e075d238392df98c5e03a64342465b03f90 F src/vdbemem.c c0dc81285b7571b0a31c40f17846fe2397ec1cd9 F src/vdbesort.c 919717d7599fa31d343ec28bffd0f9e91a4ff5f6 @@ -1246,7 +1246,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 6fc4e79a2350295a15ac464593ad39d904953041 -R f88d42f63f5075e0fafdf77b9c8623bb +P 0ee2d38deb35aefc55395e86984a9a773caf6218 +R 8a156978483ce9f9262ab29d0045e64e +T *branch * nVDestroy +T *sym-nVDestroy * +T -sym-trunk * U drh -Z b5778fea5ecdfe311fd40aa2979f5026 +Z 795f6417c17436a4fbd09f9a73f096f4 diff --git a/manifest.uuid b/manifest.uuid index 4f62d697cb..9e51355abe 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -0ee2d38deb35aefc55395e86984a9a773caf6218 \ No newline at end of file +9faefb96272967e731e83ef516a8c1e1b876391b \ No newline at end of file diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 2b1d7ebc6e..9df6d1bc4e 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -1112,6 +1112,7 @@ struct sqlite3 { int nVdbeRead; /* Number of active VDBEs that read or write */ int nVdbeWrite; /* Number of active VDBEs that read and write */ int nVdbeExec; /* Number of nested calls to VdbeExec() */ + int nVDestroy; /* Number of active OP_VDestroy operations */ int nExtension; /* Number of loaded extensions */ void **aExtension; /* Array of shared library handles */ void (*xTrace)(void*,const char*); /* Trace function */ diff --git a/src/vdbe.c b/src/vdbe.c index 7d6d2b4f5d..bba6a90bf4 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -4946,30 +4946,15 @@ case OP_IdxGE: { /* jump */ */ case OP_Destroy: { /* out2-prerelease */ int iMoved; - int iCnt; - Vdbe *pVdbe; int iDb; assert( p->readOnly==0 ); -#ifndef SQLITE_OMIT_VIRTUALTABLE - iCnt = 0; - for(pVdbe=db->pVdbe; pVdbe; pVdbe = pVdbe->pNext){ - if( pVdbe->magic==VDBE_MAGIC_RUN && pVdbe->bIsReader - && pVdbe->inVtabMethod<2 && pVdbe->pc>=0 - ){ - iCnt++; - } - } -#else - iCnt = db->nVdbeRead; -#endif pOut->flags = MEM_Null; - if( iCnt>1 ){ + if( db->nVdbeRead > db->nVDestroy+1 ){ rc = SQLITE_LOCKED; p->errorAction = OE_Abort; }else{ iDb = pOp->p3; - assert( iCnt==1 ); assert( DbMaskTest(p->btreeMask, iDb) ); iMoved = 0; /* Not needed. Only to silence a warning. */ rc = sqlite3BtreeDropTable(db->aDb[iDb].pBt, pOp->p1, &iMoved); @@ -6060,9 +6045,9 @@ case OP_VCreate: { ** of that table. */ case OP_VDestroy: { - p->inVtabMethod = 2; + db->nVDestroy++; rc = sqlite3VtabCallDestroy(db, pOp->p1, pOp->p4.z); - p->inVtabMethod = 0; + db->nVDestroy--; break; } #endif /* SQLITE_OMIT_VIRTUALTABLE */ @@ -6161,9 +6146,7 @@ case OP_VFilter: { /* jump */ apArg[i] = &pArgc[i+1]; } - p->inVtabMethod = 1; rc = pModule->xFilter(pVtabCursor, iQuery, pOp->p4.z, nArg, apArg); - p->inVtabMethod = 0; sqlite3VtabImportErrmsg(p, pVtab); if( rc==SQLITE_OK ){ res = pModule->xEof(pVtabCursor); @@ -6253,9 +6236,7 @@ case OP_VNext: { /* jump */ ** data is available) and the error code returned when xColumn or ** some other method is next invoked on the save virtual table cursor. */ - p->inVtabMethod = 1; rc = pModule->xNext(pCur->pVtabCursor); - p->inVtabMethod = 0; sqlite3VtabImportErrmsg(p, pVtab); if( rc==SQLITE_OK ){ res = pModule->xEof(pCur->pVtabCursor); diff --git a/src/vdbeInt.h b/src/vdbeInt.h index 877da1143c..d3955af31e 100644 --- a/src/vdbeInt.h +++ b/src/vdbeInt.h @@ -313,14 +313,6 @@ struct ScanStatus { ** ** The "sqlite3_stmt" structure pointer that is returned by sqlite3_prepare() ** is really a pointer to an instance of this structure. -** -** The Vdbe.inVtabMethod variable is set to non-zero for the duration of -** any virtual table method invocations made by the vdbe program. It is -** set to 2 for xDestroy method calls and 1 for all other methods. This -** variable is used for two purposes: to allow xDestroy methods to execute -** "DROP TABLE" statements and to prevent some nasty side effects of -** malloc failure when SQLite is invoked recursively by a virtual table -** method function. */ struct Vdbe { sqlite3 *db; /* The database connection that owns this statement */ @@ -351,7 +343,6 @@ struct Vdbe { u8 errorAction; /* Recovery action to do in case of an error */ u8 minWriteFileFormat; /* Minimum file format for writable database files */ bft explain:2; /* True if EXPLAIN present on SQL command */ - bft inVtabMethod:2; /* See comments above */ bft changeCntOn:1; /* True to update the change-counter */ bft expired:1; /* True if the VM needs to be recompiled */ bft runOnlyOnce:1; /* Automatically expire on reset */ diff --git a/src/vdbeaux.c b/src/vdbeaux.c index 9c105cc9e7..8397fbc10d 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -1782,9 +1782,7 @@ void sqlite3VdbeFreeCursor(Vdbe *p, VdbeCursor *pCx){ else if( pCx->pVtabCursor ){ sqlite3_vtab_cursor *pVtabCursor = pCx->pVtabCursor; const sqlite3_module *pModule = pVtabCursor->pVtab->pModule; - p->inVtabMethod = 1; pModule->xClose(pVtabCursor); - p->inVtabMethod = 0; } #endif } From a68d62829134f97df079b7b9c25fce44e1984f8f Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 24 Mar 2015 13:32:53 +0000 Subject: [PATCH 016/181] Prevent a virtual table from being destroyed while it is in use. FossilOrigin-Name: fba674c083286dabb37fed9357b67593b56ed3a5 --- manifest | 21 +++++++++------------ manifest.uuid | 2 +- src/sqlite.h.in | 2 +- src/vdbe.c | 1 + src/vdbeaux.c | 2 ++ src/vtab.c | 12 ++++++++---- 6 files changed, 22 insertions(+), 18 deletions(-) diff --git a/manifest b/manifest index 5c9a4c0330..3cbfeae1e3 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Replace\sthe\sVdbe.inVtabMethod\sfield\swith\sthe\ssqlite3.nVDestroy\scounter. -D 2015-03-24T12:51:52.656 +C Prevent\sa\svirtual\stable\sfrom\sbeing\sdestroyed\swhile\sit\sis\sin\suse. +D 2015-03-24T13:32:53.812 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -232,7 +232,7 @@ F src/resolve.c f4d79e31ffa5820c2e3d1740baa5e9b190425f2b F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e F src/select.c 72ffb62e2879956302140e9f6e6ae88aee36b0e5 F src/shell.c 3ae1e53878d2804fe77b8c8f1f6ca287a0e5d80e -F src/sqlite.h.in df180ecc3215e4b87dbd536507869511bec88841 +F src/sqlite.h.in 2f9606a682af372415ce9d1f244183c5cc8385aa F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h 17d487c3c91b0b8c584a32fbeb393f6f795eea7d F src/sqliteInt.h bedf15914c09bfb5fe3ec4e3f211a4a6fc42cd33 @@ -293,16 +293,16 @@ F src/update.c 3c4ecc282accf12d39edb8d524cf089645e55a13 F src/utf.c fc6b889ba0779b7722634cdeaa25f1930d93820c F src/util.c 98a7627ca48ad3265b6940915a1d08355eb3fc7e F src/vacuum.c 9460b9de7b2d4e34b0d374894aa6c8a0632be8ec -F src/vdbe.c 884faa91c44023891d0992311fd0feed0df060fc +F src/vdbe.c 1524e1db29a85d8e376d0f4ef2109c5296dcd83b F src/vdbe.h 6fc69d9c5e146302c56e163cb4b31d1ee64a18c3 F src/vdbeInt.h 9cbaa84f53ddd2d09a0cf61a94337a3a035d08a0 F src/vdbeapi.c 583d56b129dd27f12bed518270de9ebe521e6a75 -F src/vdbeaux.c d62823d72b8f69a3e64deb03c30e959af285e488 +F src/vdbeaux.c 741cccd410f75f6dcd9dde66c1e0601c956a42ae F src/vdbeblob.c 4f2e8e075d238392df98c5e03a64342465b03f90 F src/vdbemem.c c0dc81285b7571b0a31c40f17846fe2397ec1cd9 F src/vdbesort.c 919717d7599fa31d343ec28bffd0f9e91a4ff5f6 F src/vdbetrace.c 7e4222955e07dd707a2f360c0eb73452be1cb010 -F src/vtab.c 1680f58978ae014a331d99b4c87316d079056c5e +F src/vtab.c 62d49237bd8f3be4863815a39387b0f9897fa5e1 F src/vxworks.h c18586c8edc1bddbc15c004fa16aeb1e1342b4fb F src/wal.c 878c8e1a51cb2ec45c395d26b7d5cd9e1a098e4a F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4 @@ -1246,10 +1246,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 0ee2d38deb35aefc55395e86984a9a773caf6218 -R 8a156978483ce9f9262ab29d0045e64e -T *branch * nVDestroy -T *sym-nVDestroy * -T -sym-trunk * +P 9faefb96272967e731e83ef516a8c1e1b876391b +R 281e744f7b786f4abb8205e460d3cd79 U drh -Z 795f6417c17436a4fbd09f9a73f096f4 +Z 8d74d67cd7bcd5c907dded9ec155ff27 diff --git a/manifest.uuid b/manifest.uuid index 9e51355abe..cd8c7c5fbd 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -9faefb96272967e731e83ef516a8c1e1b876391b \ No newline at end of file +fba674c083286dabb37fed9357b67593b56ed3a5 \ No newline at end of file diff --git a/src/sqlite.h.in b/src/sqlite.h.in index 8419392cfa..8e2727f6ae 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -5627,7 +5627,7 @@ int sqlite3_create_module_v2( */ struct sqlite3_vtab { const sqlite3_module *pModule; /* The module for this virtual table */ - int nRef; /* NO LONGER USED */ + int nRef; /* Number of open cursors */ char *zErrMsg; /* Error message from sqlite3_mprintf() */ /* Virtual table implementations will typically add additional fields */ }; diff --git a/src/vdbe.c b/src/vdbe.c index bba6a90bf4..82c313a2d9 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -6081,6 +6081,7 @@ case OP_VOpen: { pCur = allocateCursor(p, pOp->p1, 0, -1, 0); if( pCur ){ pCur->pVtabCursor = pVtabCursor; + pVtab->nRef++; }else{ db->mallocFailed = 1; pModule->xClose(pVtabCursor); diff --git a/src/vdbeaux.c b/src/vdbeaux.c index 8397fbc10d..bd00786ebc 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -1782,6 +1782,8 @@ void sqlite3VdbeFreeCursor(Vdbe *p, VdbeCursor *pCx){ else if( pCx->pVtabCursor ){ sqlite3_vtab_cursor *pVtabCursor = pCx->pVtabCursor; const sqlite3_module *pModule = pVtabCursor->pVtab->pModule; + assert( pVtabCursor->pVtab->nRef>0 ); + pVtabCursor->pVtab->nRef--; pModule->xClose(pVtabCursor); } #endif diff --git a/src/vtab.c b/src/vtab.c index 4631a7d0d0..23f49bafce 100644 --- a/src/vtab.c +++ b/src/vtab.c @@ -780,11 +780,15 @@ int sqlite3VtabCallDestroy(sqlite3 *db, int iDb, const char *zTab){ pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zName); if( ALWAYS(pTab!=0 && pTab->pVTable!=0) ){ - VTable *p = vtabDisconnectAll(db, pTab); - - assert( rc==SQLITE_OK ); + VTable *p; + for(p=pTab->pVTable; p; p=p->pNext){ + assert( p->pVtab ); + if( p->pVtab->nRef>0 ){ + return SQLITE_LOCKED; + } + } + p = vtabDisconnectAll(db, pTab); rc = p->pMod->pModule->xDestroy(p->pVtab); - /* Remove the sqlite3_vtab* from the aVTrans[] array, if applicable */ if( rc==SQLITE_OK ){ assert( pTab->pVTable==p && p->pNext==0 ); From f496a7dc81dd0b2cc0c823a13a836f6a22001a4f Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 24 Mar 2015 14:05:50 +0000 Subject: [PATCH 017/181] More defenses against virtual table being deleted out from under a running statement. FossilOrigin-Name: 116c99823022c017946b6088878a2d46759deb6e --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/vdbe.c | 17 ++++++++++++----- src/vdbeaux.c | 3 ++- 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/manifest b/manifest index 3cbfeae1e3..faa3a9efb1 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Prevent\sa\svirtual\stable\sfrom\sbeing\sdestroyed\swhile\sit\sis\sin\suse. -D 2015-03-24T13:32:53.812 +C More\sdefenses\sagainst\svirtual\stable\sbeing\sdeleted\sout\sfrom\sunder\sa\srunning\nstatement. +D 2015-03-24T14:05:50.045 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -293,11 +293,11 @@ F src/update.c 3c4ecc282accf12d39edb8d524cf089645e55a13 F src/utf.c fc6b889ba0779b7722634cdeaa25f1930d93820c F src/util.c 98a7627ca48ad3265b6940915a1d08355eb3fc7e F src/vacuum.c 9460b9de7b2d4e34b0d374894aa6c8a0632be8ec -F src/vdbe.c 1524e1db29a85d8e376d0f4ef2109c5296dcd83b +F src/vdbe.c bbfede5a8a6908b3ddcd55fdb0b2301288dd4754 F src/vdbe.h 6fc69d9c5e146302c56e163cb4b31d1ee64a18c3 F src/vdbeInt.h 9cbaa84f53ddd2d09a0cf61a94337a3a035d08a0 F src/vdbeapi.c 583d56b129dd27f12bed518270de9ebe521e6a75 -F src/vdbeaux.c 741cccd410f75f6dcd9dde66c1e0601c956a42ae +F src/vdbeaux.c 056eefd33ef4457240b6d3156a96201579face0a F src/vdbeblob.c 4f2e8e075d238392df98c5e03a64342465b03f90 F src/vdbemem.c c0dc81285b7571b0a31c40f17846fe2397ec1cd9 F src/vdbesort.c 919717d7599fa31d343ec28bffd0f9e91a4ff5f6 @@ -1246,7 +1246,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 9faefb96272967e731e83ef516a8c1e1b876391b -R 281e744f7b786f4abb8205e460d3cd79 +P fba674c083286dabb37fed9357b67593b56ed3a5 +R 6651e18da796c17c1ca503ba6b1b311c U drh -Z 8d74d67cd7bcd5c907dded9ec155ff27 +Z 91702967a80a94e761fcc487487cb422 diff --git a/manifest.uuid b/manifest.uuid index cd8c7c5fbd..625bb648cf 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -fba674c083286dabb37fed9357b67593b56ed3a5 \ No newline at end of file +116c99823022c017946b6088878a2d46759deb6e \ No newline at end of file diff --git a/src/vdbe.c b/src/vdbe.c index 82c313a2d9..ec5e6d7442 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -6063,14 +6063,17 @@ case OP_VOpen: { VdbeCursor *pCur; sqlite3_vtab_cursor *pVtabCursor; sqlite3_vtab *pVtab; - sqlite3_module *pModule; + const sqlite3_module *pModule; assert( p->bIsReader ); pCur = 0; pVtabCursor = 0; pVtab = pOp->p4.pVtab->pVtab; - pModule = (sqlite3_module *)pVtab->pModule; - assert(pVtab && pModule); + if( pVtab==0 || NEVER(pVtab->pModule==0) ){ + rc = SQLITE_LOCKED; + break; + } + pModule = pVtab->pModule; rc = pModule->xOpen(pVtab, &pVtabCursor); sqlite3VtabImportErrmsg(p, pVtab); if( SQLITE_OK==rc ){ @@ -6312,7 +6315,7 @@ case OP_VRename: { */ case OP_VUpdate: { sqlite3_vtab *pVtab; - sqlite3_module *pModule; + const sqlite3_module *pModule; int nArg; int i; sqlite_int64 rowid; @@ -6324,7 +6327,11 @@ case OP_VUpdate: { ); assert( p->readOnly==0 ); pVtab = pOp->p4.pVtab->pVtab; - pModule = (sqlite3_module *)pVtab->pModule; + if( pVtab==0 || NEVER(pVtab->pModule==0) ){ + rc = SQLITE_LOCKED; + break; + } + pModule = pVtab->pModule; nArg = pOp->p2; assert( pOp->p4type==P4_VTAB ); if( ALWAYS(pModule->xUpdate) ){ diff --git a/src/vdbeaux.c b/src/vdbeaux.c index bd00786ebc..25840ccde8 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -1118,7 +1118,8 @@ static char *displayP4(Op *pOp, char *zTemp, int nTemp){ #ifndef SQLITE_OMIT_VIRTUALTABLE case P4_VTAB: { sqlite3_vtab *pVtab = pOp->p4.pVtab->pVtab; - sqlite3_snprintf(nTemp, zTemp, "vtab:%p:%p", pVtab, pVtab->pModule); + sqlite3_snprintf(nTemp, zTemp, "vtab:%p:%p", + pVtab, pVtab ? pVtab->pModule : (sqlite3_module*)0); break; } #endif From 466fd815fbdfce266f33ee61c8d06751a6170dc0 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 24 Mar 2015 14:57:02 +0000 Subject: [PATCH 018/181] Simplify the EXPLAIN output of virtual table P4 parameters to only show the pointer to the sqlite3_vtab object and omit the sqlite3_module object. FossilOrigin-Name: 85610bbbc60cb4a6ec856123447fdb2ba948e52f --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/vdbeaux.c | 3 +-- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index faa3a9efb1..e76179efbf 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C More\sdefenses\sagainst\svirtual\stable\sbeing\sdeleted\sout\sfrom\sunder\sa\srunning\nstatement. -D 2015-03-24T14:05:50.045 +C Simplify\sthe\sEXPLAIN\soutput\sof\svirtual\stable\sP4\sparameters\sto\sonly\sshow\sthe\npointer\sto\sthe\ssqlite3_vtab\sobject\sand\somit\sthe\ssqlite3_module\sobject. +D 2015-03-24T14:57:02.437 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -297,7 +297,7 @@ F src/vdbe.c bbfede5a8a6908b3ddcd55fdb0b2301288dd4754 F src/vdbe.h 6fc69d9c5e146302c56e163cb4b31d1ee64a18c3 F src/vdbeInt.h 9cbaa84f53ddd2d09a0cf61a94337a3a035d08a0 F src/vdbeapi.c 583d56b129dd27f12bed518270de9ebe521e6a75 -F src/vdbeaux.c 056eefd33ef4457240b6d3156a96201579face0a +F src/vdbeaux.c 413dc496248ac18eb0c19e35e86bb1ffd47b8907 F src/vdbeblob.c 4f2e8e075d238392df98c5e03a64342465b03f90 F src/vdbemem.c c0dc81285b7571b0a31c40f17846fe2397ec1cd9 F src/vdbesort.c 919717d7599fa31d343ec28bffd0f9e91a4ff5f6 @@ -1246,7 +1246,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 fba674c083286dabb37fed9357b67593b56ed3a5 -R 6651e18da796c17c1ca503ba6b1b311c +P 116c99823022c017946b6088878a2d46759deb6e +R 5f471e8babb874f26a1b4c65b62f02f6 U drh -Z 91702967a80a94e761fcc487487cb422 +Z ffb5a79aea5fc49ed872d8dd5ea0b00b diff --git a/manifest.uuid b/manifest.uuid index 625bb648cf..445a1dff5e 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -116c99823022c017946b6088878a2d46759deb6e \ No newline at end of file +85610bbbc60cb4a6ec856123447fdb2ba948e52f \ No newline at end of file diff --git a/src/vdbeaux.c b/src/vdbeaux.c index 25840ccde8..9c5d9acca9 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -1118,8 +1118,7 @@ static char *displayP4(Op *pOp, char *zTemp, int nTemp){ #ifndef SQLITE_OMIT_VIRTUALTABLE case P4_VTAB: { sqlite3_vtab *pVtab = pOp->p4.pVtab->pVtab; - sqlite3_snprintf(nTemp, zTemp, "vtab:%p:%p", - pVtab, pVtab ? pVtab->pModule : (sqlite3_module*)0); + sqlite3_snprintf(nTemp, zTemp, "vtab:%p", pVtab); break; } #endif From 428630cfcf50de48828f9f878ea0a13fc305dc7f Mon Sep 17 00:00:00 2001 From: dan Date: Tue, 24 Mar 2015 14:57:21 +0000 Subject: [PATCH 019/181] Add tests to check that attempting to DROP a virtual table while it is use does not cause problems. FossilOrigin-Name: 5ee625b1980f9fab6294d308349dfd9ba960b60b --- manifest | 14 ++++++------- manifest.uuid | 2 +- test/vtab1.test | 54 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index faa3a9efb1..f7fe0c8224 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C More\sdefenses\sagainst\svirtual\stable\sbeing\sdeleted\sout\sfrom\sunder\sa\srunning\nstatement. -D 2015-03-24T14:05:50.045 +C Add\stests\sto\scheck\sthat\sattempting\sto\sDROP\sa\svirtual\stable\swhile\sit\sis\suse\sdoes\snot\scause\sproblems. +D 2015-03-24T14:57:21.959 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -1111,7 +1111,7 @@ F test/vacuum4.test d3f8ecff345f166911568f397d2432c16d2867d9 F test/varint.test ab7b110089a08b9926ed7390e7e97bdefeb74102 F test/veryquick.test 57ab846bacf7b90cf4e9a672721ea5c5b669b661 F test/view.test f311691d696a5cc27e3c1b875cec1b0866b4ccd9 -F test/vtab1.test 1cef14310144718812351a61c5cfb4ba8494a171 +F test/vtab1.test c9dc2a73e93331d70b37ce4b246ef6dc18412fef F test/vtab2.test 3644649aa8d1daac57fd541f6a5f914cac59203e F test/vtab3.test b45f47d20f225ccc9c28dc915d92740c2dee311e F test/vtab4.test 942f8b8280b3ea8a41dae20e7822d065ca1cb275 @@ -1246,7 +1246,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 fba674c083286dabb37fed9357b67593b56ed3a5 -R 6651e18da796c17c1ca503ba6b1b311c -U drh -Z 91702967a80a94e761fcc487487cb422 +P 116c99823022c017946b6088878a2d46759deb6e +R 791eb1db9d6d4dcf9879622b22bdbc4e +U dan +Z 5721bb8cdc400d9869a3df977b6ecfb6 diff --git a/manifest.uuid b/manifest.uuid index 625bb648cf..5b0b4a1607 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -116c99823022c017946b6088878a2d46759deb6e \ No newline at end of file +5ee625b1980f9fab6294d308349dfd9ba960b60b \ No newline at end of file diff --git a/test/vtab1.test b/test/vtab1.test index 2929b1e54d..dfc989a643 100644 --- a/test/vtab1.test +++ b/test/vtab1.test @@ -1437,4 +1437,58 @@ ifcapable fts3 { } {SQLITE_OK} } + +#------------------------------------------------------------------------- +# The following tests verify that a DROP TABLE command on a virtual +# table does not cause other operations to crash. +# +# 23.1: Dropping a vtab while a SELECT is running on it. +# +# 23.2: Dropping a vtab while a SELECT that will, but has not yet, +# open a cursor on the vtab, is running. In this case the +# DROP TABLE succeeds and the SELECT hits an error. +# +# 23.3: Dropping a vtab from within a user-defined-function callback +# in the middle of an "INSERT INTO vtab SELECT ..." statement. +# +reset_db +load_static_extension db wholenumber +load_static_extension db eval +register_echo_module db + +do_test 23.1 { + execsql { CREATE VIRTUAL TABLE t1 USING wholenumber } + set res "" + db eval { SELECT value FROM t1 WHERE value<10 } { + if {$value == 5} { + set res [catchsql { DROP TABLE t1 }] + } + } + set res +} {1 {database table is locked}} + +do_test 23.2 { + execsql { + CREATE TABLE t2(value); + INSERT INTO t2 VALUES(1), (2), (3); + } + + set res2 [list [catch { + db eval { + SELECT value FROM t2 UNION ALL + SELECT value FROM t1 WHERE value<10 + } { + if {$value == 2} { set res1 [catchsql { DROP TABLE t1 }] } + } + } msg] $msg] + list $res1 $res2 +} {{0 {}} {1 {database table is locked}}} + +do_test 23.3.1 { + execsql { CREATE VIRTUAL TABLE t1e USING echo(t2) } + execsql { INSERT INTO t1e SELECT 4 } + catchsql { INSERT INTO t1e SELECT eval('DROP TABLE t1e') } +} {1 {database table is locked}} +do_execsql_test 23.3.2 { SELECT * FROM t1e } {1 2 3 4} + finish_test From 475640484729bbaf2510dc8798880ce51e901228 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 24 Mar 2015 18:19:39 +0000 Subject: [PATCH 020/181] Suppress a compiler warning that was appearing with SQLITE_THREADSAFE=0. FossilOrigin-Name: 436314b5728c9413f9ac2d837e1c19364f31be72 --- manifest | 14 ++++++-------- manifest.uuid | 2 +- src/status.c | 1 + 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index d1020a6d13..2022595ba2 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Prevent\sa\svirtual\stable\sfrom\sbeing\sdestroyed\swhile\sit\sis\sin\suse.\nAlso:\sreplace\sVdbe.inVtabMethod\swith\ssqlite3.nVDestroy.\s\sSimplify\sthe\nEXPLAIN\soutput\sfor\sP4.pVtab\sto\sonly\sshow\sthe\ssqlite3_vtab\spointer. -D 2015-03-24T16:43:34.928 +C Suppress\sa\scompiler\swarning\sthat\swas\sappearing\swith\sSQLITE_THREADSAFE=0. +D 2015-03-24T18:19:39.691 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -237,7 +237,7 @@ F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h 17d487c3c91b0b8c584a32fbeb393f6f795eea7d F src/sqliteInt.h bedf15914c09bfb5fe3ec4e3f211a4a6fc42cd33 F src/sqliteLimit.h 216557999cb45f2e3578ed53ebefe228d779cb46 -F src/status.c 2e5c86866ff2f30988ce10ddbaa7ba2eaf6d4146 +F src/status.c f266ad8a2892d659b74f0f50cb6a88b6e7c12179 F src/table.c e7a09215315a978057fb42c640f890160dbcc45e F src/tclsqlite.c fa72a7c5278662357c105ba7925c1d0972506ff9 F src/test1.c 90fbedce75330d48d99eadb7d5f4223e86969585 @@ -1246,9 +1246,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 0ee2d38deb35aefc55395e86984a9a773caf6218 85610bbbc60cb4a6ec856123447fdb2ba948e52f 5ee625b1980f9fab6294d308349dfd9ba960b60b -R 5e10f0a3ec239c969328e02883201fd9 -T +closed 5ee625b1980f9fab6294d308349dfd9ba960b60b -T +closed 85610bbbc60cb4a6ec856123447fdb2ba948e52f +P cbeb9a1aed8ce3fb569a7717ad03c7c058b68de6 +R 1df40f85f677c47017b13b63b82a97b5 U drh -Z 4c6da71fa5b7897deec943a0cbeb333e +Z 408df2ac27dc537c38335d50565b918f diff --git a/manifest.uuid b/manifest.uuid index 83e3226971..b639b7d8cc 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -cbeb9a1aed8ce3fb569a7717ad03c7c058b68de6 \ No newline at end of file +436314b5728c9413f9ac2d837e1c19364f31be72 \ No newline at end of file diff --git a/src/status.c b/src/status.c index aa27f70efc..ac32753a22 100644 --- a/src/status.c +++ b/src/status.c @@ -148,6 +148,7 @@ int sqlite3_status64( wsdStat.mxValue[op] = wsdStat.nowValue[op]; } sqlite3_mutex_leave(pMutex); + (void)pMutex; /* Prevent warning when SQLITE_THREADSAFE=0 */ return SQLITE_OK; } int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag){ From 59b9b02c1fa889a4f4e83f2a5597bf62baca4ccb Mon Sep 17 00:00:00 2001 From: mistachkin Date: Tue, 24 Mar 2015 21:27:27 +0000 Subject: [PATCH 021/181] Add SQLITE_STDCALL and SQLITE_CDECL macros on public function definitions. FossilOrigin-Name: 242f09d4d1c92ee9058857a5e780442f4b7bad55 --- Makefile.msc | 8 ++--- manifest | 23 ++++++++------ manifest.uuid | 2 +- src/sqlite.h.in | 7 ----- tool/mksqlite3c.tcl | 74 ++++++++++++++++++++++++++++++++++----------- tool/mksqlite3h.tcl | 41 ++++++++++++++++++++++--- 6 files changed, 112 insertions(+), 43 deletions(-) diff --git a/Makefile.msc b/Makefile.msc index 249e3c284d..837fc003c0 100644 --- a/Makefile.msc +++ b/Makefile.msc @@ -312,12 +312,12 @@ RCC = $(RC) -DSQLITE_OS_WIN=1 -I$(TOP) -I$(TOP)\src # !IF $(USE_STDCALL)!=0 !IF "$(PLATFORM)"=="x86" -CORE_CCONV_OPTS = -Gz -DSQLITE_CDECL=__cdecl -SHELL_CCONV_OPTS = -Gz -DSQLITE_CDECL=__cdecl +CORE_CCONV_OPTS = -Gz -DSQLITE_CDECL=__cdecl -DSQLITE_STDCALL=__stdcall +SHELL_CCONV_OPTS = -Gz -DSQLITE_CDECL=__cdecl -DSQLITE_STDCALL=__stdcall !ELSE !IFNDEF PLATFORM -CORE_CCONV_OPTS = -Gz -DSQLITE_CDECL=__cdecl -SHELL_CCONV_OPTS = -Gz -DSQLITE_CDECL=__cdecl +CORE_CCONV_OPTS = -Gz -DSQLITE_CDECL=__cdecl -DSQLITE_STDCALL=__stdcall +SHELL_CCONV_OPTS = -Gz -DSQLITE_CDECL=__cdecl -DSQLITE_STDCALL=__stdcall !ELSE CORE_CCONV_OPTS = SHELL_CCONV_OPTS = diff --git a/manifest b/manifest index 2022595ba2..8a9bcb9667 100644 --- a/manifest +++ b/manifest @@ -1,9 +1,9 @@ -C Suppress\sa\scompiler\swarning\sthat\swas\sappearing\swith\sSQLITE_THREADSAFE=0. -D 2015-03-24T18:19:39.691 +C Add\sSQLITE_STDCALL\sand\sSQLITE_CDECL\smacros\son\spublic\sfunction\sdefinitions. +D 2015-03-24T21:27:27.369 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 -F Makefile.msc cd626b52ebeec0e2c0dd929243bdd25b0df19a71 +F Makefile.msc 3481e2dd260968742c715542db178c2bdd5db99f F Makefile.vxworks e1b65dea203f054e71653415bd8f96dcaed47858 F README.md d58e3bebc0a4145e0f2a87994015fdb575a8e866 F VERSION 319eb1ced4b4d17a67730f2b7b85f15c1346cb60 @@ -232,7 +232,7 @@ F src/resolve.c f4d79e31ffa5820c2e3d1740baa5e9b190425f2b F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e F src/select.c 72ffb62e2879956302140e9f6e6ae88aee36b0e5 F src/shell.c 3ae1e53878d2804fe77b8c8f1f6ca287a0e5d80e -F src/sqlite.h.in 2f9606a682af372415ce9d1f244183c5cc8385aa +F src/sqlite.h.in 82977ae32ba5f5a115d4434418087c9c1088f643 F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h 17d487c3c91b0b8c584a32fbeb393f6f795eea7d F src/sqliteInt.h bedf15914c09bfb5fe3ec4e3f211a4a6fc42cd33 @@ -1213,8 +1213,8 @@ F tool/mkopts.tcl 66ac10d240cc6e86abd37dc908d50382f84ff46e F tool/mkpragmatab.tcl 94f196c9961e0ca3513e29f57125a3197808be2d F tool/mkspeedsql.tcl a1a334d288f7adfe6e996f2e712becf076745c97 F tool/mksqlite3c-noext.tcl 9ef48e1748dce7b844f67e2450ff9dfeb0fb4ab5 -F tool/mksqlite3c.tcl 95ab31eda659e7ffb091e04bd83178f260d8edfd -F tool/mksqlite3h.tcl ba24038056f51fde07c0079c41885ab85e2cff12 +F tool/mksqlite3c.tcl ab2cfb2191f1edaea0e72b6ad3bc3f71aa61a6b9 +F tool/mksqlite3h.tcl c02e391f595bf91528341ffaa53e5084d8b595ce F tool/mksqlite3internalh.tcl eb994013e833359137eb53a55acdad0b5ae1049b F tool/mkvsix.tcl 52a4c613707ac34ae9c226e5ccc69cb948556105 F tool/offsets.c fe4262fdfa378e8f5499a42136d17bf3b98f6091 @@ -1246,7 +1246,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 cbeb9a1aed8ce3fb569a7717ad03c7c058b68de6 -R 1df40f85f677c47017b13b63b82a97b5 -U drh -Z 408df2ac27dc537c38335d50565b918f +P 436314b5728c9413f9ac2d837e1c19364f31be72 +R 887ef727abd3a9965cbccad906bf79e4 +T *branch * stdcall +T *sym-stdcall * +T -sym-trunk * +U mistachkin +Z cb11de2c68ebf434af7cc941e8219588 diff --git a/manifest.uuid b/manifest.uuid index b639b7d8cc..d35f197244 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -436314b5728c9413f9ac2d837e1c19364f31be72 \ No newline at end of file +242f09d4d1c92ee9058857a5e780442f4b7bad55 \ No newline at end of file diff --git a/src/sqlite.h.in b/src/sqlite.h.in index 8e2727f6ae..6d2cc146dc 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -49,13 +49,6 @@ extern "C" { # define SQLITE_EXTERN extern #endif -/* -** Add the ability to override 'cdecl' -*/ -#ifndef SQLITE_CDECL -# define SQLITE_CDECL -#endif - /* ** These no-op macros are used in front of interfaces to mark those ** interfaces as either deprecated or experimental. New applications diff --git a/tool/mksqlite3c.tcl b/tool/mksqlite3c.tcl index fd823385b3..b33eef8f1a 100644 --- a/tool/mksqlite3c.tcl +++ b/tool/mksqlite3c.tcl @@ -83,6 +83,12 @@ if {$addstatic} { #endif #ifndef SQLITE_API # define SQLITE_API +#endif +#ifndef SQLITE_CDECL +# define SQLITE_CDECL +#endif +#ifndef SQLITE_STDCALL +# define SQLITE_STDCALL #endif} } @@ -127,6 +133,23 @@ foreach hdr { } set available_hdr(sqliteInt.h) 0 +# These headers should be copied into the amalgamation without modifying any +# of their function declarations or definitions. +set varonly_hdr(sqlite3.h) 1 + +# These are the functions that accept a variable number of arguments. They +# always need to use the "cdecl" calling convention even when another calling +# convention (e.g. "stcall") is being used for the rest of the library. +set cdecllist { + sqlite3_config + sqlite3_db_config + sqlite3_log + sqlite3_mprintf + sqlite3_snprintf + sqlite3_test_control + sqlite3_vtab_config +} + # 78 stars used for comment formatting. set s78 \ {*****************************************************************************} @@ -146,18 +169,18 @@ proc section_comment {text} { # process them appropriately. # proc copy_file {filename} { - global seen_hdr available_hdr out addstatic linemacros + global seen_hdr available_hdr varonly_hdr cdecllist out addstatic linemacros set ln 0 set tail [file tail $filename] section_comment "Begin file $tail" if {$linemacros} {puts $out "#line 1 \"$filename\""} set in [open $filename r] set varpattern {^[a-zA-Z][a-zA-Z_0-9 *]+(sqlite3[_a-zA-Z0-9]+)(\[|;| =)} - set declpattern {[a-zA-Z][a-zA-Z_0-9 ]+ \**(sqlite3[_a-zA-Z0-9]+)\(} + set declpattern {([a-zA-Z][a-zA-Z_0-9 ]+ \**)(sqlite3[_a-zA-Z0-9]+)(\(.*)} if {[file extension $filename]==".h"} { set declpattern " *$declpattern" } - set declpattern ^$declpattern + set declpattern ^$declpattern\$ while {![eof $in]} { set line [gets $in] incr ln @@ -191,32 +214,49 @@ proc copy_file {filename} { } elseif {!$linemacros && [regexp {^#line} $line]} { # Skip #line directives. } elseif {$addstatic && ![regexp {^(static|typedef)} $line]} { - regsub {^SQLITE_API } $line {} line - if {[regexp $declpattern $line all funcname]} { + # Skip adding the SQLITE_PRIVATE or SQLITE_API keyword before + # functions if this header file does not need it. + if {![info exists varonly_hdr($tail)] + && [regexp $declpattern $line all rettype funcname rest]} { + regsub {^SQLITE_API } $line {} line # Add the SQLITE_PRIVATE or SQLITE_API keyword before functions. # so that linkage can be modified at compile-time. if {[regexp {^sqlite3_} $funcname]} { - puts $out "SQLITE_API $line" + set line SQLITE_API + append line " " [string trim $rettype] + if {[string index $rettype end] ne "*"} { + append line " " + } + if {[lsearch -exact $cdecllist $funcname] >= 0} { + append line SQLITE_CDECL + } else { + append line SQLITE_STDCALL + } + append line " " $funcname $rest + puts $out $line } else { puts $out "SQLITE_PRIVATE $line" } } elseif {[regexp $varpattern $line all varname]} { - # Add the SQLITE_PRIVATE before variable declarations or - # definitions for internal use - if {![regexp {^sqlite3_} $varname]} { - regsub {^extern } $line {} line - puts $out "SQLITE_PRIVATE $line" - } else { - if {[regexp {const char sqlite3_version\[\];} $line]} { - set line {const char sqlite3_version[] = SQLITE_VERSION;} + # Add the SQLITE_PRIVATE before variable declarations or + # definitions for internal use + regsub {^SQLITE_API } $line {} line + if {![regexp {^sqlite3_} $varname]} { + regsub {^extern } $line {} line + puts $out "SQLITE_PRIVATE $line" + } else { + if {[regexp {const char sqlite3_version\[\];} $line]} { + set line {const char sqlite3_version[] = SQLITE_VERSION;} + } + regsub {^SQLITE_EXTERN } $line {} line + puts $out "SQLITE_API $line" } - regsub {^SQLITE_EXTERN } $line {} line - puts $out "SQLITE_API $line" - } } elseif {[regexp {^(SQLITE_EXTERN )?void \(\*sqlite3IoTrace\)} $line]} { + regsub {^SQLITE_API } $line {} line regsub {^SQLITE_EXTERN } $line {} line puts $out $line } elseif {[regexp {^void \(\*sqlite3Os} $line]} { + regsub {^SQLITE_API } $line {} line puts $out "SQLITE_PRIVATE $line" } else { puts $out $line diff --git a/tool/mksqlite3h.tcl b/tool/mksqlite3h.tcl index a89b9f9beb..9ed74c3f4b 100644 --- a/tool/mksqlite3h.tcl +++ b/tool/mksqlite3h.tcl @@ -63,7 +63,7 @@ close $in # Set up patterns for recognizing API declarations. # set varpattern {^[a-zA-Z][a-zA-Z_0-9 *]+sqlite3_[_a-zA-Z0-9]+(\[|;| =)} -set declpattern {^ *[a-zA-Z][a-zA-Z_0-9 ]+ \**sqlite3_[_a-zA-Z0-9]+\(} +set declpattern {^ *([a-zA-Z][a-zA-Z_0-9 ]+ \**)(sqlite3_[_a-zA-Z0-9]+)(\(.*)$} # Force the output to use unix line endings, even on Windows. fconfigure stdout -translation lf @@ -73,6 +73,19 @@ set filelist [subst { $TOP/ext/rtree/sqlite3rtree.h }] +# These are the functions that accept a variable number of arguments. They +# always need to use the "cdecl" calling convention even when another calling +# convention (e.g. "stcall") is being used for the rest of the library. +set cdecllist { + sqlite3_config + sqlite3_db_config + sqlite3_log + sqlite3_mprintf + sqlite3_snprintf + sqlite3_test_control + sqlite3_vtab_config +} + # Process the source files. # foreach file $filelist { @@ -97,13 +110,33 @@ foreach file $filelist { puts "#ifndef SQLITE_API" puts "# define SQLITE_API" puts "#endif" + puts "" + puts "#ifndef SQLITE_CDECL" + puts "# define SQLITE_CDECL" + puts "#endif" + puts "" + puts "#ifndef SQLITE_STDCALL" + puts "# define SQLITE_STDCALL" + puts "#endif" set line "" } - if {([regexp $varpattern $line] && ![regexp {^ *typedef} $line]) - || ([regexp $declpattern $line]) - } { + if {[regexp $varpattern $line] && ![regexp {^ *typedef} $line]} { set line "SQLITE_API $line" + } else { + if {[regexp $declpattern $line all rettype funcname rest]} { + set line SQLITE_API + append line " " [string trim $rettype] + if {[string index $rettype end] ne "*"} { + append line " " + } + if {[lsearch -exact $cdecllist $funcname] >= 0} { + append line SQLITE_CDECL + } else { + append line SQLITE_STDCALL + } + append line " " $funcname $rest + } } puts $line } From 26bbfaa59d58b1da578e83cf79c310a8695f0c45 Mon Sep 17 00:00:00 2001 From: mistachkin Date: Tue, 24 Mar 2015 21:34:53 +0000 Subject: [PATCH 022/181] Fix a couple comment typos in a tool script. No changes to code. FossilOrigin-Name: 83421af67063825981f6051eb415944d90e9b2f6 --- manifest | 14 +++++++------- manifest.uuid | 2 +- tool/mksqlite3c-noext.tcl | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index 2022595ba2..3ba7e5627e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Suppress\sa\scompiler\swarning\sthat\swas\sappearing\swith\sSQLITE_THREADSAFE=0. -D 2015-03-24T18:19:39.691 +C Fix\sa\scouple\scomment\stypos\sin\sa\stool\sscript.\s\sNo\schanges\sto\scode. +D 2015-03-24T21:34:53.280 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -1212,7 +1212,7 @@ F tool/mkkeywordhash.c dfff09dbbfaf950e89af294f48f902181b144670 F tool/mkopts.tcl 66ac10d240cc6e86abd37dc908d50382f84ff46e F tool/mkpragmatab.tcl 94f196c9961e0ca3513e29f57125a3197808be2d F tool/mkspeedsql.tcl a1a334d288f7adfe6e996f2e712becf076745c97 -F tool/mksqlite3c-noext.tcl 9ef48e1748dce7b844f67e2450ff9dfeb0fb4ab5 +F tool/mksqlite3c-noext.tcl f8a6223bebc9e3e9dc2700484c602f159b84c8aa F tool/mksqlite3c.tcl 95ab31eda659e7ffb091e04bd83178f260d8edfd F tool/mksqlite3h.tcl ba24038056f51fde07c0079c41885ab85e2cff12 F tool/mksqlite3internalh.tcl eb994013e833359137eb53a55acdad0b5ae1049b @@ -1246,7 +1246,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 cbeb9a1aed8ce3fb569a7717ad03c7c058b68de6 -R 1df40f85f677c47017b13b63b82a97b5 -U drh -Z 408df2ac27dc537c38335d50565b918f +P 436314b5728c9413f9ac2d837e1c19364f31be72 +R 8395df004ed39c3d4f3903ab69f7e9ed +U mistachkin +Z b92e1717d71c68278e3b78541d6aeae8 diff --git a/manifest.uuid b/manifest.uuid index b639b7d8cc..4601dfd81c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -436314b5728c9413f9ac2d837e1c19364f31be72 \ No newline at end of file +83421af67063825981f6051eb415944d90e9b2f6 \ No newline at end of file diff --git a/tool/mksqlite3c-noext.tcl b/tool/mksqlite3c-noext.tcl index 27522265bb..6a2fc2feeb 100644 --- a/tool/mksqlite3c-noext.tcl +++ b/tool/mksqlite3c-noext.tcl @@ -17,13 +17,13 @@ # After the "tsrc" directory has been created and populated, run # this script: # -# tclsh mksqlite3c.tcl +# tclsh mksqlite3c-noext.tcl # # The amalgamated SQLite code will be written into sqlite3.c # # Begin by reading the "sqlite3.h" header file. Extract the version number -# from in this file. The versioon number is needed to generate the header +# from in this file. The version number is needed to generate the header # comment of the amalgamation. # if {[lsearch $argv --nostatic]>=0} { From 8de1250638a76287cd94cbe8e4f312fbe77f9dd1 Mon Sep 17 00:00:00 2001 From: mistachkin Date: Tue, 24 Mar 2015 21:52:12 +0000 Subject: [PATCH 023/181] Update the 'mksqlite3c-noext' tool as well. FossilOrigin-Name: a532256688c3a7a6385e041ec73913842e2c3ab3 --- manifest | 15 +++---- manifest.uuid | 2 +- tool/mksqlite3c-noext.tcl | 93 ++++++++++++++++++++++++++++++--------- 3 files changed, 79 insertions(+), 31 deletions(-) diff --git a/manifest b/manifest index 8a9bcb9667..8d1f543c39 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sSQLITE_STDCALL\sand\sSQLITE_CDECL\smacros\son\spublic\sfunction\sdefinitions. -D 2015-03-24T21:27:27.369 +C Update\sthe\s'mksqlite3c-noext'\stool\sas\swell. +D 2015-03-24T21:52:12.248 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -1212,7 +1212,7 @@ F tool/mkkeywordhash.c dfff09dbbfaf950e89af294f48f902181b144670 F tool/mkopts.tcl 66ac10d240cc6e86abd37dc908d50382f84ff46e F tool/mkpragmatab.tcl 94f196c9961e0ca3513e29f57125a3197808be2d F tool/mkspeedsql.tcl a1a334d288f7adfe6e996f2e712becf076745c97 -F tool/mksqlite3c-noext.tcl 9ef48e1748dce7b844f67e2450ff9dfeb0fb4ab5 +F tool/mksqlite3c-noext.tcl 46dad185f91829a25b10291b244d2440ad4a88f4 F tool/mksqlite3c.tcl ab2cfb2191f1edaea0e72b6ad3bc3f71aa61a6b9 F tool/mksqlite3h.tcl c02e391f595bf91528341ffaa53e5084d8b595ce F tool/mksqlite3internalh.tcl eb994013e833359137eb53a55acdad0b5ae1049b @@ -1246,10 +1246,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 436314b5728c9413f9ac2d837e1c19364f31be72 -R 887ef727abd3a9965cbccad906bf79e4 -T *branch * stdcall -T *sym-stdcall * -T -sym-trunk * +P 242f09d4d1c92ee9058857a5e780442f4b7bad55 +R 4e80129117aa4b372475de5cd1490c7f U mistachkin -Z cb11de2c68ebf434af7cc941e8219588 +Z 6bcda5d8184063ac5fc3f1cb05a00dcd diff --git a/manifest.uuid b/manifest.uuid index d35f197244..52602f40c4 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -242f09d4d1c92ee9058857a5e780442f4b7bad55 \ No newline at end of file +a532256688c3a7a6385e041ec73913842e2c3ab3 \ No newline at end of file diff --git a/tool/mksqlite3c-noext.tcl b/tool/mksqlite3c-noext.tcl index 27522265bb..35c14093e9 100644 --- a/tool/mksqlite3c-noext.tcl +++ b/tool/mksqlite3c-noext.tcl @@ -83,6 +83,12 @@ if {$addstatic} { #endif #ifndef SQLITE_API # define SQLITE_API +#endif +#ifndef SQLITE_CDECL +# define SQLITE_CDECL +#endif +#ifndef SQLITE_STDCALL +# define SQLITE_STDCALL #endif} } @@ -106,6 +112,7 @@ foreach hdr { pager.h parse.h pcache.h + pragma.h sqlite3ext.h sqlite3.h sqliteicu.h @@ -113,12 +120,31 @@ foreach hdr { sqliteLimit.h vdbe.h vdbeInt.h + vxworks.h wal.h + whereInt.h } { set available_hdr($hdr) 1 } set available_hdr(sqliteInt.h) 0 +# These headers should be copied into the amalgamation without modifying any +# of their function declarations or definitions. +set varonly_hdr(sqlite3.h) 1 + +# These are the functions that accept a variable number of arguments. They +# always need to use the "cdecl" calling convention even when another calling +# convention (e.g. "stcall") is being used for the rest of the library. +set cdecllist { + sqlite3_config + sqlite3_db_config + sqlite3_log + sqlite3_mprintf + sqlite3_snprintf + sqlite3_test_control + sqlite3_vtab_config +} + # 78 stars used for comment formatting. set s78 \ {*****************************************************************************} @@ -135,21 +161,21 @@ proc section_comment {text} { # Read the source file named $filename and write it into the # sqlite3.c output file. If any #include statements are seen, -# process them approprately. +# process them appropriately. # proc copy_file {filename} { - global seen_hdr available_hdr out addstatic linemacros + global seen_hdr available_hdr varonly_hdr cdecllist out addstatic linemacros set ln 0 set tail [file tail $filename] section_comment "Begin file $tail" if {$linemacros} {puts $out "#line 1 \"$filename\""} set in [open $filename r] set varpattern {^[a-zA-Z][a-zA-Z_0-9 *]+(sqlite3[_a-zA-Z0-9]+)(\[|;| =)} - set declpattern {[a-zA-Z][a-zA-Z_0-9 ]+ \**(sqlite3[_a-zA-Z0-9]+)\(} + set declpattern {([a-zA-Z][a-zA-Z_0-9 ]+ \**)(sqlite3[_a-zA-Z0-9]+)(\(.*)} if {[file extension $filename]==".h"} { set declpattern " *$declpattern" } - set declpattern ^$declpattern + set declpattern ^$declpattern\$ while {![eof $in]} { set line [gets $in] incr ln @@ -165,42 +191,67 @@ proc copy_file {filename} { if {$linemacros} {puts $out "#line [expr {$ln+1}] \"$filename\""} } } elseif {![info exists seen_hdr($hdr)]} { - set seen_hdr($hdr) 1 + if {![regexp {/\*\s+amalgamator:\s+dontcache\s+\*/} $line]} { + set seen_hdr($hdr) 1 + } + puts $out $line + } elseif {[regexp {/\*\s+amalgamator:\s+keep\s+\*/} $line]} { + # This include file must be kept because there was a "keep" + # directive inside of a line comment. puts $out $line } else { - puts $out "/* $line */" + # Comment out the entire line, replacing any nested comment + # begin/end markers with the harmless substring "**". + puts $out "/* [string map [list /* ** */ **] $line] */" } } elseif {[regexp {^#ifdef __cplusplus} $line]} { puts $out "#if 0" } elseif {!$linemacros && [regexp {^#line} $line]} { # Skip #line directives. } elseif {$addstatic && ![regexp {^(static|typedef)} $line]} { - regsub {^SQLITE_API } $line {} line - if {[regexp $declpattern $line all funcname]} { + # Skip adding the SQLITE_PRIVATE or SQLITE_API keyword before + # functions if this header file does not need it. + if {![info exists varonly_hdr($tail)] + && [regexp $declpattern $line all rettype funcname rest]} { + regsub {^SQLITE_API } $line {} line # Add the SQLITE_PRIVATE or SQLITE_API keyword before functions. # so that linkage can be modified at compile-time. if {[regexp {^sqlite3_} $funcname]} { - puts $out "SQLITE_API $line" + set line SQLITE_API + append line " " [string trim $rettype] + if {[string index $rettype end] ne "*"} { + append line " " + } + if {[lsearch -exact $cdecllist $funcname] >= 0} { + append line SQLITE_CDECL + } else { + append line SQLITE_STDCALL + } + append line " " $funcname $rest + puts $out $line } else { puts $out "SQLITE_PRIVATE $line" } } elseif {[regexp $varpattern $line all varname]} { - # Add the SQLITE_PRIVATE before variable declarations or - # definitions for internal use - if {![regexp {^sqlite3_} $varname]} { - regsub {^extern } $line {} line - puts $out "SQLITE_PRIVATE $line" - } else { - if {[regexp {const char sqlite3_version\[\];} $line]} { - set line {const char sqlite3_version[] = SQLITE_VERSION;} + # Add the SQLITE_PRIVATE before variable declarations or + # definitions for internal use + regsub {^SQLITE_API } $line {} line + if {![regexp {^sqlite3_} $varname]} { + regsub {^extern } $line {} line + puts $out "SQLITE_PRIVATE $line" + } else { + if {[regexp {const char sqlite3_version\[\];} $line]} { + set line {const char sqlite3_version[] = SQLITE_VERSION;} + } + regsub {^SQLITE_EXTERN } $line {} line + puts $out "SQLITE_API $line" } - regsub {^SQLITE_EXTERN } $line {} line - puts $out "SQLITE_API $line" - } } elseif {[regexp {^(SQLITE_EXTERN )?void \(\*sqlite3IoTrace\)} $line]} { + regsub {^SQLITE_API } $line {} line regsub {^SQLITE_EXTERN } $line {} line - puts $out "SQLITE_PRIVATE $line" + puts $out $line } elseif {[regexp {^void \(\*sqlite3Os} $line]} { + regsub {^SQLITE_API } $line {} line puts $out "SQLITE_PRIVATE $line" } else { puts $out $line From 790fa6ec30a31b3bcb3f4a15c2b98eea6c8063d4 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 24 Mar 2015 21:54:42 +0000 Subject: [PATCH 024/181] Further simplifications to the amalgamation builder. FossilOrigin-Name: e826cd7db6b3ab010533d81a759794c2470343d2 --- manifest | 20 ++++++++++---------- manifest.uuid | 2 +- src/sqlite.h.in | 11 ++++++++++- tool/mksqlite3c-noext.tcl | 9 --------- tool/mksqlite3c.tcl | 9 --------- tool/mksqlite3h.tcl | 20 +------------------- 6 files changed, 22 insertions(+), 49 deletions(-) diff --git a/manifest b/manifest index 8d1f543c39..6b34425f06 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Update\sthe\s'mksqlite3c-noext'\stool\sas\swell. -D 2015-03-24T21:52:12.248 +C Further\ssimplifications\sto\sthe\samalgamation\sbuilder. +D 2015-03-24T21:54:42.913 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -232,7 +232,7 @@ F src/resolve.c f4d79e31ffa5820c2e3d1740baa5e9b190425f2b F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e F src/select.c 72ffb62e2879956302140e9f6e6ae88aee36b0e5 F src/shell.c 3ae1e53878d2804fe77b8c8f1f6ca287a0e5d80e -F src/sqlite.h.in 82977ae32ba5f5a115d4434418087c9c1088f643 +F src/sqlite.h.in 278602140d49575e8708e643161f4263e428a02a F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h 17d487c3c91b0b8c584a32fbeb393f6f795eea7d F src/sqliteInt.h bedf15914c09bfb5fe3ec4e3f211a4a6fc42cd33 @@ -1212,9 +1212,9 @@ F tool/mkkeywordhash.c dfff09dbbfaf950e89af294f48f902181b144670 F tool/mkopts.tcl 66ac10d240cc6e86abd37dc908d50382f84ff46e F tool/mkpragmatab.tcl 94f196c9961e0ca3513e29f57125a3197808be2d F tool/mkspeedsql.tcl a1a334d288f7adfe6e996f2e712becf076745c97 -F tool/mksqlite3c-noext.tcl 46dad185f91829a25b10291b244d2440ad4a88f4 -F tool/mksqlite3c.tcl ab2cfb2191f1edaea0e72b6ad3bc3f71aa61a6b9 -F tool/mksqlite3h.tcl c02e391f595bf91528341ffaa53e5084d8b595ce +F tool/mksqlite3c-noext.tcl 274d4243bd7c8b5b280a02ec50280d73f80a9d89 +F tool/mksqlite3c.tcl 52a3352f7aa15f1db851e45ac3a5e2173d6fe93c +F tool/mksqlite3h.tcl 44730d586c9031638cdd2eb443b801c0d2dbd9f8 F tool/mksqlite3internalh.tcl eb994013e833359137eb53a55acdad0b5ae1049b F tool/mkvsix.tcl 52a4c613707ac34ae9c226e5ccc69cb948556105 F tool/offsets.c fe4262fdfa378e8f5499a42136d17bf3b98f6091 @@ -1246,7 +1246,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 242f09d4d1c92ee9058857a5e780442f4b7bad55 -R 4e80129117aa4b372475de5cd1490c7f -U mistachkin -Z 6bcda5d8184063ac5fc3f1cb05a00dcd +P a532256688c3a7a6385e041ec73913842e2c3ab3 +R 82569f0fcef6344e8c55e30ea4294bbd +U drh +Z 70d7caefbc05dc10c257a925b1d49a53 diff --git a/manifest.uuid b/manifest.uuid index 52602f40c4..ae9df8a883 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -a532256688c3a7a6385e041ec73913842e2c3ab3 \ No newline at end of file +e826cd7db6b3ab010533d81a759794c2470343d2 \ No newline at end of file diff --git a/src/sqlite.h.in b/src/sqlite.h.in index 6d2cc146dc..acc3c51404 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -43,11 +43,20 @@ extern "C" { /* -** Add the ability to override 'extern' +** Provide the ability to override linkage features of the interface. */ #ifndef SQLITE_EXTERN # define SQLITE_EXTERN extern #endif +#ifndef SQLITE_API +# define SQLITE_API +#endif +#ifndef SQLITE_CDECL +# define SQLITE_CDECL +#endif +#ifndef SQLITE_STDCALL +# define SQLITE_STDCALL +#endif /* ** These no-op macros are used in front of interfaces to mark those diff --git a/tool/mksqlite3c-noext.tcl b/tool/mksqlite3c-noext.tcl index 35c14093e9..24462fc29e 100644 --- a/tool/mksqlite3c-noext.tcl +++ b/tool/mksqlite3c-noext.tcl @@ -80,15 +80,6 @@ if {$addstatic} { puts $out \ {#ifndef SQLITE_PRIVATE # define SQLITE_PRIVATE static -#endif -#ifndef SQLITE_API -# define SQLITE_API -#endif -#ifndef SQLITE_CDECL -# define SQLITE_CDECL -#endif -#ifndef SQLITE_STDCALL -# define SQLITE_STDCALL #endif} } diff --git a/tool/mksqlite3c.tcl b/tool/mksqlite3c.tcl index b33eef8f1a..136155089c 100644 --- a/tool/mksqlite3c.tcl +++ b/tool/mksqlite3c.tcl @@ -80,15 +80,6 @@ if {$addstatic} { puts $out \ {#ifndef SQLITE_PRIVATE # define SQLITE_PRIVATE static -#endif -#ifndef SQLITE_API -# define SQLITE_API -#endif -#ifndef SQLITE_CDECL -# define SQLITE_CDECL -#endif -#ifndef SQLITE_STDCALL -# define SQLITE_STDCALL #endif} } diff --git a/tool/mksqlite3h.tcl b/tool/mksqlite3h.tcl index 9ed74c3f4b..cabce1f50b 100644 --- a/tool/mksqlite3h.tcl +++ b/tool/mksqlite3h.tcl @@ -102,25 +102,7 @@ foreach file $filelist { regsub -- --VERS-- $line $zVersion line regsub -- --VERSION-NUMBER-- $line $nVersion line regsub -- --SOURCE-ID-- $line "$zDate $zUuid" line - - if {[regexp {define SQLITE_EXTERN extern} $line]} { - puts $line - puts [gets $in] - puts "" - puts "#ifndef SQLITE_API" - puts "# define SQLITE_API" - puts "#endif" - puts "" - puts "#ifndef SQLITE_CDECL" - puts "# define SQLITE_CDECL" - puts "#endif" - puts "" - puts "#ifndef SQLITE_STDCALL" - puts "# define SQLITE_STDCALL" - puts "#endif" - set line "" - } - + if {[regexp $varpattern $line] && ![regexp {^ *typedef} $line]} { set line "SQLITE_API $line" } else { From f94c9485ef21dd1bd48c869374846e66231ba576 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 25 Mar 2015 12:05:49 +0000 Subject: [PATCH 025/181] Add two new assert()s to the sqlite3BtreeDataSize() method. FossilOrigin-Name: 42d1793d6516e285a8925bbfd96b3d3375603d15 --- manifest | 15 +++++++-------- manifest.uuid | 2 +- src/btree.c | 2 ++ 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 384fa980e4..e78289f594 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sSQLITE_STDCALL\sand\sSQLITE_CDECL\smacros\son\spublic\sfunction\sdefinitions. -D 2015-03-24T22:00:26.504 +C Add\stwo\snew\sassert()s\sto\sthe\ssqlite3BtreeDataSize()\smethod. +D 2015-03-25T12:05:49.756 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -173,7 +173,7 @@ F src/auth.c b56c78ebe40a2110fd361379f7e8162d23f92240 F src/backup.c ff743689c4d6c5cb55ad42ed9d174b2b3e71f1e3 F src/bitvec.c 19a4ba637bd85f8f63fc8c9bae5ade9fb05ec1cb F src/btmutex.c 45a968cc85afed9b5e6cf55bf1f42f8d18107f79 -F src/btree.c 3e320cac836546c905bd90007074d887980aa70e +F src/btree.c 8d92800add6e237c883b286845d8159911acdf54 F src/btree.h 969adc948e89e449220ff0ff724c94bb2a52e9f1 F src/btreeInt.h 2bfefc01875d8da066504c233ec259fcb3b2ef72 F src/build.c 0419bba592c22f6d00e6d57a2ca7136720d02c1a @@ -1246,8 +1246,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 83421af67063825981f6051eb415944d90e9b2f6 e826cd7db6b3ab010533d81a759794c2470343d2 -R 00893342a7c77a3a3db8feef49e96714 -T +closed e826cd7db6b3ab010533d81a759794c2470343d2 -U mistachkin -Z 1978375717c0fca1b1a377840034ad4e +P cae3239aa58b4f7016fc9dcac3966fe6ef833879 +R 9d1846f3cd769389c238477907eb38ab +U drh +Z 681e7b9df0d47c3c796413431bb9a3b2 diff --git a/manifest.uuid b/manifest.uuid index 53bd3257f9..484d3c2181 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -cae3239aa58b4f7016fc9dcac3966fe6ef833879 \ No newline at end of file +42d1793d6516e285a8925bbfd96b3d3375603d15 \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index ac0c877317..1e0e57fe2e 100644 --- a/src/btree.c +++ b/src/btree.c @@ -4031,6 +4031,8 @@ int sqlite3BtreeKeySize(BtCursor *pCur, i64 *pSize){ int sqlite3BtreeDataSize(BtCursor *pCur, u32 *pSize){ assert( cursorHoldsMutex(pCur) ); assert( pCur->eState==CURSOR_VALID ); + assert( pCur->iPage>=0 ); + assert( pCur->iPageapPage[pCur->iPage]->intKeyLeaf==1 ); getCellInfo(pCur); *pSize = pCur->info.nPayload; From cbd3349ab956b3d0eb028ba2344caa3e772daaf2 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 25 Mar 2015 13:06:54 +0000 Subject: [PATCH 026/181] Reactivate an older assert() (adding an "|| CORRUPT_DB" term) and add a new assert() in btree.c. FossilOrigin-Name: 1e96520ac1d12ca83f019a60482efa0a074f2f94 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/btree.c | 13 ++++--------- 3 files changed, 11 insertions(+), 16 deletions(-) diff --git a/manifest b/manifest index e78289f594..a0f706c635 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\stwo\snew\sassert()s\sto\sthe\ssqlite3BtreeDataSize()\smethod. -D 2015-03-25T12:05:49.756 +C Reactivate\san\solder\sassert()\s(adding\san\s"||\sCORRUPT_DB"\sterm)\sand\sadd\sa\nnew\sassert()\sin\sbtree.c. +D 2015-03-25T13:06:54.837 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -173,7 +173,7 @@ F src/auth.c b56c78ebe40a2110fd361379f7e8162d23f92240 F src/backup.c ff743689c4d6c5cb55ad42ed9d174b2b3e71f1e3 F src/bitvec.c 19a4ba637bd85f8f63fc8c9bae5ade9fb05ec1cb F src/btmutex.c 45a968cc85afed9b5e6cf55bf1f42f8d18107f79 -F src/btree.c 8d92800add6e237c883b286845d8159911acdf54 +F src/btree.c 3634c2ee748bbbb2488cdca9dc8fc8c7bdc2f66f F src/btree.h 969adc948e89e449220ff0ff724c94bb2a52e9f1 F src/btreeInt.h 2bfefc01875d8da066504c233ec259fcb3b2ef72 F src/build.c 0419bba592c22f6d00e6d57a2ca7136720d02c1a @@ -1246,7 +1246,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 cae3239aa58b4f7016fc9dcac3966fe6ef833879 -R 9d1846f3cd769389c238477907eb38ab +P 42d1793d6516e285a8925bbfd96b3d3375603d15 +R 90535e28cf02760b75aa0324ce2f944c U drh -Z 681e7b9df0d47c3c796413431bb9a3b2 +Z 7ee968129b9c07925188972da6333faa diff --git a/manifest.uuid b/manifest.uuid index 484d3c2181..d4bfb47acf 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -42d1793d6516e285a8925bbfd96b3d3375603d15 \ No newline at end of file +1e96520ac1d12ca83f019a60482efa0a074f2f94 \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index 1e0e57fe2e..ac350ac92f 100644 --- a/src/btree.c +++ b/src/btree.c @@ -4511,7 +4511,7 @@ static int moveToChild(BtCursor *pCur, u32 newPgno){ return SQLITE_OK; } -#if 0 +#if SQLITE_DEBUG /* ** Page pParent is an internal (non-leaf) tree page. This function ** asserts that page number iChild is the left-child if the iIdx'th @@ -4520,6 +4520,8 @@ static int moveToChild(BtCursor *pCur, u32 newPgno){ ** the page. */ static void assertParentIndex(MemPage *pParent, int iIdx, Pgno iChild){ + if( CORRUPT_DB ) return; /* The conditions tested below might not be true + ** in a corrupt database */ assert( iIdx<=pParent->nCell ); if( iIdx==pParent->nCell ){ assert( get4byte(&pParent->aData[pParent->hdrOffset+8])==iChild ); @@ -4544,19 +4546,11 @@ static void moveToParent(BtCursor *pCur){ assert( pCur->eState==CURSOR_VALID ); assert( pCur->iPage>0 ); assert( pCur->apPage[pCur->iPage] ); - - /* UPDATE: It is actually possible for the condition tested by the assert - ** below to be untrue if the database file is corrupt. This can occur if - ** one cursor has modified page pParent while a reference to it is held - ** by a second cursor. Which can only happen if a single page is linked - ** into more than one b-tree structure in a corrupt database. */ -#if 0 assertParentIndex( pCur->apPage[pCur->iPage-1], pCur->aiIdx[pCur->iPage-1], pCur->apPage[pCur->iPage]->pgno ); -#endif testcase( pCur->aiIdx[pCur->iPage-1] > pCur->apPage[pCur->iPage-1]->nCell ); releasePage(pCur->apPage[pCur->iPage]); @@ -7504,6 +7498,7 @@ static int balance(BtCursor *pCur){ /* The next iteration of the do-loop balances the parent page. */ releasePage(pPage); pCur->iPage--; + assert( pCur->iPage>=0 ); } }while( rc==SQLITE_OK ); From d2f83139f3774c61f545095c813a28a859320b39 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 25 Mar 2015 17:35:01 +0000 Subject: [PATCH 027/181] Fix the saveCursorPosition() routine in btree.c so that it works correctly for a eState=CURSOR_SKIPNEXT cursor. FossilOrigin-Name: 37866b4d483296ab9b7fcb9f5486695d4c2b8ddd --- manifest | 13 ++++++------ manifest.uuid | 2 +- src/btree.c | 17 +++++++++++----- test/btree02.test | 52 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 72 insertions(+), 12 deletions(-) create mode 100644 test/btree02.test diff --git a/manifest b/manifest index a0f706c635..48427f05a3 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Reactivate\san\solder\sassert()\s(adding\san\s"||\sCORRUPT_DB"\sterm)\sand\sadd\sa\nnew\sassert()\sin\sbtree.c. -D 2015-03-25T13:06:54.837 +C Fix\sthe\ssaveCursorPosition()\sroutine\sin\sbtree.c\sso\sthat\sit\sworks\ncorrectly\sfor\sa\seState=CURSOR_SKIPNEXT\scursor. +D 2015-03-25T17:35:01.825 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -173,7 +173,7 @@ F src/auth.c b56c78ebe40a2110fd361379f7e8162d23f92240 F src/backup.c ff743689c4d6c5cb55ad42ed9d174b2b3e71f1e3 F src/bitvec.c 19a4ba637bd85f8f63fc8c9bae5ade9fb05ec1cb F src/btmutex.c 45a968cc85afed9b5e6cf55bf1f42f8d18107f79 -F src/btree.c 3634c2ee748bbbb2488cdca9dc8fc8c7bdc2f66f +F src/btree.c 933ab4ad883546193f5fd55f840299165adb8069 F src/btree.h 969adc948e89e449220ff0ff724c94bb2a52e9f1 F src/btreeInt.h 2bfefc01875d8da066504c233ec259fcb3b2ef72 F src/build.c 0419bba592c22f6d00e6d57a2ca7136720d02c1a @@ -384,6 +384,7 @@ F test/boundary3.test 56ef82096b4329aca2be74fa1e2b0f762ea0eb45 F test/boundary4.tcl 0bb4b1a94f4fc5ae59b79b9a2b7a140c405e2983 F test/boundary4.test 89e02fa66397b8a325d5eb102b5806f961f8ec4b F test/btree01.test e08b3613540145b353f20c81cb18ead54ff12e0f +F test/btree02.test fe69453d474d8154d19b904157ff1db4812fed99 F test/btreefault.test c2bcb542685eea44621275cfedbd8a13f65201e3 F test/busy.test 76b4887f8b9160ba903c1ac22e8ff406ad6ae2f0 F test/cache.test 13bc046b26210471ca6f2889aceb1ea52dc717de @@ -1246,7 +1247,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 42d1793d6516e285a8925bbfd96b3d3375603d15 -R 90535e28cf02760b75aa0324ce2f944c +P 1e96520ac1d12ca83f019a60482efa0a074f2f94 +R 0d2b32f8ac05ffe0443a79d106bd4efe U drh -Z 7ee968129b9c07925188972da6333faa +Z 2f58ba8b67469927a3c7d533210b0ef3 diff --git a/manifest.uuid b/manifest.uuid index d4bfb47acf..90856bf9ee 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -1e96520ac1d12ca83f019a60482efa0a074f2f94 \ No newline at end of file +37866b4d483296ab9b7fcb9f5486695d4c2b8ddd \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index ac350ac92f..dd10f6a09a 100644 --- a/src/btree.c +++ b/src/btree.c @@ -600,10 +600,15 @@ static void btreeReleaseAllCursorPages(BtCursor *pCur){ static int saveCursorPosition(BtCursor *pCur){ int rc; - assert( CURSOR_VALID==pCur->eState ); + assert( CURSOR_VALID==pCur->eState || CURSOR_SKIPNEXT==pCur->eState ); assert( 0==pCur->pKey ); assert( cursorHoldsMutex(pCur) ); + if( pCur->eState==CURSOR_SKIPNEXT ){ + pCur->eState = CURSOR_VALID; + }else{ + pCur->skipNext = 0; + } rc = sqlite3BtreeKeySize(pCur, &pCur->nKey); assert( rc==SQLITE_OK ); /* KeySize() cannot fail */ @@ -674,7 +679,7 @@ static int SQLITE_NOINLINE saveCursorsOnList( ){ do{ if( p!=pExcept && (0==iRoot || p->pgnoRoot==iRoot) ){ - if( p->eState==CURSOR_VALID ){ + if( p->eState==CURSOR_VALID || p->eState==CURSOR_SKIPNEXT ){ int rc = saveCursorPosition(p); if( SQLITE_OK!=rc ){ return rc; @@ -746,17 +751,19 @@ static int btreeMoveto( */ static int btreeRestoreCursorPosition(BtCursor *pCur){ int rc; + int skipNext; assert( cursorHoldsMutex(pCur) ); assert( pCur->eState>=CURSOR_REQUIRESEEK ); if( pCur->eState==CURSOR_FAULT ){ return pCur->skipNext; } pCur->eState = CURSOR_INVALID; - rc = btreeMoveto(pCur, pCur->pKey, pCur->nKey, 0, &pCur->skipNext); + rc = btreeMoveto(pCur, pCur->pKey, pCur->nKey, 0, &skipNext); if( rc==SQLITE_OK ){ sqlite3_free(pCur->pKey); pCur->pKey = 0; assert( pCur->eState==CURSOR_VALID || pCur->eState==CURSOR_INVALID ); + pCur->skipNext |= skipNext; if( pCur->skipNext && pCur->eState==CURSOR_VALID ){ pCur->eState = CURSOR_SKIPNEXT; } @@ -808,7 +815,7 @@ int sqlite3BtreeCursorRestore(BtCursor *pCur, int *pDifferentRow){ *pDifferentRow = 1; return rc; } - if( pCur->eState!=CURSOR_VALID || NEVER(pCur->skipNext!=0) ){ + if( pCur->eState!=CURSOR_VALID || pCur->skipNext!=0 ){ *pDifferentRow = 1; }else{ *pDifferentRow = 0; @@ -3625,7 +3632,7 @@ int sqlite3BtreeTripAllCursors(Btree *pBtree, int errCode, int writeOnly){ for(p=pBtree->pBt->pCursor; p; p=p->pNext){ int i; if( writeOnly && (p->curFlags & BTCF_WriteFlag)==0 ){ - if( p->eState==CURSOR_VALID ){ + if( p->eState==CURSOR_VALID || p->eState==CURSOR_SKIPNEXT ){ rc = saveCursorPosition(p); if( rc!=SQLITE_OK ){ (void)sqlite3BtreeTripAllCursors(pBtree, rc, 0); diff --git a/test/btree02.test b/test/btree02.test new file mode 100644 index 0000000000..de7c06d442 --- /dev/null +++ b/test/btree02.test @@ -0,0 +1,52 @@ +# 2015-03-25 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# +# The focus of this script is making multiple calls to saveCursorPosition() +# and restoreCursorPosition() when cursors have eState==CURSOR_SKIPNEXT +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +load_static_extension db eval +do_execsql_test btree02-100 { + CREATE TABLE t1(a TEXT, ax INTEGER, b INT, PRIMARY KEY(a,ax)) WITHOUT ROWID; + WITH RECURSIVE c(i) AS (VALUES(1) UNION ALL SELECT i+1 FROM c WHERE i<10) + INSERT INTO t1(a,ax,b) SELECT printf('%02x',i), random(), i FROM c; + CREATE INDEX t1a ON t1(a); + CREATE TABLE t2(x,y); + CREATE TABLE t3(cnt); + WITH RECURSIVE c(i) AS (VALUES(1) UNION ALL SELECT i+1 FROM c WHERE i<4) + INSERT INTO t3(cnt) SELECT i FROM c; + SELECT count(*) FROM t1; +} {10} +do_test btree02-110 { + db eval BEGIN + set i 0 + db eval {SELECT a, ax, b, cnt FROM t1 CROSS JOIN t3 WHERE b IS NOT NULL} { + db eval {INSERT INTO t2(x,y) VALUES($b,$cnt)} + # puts "a,b,cnt = ($a,$b,$cnt)" + incr i + if {$i%2==1} { + set bx [expr {$b+1000}] + # puts "INSERT ($a),$bx" + db eval {INSERT INTO t1(a,ax,b) VALUES(printf('(%s)',$a),random(),$bx)} + } else { + # puts "DELETE a=$a" + db eval {DELETE FROM t1 WHERE a=$a} + } + db eval {COMMIT; BEGIN} + } + db one {COMMIT; SELECT count(*) FROM t1;} +} {20} + +finish_test From 606a357288884b2666948fe518948f96fdab2b3d Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 25 Mar 2015 18:29:10 +0000 Subject: [PATCH 028/181] Change an unreachable branch into an assert(). FossilOrigin-Name: fb076b28c36975ff2e41440f22fe5de115c195da --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/btree.c | 3 ++- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 48427f05a3..6fdfb0ad40 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sthe\ssaveCursorPosition()\sroutine\sin\sbtree.c\sso\sthat\sit\sworks\ncorrectly\sfor\sa\seState=CURSOR_SKIPNEXT\scursor. -D 2015-03-25T17:35:01.825 +C Change\san\sunreachable\sbranch\sinto\san\sassert(). +D 2015-03-25T18:29:10.982 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -173,7 +173,7 @@ F src/auth.c b56c78ebe40a2110fd361379f7e8162d23f92240 F src/backup.c ff743689c4d6c5cb55ad42ed9d174b2b3e71f1e3 F src/bitvec.c 19a4ba637bd85f8f63fc8c9bae5ade9fb05ec1cb F src/btmutex.c 45a968cc85afed9b5e6cf55bf1f42f8d18107f79 -F src/btree.c 933ab4ad883546193f5fd55f840299165adb8069 +F src/btree.c 4f305e554d7d207375c3e29ab0335bd5a473a125 F src/btree.h 969adc948e89e449220ff0ff724c94bb2a52e9f1 F src/btreeInt.h 2bfefc01875d8da066504c233ec259fcb3b2ef72 F src/build.c 0419bba592c22f6d00e6d57a2ca7136720d02c1a @@ -1247,7 +1247,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 1e96520ac1d12ca83f019a60482efa0a074f2f94 -R 0d2b32f8ac05ffe0443a79d106bd4efe +P 37866b4d483296ab9b7fcb9f5486695d4c2b8ddd +R 6f3611ab9d4988693f727ae20dc9c9e5 U drh -Z 2f58ba8b67469927a3c7d533210b0ef3 +Z 3f028f44e21ab0b1619e9687cba7cf7a diff --git a/manifest.uuid b/manifest.uuid index 90856bf9ee..849f782137 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -37866b4d483296ab9b7fcb9f5486695d4c2b8ddd \ No newline at end of file +fb076b28c36975ff2e41440f22fe5de115c195da \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index dd10f6a09a..52f29428f7 100644 --- a/src/btree.c +++ b/src/btree.c @@ -815,9 +815,10 @@ int sqlite3BtreeCursorRestore(BtCursor *pCur, int *pDifferentRow){ *pDifferentRow = 1; return rc; } - if( pCur->eState!=CURSOR_VALID || pCur->skipNext!=0 ){ + if( pCur->eState!=CURSOR_VALID ){ *pDifferentRow = 1; }else{ + assert( pCur->skipNext==0 ); *pDifferentRow = 0; } return SQLITE_OK; From 57a140946f6f7508e64d91b5ae8671f3cab073a0 Mon Sep 17 00:00:00 2001 From: dan Date: Thu, 26 Mar 2015 11:55:03 +0000 Subject: [PATCH 029/181] Optimize cases where all the sorter is sorting a set of records that all begin with integer values, or that all begin with text values to be compared using BINARY. FossilOrigin-Name: ce5ad17c25cf2f8274ce304c51e4421faae0b32b --- manifest | 17 ++++++++++------- manifest.uuid | 2 +- src/vdbesort.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 59 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index 6fdfb0ad40..65ccebc2d0 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Change\san\sunreachable\sbranch\sinto\san\sassert(). -D 2015-03-25T18:29:10.982 +C Optimize\scases\swhere\sall\sthe\ssorter\sis\ssorting\sa\sset\sof\srecords\sthat\sall\sbegin\swith\sinteger\svalues,\sor\sthat\sall\sbegin\swith\stext\svalues\sto\sbe\scompared\susing\sBINARY. +D 2015-03-26T11:55:03.488 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -300,7 +300,7 @@ F src/vdbeapi.c 583d56b129dd27f12bed518270de9ebe521e6a75 F src/vdbeaux.c 413dc496248ac18eb0c19e35e86bb1ffd47b8907 F src/vdbeblob.c 4f2e8e075d238392df98c5e03a64342465b03f90 F src/vdbemem.c c0dc81285b7571b0a31c40f17846fe2397ec1cd9 -F src/vdbesort.c 919717d7599fa31d343ec28bffd0f9e91a4ff5f6 +F src/vdbesort.c a8d82ed4b09f3b1f5390c7546a9bcad72d483abf F src/vdbetrace.c 7e4222955e07dd707a2f360c0eb73452be1cb010 F src/vtab.c 62d49237bd8f3be4863815a39387b0f9897fa5e1 F src/vxworks.h c18586c8edc1bddbc15c004fa16aeb1e1342b4fb @@ -1247,7 +1247,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 37866b4d483296ab9b7fcb9f5486695d4c2b8ddd -R 6f3611ab9d4988693f727ae20dc9c9e5 -U drh -Z 3f028f44e21ab0b1619e9687cba7cf7a +P fb076b28c36975ff2e41440f22fe5de115c195da +R 1e1c6c1ab8dfb515d00c85e16ae436f0 +T *branch * sorter-opt +T *sym-sorter-opt * +T -sym-trunk * +U dan +Z 9752268c90db4ae1847219cb63314e99 diff --git a/manifest.uuid b/manifest.uuid index 849f782137..dfa9f94353 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -fb076b28c36975ff2e41440f22fe5de115c195da \ No newline at end of file +ce5ad17c25cf2f8274ce304c51e4421faae0b32b \ No newline at end of file diff --git a/src/vdbesort.c b/src/vdbesort.c index bbdafa8230..4faeebf963 100644 --- a/src/vdbesort.c +++ b/src/vdbesort.c @@ -298,6 +298,7 @@ struct SortSubtask { UnpackedRecord *pUnpacked; /* Space to unpack a record */ SorterList list; /* List for thread to write to a PMA */ int nPMA; /* Number of PMAs currently in file */ + RecordCompare xCompare; /* Compare function to use */ SorterFile file; /* Temp file for level-0 PMAs */ SorterFile file2; /* Space for other PMAs */ }; @@ -328,9 +329,13 @@ struct VdbeSorter { u8 bUseThreads; /* True to use background threads */ u8 iPrev; /* Previous thread used to flush PMA */ u8 nTask; /* Size of aTask[] array */ + u8 typeMask; SortSubtask aTask[1]; /* One or more subtasks */ }; +#define SORTER_TYPE_INTEGER 0x01 +#define SORTER_TYPE_TEXT 0x02 + /* ** An instance of the following object is used to read records out of a ** PMA, in sorted order. The next key to be read is cached in nKey/aKey. @@ -765,7 +770,7 @@ static int vdbeSorterCompare( if( pKey2 ){ sqlite3VdbeRecordUnpack(pTask->pSorter->pKeyInfo, nKey2, pKey2, r2); } - return sqlite3VdbeRecordCompare(nKey1, pKey1, r2); + return pTask->xCompare(nKey1, pKey1, r2); } /* @@ -835,9 +840,13 @@ int sqlite3VdbeSorterInit( pSorter->pKeyInfo = pKeyInfo = (KeyInfo*)((u8*)pSorter + sz); memcpy(pKeyInfo, pCsr->pKeyInfo, szKeyInfo); pKeyInfo->db = 0; - if( nField && nWorker==0 ) pKeyInfo->nField = nField; + if( nField && nWorker==0 ){ + pKeyInfo->nXField += (pKeyInfo->nField - nField); + pKeyInfo->nField = nField; + } pSorter->pgsz = pgsz = sqlite3BtreeGetPageSize(db->aDb[0].pBt); pSorter->nTask = nWorker + 1; + pSorter->iPrev = nWorker-1; pSorter->bUseThreads = (pSorter->nTask>1); pSorter->db = db; for(i=0; inTask; i++){ @@ -863,6 +872,10 @@ int sqlite3VdbeSorterInit( if( !pSorter->list.aMemory ) rc = SQLITE_NOMEM; } } + + if( (pKeyInfo->nField+pKeyInfo->nXField)<13 && pKeyInfo->aColl[0]==0 ){ + pSorter->typeMask = SORTER_TYPE_INTEGER | SORTER_TYPE_TEXT; + } } return rc; @@ -1182,6 +1195,13 @@ static int vdbeSortAllocUnpacked(SortSubtask *pTask){ if( pFree==0 ) return SQLITE_NOMEM; pTask->pUnpacked->nField = pTask->pSorter->pKeyInfo->nField; pTask->pUnpacked->errCode = 0; + if( pTask->pSorter->pKeyInfo->aSortOrder[0] ){ + pTask->pUnpacked->r1 = 1; + pTask->pUnpacked->r2 = -1; + }else{ + pTask->pUnpacked->r1 = -1; + pTask->pUnpacked->r2 = 1; + } } return SQLITE_OK; } @@ -1235,12 +1255,20 @@ static int vdbeSorterSort(SortSubtask *pTask, SorterList *pList){ rc = vdbeSortAllocUnpacked(pTask); if( rc!=SQLITE_OK ) return rc; + p = pList->pList; + if( pTask->pSorter->typeMask==0 ){ + pTask->xCompare = sqlite3VdbeRecordCompare; + }else{ + UnpackedRecord *pRec = pTask->pUnpacked; + sqlite3VdbeRecordUnpack(pTask->pSorter->pKeyInfo, p->nVal, SRVAL(p), pRec); + pTask->xCompare = sqlite3VdbeFindCompare(pRec); + } + aSlot = (SorterRecord **)sqlite3MallocZero(64 * sizeof(SorterRecord *)); if( !aSlot ){ return SQLITE_NOMEM; } - p = pList->pList; while( p ){ SorterRecord *pNext; if( pList->aMemory ){ @@ -1602,6 +1630,16 @@ int sqlite3VdbeSorterWrite( int bFlush; /* True to flush contents of memory to PMA */ int nReq; /* Bytes of memory required */ int nPMA; /* Bytes of PMA space required */ + int t; /* serial type of first record field */ + + getVarint32((const u8*)&pVal->z[1], t); + if( t>0 && t<10 && t!=7 ){ + pSorter->typeMask &= SORTER_TYPE_INTEGER; + }else if( t & 0x01 ){ + pSorter->typeMask &= SORTER_TYPE_TEXT; + }else{ + pSorter->typeMask = 0; + } assert( pSorter ); @@ -2288,6 +2326,13 @@ static int vdbeSorterSetupMerge(VdbeSorter *pSorter){ MergeEngine *pMain = 0; #if SQLITE_MAX_WORKER_THREADS sqlite3 *db = pTask0->pSorter->db; + RecordCompare xCompare = (pSorter->typeMask==0 ? + sqlite3VdbeRecordCompare : pSorter->aTask[0].xCompare + ); + int i; + for(i=0; inTask; i++){ + pSorter->aTask[i].xCompare = xCompare; + } #endif rc = vdbeSorterMergeTreeBuild(pSorter, &pMain); From f3e874868356277074833bb2e0f97ed5c689e58d Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 26 Mar 2015 14:29:51 +0000 Subject: [PATCH 030/181] Fix a harmless compiler warning in FTS3. FossilOrigin-Name: 1688f60c08cc9270948402d98a2333382aa32681 --- ext/fts3/fts3.c | 2 +- manifest | 12 ++++++------ manifest.uuid | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/ext/fts3/fts3.c b/ext/fts3/fts3.c index c92463204c..46b499e96b 100644 --- a/ext/fts3/fts3.c +++ b/ext/fts3/fts3.c @@ -1108,7 +1108,7 @@ static int fts3InitVtab( const char **aCol; /* Array of column names */ sqlite3_tokenizer *pTokenizer = 0; /* Tokenizer for this table */ - int nIndex; /* Size of aIndex[] array */ + int nIndex = 0; /* Size of aIndex[] array */ struct Fts3Index *aIndex = 0; /* Array of indexes for this table */ /* The results of parsing supported FTS4 key=value options: */ diff --git a/manifest b/manifest index 6fdfb0ad40..c1312f1107 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Change\san\sunreachable\sbranch\sinto\san\sassert(). -D 2015-03-25T18:29:10.982 +C Fix\sa\sharmless\scompiler\swarning\sin\sFTS3. +D 2015-03-26T14:29:51.209 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -78,7 +78,7 @@ F ext/fts3/README.content fdc666a70d5257a64fee209f97cf89e0e6e32b51 F ext/fts3/README.syntax a19711dc5458c20734b8e485e75fb1981ec2427a F ext/fts3/README.tokenizers e0a8b81383ea60d0334d274fadf305ea14a8c314 F ext/fts3/README.txt 8c18f41574404623b76917b9da66fcb0ab38328d -F ext/fts3/fts3.c 2a1cf23133d0c75ce296d17440c44115f8413ec7 +F ext/fts3/fts3.c d3f6f0e95d366f3c2028d916c36a0844bf805840 F ext/fts3/fts3.h 3a10a0af180d502cecc50df77b1b22df142817fe F ext/fts3/fts3Int.h 394858c12a17740f7a1f6bd372c4606d4425a8d1 F ext/fts3/fts3_aux.c 5c211e17a64885faeb16b9ba7772f9d5445c2365 @@ -1247,7 +1247,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 37866b4d483296ab9b7fcb9f5486695d4c2b8ddd -R 6f3611ab9d4988693f727ae20dc9c9e5 +P fb076b28c36975ff2e41440f22fe5de115c195da +R 8441601541e00ddcb253d7949a1f1256 U drh -Z 3f028f44e21ab0b1619e9687cba7cf7a +Z efb1de4d37ca897d2a6769bd7d529518 diff --git a/manifest.uuid b/manifest.uuid index 849f782137..5d911793d5 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -fb076b28c36975ff2e41440f22fe5de115c195da \ No newline at end of file +1688f60c08cc9270948402d98a2333382aa32681 \ No newline at end of file From 21aa6a1acbdd445284f4126178dff4ab078ac7db Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 26 Mar 2015 15:27:32 +0000 Subject: [PATCH 031/181] Provide source code line numbers for errors in the Windows VFS generated by the winLogIoerr() routine. FossilOrigin-Name: b5da0d93cd1a3c0917399af3775a32327b883c8e --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/os_win.c | 16 ++++++++-------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/manifest b/manifest index c1312f1107..d6bf4d8b95 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sharmless\scompiler\swarning\sin\sFTS3. -D 2015-03-26T14:29:51.209 +C Provide\ssource\scode\sline\snumbers\sfor\serrors\sin\sthe\sWindows\sVFS\sgenerated\nby\sthe\swinLogIoerr()\sroutine. +D 2015-03-26T15:27:32.905 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -215,7 +215,7 @@ F src/os.h 3e57a24e2794a94d3cf2342c6d9a884888cd96bf F src/os_common.h 92815ed65f805560b66166e3583470ff94478f04 F src/os_setup.h c9d4553b5aaa6f73391448b265b89bed0b890faa F src/os_unix.c a4dadbc2da41599e99093e91e276c38c17a73b89 -F src/os_win.c 8223e7db5b7c4a81d8b161098ac3959400434cdb +F src/os_win.c f65255fdc30c90bab195989776797e98dc89d709 F src/os_win.h eb7a47aa17b26b77eb97e4823f20a00b8bda12ca F src/pager.c 4120a49ecd37697e28f5ed807f470b9c0b88410c F src/pager.h c3476e7c89cdf1c6914e50a11f3714e30b4e0a77 @@ -1247,7 +1247,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 fb076b28c36975ff2e41440f22fe5de115c195da -R 8441601541e00ddcb253d7949a1f1256 +P 1688f60c08cc9270948402d98a2333382aa32681 +R 24f2e5bf8513d160bb9262017e93ddbd U drh -Z efb1de4d37ca897d2a6769bd7d529518 +Z d3e192564f0add8f7dcb502142bd9b66 diff --git a/manifest.uuid b/manifest.uuid index 5d911793d5..fb109a572d 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -1688f60c08cc9270948402d98a2333382aa32681 \ No newline at end of file +b5da0d93cd1a3c0917399af3775a32327b883c8e \ No newline at end of file diff --git a/src/os_win.c b/src/os_win.c index 7463778a2f..7a95b77a58 100644 --- a/src/os_win.c +++ b/src/os_win.c @@ -1966,11 +1966,11 @@ static int winRetryIoerr(int *pnRetry, DWORD *pError){ /* ** Log a I/O error retry episode. */ -static void winLogIoerr(int nRetry){ +static void winLogIoerr(int nRetry, int lineno){ if( nRetry ){ sqlite3_log(SQLITE_IOERR, - "delayed %dms for lock/sharing conflict", - winIoerrRetryDelay*nRetry*(nRetry+1)/2 + "delayed %dms for lock/sharing conflict at line %d", + winIoerrRetryDelay*nRetry*(nRetry+1)/2, lineno ); } } @@ -2548,7 +2548,7 @@ static int winRead( return winLogError(SQLITE_IOERR_READ, pFile->lastErrno, "winRead", pFile->zPath); } - winLogIoerr(nRetry); + winLogIoerr(nRetry, __LINE__); if( nRead<(DWORD)amt ){ /* Unread parts of the buffer must be zero-filled */ memset(&((char*)pBuf)[nRead], 0, amt-nRead); @@ -2659,7 +2659,7 @@ static int winWrite( return winLogError(SQLITE_IOERR_WRITE, pFile->lastErrno, "winWrite2", pFile->zPath); }else{ - winLogIoerr(nRetry); + winLogIoerr(nRetry, __LINE__); } OSTRACE(("WRITE file=%p, rc=SQLITE_OK\n", pFile->h)); return SQLITE_OK; @@ -4752,7 +4752,7 @@ static int winOpen( } } #endif - winLogIoerr(cnt); + winLogIoerr(cnt, __LINE__); OSTRACE(("OPEN file=%p, name=%s, access=%lx, rc=%s\n", h, zUtf8Name, dwDesiredAccess, (h==INVALID_HANDLE_VALUE) ? "failed" : "ok")); @@ -4936,7 +4936,7 @@ static int winDelete( if( rc && rc!=SQLITE_IOERR_DELETE_NOENT ){ rc = winLogError(SQLITE_IOERR_DELETE, lastErrno, "winDelete", zFilename); }else{ - winLogIoerr(cnt); + winLogIoerr(cnt, __LINE__); } sqlite3_free(zConverted); OSTRACE(("DELETE name=%s, rc=%s\n", zFilename, sqlite3ErrName(rc))); @@ -4986,7 +4986,7 @@ static int winAccess( attr = sAttrData.dwFileAttributes; } }else{ - winLogIoerr(cnt); + winLogIoerr(cnt, __LINE__); if( lastErrno!=ERROR_FILE_NOT_FOUND && lastErrno!=ERROR_PATH_NOT_FOUND ){ sqlite3_free(zConverted); return winLogError(SQLITE_IOERR_ACCESS, lastErrno, "winAccess", From 592f0cb15e44e69577d1f72b4586093ca48ea7e6 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 26 Mar 2015 17:04:23 +0000 Subject: [PATCH 032/181] Avoid leaving the malloc subsystem in a partially initialized state if the low-level initialization callback fails. FossilOrigin-Name: 3e872011ff5e27738c282f46d2b5803d94fe4b76 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/malloc.c | 5 ++++- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index d6bf4d8b95..2e013a57eb 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Provide\ssource\scode\sline\snumbers\sfor\serrors\sin\sthe\sWindows\sVFS\sgenerated\nby\sthe\swinLogIoerr()\sroutine. -D 2015-03-26T15:27:32.905 +C Avoid\sleaving\sthe\smalloc\ssubsystem\sin\sa\spartially\sinitialized\sstate\sif\nthe\slow-level\sinitialization\scallback\sfails. +D 2015-03-26T17:04:23.798 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -196,7 +196,7 @@ F src/legacy.c ba1863ea58c4c840335a84ec276fc2b25e22bc4e F src/lempar.c 7274c97d24bb46631e504332ccd3bd1b37841770 F src/loadext.c 86bd4e2fccd520b748cba52492ab60c4a770f660 F src/main.c 569d45ba9eb4fbdd631d53f440bcdb4a35ab1505 -F src/malloc.c e818a0db9ac0898f9dc74002f3a5baca32232d05 +F src/malloc.c 6a370b83d54e4bbf6f94021221c2a311cff26a18 F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645 F src/mem1.c abe6ee469b6c5a35c7f22bfeb9c9bac664a1c987 F src/mem2.c f1940d9e91948dd6a908fbb9ce3835c36b5d83c3 @@ -1247,7 +1247,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 1688f60c08cc9270948402d98a2333382aa32681 -R 24f2e5bf8513d160bb9262017e93ddbd +P b5da0d93cd1a3c0917399af3775a32327b883c8e +R 9e8f7450055b4cee99317e6c8db6583a U drh -Z d3e192564f0add8f7dcb502142bd9b66 +Z af5a15dd737e6e7d08dff92682723060 diff --git a/manifest.uuid b/manifest.uuid index fb109a572d..22f0d978f9 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -b5da0d93cd1a3c0917399af3775a32327b883c8e \ No newline at end of file +3e872011ff5e27738c282f46d2b5803d94fe4b76 \ No newline at end of file diff --git a/src/malloc.c b/src/malloc.c index 264d046ec8..f06e27d846 100644 --- a/src/malloc.c +++ b/src/malloc.c @@ -162,6 +162,7 @@ void sqlite3_soft_heap_limit(int n){ ** Initialize the memory allocation subsystem. */ int sqlite3MallocInit(void){ + int rc; if( sqlite3GlobalConfig.m.xMalloc==0 ){ sqlite3MemSetDefault(); } @@ -197,7 +198,9 @@ int sqlite3MallocInit(void){ sqlite3GlobalConfig.szPage = 0; sqlite3GlobalConfig.nPage = 0; } - return sqlite3GlobalConfig.m.xInit(sqlite3GlobalConfig.m.pAppData); + rc = sqlite3GlobalConfig.m.xInit(sqlite3GlobalConfig.m.pAppData); + if( rc!=SQLITE_OK ) memset(&mem0, 0, sizeof(mem0)); + return rc; } /* From 56d89cbee327dcd97a129d4c77f01046b20e295a Mon Sep 17 00:00:00 2001 From: mistachkin Date: Thu, 26 Mar 2015 18:24:26 +0000 Subject: [PATCH 033/181] Revise Win32 locking test to account for recent log message changes. FossilOrigin-Name: 1bc76339e8542770bff7829a3dd346680950c0a5 --- manifest | 14 +++++++------- manifest.uuid | 2 +- test/win32lock.test | 2 ++ 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 2e013a57eb..8c7cd354d7 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Avoid\sleaving\sthe\smalloc\ssubsystem\sin\sa\spartially\sinitialized\sstate\sif\nthe\slow-level\sinitialization\scallback\sfails. -D 2015-03-26T17:04:23.798 +C Revise\sWin32\slocking\stest\sto\saccount\sfor\srecent\slog\smessage\schanges. +D 2015-03-26T18:24:26.716 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -1181,7 +1181,7 @@ F test/whereK.test f8e3cf26a8513ecc7f514f54df9f0572c046c42b F test/wherelimit.test 5e9fd41e79bb2b2d588ed999d641d9c965619b31 F test/wild001.test bca33f499866f04c24510d74baf1e578d4e44b1c F test/win32heap.test ea19770974795cff26e11575e12d422dbd16893c -F test/win32lock.test 71642fa56e9b06e5cfffe6bad67cb8c1eb2c555a +F test/win32lock.test fbf107c91d8f5512be5a5b87c4c42ab9fdd54972 F test/win32longpath.test 169c75a3b2e43481f4a62122510210c67b08f26d F test/with1.test 9df5cd8a62148b3d9ef8597aea563e3863018bcd F test/with2.test ee227a663586aa09771cafd4fa269c5217eaf775 @@ -1247,7 +1247,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 b5da0d93cd1a3c0917399af3775a32327b883c8e -R 9e8f7450055b4cee99317e6c8db6583a -U drh -Z af5a15dd737e6e7d08dff92682723060 +P 3e872011ff5e27738c282f46d2b5803d94fe4b76 +R 72196f1f01590aeab1e66e07214515fd +U mistachkin +Z 13c90271975eca10437167897808ec14 diff --git a/manifest.uuid b/manifest.uuid index 22f0d978f9..1084c3d448 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -3e872011ff5e27738c282f46d2b5803d94fe4b76 \ No newline at end of file +1bc76339e8542770bff7829a3dd346680950c0a5 \ No newline at end of file diff --git a/test/win32lock.test b/test/win32lock.test index cff1ed3d87..d1f3d1a06e 100644 --- a/test/win32lock.test +++ b/test/win32lock.test @@ -64,6 +64,7 @@ while {1} { if {[info exists ::log] && $::log!=""} { do_test win32lock-1.2-$delay1-log1 { regsub {\d+} $::log # x + regsub { at line \d+} $x "" x set x } {{delayed #ms for lock/sharing conflict}} } @@ -112,6 +113,7 @@ while {1} { if {[info exists ::log] && $::log!=""} { do_test win32lock-2.2-$delay1-log1 { regsub {\d+} $::log # x + regsub { at line \d+} $x "" x set x } {{delayed #ms for lock/sharing conflict}} } From ccb43714da0768fc44aa666208236505e5703f53 Mon Sep 17 00:00:00 2001 From: mistachkin Date: Thu, 26 Mar 2015 23:36:35 +0000 Subject: [PATCH 034/181] When syncing a memory mapped file on Windows, flush the mapped view as well. FossilOrigin-Name: df204049b9ec8dd3e43ed7dc251eaecedc05af4b --- manifest | 15 +++++++++------ manifest.uuid | 2 +- src/os_win.c | 47 +++++++++++++++++++++++++++++++++++++++-------- 3 files changed, 49 insertions(+), 15 deletions(-) diff --git a/manifest b/manifest index 8c7cd354d7..8ca2cb9aa2 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Revise\sWin32\slocking\stest\sto\saccount\sfor\srecent\slog\smessage\schanges. -D 2015-03-26T18:24:26.716 +C When\ssyncing\sa\smemory\smapped\sfile\son\sWindows,\sflush\sthe\smapped\sview\sas\swell. +D 2015-03-26T23:36:35.332 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -215,7 +215,7 @@ F src/os.h 3e57a24e2794a94d3cf2342c6d9a884888cd96bf F src/os_common.h 92815ed65f805560b66166e3583470ff94478f04 F src/os_setup.h c9d4553b5aaa6f73391448b265b89bed0b890faa F src/os_unix.c a4dadbc2da41599e99093e91e276c38c17a73b89 -F src/os_win.c f65255fdc30c90bab195989776797e98dc89d709 +F src/os_win.c af359cc1f0acc6b091c971ef0cf77c1280048cd3 F src/os_win.h eb7a47aa17b26b77eb97e4823f20a00b8bda12ca F src/pager.c 4120a49ecd37697e28f5ed807f470b9c0b88410c F src/pager.h c3476e7c89cdf1c6914e50a11f3714e30b4e0a77 @@ -1247,7 +1247,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 3e872011ff5e27738c282f46d2b5803d94fe4b76 -R 72196f1f01590aeab1e66e07214515fd +P 1bc76339e8542770bff7829a3dd346680950c0a5 +R 8fcf9359fa4528c262f390ec8d494656 +T *branch * winViewFlush +T *sym-winViewFlush * +T -sym-trunk * U mistachkin -Z 13c90271975eca10437167897808ec14 +Z 96541edc57aab968aa95035dbba0935a diff --git a/manifest.uuid b/manifest.uuid index 1084c3d448..e3897a191f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -1bc76339e8542770bff7829a3dd346680950c0a5 \ No newline at end of file +df204049b9ec8dd3e43ed7dc251eaecedc05af4b \ No newline at end of file diff --git a/src/os_win.c b/src/os_win.c index 7a95b77a58..3fd310fc17 100644 --- a/src/os_win.c +++ b/src/os_win.c @@ -197,8 +197,10 @@ WINBASEAPI LPVOID WINAPI MapViewOfFile(HANDLE, DWORD, DWORD, DWORD, SIZE_T); #endif /* SQLITE_OS_WINRT */ /* -** This file mapping API is common to both Win32 and WinRT. +** These file mapping APIs are common to both Win32 and WinRT. */ + +WINBASEAPI BOOL WINAPI FlushViewOfFile(LPCVOID, SIZE_T); WINBASEAPI BOOL WINAPI UnmapViewOfFile(LPCVOID); #endif /* SQLITE_WIN32_FILEMAPPING_API */ @@ -1083,6 +1085,15 @@ static struct win_syscall { #define osUuidCreateSequential \ ((RPC_STATUS(RPC_ENTRY*)(UUID*))aSyscall[78].pCurrent) +#if !defined(SQLITE_NO_SYNC) && SQLITE_MAX_MMAP_SIZE>0 + { "FlushViewOfFile", (SYSCALL)FlushViewOfFile, 0 }, +#else + { "FlushViewOfFile", (SYSCALL)0, 0 }, +#endif + +#define osFlushViewOfFile \ + ((BOOL(WINAPI*)(LPCVOID,SIZE_T))aSyscall[79].pCurrent) + }; /* End of the overrideable system calls */ /* @@ -2753,8 +2764,9 @@ static int winSync(sqlite3_file *id, int flags){ */ SimulateDiskfullError( return SQLITE_FULL ); - OSTRACE(("SYNC file=%p, flags=%x, lock=%d\n", - pFile->h, flags, pFile->locktype)); + OSTRACE(("SYNC pid=%lu, pFile=%p, file=%p, flags=%x, lock=%d\n", + osGetCurrentProcessId(), pFile, pFile->h, flags, + pFile->locktype)); #ifndef SQLITE_TEST UNUSED_PARAMETER(flags); @@ -2769,19 +2781,38 @@ static int winSync(sqlite3_file *id, int flags){ ** no-op */ #ifdef SQLITE_NO_SYNC - OSTRACE(("SYNC-NOP file=%p, rc=SQLITE_OK\n", pFile->h)); + OSTRACE(("SYNC-NOP pid=%lu, pFile=%p, file=%p, rc=SQLITE_OK\n", + osGetCurrentProcessId(), pFile, pFile->h)); return SQLITE_OK; #else +#if SQLITE_MAX_MMAP_SIZE>0 + if( pFile->pMapRegion ){ + if( osFlushViewOfFile(pFile->pMapRegion, 0) ){ + OSTRACE(("SYNC-MMAP pid=%lu, pFile=%p, pMapRegion=%p, " + "rc=SQLITE_OK\n", osGetCurrentProcessId(), + pFile, pFile->pMapRegion)); + }else{ + pFile->lastErrno = osGetLastError(); + OSTRACE(("SYNC-MMAP pid=%lu, pFile=%p, pMapRegion=%p, " + "rc=SQLITE_IOERR_MMAP\n", osGetCurrentProcessId(), + pFile, pFile->pMapRegion)); + return winLogError(SQLITE_IOERR_MMAP, pFile->lastErrno, + "winSync1", pFile->zPath); + } + } +#endif rc = osFlushFileBuffers(pFile->h); SimulateIOError( rc=FALSE ); if( rc ){ - OSTRACE(("SYNC file=%p, rc=SQLITE_OK\n", pFile->h)); + OSTRACE(("SYNC pid=%lu, pFile=%p, file=%p, rc=SQLITE_OK\n", + osGetCurrentProcessId(), pFile, pFile->h)); return SQLITE_OK; }else{ pFile->lastErrno = osGetLastError(); - OSTRACE(("SYNC file=%p, rc=SQLITE_IOERR_FSYNC\n", pFile->h)); + OSTRACE(("SYNC pid=%lu, pFile=%p, file=%p, rc=SQLITE_IOERR_FSYNC\n", + osGetCurrentProcessId(), pFile, pFile->h)); return winLogError(SQLITE_IOERR_FSYNC, pFile->lastErrno, - "winSync", pFile->zPath); + "winSync2", pFile->zPath); } #endif } @@ -5555,7 +5586,7 @@ int sqlite3_os_init(void){ /* Double-check that the aSyscall[] array has been constructed ** correctly. See ticket [bb3a86e890c8e96ab] */ - assert( ArraySize(aSyscall)==79 ); + assert( ArraySize(aSyscall)==80 ); /* get memory map allocation granularity */ memset(&winSysInfo, 0, sizeof(SYSTEM_INFO)); From 34a8065f495147ace8564548a97c91579d0b7028 Mon Sep 17 00:00:00 2001 From: mistachkin Date: Fri, 27 Mar 2015 00:19:31 +0000 Subject: [PATCH 035/181] In the MSVC Makefile, make the DYNAMIC_SHELL option work without USE_STDCALL. FossilOrigin-Name: 25b46a9c7e03a84bee2ffddc6d7fd6ae280e9d7b --- Makefile.msc | 6 +++--- manifest | 12 ++++++------ manifest.uuid | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Makefile.msc b/Makefile.msc index 837fc003c0..7e6a077ffb 100644 --- a/Makefile.msc +++ b/Makefile.msc @@ -331,7 +331,7 @@ SHELL_CCONV_OPTS = # These are additional compiler options used for the core library. # !IFNDEF CORE_COMPILE_OPTS -!IF $(USE_STDCALL)!=0 +!IF $(DYNAMIC_SHELL)!=0 CORE_COMPILE_OPTS = $(CORE_CCONV_OPTS) -DSQLITE_API=__declspec(dllexport) !ELSE CORE_COMPILE_OPTS = $(CORE_CCONV_OPTS) @@ -342,7 +342,7 @@ CORE_COMPILE_OPTS = $(CORE_CCONV_OPTS) # when linking. # !IFNDEF CORE_LINK_DEP -!IF $(USE_STDCALL)!=0 +!IF $(DYNAMIC_SHELL)!=0 CORE_LINK_DEP = !ELSE CORE_LINK_DEP = sqlite3.def @@ -352,7 +352,7 @@ CORE_LINK_DEP = sqlite3.def # These are additional linker options used for the core library. # !IFNDEF CORE_LINK_OPTS -!IF $(USE_STDCALL)!=0 +!IF $(DYNAMIC_SHELL)!=0 CORE_LINK_OPTS = !ELSE CORE_LINK_OPTS = /DEF:sqlite3.def diff --git a/manifest b/manifest index 8c7cd354d7..f180feac72 100644 --- a/manifest +++ b/manifest @@ -1,9 +1,9 @@ -C Revise\sWin32\slocking\stest\sto\saccount\sfor\srecent\slog\smessage\schanges. -D 2015-03-26T18:24:26.716 +C In\sthe\sMSVC\sMakefile,\smake\sthe\sDYNAMIC_SHELL\soption\swork\swithout\sUSE_STDCALL. +D 2015-03-27T00:19:31.300 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 -F Makefile.msc 3481e2dd260968742c715542db178c2bdd5db99f +F Makefile.msc 23e6eaa84569829c3e7f409513caa136e5bcaf2a F Makefile.vxworks e1b65dea203f054e71653415bd8f96dcaed47858 F README.md d58e3bebc0a4145e0f2a87994015fdb575a8e866 F VERSION 319eb1ced4b4d17a67730f2b7b85f15c1346cb60 @@ -1247,7 +1247,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 3e872011ff5e27738c282f46d2b5803d94fe4b76 -R 72196f1f01590aeab1e66e07214515fd +P 1bc76339e8542770bff7829a3dd346680950c0a5 +R 0d57eafd4468edd6e6285fb5978d1b4c U mistachkin -Z 13c90271975eca10437167897808ec14 +Z 9f68da42d0682346a204d1bd4bb0b359 diff --git a/manifest.uuid b/manifest.uuid index 1084c3d448..44cdf4be9e 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -1bc76339e8542770bff7829a3dd346680950c0a5 \ No newline at end of file +25b46a9c7e03a84bee2ffddc6d7fd6ae280e9d7b \ No newline at end of file From 9871a933c143dfe61281aaa6d8107dee7aab4650 Mon Sep 17 00:00:00 2001 From: mistachkin Date: Fri, 27 Mar 2015 00:21:52 +0000 Subject: [PATCH 036/181] Using MSVC, get the sqlite3IoTrace variable working with the USE_STDCALL and/or DYNAMIC_SHELL options. FossilOrigin-Name: fe976c9130f6eecfa0a10347ee3f800f32051b89 --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/main.c | 2 +- src/shell.c | 4 ++-- src/sqliteInt.h | 2 +- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/manifest b/manifest index f180feac72..3a717ccebb 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C In\sthe\sMSVC\sMakefile,\smake\sthe\sDYNAMIC_SHELL\soption\swork\swithout\sUSE_STDCALL. -D 2015-03-27T00:19:31.300 +C Using\sMSVC,\sget\sthe\ssqlite3IoTrace\svariable\sworking\swith\sthe\sUSE_STDCALL\sand/or\sDYNAMIC_SHELL\soptions. +D 2015-03-27T00:21:52.785 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -195,7 +195,7 @@ F src/journal.c b4124532212b6952f42eb2c12fa3c25701d8ba8d F src/legacy.c ba1863ea58c4c840335a84ec276fc2b25e22bc4e F src/lempar.c 7274c97d24bb46631e504332ccd3bd1b37841770 F src/loadext.c 86bd4e2fccd520b748cba52492ab60c4a770f660 -F src/main.c 569d45ba9eb4fbdd631d53f440bcdb4a35ab1505 +F src/main.c 40e333960d53f7d50ee8ce09d40431c87ea653f2 F src/malloc.c 6a370b83d54e4bbf6f94021221c2a311cff26a18 F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645 F src/mem1.c abe6ee469b6c5a35c7f22bfeb9c9bac664a1c987 @@ -231,11 +231,11 @@ F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c f4d79e31ffa5820c2e3d1740baa5e9b190425f2b F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e F src/select.c 72ffb62e2879956302140e9f6e6ae88aee36b0e5 -F src/shell.c 3ae1e53878d2804fe77b8c8f1f6ca287a0e5d80e +F src/shell.c f21e91ab78e7b681e5c3c8d7f7a5b92f5583ed7a F src/sqlite.h.in 278602140d49575e8708e643161f4263e428a02a F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h 17d487c3c91b0b8c584a32fbeb393f6f795eea7d -F src/sqliteInt.h bedf15914c09bfb5fe3ec4e3f211a4a6fc42cd33 +F src/sqliteInt.h d02d2b85cb02a38bc442cf9302ec8209baf6771d F src/sqliteLimit.h 216557999cb45f2e3578ed53ebefe228d779cb46 F src/status.c f266ad8a2892d659b74f0f50cb6a88b6e7c12179 F src/table.c e7a09215315a978057fb42c640f890160dbcc45e @@ -1247,7 +1247,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 1bc76339e8542770bff7829a3dd346680950c0a5 -R 0d57eafd4468edd6e6285fb5978d1b4c +P 25b46a9c7e03a84bee2ffddc6d7fd6ae280e9d7b +R a3ab1f66556079c5bd7cf506cd3f9f92 U mistachkin -Z 9f68da42d0682346a204d1bd4bb0b359 +Z 0ec554b2258cca84ae33b3fc6f4637d7 diff --git a/manifest.uuid b/manifest.uuid index 44cdf4be9e..88bef69794 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -25b46a9c7e03a84bee2ffddc6d7fd6ae280e9d7b \ No newline at end of file +fe976c9130f6eecfa0a10347ee3f800f32051b89 \ No newline at end of file diff --git a/src/main.c b/src/main.c index 6967131143..d9ee77fab2 100644 --- a/src/main.c +++ b/src/main.c @@ -62,7 +62,7 @@ int sqlite3_threadsafe(void){ return SQLITE_THREADSAFE; } ** I/O active are written using this function. These messages ** are intended for debugging activity only. */ -/* not-private */ void (*sqlite3IoTrace)(const char*, ...) = 0; +SQLITE_API void (SQLITE_CDECL *sqlite3IoTrace)(const char*, ...) = 0; #endif /* diff --git a/src/shell.c b/src/shell.c index b31ea16333..14ac9bc72d 100644 --- a/src/shell.c +++ b/src/shell.c @@ -370,7 +370,7 @@ static FILE *iotrace = 0; ** is written to iotrace. */ #ifdef SQLITE_ENABLE_IOTRACE -static void iotracePrintf(const char *zFormat, ...){ +static void SQLITE_CDECL iotracePrintf(const char *zFormat, ...){ va_list ap; char *z; if( iotrace==0 ) return; @@ -3144,7 +3144,7 @@ static int do_meta_command(char *zLine, ShellState *p){ #ifdef SQLITE_ENABLE_IOTRACE if( c=='i' && strncmp(azArg[0], "iotrace", n)==0 ){ - extern void (*sqlite3IoTrace)(const char*, ...); + SQLITE_API extern void (SQLITE_CDECL *sqlite3IoTrace)(const char*, ...); if( iotrace && iotrace!=stdout ) fclose(iotrace); iotrace = 0; if( nArg<2 ){ diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 9df6d1bc4e..3841c91f14 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -3803,7 +3803,7 @@ void sqlite3Put4byte(u8*, u32); #ifdef SQLITE_ENABLE_IOTRACE # define IOTRACE(A) if( sqlite3IoTrace ){ sqlite3IoTrace A; } void sqlite3VdbeIOTraceSql(Vdbe*); -SQLITE_EXTERN void (*sqlite3IoTrace)(const char*,...); +SQLITE_API SQLITE_EXTERN void (SQLITE_CDECL *sqlite3IoTrace)(const char*,...); #else # define IOTRACE(A) # define sqlite3VdbeIOTraceSql(X) From 6f5a37a4649b800203006f23dbc63b0514d49517 Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 27 Mar 2015 02:27:20 +0000 Subject: [PATCH 037/181] Fix the ".testctrl imposter" command in the command-line shell to be consistent in error reporting and results with the other .testctrl commands. FossilOrigin-Name: 0ec08ba8a0fa188146b071a489908332693ba59a --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/shell.c | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index 3a717ccebb..ddfb25e98b 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Using\sMSVC,\sget\sthe\ssqlite3IoTrace\svariable\sworking\swith\sthe\sUSE_STDCALL\sand/or\sDYNAMIC_SHELL\soptions. -D 2015-03-27T00:21:52.785 +C Fix\sthe\s".testctrl\simposter"\scommand\sin\sthe\scommand-line\sshell\sto\sbe\nconsistent\sin\serror\sreporting\sand\sresults\swith\sthe\sother\s.testctrl\ncommands. +D 2015-03-27T02:27:20.756 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -231,7 +231,7 @@ F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c f4d79e31ffa5820c2e3d1740baa5e9b190425f2b F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e F src/select.c 72ffb62e2879956302140e9f6e6ae88aee36b0e5 -F src/shell.c f21e91ab78e7b681e5c3c8d7f7a5b92f5583ed7a +F src/shell.c 84a1593bd86aaa14f4da8a8f9b16fbc239d262aa F src/sqlite.h.in 278602140d49575e8708e643161f4263e428a02a F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h 17d487c3c91b0b8c584a32fbeb393f6f795eea7d @@ -1247,7 +1247,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 25b46a9c7e03a84bee2ffddc6d7fd6ae280e9d7b -R a3ab1f66556079c5bd7cf506cd3f9f92 -U mistachkin -Z 0ec554b2258cca84ae33b3fc6f4637d7 +P fe976c9130f6eecfa0a10347ee3f800f32051b89 +R 13326ac5b127e703532d322e93f2a662 +U drh +Z b2f8062e547cfe60af29856c986c54f4 diff --git a/manifest.uuid b/manifest.uuid index 88bef69794..980d7d833a 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -fe976c9130f6eecfa0a10347ee3f800f32051b89 \ No newline at end of file +0ec08ba8a0fa188146b071a489908332693ba59a \ No newline at end of file diff --git a/src/shell.c b/src/shell.c index 14ac9bc72d..7ff3eb6cb0 100644 --- a/src/shell.c +++ b/src/shell.c @@ -3803,9 +3803,9 @@ static int do_meta_command(char *zLine, ShellState *p){ azArg[2], integerValue(azArg[3]), integerValue(azArg[4])); + fprintf(p->out, "%d (0x%08x)\n", rc, rc); }else{ - fprintf(stderr,"Usage: .testctrl initmode dbName onoff tnum\n"); - rc = 1; + fprintf(stderr,"Usage: .testctrl imposter dbName onoff tnum\n"); } break; From ad1e55e55a869106c181ab278f89cc1bd6705b19 Mon Sep 17 00:00:00 2001 From: mistachkin Date: Fri, 27 Mar 2015 18:20:25 +0000 Subject: [PATCH 038/181] Enhancements to OSTRACE usage in the Win32 VFS. FossilOrigin-Name: ab5800291e1908b5b51d912feeacf748dc9be14b --- manifest | 14 ++++++------ manifest.uuid | 2 +- src/os_win.c | 60 +++++++++++++++++++++++++++++++++------------------ 3 files changed, 47 insertions(+), 29 deletions(-) diff --git a/manifest b/manifest index ddfb25e98b..98c814021d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sthe\s".testctrl\simposter"\scommand\sin\sthe\scommand-line\sshell\sto\sbe\nconsistent\sin\serror\sreporting\sand\sresults\swith\sthe\sother\s.testctrl\ncommands. -D 2015-03-27T02:27:20.756 +C Enhancements\sto\sOSTRACE\susage\sin\sthe\sWin32\sVFS. +D 2015-03-27T18:20:25.776 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -215,7 +215,7 @@ F src/os.h 3e57a24e2794a94d3cf2342c6d9a884888cd96bf F src/os_common.h 92815ed65f805560b66166e3583470ff94478f04 F src/os_setup.h c9d4553b5aaa6f73391448b265b89bed0b890faa F src/os_unix.c a4dadbc2da41599e99093e91e276c38c17a73b89 -F src/os_win.c f65255fdc30c90bab195989776797e98dc89d709 +F src/os_win.c 865ba15878eded98bb29a97ac898f2a799dc481a F src/os_win.h eb7a47aa17b26b77eb97e4823f20a00b8bda12ca F src/pager.c 4120a49ecd37697e28f5ed807f470b9c0b88410c F src/pager.h c3476e7c89cdf1c6914e50a11f3714e30b4e0a77 @@ -1247,7 +1247,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 fe976c9130f6eecfa0a10347ee3f800f32051b89 -R 13326ac5b127e703532d322e93f2a662 -U drh -Z b2f8062e547cfe60af29856c986c54f4 +P 0ec08ba8a0fa188146b071a489908332693ba59a +R 5fa56a67857aa9aa0bfe9c8eabbd7f2b +U mistachkin +Z 22e64f81a05ea0084d0b656c0478e6e9 diff --git a/manifest.uuid b/manifest.uuid index 980d7d833a..50a77b66aa 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -0ec08ba8a0fa188146b071a489908332693ba59a \ No newline at end of file +ab5800291e1908b5b51d912feeacf748dc9be14b \ No newline at end of file diff --git a/src/os_win.c b/src/os_win.c index 7a95b77a58..e40114000d 100644 --- a/src/os_win.c +++ b/src/os_win.c @@ -2450,7 +2450,8 @@ static int winClose(sqlite3_file *id){ assert( pFile->pShm==0 ); #endif assert( pFile->h!=NULL && pFile->h!=INVALID_HANDLE_VALUE ); - OSTRACE(("CLOSE file=%p\n", pFile->h)); + OSTRACE(("CLOSE pid=%lu, pFile=%p, file=%p\n", + osGetCurrentProcessId(), pFile, pFile->h)); #if SQLITE_MAX_MMAP_SIZE>0 winUnmapfile(pFile); @@ -2479,7 +2480,8 @@ static int winClose(sqlite3_file *id){ pFile->h = NULL; } OpenCounter(-1); - OSTRACE(("CLOSE file=%p, rc=%s\n", pFile->h, rc ? "ok" : "failed")); + OSTRACE(("CLOSE pid=%lu, pFile=%p, file=%p, rc=%s\n", + osGetCurrentProcessId(), pFile, pFile->h, rc ? "ok" : "failed")); return rc ? SQLITE_OK : winLogError(SQLITE_IOERR_CLOSE, osGetLastError(), "winClose", pFile->zPath); @@ -2507,7 +2509,8 @@ static int winRead( assert( amt>0 ); assert( offset>=0 ); SimulateIOError(return SQLITE_IOERR_READ); - OSTRACE(("READ file=%p, buffer=%p, amount=%d, offset=%lld, lock=%d\n", + OSTRACE(("READ pid=%lu, pFile=%p, file=%p, buffer=%p, amount=%d, " + "offset=%lld, lock=%d\n", osGetCurrentProcessId(), pFile, pFile->h, pBuf, amt, offset, pFile->locktype)); #if SQLITE_MAX_MMAP_SIZE>0 @@ -2516,7 +2519,8 @@ static int winRead( if( offsetmmapSize ){ if( offset+amt <= pFile->mmapSize ){ memcpy(pBuf, &((u8 *)(pFile->pMapRegion))[offset], amt); - OSTRACE(("READ-MMAP file=%p, rc=SQLITE_OK\n", pFile->h)); + OSTRACE(("READ-MMAP pid=%lu, pFile=%p, file=%p, rc=SQLITE_OK\n", + osGetCurrentProcessId(), pFile, pFile->h)); return SQLITE_OK; }else{ int nCopy = (int)(pFile->mmapSize - offset); @@ -2530,7 +2534,8 @@ static int winRead( #if SQLITE_OS_WINCE || defined(SQLITE_WIN32_NO_OVERLAPPED) if( winSeekFile(pFile, offset) ){ - OSTRACE(("READ file=%p, rc=SQLITE_FULL\n", pFile->h)); + OSTRACE(("READ pid=%lu, pFile=%p, file=%p, rc=SQLITE_FULL\n", + osGetCurrentProcessId(), pFile, pFile->h)); return SQLITE_FULL; } while( !osReadFile(pFile->h, pBuf, amt, &nRead, 0) ){ @@ -2544,7 +2549,8 @@ static int winRead( DWORD lastErrno; if( winRetryIoerr(&nRetry, &lastErrno) ) continue; pFile->lastErrno = lastErrno; - OSTRACE(("READ file=%p, rc=SQLITE_IOERR_READ\n", pFile->h)); + OSTRACE(("READ pid=%lu, pFile=%p, file=%p, rc=SQLITE_IOERR_READ\n", + osGetCurrentProcessId(), pFile, pFile->h)); return winLogError(SQLITE_IOERR_READ, pFile->lastErrno, "winRead", pFile->zPath); } @@ -2552,11 +2558,13 @@ static int winRead( if( nRead<(DWORD)amt ){ /* Unread parts of the buffer must be zero-filled */ memset(&((char*)pBuf)[nRead], 0, amt-nRead); - OSTRACE(("READ file=%p, rc=SQLITE_IOERR_SHORT_READ\n", pFile->h)); + OSTRACE(("READ pid=%lu, pFile=%p, file=%p, rc=SQLITE_IOERR_SHORT_READ\n", + osGetCurrentProcessId(), pFile, pFile->h)); return SQLITE_IOERR_SHORT_READ; } - OSTRACE(("READ file=%p, rc=SQLITE_OK\n", pFile->h)); + OSTRACE(("READ pid=%lu, pFile=%p, file=%p, rc=SQLITE_OK\n", + osGetCurrentProcessId(), pFile, pFile->h)); return SQLITE_OK; } @@ -2579,7 +2587,8 @@ static int winWrite( SimulateIOError(return SQLITE_IOERR_WRITE); SimulateDiskfullError(return SQLITE_FULL); - OSTRACE(("WRITE file=%p, buffer=%p, amount=%d, offset=%lld, lock=%d\n", + OSTRACE(("WRITE pid=%lu, pFile=%p, file=%p, buffer=%p, amount=%d, " + "offset=%lld, lock=%d\n", osGetCurrentProcessId(), pFile, pFile->h, pBuf, amt, offset, pFile->locktype)); #if SQLITE_MAX_MMAP_SIZE>0 @@ -2588,7 +2597,8 @@ static int winWrite( if( offsetmmapSize ){ if( offset+amt <= pFile->mmapSize ){ memcpy(&((u8 *)(pFile->pMapRegion))[offset], pBuf, amt); - OSTRACE(("WRITE-MMAP file=%p, rc=SQLITE_OK\n", pFile->h)); + OSTRACE(("WRITE-MMAP pid=%lu, pFile=%p, file=%p, rc=SQLITE_OK\n", + osGetCurrentProcessId(), pFile, pFile->h)); return SQLITE_OK; }else{ int nCopy = (int)(pFile->mmapSize - offset); @@ -2651,17 +2661,20 @@ static int winWrite( if( rc ){ if( ( pFile->lastErrno==ERROR_HANDLE_DISK_FULL ) || ( pFile->lastErrno==ERROR_DISK_FULL )){ - OSTRACE(("WRITE file=%p, rc=SQLITE_FULL\n", pFile->h)); + OSTRACE(("WRITE pid=%lu, pFile=%p, file=%p, rc=SQLITE_FULL\n", + osGetCurrentProcessId(), pFile, pFile->h)); return winLogError(SQLITE_FULL, pFile->lastErrno, "winWrite1", pFile->zPath); } - OSTRACE(("WRITE file=%p, rc=SQLITE_IOERR_WRITE\n", pFile->h)); + OSTRACE(("WRITE pid=%lu, pFile=%p, file=%p, rc=SQLITE_IOERR_WRITE\n", + osGetCurrentProcessId(), pFile, pFile->h)); return winLogError(SQLITE_IOERR_WRITE, pFile->lastErrno, "winWrite2", pFile->zPath); }else{ winLogIoerr(nRetry, __LINE__); } - OSTRACE(("WRITE file=%p, rc=SQLITE_OK\n", pFile->h)); + OSTRACE(("WRITE pid=%lu, pFile=%p, file=%p, rc=SQLITE_OK\n", + osGetCurrentProcessId(), pFile, pFile->h)); return SQLITE_OK; } @@ -2675,8 +2688,8 @@ static int winTruncate(sqlite3_file *id, sqlite3_int64 nByte){ assert( pFile ); SimulateIOError(return SQLITE_IOERR_TRUNCATE); - OSTRACE(("TRUNCATE file=%p, size=%lld, lock=%d\n", - pFile->h, nByte, pFile->locktype)); + OSTRACE(("TRUNCATE pid=%lu, pFile=%p, file=%p, size=%lld, lock=%d\n", + osGetCurrentProcessId(), pFile, pFile->h, nByte, pFile->locktype)); /* If the user has configured a chunk-size for this file, truncate the ** file so that it consists of an integer number of chunks (i.e. the @@ -2708,7 +2721,8 @@ static int winTruncate(sqlite3_file *id, sqlite3_int64 nByte){ } #endif - OSTRACE(("TRUNCATE file=%p, rc=%s\n", pFile->h, sqlite3ErrName(rc))); + OSTRACE(("TRUNCATE pid=%lu, pFile=%p, file=%p, rc=%s\n", + osGetCurrentProcessId(), pFile, pFile->h, sqlite3ErrName(rc))); return rc; } @@ -2753,8 +2767,9 @@ static int winSync(sqlite3_file *id, int flags){ */ SimulateDiskfullError( return SQLITE_FULL ); - OSTRACE(("SYNC file=%p, flags=%x, lock=%d\n", - pFile->h, flags, pFile->locktype)); + OSTRACE(("SYNC pid=%lu, pFile=%p, file=%p, flags=%x, lock=%d\n", + osGetCurrentProcessId(), pFile, pFile->h, flags, + pFile->locktype)); #ifndef SQLITE_TEST UNUSED_PARAMETER(flags); @@ -2769,17 +2784,20 @@ static int winSync(sqlite3_file *id, int flags){ ** no-op */ #ifdef SQLITE_NO_SYNC - OSTRACE(("SYNC-NOP file=%p, rc=SQLITE_OK\n", pFile->h)); + OSTRACE(("SYNC-NOP pid=%lu, pFile=%p, file=%p, rc=SQLITE_OK\n", + osGetCurrentProcessId(), pFile, pFile->h)); return SQLITE_OK; #else rc = osFlushFileBuffers(pFile->h); SimulateIOError( rc=FALSE ); if( rc ){ - OSTRACE(("SYNC file=%p, rc=SQLITE_OK\n", pFile->h)); + OSTRACE(("SYNC pid=%lu, pFile=%p, file=%p, rc=SQLITE_OK\n", + osGetCurrentProcessId(), pFile, pFile->h)); return SQLITE_OK; }else{ pFile->lastErrno = osGetLastError(); - OSTRACE(("SYNC file=%p, rc=SQLITE_IOERR_FSYNC\n", pFile->h)); + OSTRACE(("SYNC pid=%lu, pFile=%p, file=%p, rc=SQLITE_IOERR_FSYNC\n", + osGetCurrentProcessId(), pFile, pFile->h)); return winLogError(SQLITE_IOERR_FSYNC, pFile->lastErrno, "winSync", pFile->zPath); } From a9d9111c4aa590e197878515c7a9de526ef6feb9 Mon Sep 17 00:00:00 2001 From: dan Date: Sat, 28 Mar 2015 19:56:41 +0000 Subject: [PATCH 039/181] Further optimizations for sorting records that begin with integer or text values. FossilOrigin-Name: 24fe9f25d64ee516633fed1ae7ebc21554aa69ca --- manifest | 15 ++-- manifest.uuid | 2 +- src/vdbesort.c | 187 ++++++++++++++++++++++++++++++++++++++++--------- 3 files changed, 159 insertions(+), 45 deletions(-) diff --git a/manifest b/manifest index 65ccebc2d0..aba8fb17d1 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Optimize\scases\swhere\sall\sthe\ssorter\sis\ssorting\sa\sset\sof\srecords\sthat\sall\sbegin\swith\sinteger\svalues,\sor\sthat\sall\sbegin\swith\stext\svalues\sto\sbe\scompared\susing\sBINARY. -D 2015-03-26T11:55:03.488 +C Further\soptimizations\sfor\ssorting\srecords\sthat\sbegin\swith\sinteger\sor\stext\svalues. +D 2015-03-28T19:56:41.373 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -300,7 +300,7 @@ F src/vdbeapi.c 583d56b129dd27f12bed518270de9ebe521e6a75 F src/vdbeaux.c 413dc496248ac18eb0c19e35e86bb1ffd47b8907 F src/vdbeblob.c 4f2e8e075d238392df98c5e03a64342465b03f90 F src/vdbemem.c c0dc81285b7571b0a31c40f17846fe2397ec1cd9 -F src/vdbesort.c a8d82ed4b09f3b1f5390c7546a9bcad72d483abf +F src/vdbesort.c b3d16bbd66ff8d26b42670a8aa5dfda0e0d2e45e F src/vdbetrace.c 7e4222955e07dd707a2f360c0eb73452be1cb010 F src/vtab.c 62d49237bd8f3be4863815a39387b0f9897fa5e1 F src/vxworks.h c18586c8edc1bddbc15c004fa16aeb1e1342b4fb @@ -1247,10 +1247,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 fb076b28c36975ff2e41440f22fe5de115c195da -R 1e1c6c1ab8dfb515d00c85e16ae436f0 -T *branch * sorter-opt -T *sym-sorter-opt * -T -sym-trunk * +P ce5ad17c25cf2f8274ce304c51e4421faae0b32b +R 5a4cff4b803c75214d0e7f89bc9331f1 U dan -Z 9752268c90db4ae1847219cb63314e99 +Z 8e7d5cc07144236ce8ed9e6cb6b634d0 diff --git a/manifest.uuid b/manifest.uuid index dfa9f94353..1d45093594 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ce5ad17c25cf2f8274ce304c51e4421faae0b32b \ No newline at end of file +24fe9f25d64ee516633fed1ae7ebc21554aa69ca \ No newline at end of file diff --git a/src/vdbesort.c b/src/vdbesort.c index 4faeebf963..b8ef783a06 100644 --- a/src/vdbesort.c +++ b/src/vdbesort.c @@ -291,6 +291,7 @@ struct MergeEngine { ** after the thread has finished are not dire. So we don't worry about ** memory barriers and such here. */ +typedef int (*SorterCompare)(SortSubtask*,int*,const void*,int,const void*,int); struct SortSubtask { SQLiteThread *pThread; /* Background thread, if any */ int bDone; /* Set if thread is finished but not joined */ @@ -298,11 +299,12 @@ struct SortSubtask { UnpackedRecord *pUnpacked; /* Space to unpack a record */ SorterList list; /* List for thread to write to a PMA */ int nPMA; /* Number of PMAs currently in file */ - RecordCompare xCompare; /* Compare function to use */ + SorterCompare xCompare; /* Compare function to use */ SorterFile file; /* Temp file for level-0 PMAs */ SorterFile file2; /* Space for other PMAs */ }; + /* ** Main sorter structure. A single instance of this is allocated for each ** sorter cursor created by the VDBE. @@ -747,30 +749,136 @@ static int vdbePmaReaderInit( return rc; } - /* ** Compare key1 (buffer pKey1, size nKey1 bytes) with key2 (buffer pKey2, ** size nKey2 bytes). Use (pTask->pKeyInfo) for the collation sequences ** used by the comparison. Return the result of the comparison. ** -** Before returning, object (pTask->pUnpacked) is populated with the -** unpacked version of key2. Or, if pKey2 is passed a NULL pointer, then it -** is assumed that the (pTask->pUnpacked) structure already contains the -** unpacked key to use as key2. +** If IN/OUT parameter *pbKey2Cached is true when this function is called, +** it is assumed that (pTask->pUnpacked) contains the unpacked version +** of key2. If it is false, (pTask->pUnpacked) is populated with the unpacked +** version of key2 and *pbKey2Cached set to true before returning. ** ** If an OOM error is encountered, (pTask->pUnpacked->error_rc) is set ** to SQLITE_NOMEM. */ static int vdbeSorterCompare( SortSubtask *pTask, /* Subtask context (for pKeyInfo) */ + int *pbKey2Cached, /* True if pTask->pUnpacked is pKey2 */ const void *pKey1, int nKey1, /* Left side of comparison */ const void *pKey2, int nKey2 /* Right side of comparison */ ){ UnpackedRecord *r2 = pTask->pUnpacked; - if( pKey2 ){ + if( !*pbKey2Cached ){ sqlite3VdbeRecordUnpack(pTask->pSorter->pKeyInfo, nKey2, pKey2, r2); + *pbKey2Cached = 1; } - return pTask->xCompare(nKey1, pKey1, r2); + return sqlite3VdbeRecordCompare(nKey1, pKey1, r2); +} + +/* +** A specially optimized version of vdbeSorterCompare() that assumes that +** the first field of each key is a TEXT value and that the collation +** sequence to compare them with is BINARY. +*/ +static int vdbeSorterCompareText( + SortSubtask *pTask, /* Subtask context (for pKeyInfo) */ + int *pbKey2Cached, /* True if pTask->pUnpacked is pKey2 */ + const void *pKey1, int nKey1, /* Left side of comparison */ + const void *pKey2, int nKey2 /* Right side of comparison */ +){ + const u8 * const p1 = (const u8 * const)pKey1; + const u8 * const p2 = (const u8 * const)pKey2; + const u8 * const v1 = &p1[ p1[0] ]; /* Pointer to value 1 */ + const u8 * const v2 = &p2[ p2[0] ]; /* Pointer to value 2 */ + + int n1; + int n2; + int res; + + getVarint32(&p1[1], n1); n1 = (n1 - 13) / 2; + getVarint32(&p2[1], n2); n2 = (n2 - 13) / 2; + res = memcmp(v1, v2, MIN(n1, n2)); + if( res==0 ){ + res = n1 - n2; + } + + if( res==0 ){ + if( pTask->pSorter->pKeyInfo->nField>1 ){ + res = vdbeSorterCompare(pTask, pbKey2Cached, pKey1, nKey1, pKey2, nKey2); + } + }else{ + if( pTask->pSorter->pKeyInfo->aSortOrder[0] ){ + res = res * -1; + } + } + + return res; +} + +/* +** A specially optimized version of vdbeSorterCompare() that assumes that +** the first field of each key is an INTEGER value. +*/ +static int vdbeSorterCompareInt( + SortSubtask *pTask, /* Subtask context (for pKeyInfo) */ + int *pbKey2Cached, /* True if pTask->pUnpacked is pKey2 */ + const void *pKey1, int nKey1, /* Left side of comparison */ + const void *pKey2, int nKey2 /* Right side of comparison */ +){ + const u8 * const p1 = (const u8 * const)pKey1; + const u8 * const p2 = (const u8 * const)pKey2; + const int s1 = p1[1]; /* Left hand serial type */ + const int s2 = p2[1]; /* Right hand serial type */ + const u8 * const v1 = &p1[ p1[0] ]; /* Pointer to value 1 */ + const u8 * const v2 = &p2[ p2[0] ]; /* Pointer to value 2 */ + int res; /* Return value */ + + assert( (s1>0 && s1<7) || s1==8 || s1==9 ); + assert( (s2>0 && s2<7) || s2==8 || s2==9 ); + + if( s1>7 && s2>7 ){ + res = s1 - s2; + }else{ + if( s1==s2 ){ + if( (*v1 ^ *v2) & 0x80 ){ + /* The two values have different signs */ + res = (*v1 & 0x80) ? -1 : +1; + }else{ + /* The two values have the same sign. Compare using memcmp(). */ + static const u8 aLen[] = {0, 1, 2, 3, 4, 6, 8 }; + int i; + res = 0; + for(i=0; i7 ){ + res = +1; + }else if( s1>7 ){ + res = -1; + }else{ + res = s1 - s2; + } + + if( res>0 ){ + if( *v1 & 0x80 ) res = -1; + }else if( res<0 ){ + if( *v2 & 0x80 ) res = +1; + } + } + } + + if( res==0 ){ + if( pTask->pSorter->pKeyInfo->nField>1 ){ + res = vdbeSorterCompare(pTask, pbKey2Cached, pKey1, nKey1, pKey2, nKey2); + } + }else if( pTask->pSorter->pKeyInfo->aSortOrder[0] ){ + res = res * -1; + } + + return res; } /* @@ -873,7 +981,9 @@ int sqlite3VdbeSorterInit( } } - if( (pKeyInfo->nField+pKeyInfo->nXField)<13 && pKeyInfo->aColl[0]==0 ){ + if( (pKeyInfo->nField+pKeyInfo->nXField)<13 + && (pKeyInfo->aColl[0]==0 || pKeyInfo->aColl[0]==db->pDfltColl) + ){ pSorter->typeMask = SORTER_TYPE_INTEGER | SORTER_TYPE_TEXT; } } @@ -1219,28 +1329,42 @@ static void vdbeSorterMerge( ){ SorterRecord *pFinal = 0; SorterRecord **pp = &pFinal; - void *pVal2 = p2 ? SRVAL(p2) : 0; + int bCached = 0; while( p1 && p2 ){ int res; - res = vdbeSorterCompare(pTask, SRVAL(p1), p1->nVal, pVal2, p2->nVal); + res = pTask->xCompare( + pTask, &bCached, SRVAL(p1), p1->nVal, SRVAL(p2), p2->nVal + ); + if( res<=0 ){ *pp = p1; pp = &p1->u.pNext; p1 = p1->u.pNext; - pVal2 = 0; }else{ *pp = p2; - pp = &p2->u.pNext; + pp = &p2->u.pNext; p2 = p2->u.pNext; - if( p2==0 ) break; - pVal2 = SRVAL(p2); + bCached = 0; } } *pp = p1 ? p1 : p2; *ppOut = pFinal; } +/* +** Return the SorterCompare function to compare values collected by the +** sorter object passed as the only argument. +*/ +static SorterCompare vdbeSorterGetCompare(VdbeSorter *p){ + if( p->typeMask==SORTER_TYPE_INTEGER ){ + return vdbeSorterCompareInt; + }else if( p->typeMask==SORTER_TYPE_TEXT ){ + return vdbeSorterCompareText; + } + return vdbeSorterCompare; +} + /* ** Sort the linked list of records headed at pTask->pList. Return ** SQLITE_OK if successful, or an SQLite error code (i.e. SQLITE_NOMEM) if @@ -1256,13 +1380,7 @@ static int vdbeSorterSort(SortSubtask *pTask, SorterList *pList){ if( rc!=SQLITE_OK ) return rc; p = pList->pList; - if( pTask->pSorter->typeMask==0 ){ - pTask->xCompare = sqlite3VdbeRecordCompare; - }else{ - UnpackedRecord *pRec = pTask->pUnpacked; - sqlite3VdbeRecordUnpack(pTask->pSorter->pKeyInfo, p->nVal, SRVAL(p), pRec); - pTask->xCompare = sqlite3VdbeFindCompare(pRec); - } + pTask->xCompare = vdbeSorterGetCompare(pTask->pSorter); aSlot = (SorterRecord **)sqlite3MallocZero(64 * sizeof(SorterRecord *)); if( !aSlot ){ @@ -1482,13 +1600,12 @@ static int vdbeMergeEngineStep( int i; /* Index of aTree[] to recalculate */ PmaReader *pReadr1; /* First PmaReader to compare */ PmaReader *pReadr2; /* Second PmaReader to compare */ - u8 *pKey2; /* To pReadr2->aKey, or 0 if record cached */ + int bCached = 0; /* Find the first two PmaReaders to compare. The one that was just ** advanced (iPrev) and the one next to it in the array. */ pReadr1 = &pMerger->aReadr[(iPrev & 0xFFFE)]; pReadr2 = &pMerger->aReadr[(iPrev | 0x0001)]; - pKey2 = pReadr2->aKey; for(i=(pMerger->nTree+iPrev)/2; i>0; i=i/2){ /* Compare pReadr1 and pReadr2. Store the result in variable iRes. */ @@ -1498,8 +1615,8 @@ static int vdbeMergeEngineStep( }else if( pReadr2->pFd==0 ){ iRes = -1; }else{ - iRes = vdbeSorterCompare(pTask, - pReadr1->aKey, pReadr1->nKey, pKey2, pReadr2->nKey + iRes = pTask->xCompare(pTask, &bCached, + pReadr1->aKey, pReadr1->nKey, pReadr2->aKey, pReadr2->nKey ); } @@ -1521,9 +1638,9 @@ static int vdbeMergeEngineStep( if( iRes<0 || (iRes==0 && pReadr1aTree[i] = (int)(pReadr1 - pMerger->aReadr); pReadr2 = &pMerger->aReadr[ pMerger->aTree[i ^ 0x0001] ]; - pKey2 = pReadr2->aKey; + bCached = 0; }else{ - if( pReadr1->pFd ) pKey2 = 0; + bCached = (pReadr1->pFd!=0); pMerger->aTree[i] = (int)(pReadr2 - pMerger->aReadr); pReadr1 = &pMerger->aReadr[ pMerger->aTree[i ^ 0x0001] ]; } @@ -1635,7 +1752,7 @@ int sqlite3VdbeSorterWrite( getVarint32((const u8*)&pVal->z[1], t); if( t>0 && t<10 && t!=7 ){ pSorter->typeMask &= SORTER_TYPE_INTEGER; - }else if( t & 0x01 ){ + }else if( t>10 && (t & 0x01) ){ pSorter->typeMask &= SORTER_TYPE_TEXT; }else{ pSorter->typeMask = 0; @@ -1905,10 +2022,12 @@ static void vdbeMergeEngineCompare( }else if( p2->pFd==0 ){ iRes = i1; }else{ + SortSubtask *pTask = pMerger->pTask; + int bCached = 0; int res; - assert( pMerger->pTask->pUnpacked!=0 ); /* from vdbeSortSubtaskMain() */ - res = vdbeSorterCompare( - pMerger->pTask, p1->aKey, p1->nKey, p2->aKey, p2->nKey + assert( pTask->pUnpacked!=0 ); /* from vdbeSortSubtaskMain() */ + res = pTask->xCompare( + pTask, &bCached, p1->aKey, p1->nKey, p2->aKey, p2->nKey ); if( res<=0 ){ iRes = i1; @@ -2326,10 +2445,8 @@ static int vdbeSorterSetupMerge(VdbeSorter *pSorter){ MergeEngine *pMain = 0; #if SQLITE_MAX_WORKER_THREADS sqlite3 *db = pTask0->pSorter->db; - RecordCompare xCompare = (pSorter->typeMask==0 ? - sqlite3VdbeRecordCompare : pSorter->aTask[0].xCompare - ); int i; + SorterCompare xCompare = vdbeSorterGetCompare(pSorter); for(i=0; inTask; i++){ pSorter->aTask[i].xCompare = xCompare; } From d2e1191929c9cdceebfcf46bcaf18d03ea4d47be Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 30 Mar 2015 09:58:38 +0000 Subject: [PATCH 040/181] Remove some unnecessary code from vdbesort.c. FossilOrigin-Name: b58191e91736b1d978db4127f22867dfe2302f7c --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/vdbesort.c | 7 ------- 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/manifest b/manifest index aba8fb17d1..a3ffa9b4e0 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Further\soptimizations\sfor\ssorting\srecords\sthat\sbegin\swith\sinteger\sor\stext\svalues. -D 2015-03-28T19:56:41.373 +C Remove\ssome\sunnecessary\scode\sfrom\svdbesort.c. +D 2015-03-30T09:58:38.613 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -300,7 +300,7 @@ F src/vdbeapi.c 583d56b129dd27f12bed518270de9ebe521e6a75 F src/vdbeaux.c 413dc496248ac18eb0c19e35e86bb1ffd47b8907 F src/vdbeblob.c 4f2e8e075d238392df98c5e03a64342465b03f90 F src/vdbemem.c c0dc81285b7571b0a31c40f17846fe2397ec1cd9 -F src/vdbesort.c b3d16bbd66ff8d26b42670a8aa5dfda0e0d2e45e +F src/vdbesort.c f283b28d9d1bbaf9c4467c1275ab2146ed868ec9 F src/vdbetrace.c 7e4222955e07dd707a2f360c0eb73452be1cb010 F src/vtab.c 62d49237bd8f3be4863815a39387b0f9897fa5e1 F src/vxworks.h c18586c8edc1bddbc15c004fa16aeb1e1342b4fb @@ -1247,7 +1247,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 ce5ad17c25cf2f8274ce304c51e4421faae0b32b -R 5a4cff4b803c75214d0e7f89bc9331f1 +P 24fe9f25d64ee516633fed1ae7ebc21554aa69ca +R 7cd5cef35d63d5a82a586382f49d8e50 U dan -Z 8e7d5cc07144236ce8ed9e6cb6b634d0 +Z 51fc974a93f39baea754c6fb429251e1 diff --git a/manifest.uuid b/manifest.uuid index 1d45093594..698dbf4147 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -24fe9f25d64ee516633fed1ae7ebc21554aa69ca \ No newline at end of file +b58191e91736b1d978db4127f22867dfe2302f7c \ No newline at end of file diff --git a/src/vdbesort.c b/src/vdbesort.c index b8ef783a06..b6483b9ee7 100644 --- a/src/vdbesort.c +++ b/src/vdbesort.c @@ -1305,13 +1305,6 @@ static int vdbeSortAllocUnpacked(SortSubtask *pTask){ if( pFree==0 ) return SQLITE_NOMEM; pTask->pUnpacked->nField = pTask->pSorter->pKeyInfo->nField; pTask->pUnpacked->errCode = 0; - if( pTask->pSorter->pKeyInfo->aSortOrder[0] ){ - pTask->pUnpacked->r1 = 1; - pTask->pUnpacked->r2 = -1; - }else{ - pTask->pUnpacked->r1 = -1; - pTask->pUnpacked->r2 = 1; - } } return SQLITE_OK; } From 7004f3f6a311398f00d856b359d7389b72f802de Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 30 Mar 2015 12:06:26 +0000 Subject: [PATCH 041/181] Improve performance of multi-field sorts where the first field has a low cardinality. FossilOrigin-Name: 601e7b6b8e6bfabda03b70f75094c9014e3a3c49 --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/vdbe.h | 1 + src/vdbeaux.c | 8 ++++---- src/vdbesort.c | 27 +++++++++++++++++++++++++-- 5 files changed, 39 insertions(+), 15 deletions(-) diff --git a/manifest b/manifest index a3ffa9b4e0..a7a78bf354 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Remove\ssome\sunnecessary\scode\sfrom\svdbesort.c. -D 2015-03-30T09:58:38.613 +C Improve\sperformance\sof\smulti-field\ssorts\swhere\sthe\sfirst\sfield\shas\sa\slow\scardinality. +D 2015-03-30T12:06:26.995 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -294,13 +294,13 @@ F src/utf.c fc6b889ba0779b7722634cdeaa25f1930d93820c F src/util.c 98a7627ca48ad3265b6940915a1d08355eb3fc7e F src/vacuum.c 9460b9de7b2d4e34b0d374894aa6c8a0632be8ec F src/vdbe.c bbfede5a8a6908b3ddcd55fdb0b2301288dd4754 -F src/vdbe.h 6fc69d9c5e146302c56e163cb4b31d1ee64a18c3 +F src/vdbe.h 7e538ecf47dccb307ea2d087c3ddc2dd8d70e79d F src/vdbeInt.h 9cbaa84f53ddd2d09a0cf61a94337a3a035d08a0 F src/vdbeapi.c 583d56b129dd27f12bed518270de9ebe521e6a75 -F src/vdbeaux.c 413dc496248ac18eb0c19e35e86bb1ffd47b8907 +F src/vdbeaux.c a20504ae52392459fa08402fda3f195f19d7c79d F src/vdbeblob.c 4f2e8e075d238392df98c5e03a64342465b03f90 F src/vdbemem.c c0dc81285b7571b0a31c40f17846fe2397ec1cd9 -F src/vdbesort.c f283b28d9d1bbaf9c4467c1275ab2146ed868ec9 +F src/vdbesort.c 7b3684665ea51d642b0e664fa4d0b0d08d61d80c F src/vdbetrace.c 7e4222955e07dd707a2f360c0eb73452be1cb010 F src/vtab.c 62d49237bd8f3be4863815a39387b0f9897fa5e1 F src/vxworks.h c18586c8edc1bddbc15c004fa16aeb1e1342b4fb @@ -1247,7 +1247,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 24fe9f25d64ee516633fed1ae7ebc21554aa69ca -R 7cd5cef35d63d5a82a586382f49d8e50 +P b58191e91736b1d978db4127f22867dfe2302f7c +R ce44a3d54ad53a02b61fed80311cecef U dan -Z 51fc974a93f39baea754c6fb429251e1 +Z 8753c6822202b0898d8492105ecdb751 diff --git a/manifest.uuid b/manifest.uuid index 698dbf4147..2a8f64fa3a 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -b58191e91736b1d978db4127f22867dfe2302f7c \ No newline at end of file +601e7b6b8e6bfabda03b70f75094c9014e3a3c49 \ No newline at end of file diff --git a/src/vdbe.h b/src/vdbe.h index b715241b41..bb597b68d7 100644 --- a/src/vdbe.h +++ b/src/vdbe.h @@ -213,6 +213,7 @@ int sqlite3MemCompare(const Mem*, const Mem*, const CollSeq*); void sqlite3VdbeRecordUnpack(KeyInfo*,int,const void*,UnpackedRecord*); int sqlite3VdbeRecordCompare(int,const void*,UnpackedRecord*); +int sqlite3VdbeRecordCompareWithSkip(int, const void *, UnpackedRecord *, int); UnpackedRecord *sqlite3VdbeAllocUnpackedRecord(KeyInfo *, char *, int, char **); typedef int (*RecordCompare)(int,const void*,UnpackedRecord*); diff --git a/src/vdbeaux.c b/src/vdbeaux.c index 9c5d9acca9..1c10bab0b8 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -3585,7 +3585,7 @@ static i64 vdbeRecordDecodeInt(u32 serial_type, const u8 *aKey){ ** pPKey2->errCode is set to SQLITE_NOMEM and, if it is not NULL, the ** malloc-failed flag set on database handle (pPKey2->pKeyInfo->db). */ -static int vdbeRecordCompareWithSkip( +int sqlite3VdbeRecordCompareWithSkip( int nKey1, const void *pKey1, /* Left key */ UnpackedRecord *pPKey2, /* Right key */ int bSkip /* If true, skip the first field */ @@ -3771,7 +3771,7 @@ int sqlite3VdbeRecordCompare( int nKey1, const void *pKey1, /* Left key */ UnpackedRecord *pPKey2 /* Right key */ ){ - return vdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 0); + return sqlite3VdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 0); } @@ -3859,7 +3859,7 @@ static int vdbeRecordCompareInt( }else if( pPKey2->nField>1 ){ /* The first fields of the two keys are equal. Compare the trailing ** fields. */ - res = vdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 1); + res = sqlite3VdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 1); }else{ /* The first fields of the two keys are equal and there are no trailing ** fields. Return pPKey2->default_rc in this case. */ @@ -3907,7 +3907,7 @@ static int vdbeRecordCompareString( res = nStr - pPKey2->aMem[0].n; if( res==0 ){ if( pPKey2->nField>1 ){ - res = vdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 1); + res = sqlite3VdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 1); }else{ res = pPKey2->default_rc; } diff --git a/src/vdbesort.c b/src/vdbesort.c index b6483b9ee7..547dce2e65 100644 --- a/src/vdbesort.c +++ b/src/vdbesort.c @@ -749,6 +749,25 @@ static int vdbePmaReaderInit( return rc; } +/* +** A version of vdbeSorterCompare() that assumes that it has already been +** determined that the first field of key1 is equal to the first field of +** key2. +*/ +static int vdbeSorterCompareTail( + SortSubtask *pTask, /* Subtask context (for pKeyInfo) */ + int *pbKey2Cached, /* True if pTask->pUnpacked is pKey2 */ + const void *pKey1, int nKey1, /* Left side of comparison */ + const void *pKey2, int nKey2 /* Right side of comparison */ +){ + UnpackedRecord *r2 = pTask->pUnpacked; + if( *pbKey2Cached==0 ){ + sqlite3VdbeRecordUnpack(pTask->pSorter->pKeyInfo, nKey2, pKey2, r2); + *pbKey2Cached = 1; + } + return sqlite3VdbeRecordCompareWithSkip(nKey1, pKey1, r2, 1); +} + /* ** Compare key1 (buffer pKey1, size nKey1 bytes) with key2 (buffer pKey2, ** size nKey2 bytes). Use (pTask->pKeyInfo) for the collation sequences @@ -805,7 +824,9 @@ static int vdbeSorterCompareText( if( res==0 ){ if( pTask->pSorter->pKeyInfo->nField>1 ){ - res = vdbeSorterCompare(pTask, pbKey2Cached, pKey1, nKey1, pKey2, nKey2); + res = vdbeSorterCompareTail( + pTask, pbKey2Cached, pKey1, nKey1, pKey2, nKey2 + ); } }else{ if( pTask->pSorter->pKeyInfo->aSortOrder[0] ){ @@ -872,7 +893,9 @@ static int vdbeSorterCompareInt( if( res==0 ){ if( pTask->pSorter->pKeyInfo->nField>1 ){ - res = vdbeSorterCompare(pTask, pbKey2Cached, pKey1, nKey1, pKey2, nKey2); + res = vdbeSorterCompareTail( + pTask, pbKey2Cached, pKey1, nKey1, pKey2, nKey2 + ); } }else if( pTask->pSorter->pKeyInfo->aSortOrder[0] ){ res = res * -1; From 116f0be0244e2dc92d2a54b6a994f3a080d756ac Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 30 Mar 2015 23:43:56 +0000 Subject: [PATCH 042/181] Prevent a possible infinite loop when trying to DROP a table from a corrupt database. FossilOrigin-Name: 395bb3e677a6551b06ba96fc58c393132b93d1e8 --- manifest | 15 +++++---- manifest.uuid | 2 +- src/btree.c | 7 ++-- test/corruptJ.test | 80 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 94 insertions(+), 10 deletions(-) create mode 100644 test/corruptJ.test diff --git a/manifest b/manifest index 98c814021d..830165f1d1 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Enhancements\sto\sOSTRACE\susage\sin\sthe\sWin32\sVFS. -D 2015-03-27T18:20:25.776 +C Prevent\sa\spossible\sinfinite\sloop\swhen\strying\sto\sDROP\sa\stable\sfrom\na\scorrupt\sdatabase. +D 2015-03-30T23:43:56.191 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -173,7 +173,7 @@ F src/auth.c b56c78ebe40a2110fd361379f7e8162d23f92240 F src/backup.c ff743689c4d6c5cb55ad42ed9d174b2b3e71f1e3 F src/bitvec.c 19a4ba637bd85f8f63fc8c9bae5ade9fb05ec1cb F src/btmutex.c 45a968cc85afed9b5e6cf55bf1f42f8d18107f79 -F src/btree.c 4f305e554d7d207375c3e29ab0335bd5a473a125 +F src/btree.c e565971caa0265d3cabc8b15d7017899a7814051 F src/btree.h 969adc948e89e449220ff0ff724c94bb2a52e9f1 F src/btreeInt.h 2bfefc01875d8da066504c233ec259fcb3b2ef72 F src/build.c 0419bba592c22f6d00e6d57a2ca7136720d02c1a @@ -433,6 +433,7 @@ F test/corruptF.test be9fde98e4c93648f1ba52b74e5318edc8f59fe4 F test/corruptG.test 1ab3bf97ee7bdba70e0ff3ba2320657df55d1804 F test/corruptH.test 5dd4fa98c6c1ed33b178f9e8a48c4fdd3cfc9067 F test/corruptI.test 221ad8b7f0a9ac6b80fc577e73b5ad8cdea31243 +F test/corruptJ.test 8f584eb97b88e7b160d03edfe2f814c64e56b4ac F test/cost.test 19d314526616ce4473eb4e4e450fcb94499ce318 F test/count.test 42a251178e32f617eda33f76236a7f79825a50b5 F test/coveridxscan.test cdb47d01acc4a634a34fd25abe85189e0d0f1e62 @@ -1247,7 +1248,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 0ec08ba8a0fa188146b071a489908332693ba59a -R 5fa56a67857aa9aa0bfe9c8eabbd7f2b -U mistachkin -Z 22e64f81a05ea0084d0b656c0478e6e9 +P ab5800291e1908b5b51d912feeacf748dc9be14b +R 7b7ce803eb05ad2f210c6eb94fdd8e1c +U drh +Z 53c46ef4969a0037acc3578044ba6e9e diff --git a/manifest.uuid b/manifest.uuid index 50a77b66aa..b562506b7f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ab5800291e1908b5b51d912feeacf748dc9be14b \ No newline at end of file +395bb3e677a6551b06ba96fc58c393132b93d1e8 \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index 52f29428f7..a4eae64025 100644 --- a/src/btree.c +++ b/src/btree.c @@ -7978,6 +7978,7 @@ static int clearDatabasePage( int i; int hdr; u16 szCell; + u8 hasChildren; assert( sqlite3_mutex_held(pBt->mutex) ); if( pgno>btreePagecount(pBt) ){ @@ -7986,17 +7987,19 @@ static int clearDatabasePage( rc = getAndInitPage(pBt, pgno, &pPage, 0); if( rc ) return rc; + hasChildren = !pPage->leaf; + pPage->leaf = 1; /* Block looping if the database is corrupt */ hdr = pPage->hdrOffset; for(i=0; inCell; i++){ pCell = findCell(pPage, i); - if( !pPage->leaf ){ + if( hasChildren ){ rc = clearDatabasePage(pBt, get4byte(pCell), 1, pnChange); if( rc ) goto cleardatabasepage_out; } rc = clearCell(pPage, pCell, &szCell); if( rc ) goto cleardatabasepage_out; } - if( !pPage->leaf ){ + if( hasChildren ){ rc = clearDatabasePage(pBt, get4byte(&pPage->aData[hdr+8]), 1, pnChange); if( rc ) goto cleardatabasepage_out; }else if( pnChange ){ diff --git a/test/corruptJ.test b/test/corruptJ.test new file mode 100644 index 0000000000..ec884cc9b4 --- /dev/null +++ b/test/corruptJ.test @@ -0,0 +1,80 @@ +# 2015-03-30 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# Corruption consisting of a database page that thinks it is a child +# of itself. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix corruptJ + +if {[permutation]=="mmap"} { + finish_test + return +} + +# Do not use a codec for tests in this file, as the database file is +# manipulated directly using tcl scripts (using the [hexio_write] command). +# +do_not_use_codec +database_may_be_corrupt + +# Initialize the database. +# +do_execsql_test 1.1 { + PRAGMA page_size=1024; + PRAGMA auto_vacuum=0; + CREATE TABLE t1(a,b); + WITH RECURSIVE c(i) AS (VALUES(1) UNION ALL SELECT i+1 FROM c WHERE i<10) + INSERT INTO t1(a,b) SELECT i, zeroblob(700) FROM c; +} {} +db close + +# Corrupt the root page of the t1 table such that the left-child pointer +# for the very first cell points back to the root. Then try to DROP the +# table. The clearDatabasePage() routine should not loop. +# +do_test 1.2 { + hexio_write test.db [expr {2*1024-2}] 02 + sqlite3 db test.db + catchsql { DROP TABLE t1 } +} {1 {database disk image is malformed}} + +# Similar test using a WITHOUT ROWID table +# +do_test 2.1 { + db close + forcedelete test.db + sqlite3 db test.db + db eval { + PRAGMA page_size=1024; + PRAGMA auto_vacuum=0; + CREATE TABLE t1(a,b,PRIMARY KEY(a,b)) WITHOUT ROWID; + WITH RECURSIVE c(i) AS (VALUES(1) UNION ALL SELECT i+1 FROM c WHERE i<100) + INSERT INTO t1(a,b) SELECT i, zeroblob(200) FROM c; + } +} {} + +# The table is three levels deep. Corrupt the left child of an intermediate +# page so that it points back to the root page. +# +do_test 2.2 { + db close + hexio_read test.db [expr {9*1024+391}] 8 +} {00000008814D0401} +do_test 2.2b { + hexio_write test.db [expr {9*1024+391}] 00000002 + sqlite3 db test.db + catchsql { DROP TABLE t1 } +} {0 {}} + +finish_test From bc8a6b31b69b202cd66e6c4f51beb27cf01d9c11 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 31 Mar 2015 11:42:23 +0000 Subject: [PATCH 043/181] Ensure that comparison operators do not mess up the MEM_Dyn flag on registers when reverting affinity changes. FossilOrigin-Name: 02e3c88fbf6abdcf3975fb0fb71972b0ab30da30 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/vdbe.c | 6 ++++++ 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/manifest b/manifest index 830165f1d1..8a2a10e6c4 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Prevent\sa\spossible\sinfinite\sloop\swhen\strying\sto\sDROP\sa\stable\sfrom\na\scorrupt\sdatabase. -D 2015-03-30T23:43:56.191 +C Ensure\sthat\scomparison\soperators\sdo\snot\smess\sup\sthe\sMEM_Dyn\sflag\son\sregisters\nwhen\sreverting\saffinity\schanges. +D 2015-03-31T11:42:23.599 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -293,7 +293,7 @@ F src/update.c 3c4ecc282accf12d39edb8d524cf089645e55a13 F src/utf.c fc6b889ba0779b7722634cdeaa25f1930d93820c F src/util.c 98a7627ca48ad3265b6940915a1d08355eb3fc7e F src/vacuum.c 9460b9de7b2d4e34b0d374894aa6c8a0632be8ec -F src/vdbe.c bbfede5a8a6908b3ddcd55fdb0b2301288dd4754 +F src/vdbe.c 86ae6f4774410868af41bd839b72b7081ff03e78 F src/vdbe.h 6fc69d9c5e146302c56e163cb4b31d1ee64a18c3 F src/vdbeInt.h 9cbaa84f53ddd2d09a0cf61a94337a3a035d08a0 F src/vdbeapi.c 583d56b129dd27f12bed518270de9ebe521e6a75 @@ -1248,7 +1248,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 ab5800291e1908b5b51d912feeacf748dc9be14b -R 7b7ce803eb05ad2f210c6eb94fdd8e1c +P 395bb3e677a6551b06ba96fc58c393132b93d1e8 +R 32fb3cc594bfc0fa1b6de17fb4714420 U drh -Z 53c46ef4969a0037acc3578044ba6e9e +Z 6c9b38c06aabdc797714a509c4f32228 diff --git a/manifest.uuid b/manifest.uuid index b562506b7f..b6c886cfee 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -395bb3e677a6551b06ba96fc58c393132b93d1e8 \ No newline at end of file +02e3c88fbf6abdcf3975fb0fb71972b0ab30da30 \ No newline at end of file diff --git a/src/vdbe.c b/src/vdbe.c index ec5e6d7442..f2de90d14c 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -1920,11 +1920,15 @@ case OP_Ge: { /* same as TK_GE, jump, in1, in3 */ testcase( pIn1->flags & MEM_Int ); testcase( pIn1->flags & MEM_Real ); sqlite3VdbeMemStringify(pIn1, encoding, 1); + testcase( (flags1&MEM_Dyn) != (pIn1->flags&MEM_Dyn) ); + flags1 = (pIn1->flags & ~MEM_TypeMask) | (flags1 & MEM_TypeMask); } if( (pIn3->flags & MEM_Str)==0 && (pIn3->flags & (MEM_Int|MEM_Real))!=0 ){ testcase( pIn3->flags & MEM_Int ); testcase( pIn3->flags & MEM_Real ); sqlite3VdbeMemStringify(pIn3, encoding, 1); + testcase( (flags3&MEM_Dyn) != (pIn3->flags&MEM_Dyn) ); + flags3 = (pIn3->flags & ~MEM_TypeMask) | (flags3 & MEM_TypeMask); } } assert( pOp->p4type==P4_COLLSEQ || pOp->p4.pColl==0 ); @@ -1961,7 +1965,9 @@ case OP_Ge: { /* same as TK_GE, jump, in1, in3 */ } } /* Undo any changes made by applyAffinity() to the input registers. */ + assert( (pIn1->flags & MEM_Dyn) == (flags1 & MEM_Dyn) ); pIn1->flags = flags1; + assert( (pIn3->flags & MEM_Dyn) == (flags3 & MEM_Dyn) ); pIn3->flags = flags3; break; } From fe0ba71112dc8703ba4fcc1bbef2837b635d210e Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 31 Mar 2015 13:46:13 +0000 Subject: [PATCH 044/181] Add the "mptest" target to Makefile.msc FossilOrigin-Name: 1e814e0bd116ad5a05ab9f0ebed7e21b23ed0681 --- Makefile.msc | 14 ++++++++++++++ manifest | 12 ++++++------ manifest.uuid | 2 +- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/Makefile.msc b/Makefile.msc index 7e6a077ffb..14b49082bd 100644 --- a/Makefile.msc +++ b/Makefile.msc @@ -1158,6 +1158,20 @@ mptester.exe: $(TOP)\mptest\mptest.c $(SHELL_CORE_DEP) $(LIBRESOBJS) sqlite3.h $(LTLINK) $(SHELL_COMPILE_OPTS) $(TOP)\mptest\mptest.c \ /link $(LTLINKOPTS) $(LTLIBPATHS) $(SHELL_LINK_OPTS) $(LIBRESOBJS) $(LIBREADLINE) $(LTLIBS) $(TLIBS) +MPTEST1=mptester mptest.db $(TOP)/mptest/crash01.test --repeat 20 +MPTEST2=mptester mptest.db $(TOP)/mptest/multiwrite01.test --repeat 20 +mptest: mptester.exe + del /Q mptest.db + $(MPTEST1) --journalmode DELETE + $(MPTEST2) --journalmode WAL + $(MPTEST1) --journalmode WAL + $(MPTEST2) --journalmode PERSIST + $(MPTEST1) --journalmode PERSIST + $(MPTEST2) --journalmode TRUNCATE + $(MPTEST1) --journalmode TRUNCATE + $(MPTEST2) --journalmode DELETE + + # This target creates a directory named "tsrc" and fills it with # copies of all of the C source code and header files needed to # build on the target system. Some of the C source code and header diff --git a/manifest b/manifest index 8a2a10e6c4..698734f7c6 100644 --- a/manifest +++ b/manifest @@ -1,9 +1,9 @@ -C Ensure\sthat\scomparison\soperators\sdo\snot\smess\sup\sthe\sMEM_Dyn\sflag\son\sregisters\nwhen\sreverting\saffinity\schanges. -D 2015-03-31T11:42:23.599 +C Add\sthe\s"mptest"\starget\sto\sMakefile.msc +D 2015-03-31T13:46:13.387 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 -F Makefile.msc 23e6eaa84569829c3e7f409513caa136e5bcaf2a +F Makefile.msc d7e2bcf6634197e69628e632d441646a84bfdca8 F Makefile.vxworks e1b65dea203f054e71653415bd8f96dcaed47858 F README.md d58e3bebc0a4145e0f2a87994015fdb575a8e866 F VERSION 319eb1ced4b4d17a67730f2b7b85f15c1346cb60 @@ -1248,7 +1248,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 395bb3e677a6551b06ba96fc58c393132b93d1e8 -R 32fb3cc594bfc0fa1b6de17fb4714420 +P 02e3c88fbf6abdcf3975fb0fb71972b0ab30da30 +R d91812f133db0a587c3c0ca8a4eb33d5 U drh -Z 6c9b38c06aabdc797714a509c4f32228 +Z 3c6ff9ce8b6355a815c81088cec6c2b3 diff --git a/manifest.uuid b/manifest.uuid index b6c886cfee..37ec8cea3c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -02e3c88fbf6abdcf3975fb0fb71972b0ab30da30 \ No newline at end of file +1e814e0bd116ad5a05ab9f0ebed7e21b23ed0681 \ No newline at end of file From 8773b858e1f59737c2c958a17f67569fd8319254 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 31 Mar 2015 14:18:29 +0000 Subject: [PATCH 045/181] Additional logging information output by mptester. FossilOrigin-Name: 0cbbf6e4571ffef102c0e515f29166f2f2022126 --- manifest | 12 ++++++------ manifest.uuid | 2 +- mptest/mptest.c | 6 ++++++ 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/manifest b/manifest index 698734f7c6..34569201a8 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sthe\s"mptest"\starget\sto\sMakefile.msc -D 2015-03-31T13:46:13.387 +C Additional\slogging\sinformation\soutput\sby\smptester. +D 2015-03-31T14:18:29.822 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -160,7 +160,7 @@ F mptest/config01.test 3c6adcbc50b991866855f1977ff172eb6d901271 F mptest/config02.test 4415dfe36c48785f751e16e32c20b077c28ae504 F mptest/crash01.test 61e61469e257df0850df4293d7d4d6c2af301421 F mptest/crash02.subtest f4ef05adcd15d60e5d2bd654204f2c008b519df8 -F mptest/mptest.c 1e464f41f1bbc6578d6925043da56170f83aea96 +F mptest/mptest.c 4691e08e1fc114edd8e1875f88393718f70ba480 F mptest/multiwrite01.test dab5c5f8f9534971efce679152c5146da265222d F spec.template 86a4a43b99ebb3e75e6b9a735d5fd293a24e90ca F sqlite.pc.in 42b7bf0d02e08b9e77734a47798d1a55a9e0716b @@ -1248,7 +1248,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 02e3c88fbf6abdcf3975fb0fb71972b0ab30da30 -R d91812f133db0a587c3c0ca8a4eb33d5 +P 1e814e0bd116ad5a05ab9f0ebed7e21b23ed0681 +R bfc4505f6e856cbd418142922d77fee6 U drh -Z 3c6ff9ce8b6355a815c81088cec6c2b3 +Z 6eef793d1a736aa92f954ef3555b0150 diff --git a/manifest.uuid b/manifest.uuid index 37ec8cea3c..e135de6357 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -1e814e0bd116ad5a05ab9f0ebed7e21b23ed0681 \ No newline at end of file +0cbbf6e4571ffef102c0e515f29166f2f2022126 \ No newline at end of file diff --git a/mptest/mptest.c b/mptest/mptest.c index 40c14bc87a..1efdc0319a 100644 --- a/mptest/mptest.c +++ b/mptest/mptest.c @@ -1312,6 +1312,9 @@ int SQLITE_CDECL main(int argc, char **argv){ GETPID(), iClient); }else{ if( g.iTrace>0 ){ + printf("BEGIN: %s", argv[0]); + for(i=1; i0; } From 96e285692a92a82597736c5a89f03ed032b2c0e3 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 31 Mar 2015 14:31:41 +0000 Subject: [PATCH 046/181] Fix the corruptJ.test case so that it works with and without SQLITE_SECURE_DELETE. FossilOrigin-Name: 0c0ecfd68573957553b966229a67bfcd10ce4b99 --- manifest | 12 ++++++------ manifest.uuid | 2 +- test/corruptJ.test | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 34569201a8..64f10f7deb 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Additional\slogging\sinformation\soutput\sby\smptester. -D 2015-03-31T14:18:29.822 +C Fix\sthe\scorruptJ.test\scase\sso\sthat\sit\sworks\swith\sand\swithout\nSQLITE_SECURE_DELETE. +D 2015-03-31T14:31:41.936 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -433,7 +433,7 @@ F test/corruptF.test be9fde98e4c93648f1ba52b74e5318edc8f59fe4 F test/corruptG.test 1ab3bf97ee7bdba70e0ff3ba2320657df55d1804 F test/corruptH.test 5dd4fa98c6c1ed33b178f9e8a48c4fdd3cfc9067 F test/corruptI.test 221ad8b7f0a9ac6b80fc577e73b5ad8cdea31243 -F test/corruptJ.test 8f584eb97b88e7b160d03edfe2f814c64e56b4ac +F test/corruptJ.test 9e29e7a81ee3b6ac50f77ea7a9e2f3fa03f32d91 F test/cost.test 19d314526616ce4473eb4e4e450fcb94499ce318 F test/count.test 42a251178e32f617eda33f76236a7f79825a50b5 F test/coveridxscan.test cdb47d01acc4a634a34fd25abe85189e0d0f1e62 @@ -1248,7 +1248,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 1e814e0bd116ad5a05ab9f0ebed7e21b23ed0681 -R bfc4505f6e856cbd418142922d77fee6 +P 0cbbf6e4571ffef102c0e515f29166f2f2022126 +R 855ca787fb7bd1ab9ab088557a4f09bc U drh -Z 6eef793d1a736aa92f954ef3555b0150 +Z 3d4ee993730e7b33e6803497c50a3fdc diff --git a/manifest.uuid b/manifest.uuid index e135de6357..5400bc696e 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -0cbbf6e4571ffef102c0e515f29166f2f2022126 \ No newline at end of file +0c0ecfd68573957553b966229a67bfcd10ce4b99 \ No newline at end of file diff --git a/test/corruptJ.test b/test/corruptJ.test index ec884cc9b4..c08e628e2d 100644 --- a/test/corruptJ.test +++ b/test/corruptJ.test @@ -74,7 +74,7 @@ do_test 2.2 { do_test 2.2b { hexio_write test.db [expr {9*1024+391}] 00000002 sqlite3 db test.db - catchsql { DROP TABLE t1 } -} {0 {}} + catchsql { PRAGMA secure_delete=ON; DROP TABLE t1; } +} {1 {database disk image is malformed}} finish_test From 1cc0d11a167a1d25a1784c3ef4a6896636889299 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 31 Mar 2015 15:15:48 +0000 Subject: [PATCH 047/181] Fix harmless compiler warnings in lemon.c FossilOrigin-Name: bbe7dcda689a25860f2104804f00ba0a720c1372 --- manifest | 12 ++++++------ manifest.uuid | 2 +- tool/lemon.c | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index 64f10f7deb..f76a238037 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sthe\scorruptJ.test\scase\sso\sthat\sit\sworks\swith\sand\swithout\nSQLITE_SECURE_DELETE. -D 2015-03-31T14:31:41.936 +C Fix\sharmless\scompiler\swarnings\sin\slemon.c +D 2015-03-31T15:15:48.726 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -1206,7 +1206,7 @@ F tool/fragck.tcl 5265a95126abcf6ab357f7efa544787e5963f439 F tool/genfkey.README cf68fddd4643bbe3ff8e31b8b6d8b0a1b85e20f4 F tool/genfkey.test 4196a8928b78f51d54ef58e99e99401ab2f0a7e5 F tool/getlock.c f4c39b651370156cae979501a7b156bdba50e7ce -F tool/lemon.c 1864c4fe4a72b1bb28f1792b60504804fe82c5d2 +F tool/lemon.c ae5f61e3b164d35955777b20d6febcbaf0950702 F tool/lempar.c 01ca97f87610d1dac6d8cd96ab109ab1130e76dc F tool/logest.c eef612f8adf4d0993dafed0416064cf50d5d33c6 F tool/mkautoconfamal.sh d1a2da0e15b2ed33d60af35c7e9d483f13a8eb9f @@ -1248,7 +1248,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 0cbbf6e4571ffef102c0e515f29166f2f2022126 -R 855ca787fb7bd1ab9ab088557a4f09bc +P 0c0ecfd68573957553b966229a67bfcd10ce4b99 +R f295c13e7a998be1a5a78140716d3389 U drh -Z 3d4ee993730e7b33e6803497c50a3fdc +Z 1c953be9eacdcbbbb1c665e7b3932b7e diff --git a/manifest.uuid b/manifest.uuid index 5400bc696e..544169567d 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -0c0ecfd68573957553b966229a67bfcd10ce4b99 \ No newline at end of file +bbe7dcda689a25860f2104804f00ba0a720c1372 \ No newline at end of file diff --git a/tool/lemon.c b/tool/lemon.c index 4ada425d69..cc3066bec0 100644 --- a/tool/lemon.c +++ b/tool/lemon.c @@ -1731,7 +1731,7 @@ static char *msort( char *ep; char *set[LISTSIZE]; int i; - offset = (unsigned long)next - (unsigned long)list; + offset = (unsigned long)((char*)next - (char*)list); for(i=0; i Date: Tue, 31 Mar 2015 16:33:08 +0000 Subject: [PATCH 048/181] Handle very large URI pathnames for in-memory shared-cache databases. FossilOrigin-Name: 586a94e85bc13700a2093734711c1367fa814b8c --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/btree.c | 6 ++++-- test/attach.test | 12 ++++++++++++ 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index f76a238037..a38babcf26 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sharmless\scompiler\swarnings\sin\slemon.c -D 2015-03-31T15:15:48.726 +C Handle\svery\slarge\sURI\spathnames\sfor\sin-memory\sshared-cache\sdatabases. +D 2015-03-31T16:33:08.816 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -173,7 +173,7 @@ F src/auth.c b56c78ebe40a2110fd361379f7e8162d23f92240 F src/backup.c ff743689c4d6c5cb55ad42ed9d174b2b3e71f1e3 F src/bitvec.c 19a4ba637bd85f8f63fc8c9bae5ade9fb05ec1cb F src/btmutex.c 45a968cc85afed9b5e6cf55bf1f42f8d18107f79 -F src/btree.c e565971caa0265d3cabc8b15d7017899a7814051 +F src/btree.c 525f19f01d5976dbc12e83e7339e41488de79183 F src/btree.h 969adc948e89e449220ff0ff724c94bb2a52e9f1 F src/btreeInt.h 2bfefc01875d8da066504c233ec259fcb3b2ef72 F src/build.c 0419bba592c22f6d00e6d57a2ca7136720d02c1a @@ -340,7 +340,7 @@ F test/async3.test d73a062002376d7edc1fe3edff493edbec1fc2f7 F test/async4.test 1787e3952128aa10238bf39945126de7ca23685a F test/async5.test 383ab533fdb9f7ad228cc99ee66e1acb34cc0dc0 F test/atof1.test 08a61df9365c341f334a65f4348897312d8f3db7 -F test/attach.test 0d112b7713611fdf0340260192749737135fda5f +F test/attach.test 437107943f14d131cf5efc2ae5305a94d7cb1d58 F test/attach2.test 0ec5defa340363de6cd50fd595046465e9aaba2d F test/attach3.test 359eb65d00102cdfcef6fa4e81dc1648f8f80b27 F test/attach4.test 53bf502f17647c6d6c5add46dda6bac8b6f4665c @@ -1248,7 +1248,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 0c0ecfd68573957553b966229a67bfcd10ce4b99 -R f295c13e7a998be1a5a78140716d3389 +P bbe7dcda689a25860f2104804f00ba0a720c1372 +R 6f0e4814d1e4f882b35ba2b9dccc56cc U drh -Z 1c953be9eacdcbbbb1c665e7b3932b7e +Z d85481fb8858c2d74f205f2246e5afa6 diff --git a/manifest.uuid b/manifest.uuid index 544169567d..7c14a1b036 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -bbe7dcda689a25860f2104804f00ba0a720c1372 \ No newline at end of file +586a94e85bc13700a2093734711c1367fa814b8c \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index a4eae64025..b497cd7468 100644 --- a/src/btree.c +++ b/src/btree.c @@ -1959,16 +1959,18 @@ int sqlite3BtreeOpen( */ if( isTempDb==0 && (isMemdb==0 || (vfsFlags&SQLITE_OPEN_URI)!=0) ){ if( vfsFlags & SQLITE_OPEN_SHAREDCACHE ){ + int nFilename = sqlite3Strlen30(zFilename)+1; int nFullPathname = pVfs->mxPathname+1; - char *zFullPathname = sqlite3Malloc(nFullPathname); + char *zFullPathname = sqlite3Malloc(MAX(nFullPathname,nFilename)); MUTEX_LOGIC( sqlite3_mutex *mutexShared; ) + p->sharable = 1; if( !zFullPathname ){ sqlite3_free(p); return SQLITE_NOMEM; } if( isMemdb ){ - memcpy(zFullPathname, zFilename, sqlite3Strlen30(zFilename)+1); + memcpy(zFullPathname, zFilename, nFilename); }else{ rc = sqlite3OsFullPathname(pVfs, zFilename, nFullPathname, zFullPathname); diff --git a/test/attach.test b/test/attach.test index be5f9881c3..31c24e61d9 100644 --- a/test/attach.test +++ b/test/attach.test @@ -859,4 +859,16 @@ do_test attach-10.2 { }] 9 end } {4 noname {} 5 inmem {}} +# Attach with a very long URI filename. +# +db close +sqlite3 db test.db -uri 1 +do_execsql_test attach-11.1 { + ATTACH printf('file:%09000x/x.db?mode=memory&cache=shared',1) AS aux1; + CREATE TABLE aux1.t1(x,y); + INSERT INTO aux1.t1(x,y) VALUES(1,2),(3,4); + SELECT * FROM aux1.t1; +} {1 2 3 4} + + finish_test From 4d2daba467b1d1c53cb1d1d471df9126ae4b6873 Mon Sep 17 00:00:00 2001 From: mistachkin Date: Tue, 31 Mar 2015 16:42:16 +0000 Subject: [PATCH 049/181] Minor tweaks to the MSVC Makefile. FossilOrigin-Name: 7244ea59ede8aa2c7d1dc2c85268e12ddd452e27 --- Makefile.msc | 8 ++++---- manifest | 14 +++++++------- manifest.uuid | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Makefile.msc b/Makefile.msc index 14b49082bd..5330f8962f 100644 --- a/Makefile.msc +++ b/Makefile.msc @@ -1158,10 +1158,11 @@ mptester.exe: $(TOP)\mptest\mptest.c $(SHELL_CORE_DEP) $(LIBRESOBJS) sqlite3.h $(LTLINK) $(SHELL_COMPILE_OPTS) $(TOP)\mptest\mptest.c \ /link $(LTLINKOPTS) $(LTLIBPATHS) $(SHELL_LINK_OPTS) $(LIBRESOBJS) $(LIBREADLINE) $(LTLIBS) $(TLIBS) -MPTEST1=mptester mptest.db $(TOP)/mptest/crash01.test --repeat 20 -MPTEST2=mptester mptest.db $(TOP)/mptest/multiwrite01.test --repeat 20 +MPTEST1 = mptester mptest.db $(TOP)/mptest/crash01.test --repeat 20 +MPTEST2 = mptester mptest.db $(TOP)/mptest/multiwrite01.test --repeat 20 + mptest: mptester.exe - del /Q mptest.db + del /Q mptest.db 2>NUL $(MPTEST1) --journalmode DELETE $(MPTEST2) --journalmode WAL $(MPTEST1) --journalmode WAL @@ -1171,7 +1172,6 @@ mptest: mptester.exe $(MPTEST1) --journalmode TRUNCATE $(MPTEST2) --journalmode DELETE - # This target creates a directory named "tsrc" and fills it with # copies of all of the C source code and header files needed to # build on the target system. Some of the C source code and header diff --git a/manifest b/manifest index a38babcf26..78a4b72821 100644 --- a/manifest +++ b/manifest @@ -1,9 +1,9 @@ -C Handle\svery\slarge\sURI\spathnames\sfor\sin-memory\sshared-cache\sdatabases. -D 2015-03-31T16:33:08.816 +C Minor\stweaks\sto\sthe\sMSVC\sMakefile. +D 2015-03-31T16:42:16.959 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 -F Makefile.msc d7e2bcf6634197e69628e632d441646a84bfdca8 +F Makefile.msc a8d817fa486d8c88dfbd19ae6a6567d9d350de39 F Makefile.vxworks e1b65dea203f054e71653415bd8f96dcaed47858 F README.md d58e3bebc0a4145e0f2a87994015fdb575a8e866 F VERSION 319eb1ced4b4d17a67730f2b7b85f15c1346cb60 @@ -1248,7 +1248,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 bbe7dcda689a25860f2104804f00ba0a720c1372 -R 6f0e4814d1e4f882b35ba2b9dccc56cc -U drh -Z d85481fb8858c2d74f205f2246e5afa6 +P 586a94e85bc13700a2093734711c1367fa814b8c +R dda30a84a02345c3ad5a29c2256cdbe0 +U mistachkin +Z 140263b8fa48f28f6823c13e70219b7f diff --git a/manifest.uuid b/manifest.uuid index 7c14a1b036..6d3dfcae53 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -586a94e85bc13700a2093734711c1367fa814b8c \ No newline at end of file +7244ea59ede8aa2c7d1dc2c85268e12ddd452e27 \ No newline at end of file From d881ce8fa74bc5bf5734cda3f045a0bc2a804574 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 31 Mar 2015 17:01:52 +0000 Subject: [PATCH 050/181] Fix configure.ac and Makefile.in so that they generate pkgIndex.tcl correctly. FossilOrigin-Name: 3deff25249c59b7fc1b6eb65dda39736955679c6 --- Makefile.in | 2 +- configure | 30 ++++++++++++++++-------------- configure.ac | 1 + manifest | 18 +++++++++--------- manifest.uuid | 2 +- 5 files changed, 28 insertions(+), 25 deletions(-) diff --git a/Makefile.in b/Makefile.in index 4ac06938fd..2177488f9b 100644 --- a/Makefile.in +++ b/Makefile.in @@ -1059,7 +1059,7 @@ install: sqlite3$(BEXE) lib_install sqlite3.h sqlite3.pc ${HAVE_TCL:1=tcl_instal $(INSTALL) -m 0644 sqlite3.pc $(DESTDIR)$(pkgconfigdir) pkgIndex.tcl: - echo 'package ifneeded sqlite3 $(RELEASE) [list load $(TCLLIBDIR)/libtclsqlite3.so sqlite3]' > $@ + echo 'package ifneeded sqlite3 $(RELEASE) [list load $(TCLLIBDIR)/libtclsqlite3$(SHLIB_SUFFIX) sqlite3]' > $@ tcl_install: lib_install libtclsqlite3.la pkgIndex.tcl $(INSTALL) -d $(DESTDIR)$(TCLLIBDIR) $(LTINSTALL) libtclsqlite3.la $(DESTDIR)$(TCLLIBDIR) diff --git a/configure b/configure index 0c519e2216..d259324bdd 100755 --- a/configure +++ b/configure @@ -884,6 +884,7 @@ TCL_LIB_SPEC TCL_STUB_LIB_FILE TCL_STUB_LIB_FLAG TCL_STUB_LIB_SPEC +TCL_SHLIB_SUFFIX HAVE_TCL TARGET_READLINE_LIBS TARGET_READLINE_INC @@ -3724,13 +3725,13 @@ if test "${lt_cv_nm_interface+set}" = set; then else lt_cv_nm_interface="BSD nm" echo "int some_variable = 0;" > conftest.$ac_ext - (eval echo "\"\$as_me:3727: $ac_compile\"" >&5) + (eval echo "\"\$as_me:3728: $ac_compile\"" >&5) (eval "$ac_compile" 2>conftest.err) cat conftest.err >&5 - (eval echo "\"\$as_me:3730: $NM \\\"conftest.$ac_objext\\\"\"" >&5) + (eval echo "\"\$as_me:3731: $NM \\\"conftest.$ac_objext\\\"\"" >&5) (eval "$NM \"conftest.$ac_objext\"" 2>conftest.err > conftest.out) cat conftest.err >&5 - (eval echo "\"\$as_me:3733: output\"" >&5) + (eval echo "\"\$as_me:3734: output\"" >&5) cat conftest.out >&5 if $GREP 'External.*some_variable' conftest.out > /dev/null; then lt_cv_nm_interface="MS dumpbin" @@ -4952,7 +4953,7 @@ ia64-*-hpux*) ;; *-*-irix6*) # Find out which ABI we are using. - echo '#line 4955 "configure"' > conftest.$ac_ext + echo '#line 4956 "configure"' > conftest.$ac_ext if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 (eval $ac_compile) 2>&5 ac_status=$? @@ -6821,11 +6822,11 @@ else -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:6824: $lt_compile\"" >&5) + (eval echo "\"\$as_me:6825: $lt_compile\"" >&5) (eval "$lt_compile" 2>conftest.err) ac_status=$? cat conftest.err >&5 - echo "$as_me:6828: \$? = $ac_status" >&5 + echo "$as_me:6829: \$? = $ac_status" >&5 if (exit $ac_status) && test -s "$ac_outfile"; then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings other than the usual output. @@ -7160,11 +7161,11 @@ else -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:7163: $lt_compile\"" >&5) + (eval echo "\"\$as_me:7164: $lt_compile\"" >&5) (eval "$lt_compile" 2>conftest.err) ac_status=$? cat conftest.err >&5 - echo "$as_me:7167: \$? = $ac_status" >&5 + echo "$as_me:7168: \$? = $ac_status" >&5 if (exit $ac_status) && test -s "$ac_outfile"; then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings other than the usual output. @@ -7265,11 +7266,11 @@ else -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:7268: $lt_compile\"" >&5) + (eval echo "\"\$as_me:7269: $lt_compile\"" >&5) (eval "$lt_compile" 2>out/conftest.err) ac_status=$? cat out/conftest.err >&5 - echo "$as_me:7272: \$? = $ac_status" >&5 + echo "$as_me:7273: \$? = $ac_status" >&5 if (exit $ac_status) && test -s out/conftest2.$ac_objext then # The compiler can only warn and ignore the option if not recognized @@ -7320,11 +7321,11 @@ else -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:7323: $lt_compile\"" >&5) + (eval echo "\"\$as_me:7324: $lt_compile\"" >&5) (eval "$lt_compile" 2>out/conftest.err) ac_status=$? cat out/conftest.err >&5 - echo "$as_me:7327: \$? = $ac_status" >&5 + echo "$as_me:7328: \$? = $ac_status" >&5 if (exit $ac_status) && test -s out/conftest2.$ac_objext then # The compiler can only warn and ignore the option if not recognized @@ -10133,7 +10134,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 10136 "configure" +#line 10137 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -10229,7 +10230,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 10232 "configure" +#line 10233 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -12827,6 +12828,7 @@ $as_echo "file not found" >&6; } + fi fi if test "${use_tcl}" = "no" ; then diff --git a/configure.ac b/configure.ac index 00ecf453af..6a1188842a 100644 --- a/configure.ac +++ b/configure.ac @@ -430,6 +430,7 @@ if test "${use_tcl}" = "yes" ; then AC_SUBST(TCL_STUB_LIB_FILE) AC_SUBST(TCL_STUB_LIB_FLAG) AC_SUBST(TCL_STUB_LIB_SPEC) + AC_SUBST(TCL_SHLIB_SUFFIX) fi fi if test "${use_tcl}" = "no" ; then diff --git a/manifest b/manifest index 78a4b72821..9e2a939d3b 100644 --- a/manifest +++ b/manifest @@ -1,7 +1,7 @@ -C Minor\stweaks\sto\sthe\sMSVC\sMakefile. -D 2015-03-31T16:42:16.959 +C Fix\sconfigure.ac\sand\sMakefile.in\sso\sthat\sthey\sgenerate\spkgIndex.tcl\scorrectly. +D 2015-03-31T17:01:52.572 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f -F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb +F Makefile.in 00d12636df7a5b08af09116bcd6c7bfd49b8b3b4 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 F Makefile.msc a8d817fa486d8c88dfbd19ae6a6567d9d350de39 F Makefile.vxworks e1b65dea203f054e71653415bd8f96dcaed47858 @@ -38,8 +38,8 @@ F autoconf/tea/win/rules.vc c511f222b80064096b705dbeb97060ee1d6b6d63 F config.guess 226d9a188c6196f3033ffc651cbc9dcee1a42977 F config.h.in 42b71ad3fe21c9e88fa59e8458ca1a6bc72eb0c0 F config.sub 9ebe4c3b3dab6431ece34f16828b594fb420da55 -F configure 613b220c2f2c7adcd50eb5ee4144ab581a150b47 x -F configure.ac 6a8d145aea6d81f0b90013340780e43ed74fd5f4 +F configure 8b18c2378805a1d8aaca85d293671f450dd3c723 x +F configure.ac 0b775d383c536bbaafc1e46dd3cbb81a7ea11aeb F contrib/sqlitecon.tcl 210a913ad63f9f991070821e599d600bd913e0ad F doc/lemon.html 334dbf6621b8fb8790297ec1abf3cfa4621709d1 F doc/pager-invariants.txt 27fed9a70ddad2088750c4a2b493b63853da2710 @@ -1248,7 +1248,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 586a94e85bc13700a2093734711c1367fa814b8c -R dda30a84a02345c3ad5a29c2256cdbe0 -U mistachkin -Z 140263b8fa48f28f6823c13e70219b7f +P 7244ea59ede8aa2c7d1dc2c85268e12ddd452e27 +R 975c1f85d87faa80fd42aac5b24ed9ba +U drh +Z 016bf5cf61fe366d051895307d7b2ae3 diff --git a/manifest.uuid b/manifest.uuid index 6d3dfcae53..d92c73c696 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -7244ea59ede8aa2c7d1dc2c85268e12ddd452e27 \ No newline at end of file +3deff25249c59b7fc1b6eb65dda39736955679c6 \ No newline at end of file From 8237f6d180d0233a4abac22e12e5f52f6497fd8f Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 31 Mar 2015 17:32:06 +0000 Subject: [PATCH 051/181] Change the sqlite3_log() message generated on a retry after delay in os_win to be an SQLITE_NOTICE instead of SQLITE_IOERR. FossilOrigin-Name: 5d533eee049e63b3700f5ef7c28c588afccde57a --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/os_win.c | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 9e2a939d3b..d5d1701f1e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sconfigure.ac\sand\sMakefile.in\sso\sthat\sthey\sgenerate\spkgIndex.tcl\scorrectly. -D 2015-03-31T17:01:52.572 +C Change\sthe\ssqlite3_log()\smessage\sgenerated\son\sa\sretry\safter\sdelay\sin\sos_win\nto\sbe\san\sSQLITE_NOTICE\sinstead\sof\sSQLITE_IOERR. +D 2015-03-31T17:32:06.290 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 00d12636df7a5b08af09116bcd6c7bfd49b8b3b4 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -215,7 +215,7 @@ F src/os.h 3e57a24e2794a94d3cf2342c6d9a884888cd96bf F src/os_common.h 92815ed65f805560b66166e3583470ff94478f04 F src/os_setup.h c9d4553b5aaa6f73391448b265b89bed0b890faa F src/os_unix.c a4dadbc2da41599e99093e91e276c38c17a73b89 -F src/os_win.c 865ba15878eded98bb29a97ac898f2a799dc481a +F src/os_win.c 23c2d1fab9b44e728e7d3ac0c82d5ac2a96de290 F src/os_win.h eb7a47aa17b26b77eb97e4823f20a00b8bda12ca F src/pager.c 4120a49ecd37697e28f5ed807f470b9c0b88410c F src/pager.h c3476e7c89cdf1c6914e50a11f3714e30b4e0a77 @@ -1248,7 +1248,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 7244ea59ede8aa2c7d1dc2c85268e12ddd452e27 -R 975c1f85d87faa80fd42aac5b24ed9ba +P 3deff25249c59b7fc1b6eb65dda39736955679c6 +R 5464b14f38d360ccc6fa7360d378f7df U drh -Z 016bf5cf61fe366d051895307d7b2ae3 +Z f2a2061ec6a7f778916e1fed0b96d2ff diff --git a/manifest.uuid b/manifest.uuid index d92c73c696..1069e22d85 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -3deff25249c59b7fc1b6eb65dda39736955679c6 \ No newline at end of file +5d533eee049e63b3700f5ef7c28c588afccde57a \ No newline at end of file diff --git a/src/os_win.c b/src/os_win.c index e40114000d..e685e20fab 100644 --- a/src/os_win.c +++ b/src/os_win.c @@ -1968,7 +1968,7 @@ static int winRetryIoerr(int *pnRetry, DWORD *pError){ */ static void winLogIoerr(int nRetry, int lineno){ if( nRetry ){ - sqlite3_log(SQLITE_IOERR, + sqlite3_log(SQLITE_NOTICE, "delayed %dms for lock/sharing conflict at line %d", winIoerrRetryDelay*nRetry*(nRetry+1)/2, lineno ); From eb48b062a162f8fa3e514e1776450cd0a0f75d47 Mon Sep 17 00:00:00 2001 From: mistachkin Date: Tue, 31 Mar 2015 17:45:44 +0000 Subject: [PATCH 052/181] Testing enhancements on Windows. FossilOrigin-Name: 9cc70eee2e365dd390210f436b893b9d80a19b04 --- Makefile.msc | 8 ++++---- manifest | 25 ++++++++++++++----------- manifest.uuid | 2 +- mptest/mptest.c | 4 +++- src/main.c | 3 ++- src/os_common.h | 3 ++- src/sqliteInt.h | 3 ++- 7 files changed, 28 insertions(+), 20 deletions(-) diff --git a/Makefile.msc b/Makefile.msc index 5330f8962f..d3a40a811b 100644 --- a/Makefile.msc +++ b/Makefile.msc @@ -480,8 +480,8 @@ RCC = $(RCC) -DSQLITE_DEBUG !ENDIF !IF $(DEBUG)>4 -TCC = $(TCC) -DSQLITE_DEBUG_OS_TRACE=1 -RCC = $(RCC) -DSQLITE_DEBUG_OS_TRACE=1 +TCC = $(TCC) -DSQLITE_DEBUG_OS_TRACE=1 -DSQLITE_FORCE_OS_TRACE=1 +RCC = $(RCC) -DSQLITE_DEBUG_OS_TRACE=1 -DSQLITE_FORCE_OS_TRACE=1 !ENDIF !IF $(DEBUG)>5 @@ -1158,8 +1158,8 @@ mptester.exe: $(TOP)\mptest\mptest.c $(SHELL_CORE_DEP) $(LIBRESOBJS) sqlite3.h $(LTLINK) $(SHELL_COMPILE_OPTS) $(TOP)\mptest\mptest.c \ /link $(LTLINKOPTS) $(LTLIBPATHS) $(SHELL_LINK_OPTS) $(LIBRESOBJS) $(LIBREADLINE) $(LTLIBS) $(TLIBS) -MPTEST1 = mptester mptest.db $(TOP)/mptest/crash01.test --repeat 20 -MPTEST2 = mptester mptest.db $(TOP)/mptest/multiwrite01.test --repeat 20 +MPTEST1 = mptester mptest.db $(TOP)\mptest\crash01.test --repeat 20 +MPTEST2 = mptester mptest.db $(TOP)\mptest\multiwrite01.test --repeat 20 mptest: mptester.exe del /Q mptest.db 2>NUL diff --git a/manifest b/manifest index d5d1701f1e..8eb1667b6f 100644 --- a/manifest +++ b/manifest @@ -1,9 +1,9 @@ -C Change\sthe\ssqlite3_log()\smessage\sgenerated\son\sa\sretry\safter\sdelay\sin\sos_win\nto\sbe\san\sSQLITE_NOTICE\sinstead\sof\sSQLITE_IOERR. -D 2015-03-31T17:32:06.290 +C Testing\senhancements\son\sWindows. +D 2015-03-31T17:45:44.088 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 00d12636df7a5b08af09116bcd6c7bfd49b8b3b4 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 -F Makefile.msc a8d817fa486d8c88dfbd19ae6a6567d9d350de39 +F Makefile.msc c3744ee851d76d2be0ff247f5a89a74c88f2ece2 F Makefile.vxworks e1b65dea203f054e71653415bd8f96dcaed47858 F README.md d58e3bebc0a4145e0f2a87994015fdb575a8e866 F VERSION 319eb1ced4b4d17a67730f2b7b85f15c1346cb60 @@ -160,7 +160,7 @@ F mptest/config01.test 3c6adcbc50b991866855f1977ff172eb6d901271 F mptest/config02.test 4415dfe36c48785f751e16e32c20b077c28ae504 F mptest/crash01.test 61e61469e257df0850df4293d7d4d6c2af301421 F mptest/crash02.subtest f4ef05adcd15d60e5d2bd654204f2c008b519df8 -F mptest/mptest.c 4691e08e1fc114edd8e1875f88393718f70ba480 +F mptest/mptest.c 5360b7a1fd85e3b39daa03d98a81eaa4096a93f5 F mptest/multiwrite01.test dab5c5f8f9534971efce679152c5146da265222d F spec.template 86a4a43b99ebb3e75e6b9a735d5fd293a24e90ca F sqlite.pc.in 42b7bf0d02e08b9e77734a47798d1a55a9e0716b @@ -195,7 +195,7 @@ F src/journal.c b4124532212b6952f42eb2c12fa3c25701d8ba8d F src/legacy.c ba1863ea58c4c840335a84ec276fc2b25e22bc4e F src/lempar.c 7274c97d24bb46631e504332ccd3bd1b37841770 F src/loadext.c 86bd4e2fccd520b748cba52492ab60c4a770f660 -F src/main.c 40e333960d53f7d50ee8ce09d40431c87ea653f2 +F src/main.c 1cc847aae38c804427f155441c1b73c3f9144c9a F src/malloc.c 6a370b83d54e4bbf6f94021221c2a311cff26a18 F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645 F src/mem1.c abe6ee469b6c5a35c7f22bfeb9c9bac664a1c987 @@ -212,7 +212,7 @@ F src/mutex_w32.c 61660ada28d8308ad190f444c2170c4f2a590c2f F src/notify.c 9711a7575036f0d3040ba61bc6e217f13a9888e7 F src/os.c 8fd25588eeba74068d41102d26810e216999b6c8 F src/os.h 3e57a24e2794a94d3cf2342c6d9a884888cd96bf -F src/os_common.h 92815ed65f805560b66166e3583470ff94478f04 +F src/os_common.h 75309c5996a3d201d59ccde946caef1651f206e2 F src/os_setup.h c9d4553b5aaa6f73391448b265b89bed0b890faa F src/os_unix.c a4dadbc2da41599e99093e91e276c38c17a73b89 F src/os_win.c 23c2d1fab9b44e728e7d3ac0c82d5ac2a96de290 @@ -235,7 +235,7 @@ F src/shell.c 84a1593bd86aaa14f4da8a8f9b16fbc239d262aa F src/sqlite.h.in 278602140d49575e8708e643161f4263e428a02a F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h 17d487c3c91b0b8c584a32fbeb393f6f795eea7d -F src/sqliteInt.h d02d2b85cb02a38bc442cf9302ec8209baf6771d +F src/sqliteInt.h b54a3815ab5a353aac0e6f94c02c51a065fa7fab F src/sqliteLimit.h 216557999cb45f2e3578ed53ebefe228d779cb46 F src/status.c f266ad8a2892d659b74f0f50cb6a88b6e7c12179 F src/table.c e7a09215315a978057fb42c640f890160dbcc45e @@ -1248,7 +1248,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 3deff25249c59b7fc1b6eb65dda39736955679c6 -R 5464b14f38d360ccc6fa7360d378f7df -U drh -Z f2a2061ec6a7f778916e1fed0b96d2ff +P 5d533eee049e63b3700f5ef7c28c588afccde57a +R 9184ed6faa90f29bd59d243ded83d06c +T *branch * winTest +T *sym-winTest * +T -sym-trunk * +U mistachkin +Z fd6cc612eddf1c1ec4736ef8e7fda9d3 diff --git a/manifest.uuid b/manifest.uuid index 1069e22d85..76b24fff16 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -5d533eee049e63b3700f5ef7c28c588afccde57a \ No newline at end of file +9cc70eee2e365dd390210f436b893b9d80a19b04 \ No newline at end of file diff --git a/mptest/mptest.c b/mptest/mptest.c index 1efdc0319a..6a37231e64 100644 --- a/mptest/mptest.c +++ b/mptest/mptest.c @@ -1335,10 +1335,11 @@ int SQLITE_CDECL main(int argc, char **argv){ evalFunc, 0, 0); g.iTimeout = DEFAULT_TIMEOUT; if( g.bSqlTrace ) sqlite3_trace(g.db, sqlTraceCallback, 0); - if( !g.bSync ) trySql("PRAGMA synchronous=OFF"); if( iClient>0 ){ if( n>0 ) unrecognizedArguments(argv[0], n, argv+2); if( g.iTrace ) logMessage("start-client"); + if( !g.bSync ) trySql("PRAGMA synchronous=OFF"); + if( zJMode ) runSql("PRAGMA journal_mode=%Q;", zJMode); while(1){ char *zTaskName = 0; rc = startScript(iClient, &zScript, &taskId, &zTaskName); @@ -1358,6 +1359,7 @@ int SQLITE_CDECL main(int argc, char **argv){ fatalError("missing script filename"); } if( n>1 ) unrecognizedArguments(argv[0], n, argv+2); + if( !g.bSync ) trySql("PRAGMA synchronous=OFF"); if( zJMode ) runSql("PRAGMA journal_mode=%Q;", zJMode); runSql( "DROP TABLE IF EXISTS task;\n" diff --git a/src/main.c b/src/main.c index d9ee77fab2..46823a2d93 100644 --- a/src/main.c +++ b/src/main.c @@ -1194,7 +1194,8 @@ void sqlite3RollbackAll(sqlite3 *db, int tripCode){ ** Return a static string containing the name corresponding to the error code ** specified in the argument. */ -#if (defined(SQLITE_DEBUG) && SQLITE_OS_WIN) || defined(SQLITE_TEST) +#if defined(SQLITE_DEBUG) && \ + (defined(SQLITE_TEST) || defined(SQLITE_FORCE_OS_TRACE)) const char *sqlite3ErrName(int rc){ const char *zName = 0; int i, origRc = rc; diff --git a/src/os_common.h b/src/os_common.h index f6c3e7ff89..b5ecb9bbff 100644 --- a/src/os_common.h +++ b/src/os_common.h @@ -29,7 +29,8 @@ # error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead." #endif -#if defined(SQLITE_TEST) && defined(SQLITE_DEBUG) +#if defined(SQLITE_DEBUG) && \ + (defined(SQLITE_TEST) || defined(SQLITE_FORCE_OS_TRACE)) # ifndef SQLITE_DEBUG_OS_TRACE # define SQLITE_DEBUG_OS_TRACE 0 # endif diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 3841c91f14..92df2b703a 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -3491,7 +3491,8 @@ void *sqlite3HexToBlob(sqlite3*, const char *z, int n); u8 sqlite3HexToInt(int h); int sqlite3TwoPartName(Parse *, Token *, Token *, Token **); -#if defined(SQLITE_TEST) +#if defined(SQLITE_DEBUG) && \ + (defined(SQLITE_TEST) || defined(SQLITE_FORCE_OS_TRACE)) const char *sqlite3ErrName(int); #endif From 25a72de917a2c197ffa2a2982b4c4370506874d2 Mon Sep 17 00:00:00 2001 From: mistachkin Date: Tue, 31 Mar 2015 17:58:13 +0000 Subject: [PATCH 053/181] Path handling portability enhancements for mptester. FossilOrigin-Name: da49634b331812fa4d6e33d72c9661aeab203ae8 --- manifest | 15 ++++++--------- manifest.uuid | 2 +- mptest/mptest.c | 15 +++++++++++---- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/manifest b/manifest index 8eb1667b6f..c8faf609ad 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Testing\senhancements\son\sWindows. -D 2015-03-31T17:45:44.088 +C Path\shandling\sportability\senhancements\sfor\smptester. +D 2015-03-31T17:58:13.315 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 00d12636df7a5b08af09116bcd6c7bfd49b8b3b4 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -160,7 +160,7 @@ F mptest/config01.test 3c6adcbc50b991866855f1977ff172eb6d901271 F mptest/config02.test 4415dfe36c48785f751e16e32c20b077c28ae504 F mptest/crash01.test 61e61469e257df0850df4293d7d4d6c2af301421 F mptest/crash02.subtest f4ef05adcd15d60e5d2bd654204f2c008b519df8 -F mptest/mptest.c 5360b7a1fd85e3b39daa03d98a81eaa4096a93f5 +F mptest/mptest.c d1e8ff5488bda5ff51407d6e86b4f6e8de7ff443 F mptest/multiwrite01.test dab5c5f8f9534971efce679152c5146da265222d F spec.template 86a4a43b99ebb3e75e6b9a735d5fd293a24e90ca F sqlite.pc.in 42b7bf0d02e08b9e77734a47798d1a55a9e0716b @@ -1248,10 +1248,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 5d533eee049e63b3700f5ef7c28c588afccde57a -R 9184ed6faa90f29bd59d243ded83d06c -T *branch * winTest -T *sym-winTest * -T -sym-trunk * +P 9cc70eee2e365dd390210f436b893b9d80a19b04 +R be2bc38a728d3b9a8c390950640aab4e U mistachkin -Z fd6cc612eddf1c1ec4736ef8e7fda9d3 +Z 01af2fb4ec1ab808dcf4522c94181a8f diff --git a/manifest.uuid b/manifest.uuid index 76b24fff16..eb12a9de38 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -9cc70eee2e365dd390210f436b893b9d80a19b04 \ No newline at end of file +da49634b331812fa4d6e33d72c9661aeab203ae8 \ No newline at end of file diff --git a/mptest/mptest.c b/mptest/mptest.c index 6a37231e64..366375424b 100644 --- a/mptest/mptest.c +++ b/mptest/mptest.c @@ -53,6 +53,13 @@ # define GETPID getpid #endif +/* The directory separator character(s) */ +#if defined(_WIN32) +# define isDirSep(c) (((c) == '/') || ((c) == '\\')) +#else +# define isDirSep(c) ((c) == '/') +#endif + /* Mark a parameter as unused to suppress compiler warnings */ #define UNUSED_PARAMETER(x) (void)x @@ -824,7 +831,7 @@ static void waitForClient(int iClient, int iTimeout, char *zErrPrefix){ */ static char *filenameTail(char *z){ int i, j; - for(i=j=0; z[i]; i++) if( z[i]=='/' ) j = i+1; + for(i=j=0; z[i]; i++) if( isDirSep(z[i]) ) j = i+1; return z+j; } @@ -1021,9 +1028,9 @@ static void runScript( char *zNewFile, *zNewScript; char *zToDel = 0; zNewFile = azArg[0]; - if( zNewFile[0]!='/' ){ + if( !isDirSep(zNewFile[0]) ){ int k; - for(k=(int)strlen(zFilename)-1; k>=0 && zFilename[k]!='/'; k--){} + for(k=(int)strlen(zFilename)-1; k>=0 && !isDirSep(zFilename[k]); k--){} if( k>0 ){ zNewFile = zToDel = sqlite3_mprintf("%.*s/%s", k,zFilename,zNewFile); } @@ -1231,7 +1238,7 @@ static void usage(const char *argv0){ int i; const char *zTail = argv0; for(i=0; argv0[i]; i++){ - if( argv0[i]=='/' ) zTail = argv0+i+1; + if( isDirSep(argv0[i]) ) zTail = argv0+i+1; } fprintf(stderr,"Usage: %s DATABASE ?OPTIONS? ?SCRIPT?\n", zTail); exit(1); From 4c45196a76c92309980cdbd7fd570e183c272c36 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 31 Mar 2015 18:05:49 +0000 Subject: [PATCH 054/181] Add the "mptest" target to main.mk. Change TRUNCATE and PERSIST to DELETE for mptest.c on Windows because of problems trying to delete the journal. FossilOrigin-Name: ea697e6d9ff1f4d77774589a02ba4a18feafbf03 --- main.mk | 13 +++++++++++++ manifest | 14 +++++++------- manifest.uuid | 2 +- mptest/mptest.c | 12 +++++++++++- 4 files changed, 32 insertions(+), 9 deletions(-) diff --git a/main.mk b/main.mk index 7d21dbb25e..57bb35c486 100644 --- a/main.mk +++ b/main.mk @@ -408,6 +408,19 @@ mptester$(EXE): sqlite3.c $(TOP)/mptest/mptest.c $(TCCX) -o $@ -I. $(TOP)/mptest/mptest.c sqlite3.c \ $(TLIBS) $(THREADLIB) +MPTEST1=./mptester$(EXE) mptest.db $(TOP)/mptest/crash01.test --repeat 20 +MPTEST2=./mptester$(EXE) mptest.db $(TOP)/mptest/multiwrite01.test --repeat 20 +mptest: mptester$(EXE) + rm -f mptest.db + $(MPTEST1) --journalmode DELETE + $(MPTEST2) --journalmode WAL + $(MPTEST1) --journalmode WAL + $(MPTEST2) --journalmode PERSIST + $(MPTEST1) --journalmode PERSIST + $(MPTEST2) --journalmode TRUNCATE + $(MPTEST1) --journalmode TRUNCATE + $(MPTEST2) --journalmode DELETE + sqlite3.o: sqlite3.c $(TCCX) -I. -c sqlite3.c diff --git a/manifest b/manifest index d5d1701f1e..74afeab247 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Change\sthe\ssqlite3_log()\smessage\sgenerated\son\sa\sretry\safter\sdelay\sin\sos_win\nto\sbe\san\sSQLITE_NOTICE\sinstead\sof\sSQLITE_IOERR. -D 2015-03-31T17:32:06.290 +C Add\sthe\s"mptest"\starget\sto\smain.mk.\s\sChange\sTRUNCATE\sand\sPERSIST\sto\sDELETE\nfor\smptest.c\son\sWindows\sbecause\sof\sproblems\strying\sto\sdelete\sthe\sjournal. +D 2015-03-31T18:05:49.317 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 00d12636df7a5b08af09116bcd6c7bfd49b8b3b4 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -152,7 +152,7 @@ F ext/userauth/userauth.c 5fa3bdb492f481bbc1709fc83c91ebd13460c69e F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 x F ltmain.sh 3ff0879076df340d2e23ae905484d8c15d5fdea8 F magic.txt 8273bf49ba3b0c8559cb2774495390c31fd61c60 -F main.mk 04c49c495795b18a7b70053eef285be1e4d43fa4 +F main.mk 997eee18387a3e69394f2f948c9c6ccf079655a4 F mkopcodec.awk c2ff431854d702cdd2d779c9c0d1f58fa16fa4ea F mkopcodeh.awk c6b3fa301db6ef7ac916b14c60868aeaec1337b5 F mkso.sh fd21c06b063bb16a5d25deea1752c2da6ac3ed83 @@ -160,7 +160,7 @@ F mptest/config01.test 3c6adcbc50b991866855f1977ff172eb6d901271 F mptest/config02.test 4415dfe36c48785f751e16e32c20b077c28ae504 F mptest/crash01.test 61e61469e257df0850df4293d7d4d6c2af301421 F mptest/crash02.subtest f4ef05adcd15d60e5d2bd654204f2c008b519df8 -F mptest/mptest.c 4691e08e1fc114edd8e1875f88393718f70ba480 +F mptest/mptest.c dae6de83eddac3ef97fc4111632f6066760f939a F mptest/multiwrite01.test dab5c5f8f9534971efce679152c5146da265222d F spec.template 86a4a43b99ebb3e75e6b9a735d5fd293a24e90ca F sqlite.pc.in 42b7bf0d02e08b9e77734a47798d1a55a9e0716b @@ -1248,7 +1248,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 3deff25249c59b7fc1b6eb65dda39736955679c6 -R 5464b14f38d360ccc6fa7360d378f7df +P 5d533eee049e63b3700f5ef7c28c588afccde57a +R 9e646d8c9c851fc471bfbde27cfe2ec7 U drh -Z f2a2061ec6a7f778916e1fed0b96d2ff +Z 7401f8256f1a048a9f3296d27a2e41e1 diff --git a/manifest.uuid b/manifest.uuid index 1069e22d85..9e31354eac 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -5d533eee049e63b3700f5ef7c28c588afccde57a \ No newline at end of file +ea697e6d9ff1f4d77774589a02ba4a18feafbf03 \ No newline at end of file diff --git a/mptest/mptest.c b/mptest/mptest.c index 1efdc0319a..52ff6a4c83 100644 --- a/mptest/mptest.c +++ b/mptest/mptest.c @@ -1327,6 +1327,17 @@ int SQLITE_CDECL main(int argc, char **argv){ } rc = sqlite3_open_v2(g.zDbFile, &g.db, openFlags, g.zVfs); if( rc ) fatalError("cannot open [%s]", g.zDbFile); + if( zJMode ){ +#if defined(_WIN32) + if( sqlite3_stricmp(zJMode,"persist")==0 + || sqlite3_stricmp(zJMode,"truncate")==0 + ){ + printf("Changing journal mode to DELETE from %s", zJMode); + zJMode = "DELETE"; + } +#endif + runSql("PRAGMA journal_mode=%Q;", zJMode); + } sqlite3_enable_load_extension(g.db, 1); sqlite3_busy_handler(g.db, busyHandler, 0); sqlite3_create_function(g.db, "vfsname", 0, SQLITE_UTF8, 0, @@ -1358,7 +1369,6 @@ int SQLITE_CDECL main(int argc, char **argv){ fatalError("missing script filename"); } if( n>1 ) unrecognizedArguments(argv[0], n, argv+2); - if( zJMode ) runSql("PRAGMA journal_mode=%Q;", zJMode); runSql( "DROP TABLE IF EXISTS task;\n" "DROP TABLE IF EXISTS counters;\n" From d25675f8978e9d8dc662421f17a0405fcddde3f9 Mon Sep 17 00:00:00 2001 From: mistachkin Date: Tue, 31 Mar 2015 19:06:46 +0000 Subject: [PATCH 055/181] Build fixes for OSTRACE enhancements. FossilOrigin-Name: f79c236fc537ecee1ea7448a3e3216a2415561a1 --- manifest | 23 +++++++++++------------ manifest.uuid | 2 +- src/main.c | 2 +- src/os_common.h | 2 +- src/os_win.c | 12 ++++++++++-- src/printf.c | 3 ++- src/sqliteInt.h | 2 +- 7 files changed, 27 insertions(+), 19 deletions(-) diff --git a/manifest b/manifest index f1aa496dd8..e3db2ee4c4 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Path\sportability\senhancements\sfor\smptester.exe. -D 2015-03-31T18:18:53.022 +C Build\sfixes\sfor\sOSTRACE\senhancements. +D 2015-03-31T19:06:46.659 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 00d12636df7a5b08af09116bcd6c7bfd49b8b3b4 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -195,7 +195,7 @@ F src/journal.c b4124532212b6952f42eb2c12fa3c25701d8ba8d F src/legacy.c ba1863ea58c4c840335a84ec276fc2b25e22bc4e F src/lempar.c 7274c97d24bb46631e504332ccd3bd1b37841770 F src/loadext.c 86bd4e2fccd520b748cba52492ab60c4a770f660 -F src/main.c 1cc847aae38c804427f155441c1b73c3f9144c9a +F src/main.c cc3ac7793d38cb3e7e185edbc1f53ca311621a3a F src/malloc.c 6a370b83d54e4bbf6f94021221c2a311cff26a18 F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645 F src/mem1.c abe6ee469b6c5a35c7f22bfeb9c9bac664a1c987 @@ -212,10 +212,10 @@ F src/mutex_w32.c 61660ada28d8308ad190f444c2170c4f2a590c2f F src/notify.c 9711a7575036f0d3040ba61bc6e217f13a9888e7 F src/os.c 8fd25588eeba74068d41102d26810e216999b6c8 F src/os.h 3e57a24e2794a94d3cf2342c6d9a884888cd96bf -F src/os_common.h 75309c5996a3d201d59ccde946caef1651f206e2 +F src/os_common.h 4fccbf81ef328c9ac231211de379e753b1365313 F src/os_setup.h c9d4553b5aaa6f73391448b265b89bed0b890faa F src/os_unix.c a4dadbc2da41599e99093e91e276c38c17a73b89 -F src/os_win.c 23c2d1fab9b44e728e7d3ac0c82d5ac2a96de290 +F src/os_win.c 6c4752b58c0b795ef9c2ea667b7ea0966937a796 F src/os_win.h eb7a47aa17b26b77eb97e4823f20a00b8bda12ca F src/pager.c 4120a49ecd37697e28f5ed807f470b9c0b88410c F src/pager.h c3476e7c89cdf1c6914e50a11f3714e30b4e0a77 @@ -226,7 +226,7 @@ F src/pcache1.c 69d137620a305f814398bd29a0c998038c0695e9 F src/pragma.c ac4f3f856b4234e85f55b0f069698a4766011100 F src/pragma.h 09c89bca58e9a44de2116cc8272b8d454657129f F src/prepare.c 173a5a499138451b2561614ecb87d78f9f4644b9 -F src/printf.c 8da9a2687a396daa19860f4dc90975d319304744 +F src/printf.c 8fff88d299f00e114e1a5afc90aa4c8744bf8877 F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c f4d79e31ffa5820c2e3d1740baa5e9b190425f2b F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e @@ -235,7 +235,7 @@ F src/shell.c 84a1593bd86aaa14f4da8a8f9b16fbc239d262aa F src/sqlite.h.in 278602140d49575e8708e643161f4263e428a02a F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h 17d487c3c91b0b8c584a32fbeb393f6f795eea7d -F src/sqliteInt.h b54a3815ab5a353aac0e6f94c02c51a065fa7fab +F src/sqliteInt.h 75e86ef580cae23a36c4acfc2f664f528f8aee91 F src/sqliteLimit.h 216557999cb45f2e3578ed53ebefe228d779cb46 F src/status.c f266ad8a2892d659b74f0f50cb6a88b6e7c12179 F src/table.c e7a09215315a978057fb42c640f890160dbcc45e @@ -1248,8 +1248,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 ea697e6d9ff1f4d77774589a02ba4a18feafbf03 da49634b331812fa4d6e33d72c9661aeab203ae8 -R 126147c160c4bad0e1b7fe3417e6316b -T +closed da49634b331812fa4d6e33d72c9661aeab203ae8 -U drh -Z 3bf817d5b936af30f76c04f3a5290142 +P c8694657bdc5d0917d8fe78fd3937d8e9cd9d04b +R 7fff6ef631e32e4acabaf29648c7d2ea +U mistachkin +Z 26798f0cab8ceff11e56a6de19170f96 diff --git a/manifest.uuid b/manifest.uuid index 012d207f50..90215aece6 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c8694657bdc5d0917d8fe78fd3937d8e9cd9d04b \ No newline at end of file +f79c236fc537ecee1ea7448a3e3216a2415561a1 \ No newline at end of file diff --git a/src/main.c b/src/main.c index 46823a2d93..0e2f2bdc03 100644 --- a/src/main.c +++ b/src/main.c @@ -1194,7 +1194,7 @@ void sqlite3RollbackAll(sqlite3 *db, int tripCode){ ** Return a static string containing the name corresponding to the error code ** specified in the argument. */ -#if defined(SQLITE_DEBUG) && \ +#if (defined(SQLITE_DEBUG) && SQLITE_OS_WIN) || \ (defined(SQLITE_TEST) || defined(SQLITE_FORCE_OS_TRACE)) const char *sqlite3ErrName(int rc){ const char *zName = 0; diff --git a/src/os_common.h b/src/os_common.h index b5ecb9bbff..0f5f779438 100644 --- a/src/os_common.h +++ b/src/os_common.h @@ -29,7 +29,7 @@ # error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead." #endif -#if defined(SQLITE_DEBUG) && \ +#if (defined(SQLITE_DEBUG) && SQLITE_OS_WIN) || \ (defined(SQLITE_TEST) || defined(SQLITE_FORCE_OS_TRACE)) # ifndef SQLITE_DEBUG_OS_TRACE # define SQLITE_DEBUG_OS_TRACE 0 diff --git a/src/os_win.c b/src/os_win.c index e685e20fab..acb06c69e9 100644 --- a/src/os_win.c +++ b/src/os_win.c @@ -25,6 +25,14 @@ */ #include "os_win.h" +/* +** Is the OSTRACE macro defined to actually do something? +*/ +#if (defined(SQLITE_DEBUG) && SQLITE_OS_WIN) || \ + (defined(SQLITE_TEST) || defined(SQLITE_FORCE_OS_TRACE)) +# define SQLITE_WIN32_HAS_OS_TRACE +#endif + /* ** Compiling and using WAL mode requires several APIs that are only ** available in Windows platforms based on the NT kernel. @@ -2746,7 +2754,7 @@ static int winSync(sqlite3_file *id, int flags){ BOOL rc; #endif #if !defined(NDEBUG) || !defined(SQLITE_NO_SYNC) || \ - (defined(SQLITE_TEST) && defined(SQLITE_DEBUG)) + defined(SQLITE_WIN32_HAS_OS_TRACE) /* ** Used when SQLITE_NO_SYNC is not defined and by the assert() and/or ** OSTRACE() macros. @@ -3438,7 +3446,7 @@ struct winShm { u8 hasMutex; /* True if holding the winShmNode mutex */ u16 sharedMask; /* Mask of shared locks held */ u16 exclMask; /* Mask of exclusive locks held */ -#ifdef SQLITE_DEBUG +#if defined(SQLITE_DEBUG) || defined(SQLITE_WIN32_HAS_OS_TRACE) u8 id; /* Id of this connection with its winShmNode */ #endif }; diff --git a/src/printf.c b/src/printf.c index 81efa057fc..b559e9dfc3 100644 --- a/src/printf.c +++ b/src/printf.c @@ -1045,7 +1045,8 @@ void sqlite3_log(int iErrCode, const char *zFormat, ...){ } } -#if defined(SQLITE_DEBUG) +#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST) || \ + defined(SQLITE_FORCE_OS_TRACE) /* ** A version of printf() that understands %lld. Used for debugging. ** The printf() built into some versions of windows does not understand %lld diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 92df2b703a..45250bfd10 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -3491,7 +3491,7 @@ void *sqlite3HexToBlob(sqlite3*, const char *z, int n); u8 sqlite3HexToInt(int h); int sqlite3TwoPartName(Parse *, Token *, Token *, Token **); -#if defined(SQLITE_DEBUG) && \ +#if (defined(SQLITE_DEBUG) && SQLITE_OS_WIN) || \ (defined(SQLITE_TEST) || defined(SQLITE_FORCE_OS_TRACE)) const char *sqlite3ErrName(int); #endif From 98f1c4086df052634215cf5f071be8d33cc34e5f Mon Sep 17 00:00:00 2001 From: mistachkin Date: Tue, 31 Mar 2015 19:17:44 +0000 Subject: [PATCH 056/181] Set the winShm.id member when it is going to be traced. FossilOrigin-Name: fa7916b67efbc44e6f115bb0d32d8b92fd0acf3c --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/os_win.c | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index e3db2ee4c4..0a765e257a 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Build\sfixes\sfor\sOSTRACE\senhancements. -D 2015-03-31T19:06:46.659 +C Set\sthe\swinShm.id\smember\swhen\sit\sis\sgoing\sto\sbe\straced. +D 2015-03-31T19:17:44.993 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 00d12636df7a5b08af09116bcd6c7bfd49b8b3b4 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -215,7 +215,7 @@ F src/os.h 3e57a24e2794a94d3cf2342c6d9a884888cd96bf F src/os_common.h 4fccbf81ef328c9ac231211de379e753b1365313 F src/os_setup.h c9d4553b5aaa6f73391448b265b89bed0b890faa F src/os_unix.c a4dadbc2da41599e99093e91e276c38c17a73b89 -F src/os_win.c 6c4752b58c0b795ef9c2ea667b7ea0966937a796 +F src/os_win.c 87ae49ff973c3e01fff4cd002e1bbc135a63107e F src/os_win.h eb7a47aa17b26b77eb97e4823f20a00b8bda12ca F src/pager.c 4120a49ecd37697e28f5ed807f470b9c0b88410c F src/pager.h c3476e7c89cdf1c6914e50a11f3714e30b4e0a77 @@ -1248,7 +1248,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 c8694657bdc5d0917d8fe78fd3937d8e9cd9d04b -R 7fff6ef631e32e4acabaf29648c7d2ea +P f79c236fc537ecee1ea7448a3e3216a2415561a1 +R c0e6ffe8bce6c29d87c8228cd21b6e7e U mistachkin -Z 26798f0cab8ceff11e56a6de19170f96 +Z c7f453d4a005311b5f674545bd39b5a8 diff --git a/manifest.uuid b/manifest.uuid index 90215aece6..5fdcfe2a1c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -f79c236fc537ecee1ea7448a3e3216a2415561a1 \ No newline at end of file +fa7916b67efbc44e6f115bb0d32d8b92fd0acf3c \ No newline at end of file diff --git a/src/os_win.c b/src/os_win.c index acb06c69e9..abfa454bd9 100644 --- a/src/os_win.c +++ b/src/os_win.c @@ -3415,7 +3415,7 @@ struct winShmNode { int nRef; /* Number of winShm objects pointing to this */ winShm *pFirst; /* All winShm objects pointing to this */ winShmNode *pNext; /* Next in list of all winShmNode objects */ -#ifdef SQLITE_DEBUG +#if defined(SQLITE_DEBUG) || defined(SQLITE_WIN32_HAS_OS_TRACE) u8 nextShmId; /* Next available winShm.id value */ #endif }; @@ -3637,7 +3637,7 @@ static int winOpenSharedMemory(winFile *pDbFd){ /* Make the new connection a child of the winShmNode */ p->pShmNode = pShmNode; -#ifdef SQLITE_DEBUG +#if defined(SQLITE_DEBUG) || defined(SQLITE_WIN32_HAS_OS_TRACE) p->id = pShmNode->nextShmId++; #endif pShmNode->nRef++; From ccf46d0b9020d88fddbdc2dd9b9104b403f7d615 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 1 Apr 2015 13:21:33 +0000 Subject: [PATCH 057/181] Improved detection and suppression of endless loops in clearDatabasePage(). FossilOrigin-Name: 30011ad2f55cfcacaf23a58ebcc17b17a7b9355e --- manifest | 15 +++++++-------- manifest.uuid | 2 +- src/btree.c | 14 ++++++++------ src/btreeInt.h | 1 + 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/manifest b/manifest index 63d5d9eccf..83880531e8 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C On\swindows,\sflush\sthe\smapping\sview\swhen\ssyncing\scontent\sto\sdisk. -D 2015-03-31T19:40:05.313 +C Improved\sdetection\sand\ssuppression\sof\sendless\sloops\sin\sclearDatabasePage(). +D 2015-04-01T13:21:33.901 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 00d12636df7a5b08af09116bcd6c7bfd49b8b3b4 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -173,9 +173,9 @@ F src/auth.c b56c78ebe40a2110fd361379f7e8162d23f92240 F src/backup.c ff743689c4d6c5cb55ad42ed9d174b2b3e71f1e3 F src/bitvec.c 19a4ba637bd85f8f63fc8c9bae5ade9fb05ec1cb F src/btmutex.c 45a968cc85afed9b5e6cf55bf1f42f8d18107f79 -F src/btree.c 525f19f01d5976dbc12e83e7339e41488de79183 +F src/btree.c 2caf598165f3608fde8abac2b243826616ce54b7 F src/btree.h 969adc948e89e449220ff0ff724c94bb2a52e9f1 -F src/btreeInt.h 2bfefc01875d8da066504c233ec259fcb3b2ef72 +F src/btreeInt.h 973a22a6fd61350b454ad614832b1f0a5e25a1e4 F src/build.c 0419bba592c22f6d00e6d57a2ca7136720d02c1a F src/callback.c 7b44ce59674338ad48b0e84e7b72f935ea4f68b0 F src/complete.c 198a0066ba60ab06fc00fba1998d870a4d575463 @@ -1248,8 +1248,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 ea697e6d9ff1f4d77774589a02ba4a18feafbf03 45acf6a85150839d591316418dad59ae20ce3aa4 -R 00dcdcdf447a25afe74cb2a2ac195e0b -T +closed 45acf6a85150839d591316418dad59ae20ce3aa4 +P a828e73dc1ae50189bdf73f60caeb7308738ad7a +R 9ae26e7b05df4833a239ec9186729882 U drh -Z e131d4f6392434ebe038899ef79bd289 +Z b113a7338e765a6278a4e0ffd57f1cf8 diff --git a/manifest.uuid b/manifest.uuid index 6301587c11..925ee38b4d 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -a828e73dc1ae50189bdf73f60caeb7308738ad7a \ No newline at end of file +30011ad2f55cfcacaf23a58ebcc17b17a7b9355e \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index b497cd7468..789796d55a 100644 --- a/src/btree.c +++ b/src/btree.c @@ -7980,28 +7980,29 @@ static int clearDatabasePage( int i; int hdr; u16 szCell; - u8 hasChildren; assert( sqlite3_mutex_held(pBt->mutex) ); if( pgno>btreePagecount(pBt) ){ return SQLITE_CORRUPT_BKPT; } - rc = getAndInitPage(pBt, pgno, &pPage, 0); if( rc ) return rc; - hasChildren = !pPage->leaf; - pPage->leaf = 1; /* Block looping if the database is corrupt */ + if( pPage->bBusy ){ + rc = SQLITE_CORRUPT_BKPT; + goto cleardatabasepage_out; + } + pPage->bBusy = 1; hdr = pPage->hdrOffset; for(i=0; inCell; i++){ pCell = findCell(pPage, i); - if( hasChildren ){ + if( !pPage->leaf ){ rc = clearDatabasePage(pBt, get4byte(pCell), 1, pnChange); if( rc ) goto cleardatabasepage_out; } rc = clearCell(pPage, pCell, &szCell); if( rc ) goto cleardatabasepage_out; } - if( hasChildren ){ + if( !pPage->leaf ){ rc = clearDatabasePage(pBt, get4byte(&pPage->aData[hdr+8]), 1, pnChange); if( rc ) goto cleardatabasepage_out; }else if( pnChange ){ @@ -8015,6 +8016,7 @@ static int clearDatabasePage( } cleardatabasepage_out: + pPage->bBusy = 0; releasePage(pPage); return rc; } diff --git a/src/btreeInt.h b/src/btreeInt.h index 87d0ef1bb8..33ef641059 100644 --- a/src/btreeInt.h +++ b/src/btreeInt.h @@ -280,6 +280,7 @@ struct MemPage { u8 hdrOffset; /* 100 for page 1. 0 otherwise */ u8 childPtrSize; /* 0 if leaf==1. 4 if leaf==0 */ u8 max1bytePayload; /* min(maxLocal,127) */ + u8 bBusy; /* Prevent endless loops on corrupt database files */ u16 maxLocal; /* Copy of BtShared.maxLocal or BtShared.maxLeaf */ u16 minLocal; /* Copy of BtShared.minLocal or BtShared.minLeaf */ u16 cellOffset; /* Index in aData of first cell pointer */ From b18e60b3e43270773c163d7b6424b904fb9ffb9a Mon Sep 17 00:00:00 2001 From: dan Date: Wed, 1 Apr 2015 16:18:00 +0000 Subject: [PATCH 058/181] Reduce the CPU used by CREATE INDEX statements by taking better advantage of the fact that keys are inserted in sorted order. FossilOrigin-Name: 592cdc5d7254be7032aa9c0b03405a74ca060b51 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/build.c | 3 ++- src/vdbe.c | 3 ++- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index a7a78bf354..be112fc01e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Improve\sperformance\sof\smulti-field\ssorts\swhere\sthe\sfirst\sfield\shas\sa\slow\scardinality. -D 2015-03-30T12:06:26.995 +C Reduce\sthe\sCPU\sused\sby\sCREATE\sINDEX\sstatements\sby\staking\sbetter\sadvantage\sof\sthe\sfact\sthat\skeys\sare\sinserted\sin\ssorted\sorder. +D 2015-04-01T16:18:00.779 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -176,7 +176,7 @@ F src/btmutex.c 45a968cc85afed9b5e6cf55bf1f42f8d18107f79 F src/btree.c 4f305e554d7d207375c3e29ab0335bd5a473a125 F src/btree.h 969adc948e89e449220ff0ff724c94bb2a52e9f1 F src/btreeInt.h 2bfefc01875d8da066504c233ec259fcb3b2ef72 -F src/build.c 0419bba592c22f6d00e6d57a2ca7136720d02c1a +F src/build.c 9103f5cd8f4071dc0c44a3312956e53f5b7f52c8 F src/callback.c 7b44ce59674338ad48b0e84e7b72f935ea4f68b0 F src/complete.c 198a0066ba60ab06fc00fba1998d870a4d575463 F src/ctime.c 98f89724adc891a1a4c655bee04e33e716e05887 @@ -293,7 +293,7 @@ F src/update.c 3c4ecc282accf12d39edb8d524cf089645e55a13 F src/utf.c fc6b889ba0779b7722634cdeaa25f1930d93820c F src/util.c 98a7627ca48ad3265b6940915a1d08355eb3fc7e F src/vacuum.c 9460b9de7b2d4e34b0d374894aa6c8a0632be8ec -F src/vdbe.c bbfede5a8a6908b3ddcd55fdb0b2301288dd4754 +F src/vdbe.c a9d916abb1e22355a81b0e72040917ba33c87ed7 F src/vdbe.h 7e538ecf47dccb307ea2d087c3ddc2dd8d70e79d F src/vdbeInt.h 9cbaa84f53ddd2d09a0cf61a94337a3a035d08a0 F src/vdbeapi.c 583d56b129dd27f12bed518270de9ebe521e6a75 @@ -1247,7 +1247,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 b58191e91736b1d978db4127f22867dfe2302f7c -R ce44a3d54ad53a02b61fed80311cecef +P 601e7b6b8e6bfabda03b70f75094c9014e3a3c49 +R 151febe3c42a1563a662898adadb6b2d U dan -Z 8753c6822202b0898d8492105ecdb751 +Z 37e9d6c37bda7e19a2c8ebf1573e150d diff --git a/manifest.uuid b/manifest.uuid index 2a8f64fa3a..6bc7a444cf 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -601e7b6b8e6bfabda03b70f75094c9014e3a3c49 \ No newline at end of file +592cdc5d7254be7032aa9c0b03405a74ca060b51 \ No newline at end of file diff --git a/src/build.c b/src/build.c index fcf96bd42c..11c790d311 100644 --- a/src/build.c +++ b/src/build.c @@ -2763,7 +2763,8 @@ static void sqlite3RefillIndex(Parse *pParse, Index *pIndex, int memRootPage){ addr2 = sqlite3VdbeCurrentAddr(v); } sqlite3VdbeAddOp3(v, OP_SorterData, iSorter, regRecord, iIdx); - sqlite3VdbeAddOp3(v, OP_IdxInsert, iIdx, regRecord, 1); + sqlite3VdbeAddOp3(v, OP_Last, iIdx, 0, -1); + sqlite3VdbeAddOp3(v, OP_IdxInsert, iIdx, regRecord, 0); sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT); sqlite3ReleaseTempReg(pParse, regRecord); sqlite3VdbeAddOp2(v, OP_SorterNext, iSorter, addr2); VdbeCoverage(v); diff --git a/src/vdbe.c b/src/vdbe.c index ec5e6d7442..150b2c150f 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -4480,7 +4480,7 @@ case OP_NullRow: { break; } -/* Opcode: Last P1 P2 * * * +/* Opcode: Last P1 P2 P3 * * ** ** The next use of the Rowid or Column or Prev instruction for P1 ** will refer to the last entry in the database table or index. @@ -4507,6 +4507,7 @@ case OP_Last: { /* jump */ pC->nullRow = (u8)res; pC->deferredMoveto = 0; pC->cacheStatus = CACHE_STALE; + pC->seekResult = pOp->p3; #ifdef SQLITE_DEBUG pC->seekOp = OP_Last; #endif From e34162b14f24aae2b478b917ceb6f516289ac39a Mon Sep 17 00:00:00 2001 From: dan Date: Wed, 1 Apr 2015 18:20:25 +0000 Subject: [PATCH 059/181] When vacuuming an index that uses no collations other than BINARY, assume that the order of index entries will not be changed by the VACUUM. FossilOrigin-Name: e403460b96814ac8cb976d58b27939b3bd3c61f9 --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/insert.c | 48 ++++++++++++++++++++++++++++++++++++++++-------- src/sqliteInt.h | 1 + src/vacuum.c | 4 ++++ 5 files changed, 54 insertions(+), 17 deletions(-) diff --git a/manifest b/manifest index be112fc01e..16584352e7 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Reduce\sthe\sCPU\sused\sby\sCREATE\sINDEX\sstatements\sby\staking\sbetter\sadvantage\sof\sthe\sfact\sthat\skeys\sare\sinserted\sin\ssorted\sorder. -D 2015-04-01T16:18:00.779 +C When\svacuuming\san\sindex\sthat\suses\sno\scollations\sother\sthan\sBINARY,\sassume\sthat\sthe\sorder\sof\sindex\sentries\swill\snot\sbe\schanged\sby\sthe\sVACUUM. +D 2015-04-01T18:20:25.537 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -190,7 +190,7 @@ F src/global.c 4f77cadbc5427d00139ba43d0f3979804cbb700e F src/hash.c 4263fbc955f26c2e8cdc0cf214bc42435aa4e4f5 F src/hash.h c8f3c31722cf3277d03713909761e152a5b81094 F src/hwtime.h d32741c8f4df852c7d959236615444e2b1063b08 -F src/insert.c 5b9243a33726008cc4132897d2be371db12a13be +F src/insert.c 1cc9dc4e939b5dd4a74ac4a3222b89e66b074210 F src/journal.c b4124532212b6952f42eb2c12fa3c25701d8ba8d F src/legacy.c ba1863ea58c4c840335a84ec276fc2b25e22bc4e F src/lempar.c 7274c97d24bb46631e504332ccd3bd1b37841770 @@ -235,7 +235,7 @@ F src/shell.c 3ae1e53878d2804fe77b8c8f1f6ca287a0e5d80e F src/sqlite.h.in 278602140d49575e8708e643161f4263e428a02a F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h 17d487c3c91b0b8c584a32fbeb393f6f795eea7d -F src/sqliteInt.h bedf15914c09bfb5fe3ec4e3f211a4a6fc42cd33 +F src/sqliteInt.h df0ee3545220b8687d8640d433d1417b31e1675a F src/sqliteLimit.h 216557999cb45f2e3578ed53ebefe228d779cb46 F src/status.c f266ad8a2892d659b74f0f50cb6a88b6e7c12179 F src/table.c e7a09215315a978057fb42c640f890160dbcc45e @@ -292,7 +292,7 @@ F src/trigger.c 25571661fdeae8c7f975ff40ffec205520a3f92f F src/update.c 3c4ecc282accf12d39edb8d524cf089645e55a13 F src/utf.c fc6b889ba0779b7722634cdeaa25f1930d93820c F src/util.c 98a7627ca48ad3265b6940915a1d08355eb3fc7e -F src/vacuum.c 9460b9de7b2d4e34b0d374894aa6c8a0632be8ec +F src/vacuum.c 2ddd5cad2a7b9cef7f9e431b8c7771634c6b1701 F src/vdbe.c a9d916abb1e22355a81b0e72040917ba33c87ed7 F src/vdbe.h 7e538ecf47dccb307ea2d087c3ddc2dd8d70e79d F src/vdbeInt.h 9cbaa84f53ddd2d09a0cf61a94337a3a035d08a0 @@ -1247,7 +1247,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 601e7b6b8e6bfabda03b70f75094c9014e3a3c49 -R 151febe3c42a1563a662898adadb6b2d +P 592cdc5d7254be7032aa9c0b03405a74ca060b51 +R d93391642538d3e00eae6a1c718cf53f U dan -Z 37e9d6c37bda7e19a2c8ebf1573e150d +Z 6ea2b15ffbb091b1ac11e4173c1e9ec7 diff --git a/manifest.uuid b/manifest.uuid index 6bc7a444cf..180597c5c9 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -592cdc5d7254be7032aa9c0b03405a74ca060b51 \ No newline at end of file +e403460b96814ac8cb976d58b27939b3bd3c61f9 \ No newline at end of file diff --git a/src/insert.c b/src/insert.c index a5c3f3e92d..f8ae4d7d3c 100644 --- a/src/insert.c +++ b/src/insert.c @@ -1765,6 +1765,7 @@ static int xferOptimization( int onError, /* How to handle constraint errors */ int iDbDest /* The database of pDest */ ){ + sqlite3 *db = pParse->db; ExprList *pEList; /* The result set of the SELECT */ Table *pSrc; /* The table in the FROM clause of SELECT */ Index *pSrcIdx, *pDestIdx; /* Source and destination indices */ @@ -1912,11 +1913,11 @@ static int xferOptimization( ** the extra complication to make this rule less restrictive is probably ** not worth the effort. Ticket [6284df89debdfa61db8073e062908af0c9b6118e] */ - if( (pParse->db->flags & SQLITE_ForeignKeys)!=0 && pDest->pFKey!=0 ){ + if( (db->flags & SQLITE_ForeignKeys)!=0 && pDest->pFKey!=0 ){ return 0; } #endif - if( (pParse->db->flags & SQLITE_CountRows)!=0 ){ + if( (db->flags & SQLITE_CountRows)!=0 ){ return 0; /* xfer opt does not play well with PRAGMA count_changes */ } @@ -1927,7 +1928,7 @@ static int xferOptimization( #ifdef SQLITE_TEST sqlite3_xferopt_count++; #endif - iDbSrc = sqlite3SchemaToIndex(pParse->db, pSrc->pSchema); + iDbSrc = sqlite3SchemaToIndex(db, pSrc->pSchema); v = sqlite3GetVdbe(pParse); sqlite3CodeVerifySchema(pParse, iDbSrc); iSrc = pParse->nTab++; @@ -1937,14 +1938,18 @@ static int xferOptimization( regRowid = sqlite3GetTempReg(pParse); sqlite3OpenTable(pParse, iDest, iDbDest, pDest, OP_OpenWrite); assert( HasRowid(pDest) || destHasUniqueIdx ); - if( (pDest->iPKey<0 && pDest->pIndex!=0) /* (1) */ + if( (db->flags & SQLITE_Vacuum)==0 && ( + (pDest->iPKey<0 && pDest->pIndex!=0) /* (1) */ || destHasUniqueIdx /* (2) */ || (onError!=OE_Abort && onError!=OE_Rollback) /* (3) */ - ){ + )){ /* In some circumstances, we are able to run the xfer optimization - ** only if the destination table is initially empty. This code makes - ** that determination. Conditions under which the destination must - ** be empty: + ** only if the destination table is initially empty. Unless the + ** SQLITE_Vacuum flag is set, this block generates code to make + ** that determination. If SQLITE_Vacuum is set, then the destination + ** table is always empty. + ** + ** Conditions under which the destination must be empty: ** ** (1) There is no INTEGER PRIMARY KEY but there are indices. ** (If the destination is not initially empty, the rowid fields @@ -1987,6 +1992,7 @@ static int xferOptimization( sqlite3TableLock(pParse, iDbSrc, pSrc->tnum, 0, pSrc->zName); } for(pDestIdx=pDest->pIndex; pDestIdx; pDestIdx=pDestIdx->pNext){ + u8 useSeekResult = 0; for(pSrcIdx=pSrc->pIndex; ALWAYS(pSrcIdx); pSrcIdx=pSrcIdx->pNext){ if( xferCompatibleIndex(pDestIdx, pSrcIdx) ) break; } @@ -2000,7 +2006,33 @@ static int xferOptimization( VdbeComment((v, "%s", pDestIdx->zName)); addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0); VdbeCoverage(v); sqlite3VdbeAddOp2(v, OP_RowKey, iSrc, regData); + if( db->flags & SQLITE_Vacuum ){ + /* This INSERT command is part of a VACUUM operation, which guarantees + ** that the destination table is empty. If all indexed columns use + ** collation sequence BINARY, then it can also be assumed that the + ** index will be populated by inserting keys in strictly sorted + ** order. In this case, instead of seeking within the b-tree as part + ** of every OP_IdxInsert opcode, an OP_Last is added before the + ** OP_IdxInsert to seek to the point within the b-tree where each key + ** should be inserted. This is faster. + ** + ** If any of the indexed columns use a collation sequence other than + ** BINARY, this optimization is disabled. This is because the user + ** might change the definition of a collation sequence and then run + ** a VACUUM command. In that case keys may not be written in strictly + ** sorted order. */ + int i; + for(i=0; inColumn; i++){ + char *zColl = pSrcIdx->azColl[i]; + if( zColl && sqlite3_stricmp("BINARY", zColl) ) break; + } + if( i==pSrcIdx->nColumn ){ + useSeekResult = OPFLAG_USESEEKRESULT; + sqlite3VdbeAddOp3(v, OP_Last, iDest, 0, -1); + } + } sqlite3VdbeAddOp3(v, OP_IdxInsert, iDest, regData, 1); + sqlite3VdbeChangeP5(v, useSeekResult); sqlite3VdbeAddOp2(v, OP_Next, iSrc, addr1+1); VdbeCoverage(v); sqlite3VdbeJumpHere(v, addr1); sqlite3VdbeAddOp2(v, OP_Close, iSrc, 0); diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 9df6d1bc4e..5e49bf58ff 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -1226,6 +1226,7 @@ struct sqlite3 { #define SQLITE_DeferFKs 0x01000000 /* Defer all FK constraints */ #define SQLITE_QueryOnly 0x02000000 /* Disable database changes */ #define SQLITE_VdbeEQP 0x04000000 /* Debug EXPLAIN QUERY PLAN */ +#define SQLITE_Vacuum 0x08000000 /* Currently in a VACUUM */ /* diff --git a/src/vacuum.c b/src/vacuum.c index dca43e217e..adc802e60b 100644 --- a/src/vacuum.c +++ b/src/vacuum.c @@ -250,6 +250,8 @@ int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db){ ** an "INSERT INTO vacuum_db.xxx SELECT * FROM main.xxx;" to copy ** the contents to the temporary database. */ + assert( (db->flags & SQLITE_Vacuum)==0 ); + db->flags |= SQLITE_Vacuum; rc = execExecSql(db, pzErrMsg, "SELECT 'INSERT INTO vacuum_db.' || quote(name) " "|| ' SELECT * FROM main.' || quote(name) || ';'" @@ -257,6 +259,8 @@ int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db){ "WHERE type = 'table' AND name!='sqlite_sequence' " " AND coalesce(rootpage,1)>0" ); + assert( (db->flags & SQLITE_Vacuum)!=0 ); + db->flags &= ~SQLITE_Vacuum; if( rc!=SQLITE_OK ) goto end_of_vacuum; /* Copy over the sequence table From 29f1a19cd96e8d7f72366492986cce2053df0deb Mon Sep 17 00:00:00 2001 From: dan Date: Thu, 2 Apr 2015 09:06:21 +0000 Subject: [PATCH 060/181] Fix a problem in vdbesort.c to do with caching unpacked records. FossilOrigin-Name: 80a00539506c95443165a781d1d869205057ca6c --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/vdbesort.c | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 8108693bf7..f9ce3a510d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Merge\slatest\strunk\schanges\swith\sthis\sbranch. -D 2015-04-01T18:22:26.384 +C Fix\sa\sproblem\sin\svdbesort.c\sto\sdo\swith\scaching\sunpacked\srecords. +D 2015-04-02T09:06:21.116 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 00d12636df7a5b08af09116bcd6c7bfd49b8b3b4 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -300,7 +300,7 @@ F src/vdbeapi.c 583d56b129dd27f12bed518270de9ebe521e6a75 F src/vdbeaux.c a20504ae52392459fa08402fda3f195f19d7c79d F src/vdbeblob.c 4f2e8e075d238392df98c5e03a64342465b03f90 F src/vdbemem.c c0dc81285b7571b0a31c40f17846fe2397ec1cd9 -F src/vdbesort.c 7b3684665ea51d642b0e664fa4d0b0d08d61d80c +F src/vdbesort.c 74a41fcd3adc22bc47ede68443d0b3e26ae13bb8 F src/vdbetrace.c 7e4222955e07dd707a2f360c0eb73452be1cb010 F src/vtab.c 62d49237bd8f3be4863815a39387b0f9897fa5e1 F src/vxworks.h c18586c8edc1bddbc15c004fa16aeb1e1342b4fb @@ -1248,7 +1248,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 e403460b96814ac8cb976d58b27939b3bd3c61f9 30011ad2f55cfcacaf23a58ebcc17b17a7b9355e -R 768d1278a2c7aae9e472dc5791f2f6a1 +P 4621b2eef8be6d944f87de097bd11c649fe43333 +R 0796456518338cd116674974cfde4890 U dan -Z 2045741c9810a18232145862154fc073 +Z 0cef8df18e8711c69cda8f5613bc4995 diff --git a/manifest.uuid b/manifest.uuid index a5a195f19f..0941cff2b9 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -4621b2eef8be6d944f87de097bd11c649fe43333 \ No newline at end of file +80a00539506c95443165a781d1d869205057ca6c \ No newline at end of file diff --git a/src/vdbesort.c b/src/vdbesort.c index 547dce2e65..f4b995c88a 100644 --- a/src/vdbesort.c +++ b/src/vdbesort.c @@ -1656,7 +1656,7 @@ static int vdbeMergeEngineStep( pReadr2 = &pMerger->aReadr[ pMerger->aTree[i ^ 0x0001] ]; bCached = 0; }else{ - bCached = (pReadr1->pFd!=0); + if( pReadr1->pFd ) bCached = 0; pMerger->aTree[i] = (int)(pReadr2 - pMerger->aReadr); pReadr1 = &pMerger->aReadr[ pMerger->aTree[i ^ 0x0001] ]; } From 5f1731f67000d8e0c7cd9ce14ffd48e37bf42866 Mon Sep 17 00:00:00 2001 From: dan Date: Thu, 2 Apr 2015 15:24:53 +0000 Subject: [PATCH 061/181] Disable e_walauto.test on OpenBSD, as it requires a coherent cache. FossilOrigin-Name: 90701227085b8b8eb10a8eebe8d55f38b4778574 --- manifest | 14 +++++++------- manifest.uuid | 2 +- test/e_walauto.test | 8 ++++++++ 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 83880531e8..e116e655ac 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Improved\sdetection\sand\ssuppression\sof\sendless\sloops\sin\sclearDatabasePage(). -D 2015-04-01T13:21:33.901 +C Disable\se_walauto.test\son\sOpenBSD,\sas\sit\srequires\sa\scoherent\scache. +D 2015-04-02T15:24:53.782 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 00d12636df7a5b08af09116bcd6c7bfd49b8b3b4 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -485,7 +485,7 @@ F test/e_update.test 312cb8f5ccfe41515a6bb092f8ea562a9bd54d52 F test/e_uri.test 5ae33760fb2039c61aa2d90886f1664664173585 F test/e_vacuum.test 5bfbdc21b65c0abf24398d0ba31dc88d93ca77a9 F test/e_wal.test ae9a593207a77d711443ee69ffe081fda9243625 -F test/e_walauto.test ca70cf75c07a6cb1874ced101dd426da76625649 +F test/e_walauto.test 6544af03423abc61b53cfb976839385ddc2a0a70 F test/e_walckpt.test 65e29b6631e51f210f83e4ff11571e647ba93608 F test/e_walhook.test da3ea8b3483d1af72190337bda50155a91a4b664 F test/enc.test e54531cd6bf941ee6760be041dff19a104c7acea @@ -1248,7 +1248,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 a828e73dc1ae50189bdf73f60caeb7308738ad7a -R 9ae26e7b05df4833a239ec9186729882 -U drh -Z b113a7338e765a6278a4e0ffd57f1cf8 +P 30011ad2f55cfcacaf23a58ebcc17b17a7b9355e +R 0b149500fabb905b0771216875924384 +U dan +Z 259e8553f23f2ead0f4917d2e8d05aa6 diff --git a/manifest.uuid b/manifest.uuid index 925ee38b4d..67f1e1b12f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -30011ad2f55cfcacaf23a58ebcc17b17a7b9355e \ No newline at end of file +90701227085b8b8eb10a8eebe8d55f38b4778574 \ No newline at end of file diff --git a/test/e_walauto.test b/test/e_walauto.test index b624b2469c..a1f4eb7079 100644 --- a/test/e_walauto.test +++ b/test/e_walauto.test @@ -15,6 +15,14 @@ source $testdir/tester.tcl source $testdir/wal_common.tcl set testprefix e_walauto +# Do not run this test on OpenBSD, as it depends on read() and mmap both +# accessing the same coherent view of the "test.db-shm" file. This doesn't +# work on OpenBSD. +# +if {$tcl_platform(os) == "OpenBSD"} { + finish_test + return +} proc read_nbackfill {} { seek $::shmfd 96 From 34cf25830249a17e665e0ad22c95928cfaf9e1dc Mon Sep 17 00:00:00 2001 From: mistachkin Date: Thu, 2 Apr 2015 17:46:52 +0000 Subject: [PATCH 062/181] Fix build with OSTRACE enabled on Windows when building using separate source files. FossilOrigin-Name: 5f6e35802fcf7b5e9fc3dd4424e9074523fa8ad3 --- manifest | 17 ++++++++--------- manifest.uuid | 2 +- src/main.c | 13 +++++++++++++ src/os_common.h | 8 ++++---- 4 files changed, 26 insertions(+), 14 deletions(-) diff --git a/manifest b/manifest index 5d40a858f2..dabb61374f 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Improved\stracing\sand\sdebugging\ssupport\son\swindows. -D 2015-04-01T01:26:12.429 +C Fix\sbuild\swith\sOSTRACE\senabled\son\sWindows\swhen\sbuilding\susing\sseparate\ssource\sfiles. +D 2015-04-02T17:46:52.559 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 00d12636df7a5b08af09116bcd6c7bfd49b8b3b4 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -195,7 +195,7 @@ F src/journal.c b4124532212b6952f42eb2c12fa3c25701d8ba8d F src/legacy.c ba1863ea58c4c840335a84ec276fc2b25e22bc4e F src/lempar.c 7274c97d24bb46631e504332ccd3bd1b37841770 F src/loadext.c 86bd4e2fccd520b748cba52492ab60c4a770f660 -F src/main.c cc3ac7793d38cb3e7e185edbc1f53ca311621a3a +F src/main.c 1ce947628ff241608fd4a122976fa29d36b8838f F src/malloc.c 6a370b83d54e4bbf6f94021221c2a311cff26a18 F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645 F src/mem1.c abe6ee469b6c5a35c7f22bfeb9c9bac664a1c987 @@ -212,7 +212,7 @@ F src/mutex_w32.c 61660ada28d8308ad190f444c2170c4f2a590c2f F src/notify.c 9711a7575036f0d3040ba61bc6e217f13a9888e7 F src/os.c 8fd25588eeba74068d41102d26810e216999b6c8 F src/os.h 3e57a24e2794a94d3cf2342c6d9a884888cd96bf -F src/os_common.h 4fccbf81ef328c9ac231211de379e753b1365313 +F src/os_common.h 05c8d05b4f1bce4262c9e2e74ab10c2d0dec964a F src/os_setup.h c9d4553b5aaa6f73391448b265b89bed0b890faa F src/os_unix.c a4dadbc2da41599e99093e91e276c38c17a73b89 F src/os_win.c eeb317cd504f39ef2dbcf50eb228bc9dd301d024 @@ -1248,8 +1248,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 a828e73dc1ae50189bdf73f60caeb7308738ad7a fa7916b67efbc44e6f115bb0d32d8b92fd0acf3c -R 7fa87c853794881c54344291c71c3804 -T +closed fa7916b67efbc44e6f115bb0d32d8b92fd0acf3c -U drh -Z ed8d955d5896e461a30bebb3cc60c312 +P 5c965a71b957fdb0310ac1af9bf2fc3b418af668 +R a13de84916db5713aa965bbf949c399f +U mistachkin +Z d93e90a8dd0c05d351cfea868c3bfa91 diff --git a/manifest.uuid b/manifest.uuid index d53ff492b9..15bc18f89e 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -5c965a71b957fdb0310ac1af9bf2fc3b418af668 \ No newline at end of file +5f6e35802fcf7b5e9fc3dd4424e9074523fa8ad3 \ No newline at end of file diff --git a/src/main.c b/src/main.c index 0e2f2bdc03..a2177fd796 100644 --- a/src/main.c +++ b/src/main.c @@ -55,6 +55,19 @@ int sqlite3_libversion_number(void){ return SQLITE_VERSION_NUMBER; } */ int sqlite3_threadsafe(void){ return SQLITE_THREADSAFE; } +/* +** When compiling the test fixture or with debugging enabled (on Win32), +** this variable being set to non-zero will cause OSTRACE macros to emit +** extra diagnostic information. +*/ +#if (defined(SQLITE_DEBUG) && SQLITE_OS_WIN) || \ + (defined(SQLITE_TEST) || defined(SQLITE_FORCE_OS_TRACE)) +# ifndef SQLITE_DEBUG_OS_TRACE +# define SQLITE_DEBUG_OS_TRACE 0 +# endif + int sqlite3OSTrace = SQLITE_DEBUG_OS_TRACE; +#endif + #if !defined(SQLITE_OMIT_TRACE) && defined(SQLITE_ENABLE_IOTRACE) /* ** If the following function pointer is not NULL and if diff --git a/src/os_common.h b/src/os_common.h index 0f5f779438..3ff4411992 100644 --- a/src/os_common.h +++ b/src/os_common.h @@ -29,12 +29,12 @@ # error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead." #endif +/* +** Declarations used for tracing the operating system interfaces. +*/ #if (defined(SQLITE_DEBUG) && SQLITE_OS_WIN) || \ (defined(SQLITE_TEST) || defined(SQLITE_FORCE_OS_TRACE)) -# ifndef SQLITE_DEBUG_OS_TRACE -# define SQLITE_DEBUG_OS_TRACE 0 -# endif - int sqlite3OSTrace = SQLITE_DEBUG_OS_TRACE; + extern int sqlite3OSTrace; # define OSTRACE(X) if( sqlite3OSTrace ) sqlite3DebugPrintf X #else # define OSTRACE(X) From eaf26402370336186d8119e3130eaf050595ff44 Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 3 Apr 2015 18:33:40 +0000 Subject: [PATCH 063/181] Add source code to the "showlocks" utility program in the tool/ subdirectory. FossilOrigin-Name: 6868cc66d2be67b7f03776c982962ffa4b30de11 --- manifest | 13 +++++----- manifest.uuid | 2 +- tool/showlocks.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+), 7 deletions(-) create mode 100644 tool/showlocks.c diff --git a/manifest b/manifest index e116e655ac..73436f25df 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Disable\se_walauto.test\son\sOpenBSD,\sas\sit\srequires\sa\scoherent\scache. -D 2015-04-02T15:24:53.782 +C Add\ssource\scode\sto\sthe\s"showlocks"\sutility\sprogram\sin\sthe\stool/\ssubdirectory. +D 2015-04-03T18:33:40.031 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 00d12636df7a5b08af09116bcd6c7bfd49b8b3b4 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -1227,6 +1227,7 @@ F tool/restore_jrnl.tcl 6957a34f8f1f0f8285e07536225ec3b292a9024a F tool/rollback-test.c 9fc98427d1e23e84429d7e6d07d9094fbdec65a5 F tool/showdb.c 63cdef19e7fbca0c164b096ef8aef3bb9e9dd222 F tool/showjournal.c 053eb1cc774710c6890b7dd6293300cc297b16a5 +F tool/showlocks.c 9920bcc64f58378ff1118caead34147201f48c68 F tool/showstat4.c 9515faa8ec176599d4a8288293ba8ec61f7b728a F tool/showwal.c 85cb36d4fe3e93e2fbd63e786e0d1ce42d0c4fad F tool/soak1.tcl 8d407956e1a45b485a8e072470a3e629a27037fe @@ -1248,7 +1249,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 30011ad2f55cfcacaf23a58ebcc17b17a7b9355e -R 0b149500fabb905b0771216875924384 -U dan -Z 259e8553f23f2ead0f4917d2e8d05aa6 +P 90701227085b8b8eb10a8eebe8d55f38b4778574 +R f70ddacff9e1db6211fe7e92067ecf89 +U drh +Z 4cde991c3d8a79a805d8a208c5613c13 diff --git a/manifest.uuid b/manifest.uuid index 67f1e1b12f..1722db95be 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -90701227085b8b8eb10a8eebe8d55f38b4778574 \ No newline at end of file +6868cc66d2be67b7f03776c982962ffa4b30de11 \ No newline at end of file diff --git a/tool/showlocks.c b/tool/showlocks.c new file mode 100644 index 0000000000..752c535cc3 --- /dev/null +++ b/tool/showlocks.c @@ -0,0 +1,64 @@ +/* +** This file implements a simple command-line utility that shows all of the +** Posix Advisory Locks on a file. +** +** Usage: +** +** showlocks FILENAME +** +** To compile: gcc -o showlocks showlocks.c +*/ +#include +#include +#include +#include +#include + +/* This utility only looks for locks in the first 2 billion bytes */ +#define MX_LCK 2147483647 + +/* +** Print all locks on the inode of "fd" that occur in between +** lwr and upr, inclusive. +*/ +static int showLocksInRange(int fd, off_t lwr, off_t upr){ + int cnt = 0; + struct flock x; + + x.l_type = F_WRLCK; + x.l_whence = SEEK_SET; + x.l_start = lwr; + x.l_len = upr-lwr; + fcntl(fd, F_GETLK, &x); + if( x.l_type==F_UNLCK ) return 0; + printf("start: %-12d len: %-5d pid: %-5d type: %s\n", + (int)x.l_start, (int)x.l_len, + x.l_pid, x.l_type==F_WRLCK ? "WRLCK" : "RDLCK"); + cnt++; + if( x.l_start>lwr ){ + cnt += showLocksInRange(fd, lwr, x.l_start-1); + } + if( x.l_start+x.l_len Date: Fri, 3 Apr 2015 20:33:33 +0000 Subject: [PATCH 064/181] Disable the SQLITE_FCNTL_WAL_BLOCK feature for now. It needs more work and is not yet ready for release. FossilOrigin-Name: 4ae9a3acc4eeeb7998769eb856c97c2233476f72 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/os_unix.c | 2 +- test/walblock.test | 5 +---- 4 files changed, 10 insertions(+), 13 deletions(-) diff --git a/manifest b/manifest index 73436f25df..31dda70760 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\ssource\scode\sto\sthe\s"showlocks"\sutility\sprogram\sin\sthe\stool/\ssubdirectory. -D 2015-04-03T18:33:40.031 +C Disable\sthe\sSQLITE_FCNTL_WAL_BLOCK\sfeature\sfor\snow.\s\sIt\sneeds\smore\swork\sand\nis\snot\syet\sready\sfor\srelease. +D 2015-04-03T20:33:33.240 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 00d12636df7a5b08af09116bcd6c7bfd49b8b3b4 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -214,7 +214,7 @@ F src/os.c 8fd25588eeba74068d41102d26810e216999b6c8 F src/os.h 3e57a24e2794a94d3cf2342c6d9a884888cd96bf F src/os_common.h 92815ed65f805560b66166e3583470ff94478f04 F src/os_setup.h c9d4553b5aaa6f73391448b265b89bed0b890faa -F src/os_unix.c a4dadbc2da41599e99093e91e276c38c17a73b89 +F src/os_unix.c 25b80a3d167da44226a2084dc9e89a6cb1f02e2e F src/os_win.c 03d27be3a20048ef52a648d5f0a15f5edda9f2a3 F src/os_win.h eb7a47aa17b26b77eb97e4823f20a00b8bda12ca F src/pager.c 4120a49ecd37697e28f5ed807f470b9c0b88410c @@ -1144,7 +1144,7 @@ F test/wal9.test 378e76a9ad09cd9bee06c172ad3547b0129a6750 F test/wal_common.tcl a98f17fba96206122eff624db0ab13ec377be4fe F test/walbak.test b9f68e39646375c2b877be906babcc15d38b4877 F test/walbig.test f437473a16cfb314867c6b5d1dbcd519e73e3434 -F test/walblock.test ffc761cd467a93ccd8cd998a23be2f21b95a83b1 +F test/walblock.test be48f3a75eff0b4456209f26b3ce186c2015497d F test/walcksum.test 9afeb96240296c08c72fc524d199c912cfe34daa F test/walcrash.test 451d79e528add5c42764cea74aa2750754171b25 F test/walcrash2.test a0edab4e5390f03b99a790de89aad15d6ec70b36 @@ -1249,7 +1249,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 90701227085b8b8eb10a8eebe8d55f38b4778574 -R f70ddacff9e1db6211fe7e92067ecf89 +P 6868cc66d2be67b7f03776c982962ffa4b30de11 +R f821ca69e41f19033ce555eacc91c4ed U drh -Z 4cde991c3d8a79a805d8a208c5613c13 +Z 7ec9ecc18bf834ba571fcbb8e1e49df1 diff --git a/manifest.uuid b/manifest.uuid index 1722db95be..174ac4daaf 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -6868cc66d2be67b7f03776c982962ffa4b30de11 \ No newline at end of file +4ae9a3acc4eeeb7998769eb856c97c2233476f72 \ No newline at end of file diff --git a/src/os_unix.c b/src/os_unix.c index a9c883a935..1d867d7cd8 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -3783,7 +3783,7 @@ static int unixFileControl(sqlite3_file *id, int op, void *pArg){ unixFile *pFile = (unixFile*)id; switch( op ){ case SQLITE_FCNTL_WAL_BLOCK: { - pFile->ctrlFlags |= UNIXFILE_BLOCK; + /* pFile->ctrlFlags |= UNIXFILE_BLOCK; // Deferred feature */ return SQLITE_OK; } case SQLITE_FCNTL_LOCKSTATE: { diff --git a/test/walblock.test b/test/walblock.test index 0b0b2241e6..23167a8830 100644 --- a/test/walblock.test +++ b/test/walblock.test @@ -15,6 +15,7 @@ source $testdir/tester.tcl source $testdir/lock_common.tcl source $testdir/wal_common.tcl +finish_test; return; # Feature currently not implemented. ifcapable !wal {finish_test ; return } if {$::tcl_platform(platform)!="unix"} { finish_test ; return } set testprefix walblock @@ -111,7 +112,3 @@ do_test "1.2.3.(blocking 0.5 seconds)" { finish_test - - - - From 00eb70d89c427a6d0e86788346c8ddd6f93d6ec5 Mon Sep 17 00:00:00 2001 From: mistachkin Date: Sat, 4 Apr 2015 00:02:07 +0000 Subject: [PATCH 065/181] Enhance the 'releasetest.tcl' tool to support MSVC. FossilOrigin-Name: f664bfdc82597a4530d4f4938bb96557b43b171b --- Makefile.msc | 3 ++ manifest | 14 ++++----- manifest.uuid | 2 +- test/releasetest.tcl | 75 ++++++++++++++++++++++++++++++++++++++------ 4 files changed, 77 insertions(+), 17 deletions(-) diff --git a/Makefile.msc b/Makefile.msc index d3a40a811b..e68fb78717 100644 --- a/Makefile.msc +++ b/Makefile.msc @@ -1608,6 +1608,9 @@ queryplantest: testfixture.exe sqlite3.exe test: testfixture.exe sqlite3.exe .\testfixture.exe $(TOP)\test\veryquick.test +smoketest: testfixture.exe + .\testfixture.exe $(TOP)\test\main.test + sqlite3_analyzer.c: $(SQLITE3C) $(TOP)\src\test_stat.c $(TOP)\src\tclsqlite.c $(TOP)\tool\spaceanal.tcl copy $(SQLITE3C) + $(TOP)\src\test_stat.c + $(TOP)\src\tclsqlite.c $@ echo static const char *tclsh_main_loop(void){ >> $@ diff --git a/manifest b/manifest index dabb61374f..e2d9993f0b 100644 --- a/manifest +++ b/manifest @@ -1,9 +1,9 @@ -C Fix\sbuild\swith\sOSTRACE\senabled\son\sWindows\swhen\sbuilding\susing\sseparate\ssource\sfiles. -D 2015-04-02T17:46:52.559 +C Enhance\sthe\s'releasetest.tcl'\stool\sto\ssupport\sMSVC. +D 2015-04-04T00:02:07.856 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 00d12636df7a5b08af09116bcd6c7bfd49b8b3b4 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 -F Makefile.msc c3744ee851d76d2be0ff247f5a89a74c88f2ece2 +F Makefile.msc a95303d8bd37f8cf176be19cb5542355cc3c243b F Makefile.vxworks e1b65dea203f054e71653415bd8f96dcaed47858 F README.md d58e3bebc0a4145e0f2a87994015fdb575a8e866 F VERSION 319eb1ced4b4d17a67730f2b7b85f15c1346cb60 @@ -812,7 +812,7 @@ F test/randexpr1.test eda062a97e60f9c38ae8d806b03b0ddf23d796df F test/rdonly.test 64e2696c322e3538df0b1ed624e21f9a23ed9ff8 F test/regexp1.test 497ea812f264d12b6198d6e50a76be4a1973a9d8 F test/reindex.test 44edd3966b474468b823d481eafef0c305022254 -F test/releasetest.tcl 13f401c10dd4fe1a2fb811ae6ed27fd7d1300d3c +F test/releasetest.tcl a37cd82092c8be438255d65804b5951d6e3ecdae F test/resolver01.test 33abf37ff8335e6bf98f2b45a0af3e06996ccd9a F test/rollback.test 458fe73eb3ffdfdf9f6ba3e9b7350a6220414dea F test/rollback2.test fc14cf6d1a2b250d2735ef16124b971bce152f14 @@ -1248,7 +1248,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 5c965a71b957fdb0310ac1af9bf2fc3b418af668 -R a13de84916db5713aa965bbf949c399f +P 5f6e35802fcf7b5e9fc3dd4424e9074523fa8ad3 +R beb5360693babbdb25b957a67e8a7b0e U mistachkin -Z d93e90a8dd0c05d351cfea868c3bfa91 +Z 6aedfad85a42d725bf8ce314c14e99d1 diff --git a/manifest.uuid b/manifest.uuid index 15bc18f89e..3312a66aa2 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -5f6e35802fcf7b5e9fc3dd4424e9074523fa8ad3 \ No newline at end of file +f664bfdc82597a4530d4f4938bb96557b43b171b \ No newline at end of file diff --git a/test/releasetest.tcl b/test/releasetest.tcl index 746fc9bb35..95cacf590f 100644 --- a/test/releasetest.tcl +++ b/test/releasetest.tcl @@ -14,6 +14,7 @@ optional) are: --config CONFIGNAME (Run only CONFIGNAME) --quick (Run "veryquick.test" only) --veryquick (Run "make smoketest" only) + --msvc (Use MSVC as the compiler) --buildonly (Just build testfixture - do not run) --dryrun (Print what would have happened) --info (Show diagnostic info) @@ -22,8 +23,9 @@ The default value for --srcdir is the parent of the directory holding this script. The script determines the default value for --platform using the -$tcl_platform(os) and $tcl_platform(machine) variables. Supported -platforms are "Linux-x86", "Linux-x86_64" and "Darwin-i386". +$tcl_platform(os) and $tcl_platform(machine) variables. Supported +platforms are "Linux-x86", "Linux-x86_64", "Darwin-i386", +"Darwin-x86_64", "Windows NT-intel", and "Windows NT-amd64". Every test begins with a fresh run of the configure script at the top of the SQLite source tree. @@ -238,6 +240,10 @@ array set ::Platforms [strip_comments { "Default" "mptest fulltestonly" "Have-Not" test } + "Windows NT-amd64" { + "Default" "mptest fulltestonly" + "Have-Not" test + } # The Failure-Detection platform runs various tests that deliberately # fail. This is used as a test of this script to verify that this script @@ -296,6 +302,13 @@ proc count_tests_and_errors {logfile rcVar errmsgVar} { set errmsg $msg } } + if {[regexp {fatal error +(.*)} $line all msg]} { + incr ::NERRCASE + if {$rc==0} { + set rc 1 + set errmsg $msg + } + } if {[regexp {ERROR SUMMARY: (\d+) errors.*} $line all cnt] && $cnt>0} { incr ::NERRCASE if {$rc==0} { @@ -314,7 +327,13 @@ proc count_tests_and_errors {logfile rcVar errmsgVar} { } } close $fd - if {!$seen} { + if {$::BUILDONLY} { + if {$rc==0} { + set errmsg "Build complete" + } else { + set errmsg "Build failed" + } + } elseif {!$seen} { set rc 1 set errmsg "Test did not complete" if {[file readable core]} { @@ -329,7 +348,7 @@ proc run_test_suite {name testtarget config} { # CFLAGS. The makefile will pass OPTS to both gcc and lemon, but # CFLAGS is only passed to gcc. # - set cflags "-g" + set cflags [expr {$::MSVC ? "-Zi" : "-g"}] set opts "" set title ${name}($testtarget) set configOpts "" @@ -349,7 +368,14 @@ proc run_test_suite {name testtarget config} { set cflags [join $cflags " "] set opts [join $opts " "] - append opts " -DSQLITE_NO_SYNC=1 -DHAVE_USLEEP" + append opts " -DSQLITE_NO_SYNC=1" + + # Some configurations already set HAVE_USLEEP; in that case, skip it. + # + if {![regexp { -DHAVE_USLEEP$} $opts] + && ![regexp { -DHAVE_USLEEP[ =]+} $opts]} { + append opts " -DHAVE_USLEEP=1" + } # Set the sub-directory to use. # @@ -390,10 +416,10 @@ proc run_test_suite {name testtarget config} { if {$rc} { puts " FAIL $tm" incr ::NERR - if {$errmsg!=""} {puts " $errmsg"} } else { puts " Ok $tm" } + if {$errmsg!=""} {puts " $errmsg"} } } @@ -401,6 +427,7 @@ proc run_test_suite {name testtarget config} { # the current platform, which may be Windows (via MinGW, etc). # proc configureCommand {opts} { + if {$::MSVC} return [list]; # This is not needed for MSVC. set result [list trace_cmd exec] if {$::tcl_platform(platform)=="windows"} { lappend result sh @@ -414,7 +441,14 @@ proc configureCommand {opts} { # specified targets, compiler flags, and options. # proc makeCommand { targets cflags opts } { - set result [list trace_cmd exec make clean] + set result [list trace_cmd exec] + if {$::MSVC} { + set nmakeDir [file nativename $::SRCDIR] + set nmakeFile [file join $nmakeDir Makefile.msc] + lappend result nmake /f $nmakeFile TOP=$nmakeDir clean + } else { + lappend result make clean + } foreach target $targets { lappend result $target } @@ -443,6 +477,7 @@ proc trace_cmd {args} { proc process_options {argv} { set ::SRCDIR [file normalize [file dirname [file dirname $::argv0]]] set ::QUICK 0 + set ::MSVC 0 set ::BUILDONLY 0 set ::DRYRUN 0 set ::EXEC exec @@ -476,6 +511,10 @@ proc process_options {argv} { set config [lindex $argv $i] } + -msvc { + set ::MSVC 1 + } + -buildonly { set ::BUILDONLY 1 } @@ -494,6 +533,7 @@ proc process_options {argv} { puts " --platform [list $platform]" puts " --config [list $config]" if {$::QUICK} {puts " --quick"} + if {$::MSVC} {puts " --msvc"} if {$::BUILDONLY} {puts " --buildonly"} if {$::DRYRUN} {puts " --dryrun"} if {$::TRACE} {puts " --trace"} @@ -507,7 +547,15 @@ proc process_options {argv} { } exit } - -g - + + -g { + if {$::MSVC} { + lappend ::EXTRACONFIG -Zi + } else { + lappend ::EXTRACONFIG [lindex $argv $i] + } + } + -D* - -O* - -enable-* - @@ -547,6 +595,7 @@ proc process_options {argv} { puts -nonewline "Flags:" if {$::DRYRUN} {puts -nonewline " --dryrun"} if {$::BUILDONLY} {puts -nonewline " --buildonly"} + if {$::MSVC} {puts -nonewline " --msvc"} switch -- $::QUICK { 1 {puts -nonewline " --quick"} 2 {puts -nonewline " --veryquick"} @@ -570,12 +619,20 @@ proc main {argv} { set ::SQLITE_VERSION {} set STARTTIME [clock seconds] foreach {zConfig target} $::CONFIGLIST { + if {$::MSVC && ($zConfig eq "Sanitize" || "checksymbols" in $target + || "valgrindtest" in $target)} { + puts "Skipping $zConfig / $target for MSVC..." + continue + } if {$target ne "checksymbols"} { switch -- $::QUICK { 1 {set target test} 2 {set target smoketest} } - if {$::BUILDONLY} {set target testfixture} + if {$::BUILDONLY} { + set target testfixture + if {$::MSVC} {append target .exe} + } } set config_options [concat $::Configs($zConfig) $::EXTRACONFIG] From b33c50f215b45acd1b6f47008562e64d895d3fba Mon Sep 17 00:00:00 2001 From: dan Date: Sat, 4 Apr 2015 16:43:16 +0000 Subject: [PATCH 066/181] Fix a problem with resolving ORDER BY clauses that feature COLLATE clauses attached to compound SELECT statements. FossilOrigin-Name: 427b50fba7362e5b447e79d39050f25ed2ef10af --- manifest | 23 ++++++++++-------- manifest.uuid | 2 +- src/resolve.c | 25 ++++++++++++++++++++ src/select.c | 2 ++ src/sqliteInt.h | 1 + test/selectA.test | 60 +++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 102 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index 31dda70760..ad90ce9662 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Disable\sthe\sSQLITE_FCNTL_WAL_BLOCK\sfeature\sfor\snow.\s\sIt\sneeds\smore\swork\sand\nis\snot\syet\sready\sfor\srelease. -D 2015-04-03T20:33:33.240 +C Fix\sa\sproblem\swith\sresolving\sORDER\sBY\sclauses\sthat\sfeature\sCOLLATE\sclauses\sattached\sto\scompound\sSELECT\sstatements. +D 2015-04-04T16:43:16.254 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 00d12636df7a5b08af09116bcd6c7bfd49b8b3b4 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -228,14 +228,14 @@ F src/pragma.h 09c89bca58e9a44de2116cc8272b8d454657129f F src/prepare.c 173a5a499138451b2561614ecb87d78f9f4644b9 F src/printf.c 8da9a2687a396daa19860f4dc90975d319304744 F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 -F src/resolve.c f4d79e31ffa5820c2e3d1740baa5e9b190425f2b +F src/resolve.c 41aa91af56d960e9414ce1d7c17cfb68e0d1c6cb F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e -F src/select.c 72ffb62e2879956302140e9f6e6ae88aee36b0e5 +F src/select.c c28c52e353287434fac8473e56ee4be848d12c9d F src/shell.c 84a1593bd86aaa14f4da8a8f9b16fbc239d262aa F src/sqlite.h.in 278602140d49575e8708e643161f4263e428a02a F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h 17d487c3c91b0b8c584a32fbeb393f6f795eea7d -F src/sqliteInt.h d02d2b85cb02a38bc442cf9302ec8209baf6771d +F src/sqliteInt.h 107b02ed6c64162b653acc2368e982de529e14f6 F src/sqliteLimit.h 216557999cb45f2e3578ed53ebefe228d779cb46 F src/status.c f266ad8a2892d659b74f0f50cb6a88b6e7c12179 F src/table.c e7a09215315a978057fb42c640f890160dbcc45e @@ -845,7 +845,7 @@ F test/select6.test 39eac4a5c03650b2b473c532882273283ee8b7a0 F test/select7.test 7fd2ef598cfabb6b9ff6ac13973b91d0527df49d F test/select8.test 391de11bdd52339c30580dabbbbe97e3e9a3c79d F test/select9.test aebc2bb0c3bc44606125033cbcaac2c8d1f33a95 -F test/selectA.test 64b88a80271c1710966e50e633380696b60a12a4 +F test/selectA.test e452bdb975f488ea46d091382a9185b5853ed2c7 F test/selectB.test 954e4e49cf1f896d61794e440669e03a27ceea25 F test/selectC.test 871fb55d884d3de5943c4057ebd22c2459e71977 F test/selectD.test b0f02a04ef7737decb24e08be2c39b9664b43394 @@ -1249,7 +1249,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 6868cc66d2be67b7f03776c982962ffa4b30de11 -R f821ca69e41f19033ce555eacc91c4ed -U drh -Z 7ec9ecc18bf834ba571fcbb8e1e49df1 +P 4ae9a3acc4eeeb7998769eb856c97c2233476f72 +R 0a683c8bd67cbd2be5ea29e95266b636 +T *branch * compound-order-by-fix +T *sym-compound-order-by-fix * +T -sym-trunk * +U dan +Z 235b3663512a162fe4fda68eec524b54 diff --git a/manifest.uuid b/manifest.uuid index 174ac4daaf..dcc45e2918 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -4ae9a3acc4eeeb7998769eb856c97c2233476f72 \ No newline at end of file +427b50fba7362e5b447e79d39050f25ed2ef10af \ No newline at end of file diff --git a/src/resolve.c b/src/resolve.c index 47df7243f8..a7b14cd005 100644 --- a/src/resolve.c +++ b/src/resolve.c @@ -1186,6 +1186,20 @@ static int resolveSelectStep(Walker *pWalker, Select *p){ sqlite3ResolveExprNames(&sNC, p->pOffset) ){ return WRC_Abort; } + + /* If the SF_Converted flags is set, then this Select object was + ** was created by the convertCompoundSelectToSubquery() function. + ** In this case the ORDER BY clause (p->pOrderBy) should be resolved + ** as if it were part of the sub-query, not the parent. This block + ** moves the pOrderBy down to the sub-query. It will be moved back + ** after the names have been resolved. */ + if( p->selFlags & SF_Converted ){ + Select *pSub = p->pSrc->a[0].pSelect; + assert( p->pSrc->nSrc==1 && isCompound==0 && p->pOrderBy ); + assert( pSub->pPrior && pSub->pOrderBy==0 ); + pSub->pOrderBy = p->pOrderBy; + p->pOrderBy = 0; + } /* Recursively resolve names in all subqueries */ @@ -1268,6 +1282,17 @@ static int resolveSelectStep(Walker *pWalker, Select *p){ sNC.pNext = 0; sNC.ncFlags |= NC_AllowAgg; + /* If this is a converted compound query, move the ORDER BY clause from + ** the sub-query back to the parent query. At this point each term + ** within the ORDER BY clause has been transformed to an integer value. + ** These integers will be replaced by copies of the corresponding result + ** set expressions by the call to resolveOrderGroupBy() below. */ + if( p->selFlags & SF_Converted ){ + Select *pSub = p->pSrc->a[0].pSelect; + p->pOrderBy = pSub->pOrderBy; + pSub->pOrderBy = 0; + } + /* Process the ORDER BY clause for singleton SELECT statements. ** The ORDER BY clause for compounds SELECT statements is handled ** below, after all of the result-sets for all of the elements of diff --git a/src/select.c b/src/select.c index 8fd0f15918..90aaa842a6 100644 --- a/src/select.c +++ b/src/select.c @@ -3884,6 +3884,8 @@ static int convertCompoundSelectToSubquery(Walker *pWalker, Select *p){ p->pPrior = 0; p->pNext = 0; p->selFlags &= ~SF_Compound; + assert( (p->selFlags & SF_Converted)==0 ); + p->selFlags |= SF_Converted; assert( pNew->pPrior!=0 ); pNew->pPrior->pNext = pNew; pNew->pLimit = 0; diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 3841c91f14..1c0ad44e3a 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -2389,6 +2389,7 @@ struct Select { #define SF_MaybeConvert 0x0400 /* Need convertCompoundSelectToSubquery() */ #define SF_Recursive 0x0800 /* The recursive part of a recursive CTE */ #define SF_MinMaxAgg 0x1000 /* Aggregate containing min() or max() */ +#define SF_Converted 0x2000 /* By convertCompoundSelectToSubquery() */ /* diff --git a/test/selectA.test b/test/selectA.test index 6e593e8e22..0338338902 100644 --- a/test/selectA.test +++ b/test/selectA.test @@ -1375,4 +1375,64 @@ do_execsql_test 4.2.2 { } {/2 . 3 . 4 . 5 . 6 . 7 ./} +proc strip_rnd {explain} { + regexp -all {sqlite_sq_[0123456789ABCDEF]*} $explain sqlite_sq +} + +proc do_same_test {tn q1 args} { + set r2 [strip_rnd [db eval "EXPLAIN $q1"]] + set i 1 + foreach q $args { + set tst [subst -nocommands {strip_rnd [db eval "EXPLAIN $q"]}] + uplevel do_test $tn.$i [list $tst] [list $r2] + incr i + } +} + +do_execsql_test 5.0 { + CREATE TABLE t8(a, b); + CREATE TABLE t9(c, d); +} {} + +do_same_test 5.1 { + SELECT a, b FROM t8 INTERSECT SELECT c, d FROM t9 ORDER BY a; +} { + SELECT a, b FROM t8 INTERSECT SELECT c, d FROM t9 ORDER BY t8.a; +} { + SELECT a, b FROM t8 INTERSECT SELECT c, d FROM t9 ORDER BY 1; +} { + SELECT a, b FROM t8 INTERSECT SELECT c, d FROM t9 ORDER BY c; +} { + SELECT a, b FROM t8 INTERSECT SELECT c, d FROM t9 ORDER BY t9.c; +} + +do_same_test 5.2 { + SELECT a, b FROM t8 UNION SELECT c, d FROM t9 ORDER BY a COLLATE NOCASE +} { + SELECT a, b FROM t8 UNION SELECT c, d FROM t9 ORDER BY t8.a COLLATE NOCASE +} { + SELECT a, b FROM t8 UNION SELECT c, d FROM t9 ORDER BY 1 COLLATE NOCASE +} { + SELECT a, b FROM t8 UNION SELECT c, d FROM t9 ORDER BY c COLLATE NOCASE +} { + SELECT a, b FROM t8 UNION SELECT c, d FROM t9 ORDER BY t9.c COLLATE NOCASE +} + +do_same_test 5.3 { + SELECT a, b FROM t8 EXCEPT SELECT c, d FROM t9 ORDER BY b, c COLLATE NOCASE +} { + SELECT a, b FROM t8 EXCEPT SELECT c, d FROM t9 ORDER BY 2, 1 COLLATE NOCASE +} { + SELECT a, b FROM t8 EXCEPT SELECT c, d FROM t9 ORDER BY d, a COLLATE NOCASE +} { + SELECT a, b FROM t8 EXCEPT SELECT * FROM t9 ORDER BY t9.d, c COLLATE NOCASE +} { + SELECT * FROM t8 EXCEPT SELECT c, d FROM t9 ORDER BY d, t8.a COLLATE NOCASE +} + +do_catchsql_test 5.4 { + SELECT * FROM t8 UNION SELECT * FROM t9 ORDER BY a+b COLLATE NOCASE +} {1 {1st ORDER BY term does not match any column in the result set}} + + finish_test From 4b0000c9a89800c2c7603b2fd722431776685d52 Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 6 Apr 2015 09:05:29 +0000 Subject: [PATCH 067/181] Fix a problem with fts3 prefix terms within phrase queries on "order=DESC" tables with a mix of negative and positive rowids. FossilOrigin-Name: 0cdf502885ea7e5805d7ba3719f055f5d48fc78d --- ext/fts3/fts3.c | 57 ++++++++++++++++++++++++++++++++++++-------- manifest | 17 +++++++------ manifest.uuid | 2 +- test/fts3prefix.test | 18 ++++++++++++++ 4 files changed, 76 insertions(+), 18 deletions(-) diff --git a/ext/fts3/fts3.c b/ext/fts3/fts3.c index 46b499e96b..7a15379b83 100644 --- a/ext/fts3/fts3.c +++ b/ext/fts3/fts3.c @@ -2502,26 +2502,33 @@ static int fts3DoclistOrMerge( ** ** The right-hand input doclist is overwritten by this function. */ -static void fts3DoclistPhraseMerge( +static int fts3DoclistPhraseMerge( int bDescDoclist, /* True if arguments are desc */ int nDist, /* Distance from left to right (1=adjacent) */ char *aLeft, int nLeft, /* Left doclist */ - char *aRight, int *pnRight /* IN/OUT: Right/output doclist */ + char **paRight, int *pnRight /* IN/OUT: Right/output doclist */ ){ sqlite3_int64 i1 = 0; sqlite3_int64 i2 = 0; sqlite3_int64 iPrev = 0; + char *aRight = *paRight; char *pEnd1 = &aLeft[nLeft]; char *pEnd2 = &aRight[*pnRight]; char *p1 = aLeft; char *p2 = aRight; char *p; int bFirstOut = 0; - char *aOut = aRight; + char *aOut; assert( nDist>0 ); - + if( bDescDoclist ){ + aOut = sqlite3_malloc(*pnRight + FTS3_VARINT_MAX); + if( aOut==0 ) return SQLITE_NOMEM; + }else{ + aOut = aRight; + } p = aOut; + fts3GetDeltaVarint3(&p1, pEnd1, 0, &i1); fts3GetDeltaVarint3(&p2, pEnd2, 0, &i2); @@ -2550,6 +2557,12 @@ static void fts3DoclistPhraseMerge( } *pnRight = (int)(p - aOut); + if( bDescDoclist ){ + sqlite3_free(aRight); + *paRight = aOut; + } + + return SQLITE_OK; } /* @@ -2674,8 +2687,22 @@ static int fts3TermSelectMerge( ){ if( pTS->aaOutput[0]==0 ){ /* If this is the first term selected, copy the doclist to the output - ** buffer using memcpy(). */ - pTS->aaOutput[0] = sqlite3_malloc(nDoclist); + ** buffer using memcpy(). + ** + ** Add FTS3_VARINT_MAX bytes of unused space to the end of the + ** allocation. This is so as to ensure that the buffer is big enough + ** to hold the current doclist AND'd with any other doclist. If the + ** doclists are stored in order=ASC order, this padding would not be + ** required (since the size of [doclistA AND doclistB] is always less + ** than or equal to the size of [doclistA] in that case). But this is + ** not true for order=DESC. For example, a doclist containing (1, -1) + ** may be smaller than (-1), as in the first example the -1 may be stored + ** as a single-byte delta, whereas in the second it must be stored as a + ** FTS3_VARINT_MAX byte varint. + ** + ** Similar padding is added in the fts3DoclistOrMerge() function. + */ + pTS->aaOutput[0] = sqlite3_malloc(nDoclist + FTS3_VARINT_MAX + 1); pTS->anOutput[0] = nDoclist; if( pTS->aaOutput[0] ){ memcpy(pTS->aaOutput[0], aDoclist, nDoclist); @@ -3931,14 +3958,17 @@ static void fts3EvalAllocateReaders( ** This function assumes that pList points to a buffer allocated using ** sqlite3_malloc(). This function takes responsibility for eventually ** freeing the buffer. +** +** SQLITE_OK is returned if successful, or SQLITE_NOMEM if an error occurs. */ -static void fts3EvalPhraseMergeToken( +static int fts3EvalPhraseMergeToken( Fts3Table *pTab, /* FTS Table pointer */ Fts3Phrase *p, /* Phrase to merge pList/nList into */ int iToken, /* Token pList/nList corresponds to */ char *pList, /* Pointer to doclist */ int nList /* Number of bytes in pList */ ){ + int rc = SQLITE_OK; assert( iToken!=p->iDoclistToken ); if( pList==0 ){ @@ -3977,13 +4007,16 @@ static void fts3EvalPhraseMergeToken( nDiff = p->iDoclistToken - iToken; } - fts3DoclistPhraseMerge(pTab->bDescIdx, nDiff, pLeft, nLeft, pRight,&nRight); + rc = fts3DoclistPhraseMerge( + pTab->bDescIdx, nDiff, pLeft, nLeft, &pRight, &nRight + ); sqlite3_free(pLeft); p->doclist.aAll = pRight; p->doclist.nAll = nRight; } if( iToken>p->iDoclistToken ) p->iDoclistToken = iToken; + return rc; } /* @@ -4009,7 +4042,7 @@ static int fts3EvalPhraseLoad( char *pThis = 0; rc = fts3TermSelect(pTab, pToken, p->iColumn, &nThis, &pThis); if( rc==SQLITE_OK ){ - fts3EvalPhraseMergeToken(pTab, p, iToken, pThis, nThis); + rc = fts3EvalPhraseMergeToken(pTab, p, iToken, pThis, nThis); } } assert( pToken->pSegcsr==0 ); @@ -4811,9 +4844,13 @@ static int fts3EvalSelectDeferred( char *pList = 0; rc = fts3TermSelect(pTab, pToken, pTC->iCol, &nList, &pList); assert( rc==SQLITE_OK || pList==0 ); + if( rc==SQLITE_OK ){ + rc = fts3EvalPhraseMergeToken( + pTab, pTC->pPhrase, pTC->iToken,pList,nList + ); + } if( rc==SQLITE_OK ){ int nCount; - fts3EvalPhraseMergeToken(pTab, pTC->pPhrase, pTC->iToken,pList,nList); nCount = fts3DoclistCountDocids( pTC->pPhrase->doclist.aAll, pTC->pPhrase->doclist.nAll ); diff --git a/manifest b/manifest index 762233f676..12c20e5b8a 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sproblem\swith\sresolving\sORDER\sBY\sclauses\sthat\sfeature\sCOLLATE\sclauses\sattached\sto\scompound\sSELECT\sstatements. -D 2015-04-04T16:49:04.697 +C Fix\sa\sproblem\swith\sfts3\sprefix\sterms\swithin\sphrase\squeries\son\s"order=DESC"\stables\swith\sa\smix\sof\snegative\sand\spositive\srowids. +D 2015-04-06T09:05:29.052 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 00d12636df7a5b08af09116bcd6c7bfd49b8b3b4 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -78,7 +78,7 @@ F ext/fts3/README.content fdc666a70d5257a64fee209f97cf89e0e6e32b51 F ext/fts3/README.syntax a19711dc5458c20734b8e485e75fb1981ec2427a F ext/fts3/README.tokenizers e0a8b81383ea60d0334d274fadf305ea14a8c314 F ext/fts3/README.txt 8c18f41574404623b76917b9da66fcb0ab38328d -F ext/fts3/fts3.c d3f6f0e95d366f3c2028d916c36a0844bf805840 +F ext/fts3/fts3.c 23bd9d37a777342f5c22a648e9b4b005dde9e58f F ext/fts3/fts3.h 3a10a0af180d502cecc50df77b1b22df142817fe F ext/fts3/fts3Int.h 394858c12a17740f7a1f6bd372c4606d4425a8d1 F ext/fts3/fts3_aux.c 5c211e17a64885faeb16b9ba7772f9d5445c2365 @@ -594,7 +594,7 @@ F test/fts3join.test 53e66a0c21eb568580674a43b21c059acb26f499 F test/fts3malloc.test b0e4c133b8d61d4f6d112d8110f8320e9e453ef6 F test/fts3matchinfo.test 58544fa4d254000fa4e7f494b0a832f7ba61d45e F test/fts3near.test 7e3354d46f155a822b59c0e957fd2a70c1d7e905 -F test/fts3prefix.test 9f68e3598a139c23ec47d09299420e0fc4c72a83 +F test/fts3prefix.test fa794eaab0bdae466494947b0b153d7844478ab2 F test/fts3prefix2.test e1f0a822ca661dced7f12ce392e14eaf65609dce F test/fts3query.test c838b18f2b859e15fd31c64be3d79ef1556803ca F test/fts3rnd.test 1320d8826a845e38a96e769562bf83d7a92a15d0 @@ -1249,7 +1249,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 4ae9a3acc4eeeb7998769eb856c97c2233476f72 427b50fba7362e5b447e79d39050f25ed2ef10af -R 0a683c8bd67cbd2be5ea29e95266b636 +P edc1de2a588fd50c0049bb2be76d3f6783443165 +R a8252a4468bea13d638722c58d3ce9cc +T *branch * fts3-prefix-query-fix +T *sym-fts3-prefix-query-fix * +T -sym-trunk * U dan -Z c9ac74415bdb7893d918eacf5a95862c +Z 7c1c374a4c4efe674ae583b0f9d983d2 diff --git a/manifest.uuid b/manifest.uuid index ff36ec293f..2a42d14f33 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -edc1de2a588fd50c0049bb2be76d3f6783443165 \ No newline at end of file +0cdf502885ea7e5805d7ba3719f055f5d48fc78d \ No newline at end of file diff --git a/test/fts3prefix.test b/test/fts3prefix.test index 8ffabe8d65..e8d2b2b5fb 100644 --- a/test/fts3prefix.test +++ b/test/fts3prefix.test @@ -274,4 +274,22 @@ do_execsql_test 6.5.2 { SELECT md5sum(quote(root)) FROM t1_segdir; } [db eval {SELECT md5sum(quote(root)) FROM t2_segdir}] + +do_execsql_test 7.0 { + CREATE VIRTUAL TABLE t6 USING fts4(x,order=DESC); + INSERT INTO t6(docid, x) VALUES(-1,'a b'); + INSERT INTO t6(docid, x) VALUES(1, 'b'); +} +do_execsql_test 7.1 { + SELECT docid FROM t6 WHERE t6 MATCH '"a* b"'; +} {-1} +do_execsql_test 7.2 { + SELECT docid FROM t6 WHERE t6 MATCH 'a*'; +} {-1} +do_execsql_test 7.3 { + SELECT docid FROM t6 WHERE t6 MATCH 'a* b'; +} {-1} + + + finish_test From 74b42275eca70ba323730c5a1088f1baf9937383 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 7 Apr 2015 12:41:17 +0000 Subject: [PATCH 068/181] Guard against excessive width and precision in floating-point conversions in the printf routines. FossilOrigin-Name: c494171f77dc2e5e04cb6d865e688448f04e5920 --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/printf.c | 7 ++++--- test/printf.test | 3 +++ 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/manifest b/manifest index 839dc44cc6..31581470a9 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sproblem\swith\sfts3\sprefix\sterms\swithin\sphrase\squeries\son\s"order=DESC"\stables\swith\sa\smix\sof\snegative\sand\spositive\srowids. -D 2015-04-06T11:04:51.176 +C Guard\sagainst\sexcessive\swidth\sand\sprecision\sin\sfloating-point\sconversions\nin\sthe\sprintf\sroutines. +D 2015-04-07T12:41:17.461 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 00d12636df7a5b08af09116bcd6c7bfd49b8b3b4 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -226,7 +226,7 @@ F src/pcache1.c 69d137620a305f814398bd29a0c998038c0695e9 F src/pragma.c ac4f3f856b4234e85f55b0f069698a4766011100 F src/pragma.h 09c89bca58e9a44de2116cc8272b8d454657129f F src/prepare.c 173a5a499138451b2561614ecb87d78f9f4644b9 -F src/printf.c 8da9a2687a396daa19860f4dc90975d319304744 +F src/printf.c 32f69fcba9ddfb71f9466b867f7ee7b7ffee30de F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c 41aa91af56d960e9414ce1d7c17cfb68e0d1c6cb F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e @@ -797,7 +797,7 @@ F test/permutations.test f9cc1dd987986c9d4949211c7a4ed55ec9aecba1 F test/pragma.test ad99d05e411c7687302124be56f3b362204be041 F test/pragma2.test f624a496a95ee878e81e59961eade66d5c00c028 F test/pragma3.test 6f849ccffeee7e496d2f2b5e74152306c0b8757c -F test/printf.test ec9870c4dce8686a37818e0bf1aba6e6a1863552 +F test/printf.test 2f11179e8b7210f3ea262d96b7f7b4cb78b34500 F test/printf2.test b4acd4bf8734243257f01ddefa17c4fb090acc8a F test/progress.test a282973d1d17f08071bc58a77d6b80f2a81c354d F test/ptrchng.test ef1aa72d6cf35a2bbd0869a649b744e9d84977fc @@ -1249,7 +1249,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 edc1de2a588fd50c0049bb2be76d3f6783443165 0cdf502885ea7e5805d7ba3719f055f5d48fc78d -R 3d0aeff53f9d343a974360d23614c066 -U dan -Z ac6175e8f164395f5f3f99cbe84625aa +P 3ad829e50faca538db3abb2afb898b5521550c5c +R 1f357953eb69048c3e73348b4613f5e5 +U drh +Z 21bd74616576d30557b17c20f6eb18f9 diff --git a/manifest.uuid b/manifest.uuid index 60fdaf0098..45e0581d32 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -3ad829e50faca538db3abb2afb898b5521550c5c \ No newline at end of file +c494171f77dc2e5e04cb6d865e688448f04e5920 \ No newline at end of file diff --git a/src/printf.c b/src/printf.c index 81efa057fc..0ff9887eb7 100644 --- a/src/printf.c +++ b/src/printf.c @@ -450,7 +450,7 @@ void sqlite3VXPrintf( else prefix = 0; } if( xtype==etGENERIC && precision>0 ) precision--; - for(idx=precision, rounder=0.5; idx>0; idx--, rounder*=0.1){} + for(idx=precision&0xfff, rounder=0.5; idx>0; idx--, rounder*=0.1){} if( xtype==etFLOAT ) realvalue += rounder; /* Normalize realvalue to within 10.0 > realvalue >= 1.0 */ exp = 0; @@ -505,8 +505,9 @@ void sqlite3VXPrintf( }else{ e2 = exp; } - if( MAX(e2,0)+precision+width > etBUFSIZE - 15 ){ - bufpt = zExtra = sqlite3Malloc( MAX(e2,0)+precision+width+15 ); + if( MAX(e2,0)+(i64)precision+(i64)width > etBUFSIZE - 15 ){ + bufpt = zExtra + = sqlite3Malloc( MAX(e2,0)+(i64)precision+(i64)width+15 ); if( bufpt==0 ){ setStrAccumError(pAccum, STRACCUM_NOMEM); return; diff --git a/test/printf.test b/test/printf.test index 73222720ab..5dfc6d06cf 100644 --- a/test/printf.test +++ b/test/printf.test @@ -526,6 +526,9 @@ do_test printf-2.1.2.8 { do_test printf-2.1.2.9 { sqlite3_mprintf_double {abc: %d %d (%1.1g) :xyz} 1 1 1.0e-20 } {abc: 1 1 (1e-20) :xyz} +do_test printf-2.1.2.10 { + sqlite3_mprintf_double {abc: %*.*f} 2000000000 1000000000 1.0e-20 +} {abc: } do_test printf-2.1.3.1 { sqlite3_mprintf_double {abc: (%*.*f) :xyz} 1 1 1.0 } {abc: (1.0) :xyz} From a30d22a7a6b1eff78d2869ab4e56782522d5a758 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 7 Apr 2015 13:28:41 +0000 Subject: [PATCH 069/181] Further changes to guard against integer overflow in the width and precision of printf() arguments. FossilOrigin-Name: 5ce4e7d7651e5c72a59f03f7aeb366291e62ab57 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/printf.c | 9 +++++++-- test/printf.test | 21 +++++++++++++++++++++ 4 files changed, 36 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index 31581470a9..3aa52a9c50 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Guard\sagainst\sexcessive\swidth\sand\sprecision\sin\sfloating-point\sconversions\nin\sthe\sprintf\sroutines. -D 2015-04-07T12:41:17.461 +C Further\schanges\sto\sguard\sagainst\sinteger\soverflow\sin\sthe\swidth\sand\sprecision\nof\sprintf()\sarguments. +D 2015-04-07T13:28:41.878 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 00d12636df7a5b08af09116bcd6c7bfd49b8b3b4 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -226,7 +226,7 @@ F src/pcache1.c 69d137620a305f814398bd29a0c998038c0695e9 F src/pragma.c ac4f3f856b4234e85f55b0f069698a4766011100 F src/pragma.h 09c89bca58e9a44de2116cc8272b8d454657129f F src/prepare.c 173a5a499138451b2561614ecb87d78f9f4644b9 -F src/printf.c 32f69fcba9ddfb71f9466b867f7ee7b7ffee30de +F src/printf.c 0f3476d9c8befc12708a3d614c22859b0cb79f19 F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c 41aa91af56d960e9414ce1d7c17cfb68e0d1c6cb F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e @@ -797,7 +797,7 @@ F test/permutations.test f9cc1dd987986c9d4949211c7a4ed55ec9aecba1 F test/pragma.test ad99d05e411c7687302124be56f3b362204be041 F test/pragma2.test f624a496a95ee878e81e59961eade66d5c00c028 F test/pragma3.test 6f849ccffeee7e496d2f2b5e74152306c0b8757c -F test/printf.test 2f11179e8b7210f3ea262d96b7f7b4cb78b34500 +F test/printf.test 5ab2b4666ca544645c4af2d78198f93b1e030d6e F test/printf2.test b4acd4bf8734243257f01ddefa17c4fb090acc8a F test/progress.test a282973d1d17f08071bc58a77d6b80f2a81c354d F test/ptrchng.test ef1aa72d6cf35a2bbd0869a649b744e9d84977fc @@ -1249,7 +1249,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 3ad829e50faca538db3abb2afb898b5521550c5c -R 1f357953eb69048c3e73348b4613f5e5 +P c494171f77dc2e5e04cb6d865e688448f04e5920 +R 7b4db908cf9a9f885bafc7fac7b1a77f U drh -Z 21bd74616576d30557b17c20f6eb18f9 +Z 16061aae0366142fcfaf02b796330263 diff --git a/manifest.uuid b/manifest.uuid index 45e0581d32..dddcbe141c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c494171f77dc2e5e04cb6d865e688448f04e5920 \ No newline at end of file +5ce4e7d7651e5c72a59f03f7aeb366291e62ab57 \ No newline at end of file diff --git a/src/printf.c b/src/printf.c index 0ff9887eb7..13eb491cda 100644 --- a/src/printf.c +++ b/src/printf.c @@ -390,6 +390,7 @@ void sqlite3VXPrintf( if( precision0 ) precision--; + testcase( precision>0xfff ); for(idx=precision&0xfff, rounder=0.5; idx>0; idx--, rounder*=0.1){} if( xtype==etFLOAT ) realvalue += rounder; /* Normalize realvalue to within 10.0 > realvalue >= 1.0 */ @@ -739,7 +741,7 @@ void sqlite3VXPrintf( */ static int sqlite3StrAccumEnlarge(StrAccum *p, int N){ char *zNew; - assert( p->nChar+N >= p->nAlloc ); /* Only called if really needed */ + assert( p->nChar+(i64)N >= p->nAlloc ); /* Only called if really needed */ if( p->accError ){ testcase(p->accError==STRACCUM_TOOBIG); testcase(p->accError==STRACCUM_NOMEM); @@ -788,7 +790,10 @@ static int sqlite3StrAccumEnlarge(StrAccum *p, int N){ ** Append N copies of character c to the given string buffer. */ void sqlite3AppendChar(StrAccum *p, int N, char c){ - if( p->nChar+N >= p->nAlloc && (N = sqlite3StrAccumEnlarge(p, N))<=0 ) return; + testcase( p->nChar + (i64)N > 0x7fffffff ); + if( p->nChar+(i64)N >= p->nAlloc && (N = sqlite3StrAccumEnlarge(p, N))<=0 ){ + return; + } while( (N--)>0 ) p->zText[p->nChar++] = c; } diff --git a/test/printf.test b/test/printf.test index 5dfc6d06cf..dadc23194e 100644 --- a/test/printf.test +++ b/test/printf.test @@ -472,6 +472,18 @@ do_test printf-1.16.7 { sqlite3_mprintf_int {abc: (%#6d) (%#6x) (%#6o) :xyz}\ 0xff676981 0xff676981 0xff676981 } {abc: (-9999999) (0xff676981) (037731664601) :xyz} +do_test printf-1.17.1 { + sqlite3_mprintf_int {abd: %2147483647d %2147483647x %2147483647o} 1 1 1 +} {} +do_test printf-1.17.2 { + sqlite3_mprintf_int {abd: %*d %x} 2147483647 1 1 +} {} +do_test printf-1.17.3 { + sqlite3_mprintf_int {abd: %*d %x} -2147483648 1 1 +} {} +do_test printf-1.17.4 { + sqlite3_mprintf_int {abd: %.2147483648d %x %x} 1 1 1 +} {abd: 1 1 1} do_test printf-2.1.1.1 { sqlite3_mprintf_double {abc: (%*.*f) :xyz} 1 1 0.001 } {abc: (0.0) :xyz} @@ -3469,6 +3481,15 @@ do_test printf-3.5 { do_test printf-3.6 { sqlite3_mprintf_str {%d %d A String: (%-30s)} 1 2 {This is the string} } [format {%d %d A String: (%-30s)} 1 2 {This is the string}] +do_test printf-3.7 { + sqlite3_mprintf_str {%d A String: (%*s)} 1 2147483647 {This is the string} +} [] +do_test printf-3.8 { + sqlite3_mprintf_str {%d A String: (%*s)} 1 -2147483648 {This is the string} +} [] +do_test printf-3.9 { + sqlite3_mprintf_str {%d A String: (%.*s)} 1 -2147483648 {This is the string} +} {1 A String: (This is the string)} do_test snprintf-3.11 { sqlite3_snprintf_str 2 {x%d %d %s} 10 10 {This is the string} } {x} From 8c069147cecc868648b2ef701b77d74be073095f Mon Sep 17 00:00:00 2001 From: dan Date: Tue, 7 Apr 2015 14:38:57 +0000 Subject: [PATCH 070/181] Another change to avoid a problem caused by integer overflow in the printf() code. FossilOrigin-Name: 95625ef3adc3c408d67e70f877f390445fbb8292 --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/printf.c | 10 ++++++++-- test/printf.test | 9 ++++++--- 4 files changed, 23 insertions(+), 14 deletions(-) diff --git a/manifest b/manifest index 3aa52a9c50..476d45c6a9 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Further\schanges\sto\sguard\sagainst\sinteger\soverflow\sin\sthe\swidth\sand\sprecision\nof\sprintf()\sarguments. -D 2015-04-07T13:28:41.878 +C Another\schange\sto\savoid\sa\sproblem\scaused\sby\sinteger\soverflow\sin\sthe\sprintf()\scode. +D 2015-04-07T14:38:57.638 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 00d12636df7a5b08af09116bcd6c7bfd49b8b3b4 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -226,7 +226,7 @@ F src/pcache1.c 69d137620a305f814398bd29a0c998038c0695e9 F src/pragma.c ac4f3f856b4234e85f55b0f069698a4766011100 F src/pragma.h 09c89bca58e9a44de2116cc8272b8d454657129f F src/prepare.c 173a5a499138451b2561614ecb87d78f9f4644b9 -F src/printf.c 0f3476d9c8befc12708a3d614c22859b0cb79f19 +F src/printf.c 62f93b9276807b053e9c9625b48f4843ef82e978 F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c 41aa91af56d960e9414ce1d7c17cfb68e0d1c6cb F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e @@ -797,7 +797,7 @@ F test/permutations.test f9cc1dd987986c9d4949211c7a4ed55ec9aecba1 F test/pragma.test ad99d05e411c7687302124be56f3b362204be041 F test/pragma2.test f624a496a95ee878e81e59961eade66d5c00c028 F test/pragma3.test 6f849ccffeee7e496d2f2b5e74152306c0b8757c -F test/printf.test 5ab2b4666ca544645c4af2d78198f93b1e030d6e +F test/printf.test b38d5d81a8cc20a040667c9acad68ddf5b18ccdd F test/printf2.test b4acd4bf8734243257f01ddefa17c4fb090acc8a F test/progress.test a282973d1d17f08071bc58a77d6b80f2a81c354d F test/ptrchng.test ef1aa72d6cf35a2bbd0869a649b744e9d84977fc @@ -1249,7 +1249,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 c494171f77dc2e5e04cb6d865e688448f04e5920 -R 7b4db908cf9a9f885bafc7fac7b1a77f -U drh -Z 16061aae0366142fcfaf02b796330263 +P 5ce4e7d7651e5c72a59f03f7aeb366291e62ab57 +R d822c3498c99ae588b224a89f4618062 +U dan +Z d5717f1cffb0747ad695b3c7e862b042 diff --git a/manifest.uuid b/manifest.uuid index dddcbe141c..50a22e5cce 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -5ce4e7d7651e5c72a59f03f7aeb366291e62ab57 \ No newline at end of file +95625ef3adc3c408d67e70f877f390445fbb8292 \ No newline at end of file diff --git a/src/printf.c b/src/printf.c index 13eb491cda..3eab6d47d6 100644 --- a/src/printf.c +++ b/src/printf.c @@ -270,6 +270,8 @@ void sqlite3VXPrintf( c = *++fmt; } } + if( width<0 ) width = 0; /* force to non-negative after int overflow */ + /* Get the precision */ if( c=='.' ){ precision = 0; @@ -280,7 +282,6 @@ void sqlite3VXPrintf( }else{ precision = va_arg(ap,int); } - if( precision<0 ) precision = -precision; c = *++fmt; }else{ while( c>='0' && c<='9' ){ @@ -288,6 +289,12 @@ void sqlite3VXPrintf( c = *++fmt; } } + + /* If a negative precision has been specified, use its absolute value + ** instead. This is (probably) not standard printf() behaviour, but + ** it is what sqlite3_mprintf() and friends have always done. If the + ** precision specified is -2147483648, use 0. */ + if( precision<0 ) precision = (-precision) & 0x7fffffff; }else{ precision = -1; } @@ -390,7 +397,6 @@ void sqlite3VXPrintf( if( precision Date: Tue, 7 Apr 2015 15:39:29 +0000 Subject: [PATCH 071/181] Avoid signed integer overflow when converting oversized in-line integer widths and precisions in printf(). FossilOrigin-Name: 8e4ac2ce24415926247961b00a62425ae85d6ffb --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/printf.c | 22 ++++++++++++---------- test/printf.test | 8 ++++---- 4 files changed, 25 insertions(+), 23 deletions(-) diff --git a/manifest b/manifest index 476d45c6a9..aa53c43007 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Another\schange\sto\savoid\sa\sproblem\scaused\sby\sinteger\soverflow\sin\sthe\sprintf()\scode. -D 2015-04-07T14:38:57.638 +C Avoid\ssigned\sinteger\soverflow\swhen\sconverting\soversized\sin-line\sinteger\nwidths\sand\sprecisions\sin\sprintf(). +D 2015-04-07T15:39:29.937 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 00d12636df7a5b08af09116bcd6c7bfd49b8b3b4 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -226,7 +226,7 @@ F src/pcache1.c 69d137620a305f814398bd29a0c998038c0695e9 F src/pragma.c ac4f3f856b4234e85f55b0f069698a4766011100 F src/pragma.h 09c89bca58e9a44de2116cc8272b8d454657129f F src/prepare.c 173a5a499138451b2561614ecb87d78f9f4644b9 -F src/printf.c 62f93b9276807b053e9c9625b48f4843ef82e978 +F src/printf.c 8ae1fa9d30c1200a9268a390ba9e9cea9197b27a F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c 41aa91af56d960e9414ce1d7c17cfb68e0d1c6cb F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e @@ -797,7 +797,7 @@ F test/permutations.test f9cc1dd987986c9d4949211c7a4ed55ec9aecba1 F test/pragma.test ad99d05e411c7687302124be56f3b362204be041 F test/pragma2.test f624a496a95ee878e81e59961eade66d5c00c028 F test/pragma3.test 6f849ccffeee7e496d2f2b5e74152306c0b8757c -F test/printf.test b38d5d81a8cc20a040667c9acad68ddf5b18ccdd +F test/printf.test b3ff34e73d59124140eaf89f7672e21bc2ca5fcc F test/printf2.test b4acd4bf8734243257f01ddefa17c4fb090acc8a F test/progress.test a282973d1d17f08071bc58a77d6b80f2a81c354d F test/ptrchng.test ef1aa72d6cf35a2bbd0869a649b744e9d84977fc @@ -1249,7 +1249,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 5ce4e7d7651e5c72a59f03f7aeb366291e62ab57 -R d822c3498c99ae588b224a89f4618062 -U dan -Z d5717f1cffb0747ad695b3c7e862b042 +P 95625ef3adc3c408d67e70f877f390445fbb8292 +R 5875861747bb686954783d9ce4259b86 +U drh +Z e5281cee406ead55e17262e5bdbb2163 diff --git a/manifest.uuid b/manifest.uuid index 50a22e5cce..786af92027 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -95625ef3adc3c408d67e70f877f390445fbb8292 \ No newline at end of file +8e4ac2ce24415926247961b00a62425ae85d6ffb \ No newline at end of file diff --git a/src/printf.c b/src/printf.c index 3eab6d47d6..9714fa1565 100644 --- a/src/printf.c +++ b/src/printf.c @@ -261,16 +261,18 @@ void sqlite3VXPrintf( } if( width<0 ){ flag_leftjustify = 1; - width = -width; + width = width >= -2147483647 ? -width : 0; } c = *++fmt; }else{ + unsigned wx = 0; while( c>='0' && c<='9' ){ - width = width*10 + c - '0'; + wx = wx*10 + c - '0'; c = *++fmt; } + testcase( wx>0x7fffffff ); + width = wx & 0x7fffffff; } - if( width<0 ) width = 0; /* force to non-negative after int overflow */ /* Get the precision */ if( c=='.' ){ @@ -283,18 +285,18 @@ void sqlite3VXPrintf( precision = va_arg(ap,int); } c = *++fmt; + if( precision<0 ){ + precision = precision >= -2147483647 ? -precision : -1; + } }else{ + unsigned px = 0; while( c>='0' && c<='9' ){ - precision = precision*10 + c - '0'; + px = px*10 + c - '0'; c = *++fmt; } + testcase( px>0x7fffffff ); + precision = px & 0x7fffffff; } - - /* If a negative precision has been specified, use its absolute value - ** instead. This is (probably) not standard printf() behaviour, but - ** it is what sqlite3_mprintf() and friends have always done. If the - ** precision specified is -2147483648, use 0. */ - if( precision<0 ) precision = (-precision) & 0x7fffffff; }else{ precision = -1; } diff --git a/test/printf.test b/test/printf.test index 3bf13f4eb9..6103d8acf8 100644 --- a/test/printf.test +++ b/test/printf.test @@ -483,7 +483,7 @@ do_test printf-1.17.3 { } {abd: 1 1} do_test printf-1.17.4 { sqlite3_mprintf_int {abd: %.2147483648d %x %x} 1 1 1 -} {abd: 1 1 1} +} {/.*/} do_test printf-2.1.1.1 { sqlite3_mprintf_double {abc: (%*.*f) :xyz} 1 1 0.001 } {abc: (0.0) :xyz} @@ -3489,7 +3489,7 @@ do_test printf-3.8 { } {1 A String: (This is the string)} do_test printf-3.9 { sqlite3_mprintf_str {%d A String: (%.*s)} 1 -2147483648 {This is the string} -} {1 A String: ()} +} {1 A String: (This is the string)} do_test snprintf-3.11 { sqlite3_snprintf_str 2 {x%d %d %s} 10 10 {This is the string} } {x} @@ -3710,8 +3710,8 @@ do_test printf-13.6 { sqlite3_mprintf_hexdouble %.20f fff8000000000000 } {NaN} do_test printf-13.7 { - sqlite3_mprintf_hexdouble %3000000000.10000f 4693b8b5b5056e17 -} "100000000000000000000000000000000.[string repeat 0 10000]" + sqlite3_mprintf_hexdouble %2147483648.10000f 4693b8b5b5056e17 +} {/100000000000000000000000000000000.00/} do_test printf-14.1 { sqlite3_mprintf_str {abc-%y-123} 0 0 {not used} From 5efbd06ab31aa0853d79b5361142b44c211a33b6 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 8 Apr 2015 12:16:33 +0000 Subject: [PATCH 072/181] Version 3.8.9 FossilOrigin-Name: 8a8ffc862e96f57aa698f93de10dee28e69f6e09 --- manifest | 11 +++++++---- manifest.uuid | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/manifest b/manifest index aa53c43007..e3dc7c37f3 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Avoid\ssigned\sinteger\soverflow\swhen\sconverting\soversized\sin-line\sinteger\nwidths\sand\sprecisions\sin\sprintf(). -D 2015-04-07T15:39:29.937 +C Version\s3.8.9 +D 2015-04-08T12:16:33.323 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 00d12636df7a5b08af09116bcd6c7bfd49b8b3b4 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -1249,7 +1249,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 95625ef3adc3c408d67e70f877f390445fbb8292 +P 8e4ac2ce24415926247961b00a62425ae85d6ffb R 5875861747bb686954783d9ce4259b86 +T +bgcolor * #d0c0ff +T +sym-release * +T +sym-version-3.8.9 * U drh -Z e5281cee406ead55e17262e5bdbb2163 +Z 05045ab8d5dbbaefca88cc23b8dca09c diff --git a/manifest.uuid b/manifest.uuid index 786af92027..a38b33773e 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -8e4ac2ce24415926247961b00a62425ae85d6ffb \ No newline at end of file +8a8ffc862e96f57aa698f93de10dee28e69f6e09 \ No newline at end of file From 50c7bb67f0e23c0b9618c7d488e234fb789505c3 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 9 Apr 2015 11:24:03 +0000 Subject: [PATCH 073/181] Remove a variable initializion to silence a harmless compiler warning. FossilOrigin-Name: 79861adbef8998c0f23e160543af8212d5546cd0 --- manifest | 15 ++++++--------- manifest.uuid | 2 +- src/complete.c | 2 +- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index e3dc7c37f3..2af0d5f0d6 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Version\s3.8.9 -D 2015-04-08T12:16:33.323 +C Remove\sa\svariable\sinitializion\sto\ssilence\sa\sharmless\scompiler\swarning. +D 2015-04-09T11:24:03.589 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 00d12636df7a5b08af09116bcd6c7bfd49b8b3b4 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -178,7 +178,7 @@ F src/btree.h 969adc948e89e449220ff0ff724c94bb2a52e9f1 F src/btreeInt.h 973a22a6fd61350b454ad614832b1f0a5e25a1e4 F src/build.c 0419bba592c22f6d00e6d57a2ca7136720d02c1a F src/callback.c 7b44ce59674338ad48b0e84e7b72f935ea4f68b0 -F src/complete.c 198a0066ba60ab06fc00fba1998d870a4d575463 +F src/complete.c a5cf5b4b56390cfb7b8636e8f7ddef90258dd575 F src/ctime.c 98f89724adc891a1a4c655bee04e33e716e05887 F src/date.c e4d50b3283696836ec1036b695ead9a19e37a5ac F src/delete.c 37964e6c1d73ff49cbea9ff690c9605fb15f600e @@ -1249,10 +1249,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 8e4ac2ce24415926247961b00a62425ae85d6ffb -R 5875861747bb686954783d9ce4259b86 -T +bgcolor * #d0c0ff -T +sym-release * -T +sym-version-3.8.9 * +P 8a8ffc862e96f57aa698f93de10dee28e69f6e09 +R 94d9923532f03d2c01923395a653f609 U drh -Z 05045ab8d5dbbaefca88cc23b8dca09c +Z 1ec7205940b0e152091a81dfbeda06fb diff --git a/manifest.uuid b/manifest.uuid index a38b33773e..acb9c7faab 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -8a8ffc862e96f57aa698f93de10dee28e69f6e09 \ No newline at end of file +79861adbef8998c0f23e160543af8212d5546cd0 \ No newline at end of file diff --git a/src/complete.c b/src/complete.c index f7a35cc6f3..a12184e64d 100644 --- a/src/complete.c +++ b/src/complete.c @@ -269,7 +269,7 @@ int sqlite3_complete(const char *zSql){ int sqlite3_complete16(const void *zSql){ sqlite3_value *pVal; char const *zSql8; - int rc = SQLITE_NOMEM; + int rc; #ifndef SQLITE_OMIT_AUTOINIT rc = sqlite3_initialize(); From d62c0f4c2daa03886116576b65866bfedb2e6ed6 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 9 Apr 2015 13:34:29 +0000 Subject: [PATCH 074/181] Add the "sqldiff" utility program. FossilOrigin-Name: 88da5bf5d2c4f848dbd4b5ffb1539abfbbdaff18 --- Makefile.in | 3 + Makefile.msc | 3 + main.mk | 4 + manifest | 17 +- manifest.uuid | 2 +- tool/sqldiff.c | 783 +++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 803 insertions(+), 9 deletions(-) create mode 100644 tool/sqldiff.c diff --git a/Makefile.in b/Makefile.in index 2177488f9b..295a6bc9c1 100644 --- a/Makefile.in +++ b/Makefile.in @@ -536,6 +536,9 @@ sqlite3$(TEXE): $(TOP)/src/shell.c libsqlite3.la sqlite3.h -o $@ $(TOP)/src/shell.c libsqlite3.la \ $(LIBREADLINE) $(TLIBS) -rpath "$(libdir)" +sqldiff$(EXE): $(TOP)/tool/sqldiff.c sqlite3.c sqlite3.h + $(LTLINK) -o $@ $(TOP)/tool/sqldiff.c sqlite3.c $(TLIBS) + mptester$(EXE): sqlite3.c $(TOP)/mptest/mptest.c $(LTLINK) -o $@ -I. $(TOP)/mptest/mptest.c sqlite3.c \ $(TLIBS) -rpath "$(libdir)" diff --git a/Makefile.msc b/Makefile.msc index 5330f8962f..b49a3eb0e1 100644 --- a/Makefile.msc +++ b/Makefile.msc @@ -1154,6 +1154,9 @@ sqlite3.exe: $(TOP)\src\shell.c $(SHELL_CORE_DEP) $(LIBRESOBJS) sqlite3.h $(LTLINK) $(SHELL_COMPILE_OPTS) $(READLINE_FLAGS) $(TOP)\src\shell.c \ /link /pdb:sqlite3sh.pdb $(LTLINKOPTS) $(SHELL_LINK_OPTS) $(LTLIBPATHS) $(LIBRESOBJS) $(LIBREADLINE) $(LTLIBS) $(TLIBS) +sqldiff.exe: $(TOP)\tool\sqldiff.c sqlite3.c sqlite3.h + $(LTLINK) $(TOP)\tool\sqldiff.c sqlite3.c + mptester.exe: $(TOP)\mptest\mptest.c $(SHELL_CORE_DEP) $(LIBRESOBJS) sqlite3.h $(LTLINK) $(SHELL_COMPILE_OPTS) $(TOP)\mptest\mptest.c \ /link $(LTLINKOPTS) $(LTLIBPATHS) $(SHELL_LINK_OPTS) $(LIBRESOBJS) $(LIBREADLINE) $(LTLIBS) $(TLIBS) diff --git a/main.mk b/main.mk index 57bb35c486..c5328dc6c7 100644 --- a/main.mk +++ b/main.mk @@ -404,6 +404,10 @@ sqlite3$(EXE): $(TOP)/src/shell.c libsqlite3.a sqlite3.h $(TOP)/src/shell.c \ libsqlite3.a $(LIBREADLINE) $(TLIBS) $(THREADLIB) +sqldiff$(EXE): $(TOP)/tool/sqldiff.c sqlite3.c sqlite3.h + $(TCCX) -o sqldiff$(EXE) -DSQLITE_THREADSAFE=0 \ + $(TOP)/tool/sqldiff.c sqlite3.c $(TLIBS) $(THREADLIB) + mptester$(EXE): sqlite3.c $(TOP)/mptest/mptest.c $(TCCX) -o $@ -I. $(TOP)/mptest/mptest.c sqlite3.c \ $(TLIBS) $(THREADLIB) diff --git a/manifest b/manifest index 2af0d5f0d6..bcddd8c661 100644 --- a/manifest +++ b/manifest @@ -1,9 +1,9 @@ -C Remove\sa\svariable\sinitializion\sto\ssilence\sa\sharmless\scompiler\swarning. -D 2015-04-09T11:24:03.589 +C Add\sthe\s"sqldiff"\sutility\sprogram. +D 2015-04-09T13:34:29.580 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f -F Makefile.in 00d12636df7a5b08af09116bcd6c7bfd49b8b3b4 +F Makefile.in 5f78b1ab81b64e7c57a75d170832443e66c0880a F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 -F Makefile.msc a8d817fa486d8c88dfbd19ae6a6567d9d350de39 +F Makefile.msc fa6a6de11af800d89f86e8a4266fd40a46008347 F Makefile.vxworks e1b65dea203f054e71653415bd8f96dcaed47858 F README.md d58e3bebc0a4145e0f2a87994015fdb575a8e866 F VERSION 319eb1ced4b4d17a67730f2b7b85f15c1346cb60 @@ -152,7 +152,7 @@ F ext/userauth/userauth.c 5fa3bdb492f481bbc1709fc83c91ebd13460c69e F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 x F ltmain.sh 3ff0879076df340d2e23ae905484d8c15d5fdea8 F magic.txt 8273bf49ba3b0c8559cb2774495390c31fd61c60 -F main.mk 997eee18387a3e69394f2f948c9c6ccf079655a4 +F main.mk ddffac494a82d42772df9fe30d3a78acf4f7cb41 F mkopcodec.awk c2ff431854d702cdd2d779c9c0d1f58fa16fa4ea F mkopcodeh.awk c6b3fa301db6ef7ac916b14c60868aeaec1337b5 F mkso.sh fd21c06b063bb16a5d25deea1752c2da6ac3ed83 @@ -1239,6 +1239,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/split-sqlite3c.tcl d9be87f1c340285a3e081eb19b4a247981ed290c +F tool/sqldiff.c 9c1c1e0aef974f1ad52aa720440a8a105d24d6f0 F tool/stack_usage.tcl f8e71b92cdb099a147dad572375595eae55eca43 F tool/symbols-mingw.sh 4dbcea7e74768305384c9fd2ed2b41bbf9f0414d F tool/symbols.sh fec58532668296d7c7dc48be9c87f75ccdb5814f @@ -1249,7 +1250,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 8a8ffc862e96f57aa698f93de10dee28e69f6e09 -R 94d9923532f03d2c01923395a653f609 +P 79861adbef8998c0f23e160543af8212d5546cd0 +R 55392413d804c3fa91206c94bb3d11f7 U drh -Z 1ec7205940b0e152091a81dfbeda06fb +Z a808bd48a859f116c92ef95210be5fe3 diff --git a/manifest.uuid b/manifest.uuid index acb9c7faab..32da2f232b 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -79861adbef8998c0f23e160543af8212d5546cd0 \ No newline at end of file +88da5bf5d2c4f848dbd4b5ffb1539abfbbdaff18 \ No newline at end of file diff --git a/tool/sqldiff.c b/tool/sqldiff.c new file mode 100644 index 0000000000..9aa68caaa9 --- /dev/null +++ b/tool/sqldiff.c @@ -0,0 +1,783 @@ +/* +** 2015-04-06 +** +** The author disclaims copyright to this source code. In place of +** a legal notice, here is a blessing: +** +** May you do good and not evil. +** May you find forgiveness for yourself and forgive others. +** May you share freely, never taking more than you give. +** +************************************************************************* +** +** This is a utility problem that computes the differences in content +** between two SQLite databases. +*/ +#include +#include +#include +#include +#include +#include "sqlite3.h" + +/* +** All global variables are gathered into the "g" singleton. +*/ +struct GlobalVars { + const char *zArgv0; /* Name of program */ + int bSchemaOnly; /* Only show schema differences */ + unsigned fDebug; /* Debug flags */ + sqlite3 *db; /* The database connection */ +} g; + +/* +** Allowed values for g.fDebug +*/ +#define DEBUG_COLUMN_NAMES 0x000001 +#define DEBUG_DIFF_SQL 0x000002 + +/* +** Dynamic string object +*/ +typedef struct Str Str; +struct Str { + char *z; /* Text of the string */ + int nAlloc; /* Bytes allocated in z[] */ + int nUsed; /* Bytes actually used in z[] */ +}; + +/* +** Initialize a Str object +*/ +static void strInit(Str *p){ + p->z = 0; + p->nAlloc = 0; + p->nUsed = 0; +} + +/* +** Print an error resulting from faulting command-line arguments and +** abort the program. +*/ +static void cmdlineError(const char *zFormat, ...){ + va_list ap; + fprintf(stderr, "%s: ", g.zArgv0); + va_start(ap, zFormat); + vfprintf(stderr, zFormat, ap); + va_end(ap); + fprintf(stderr, "\n\"%s --help\" for more help\n", g.zArgv0); + exit(1); +} + +/* +** Print an error message for an error that occurs at runtime, then +** abort the program. +*/ +static void runtimeError(const char *zFormat, ...){ + va_list ap; + fprintf(stderr, "%s: ", g.zArgv0); + va_start(ap, zFormat); + vfprintf(stderr, zFormat, ap); + va_end(ap); + fprintf(stderr, "\n"); + exit(1); +} + +/* +** Free all memory held by a Str object +*/ +static void strFree(Str *p){ + sqlite3_free(p->z); + strInit(p); +} + +/* +** Add formatted text to the end of a Str object +*/ +static void strPrintf(Str *p, const char *zFormat, ...){ + int nNew; + for(;;){ + if( p->z ){ + va_list ap; + va_start(ap, zFormat); + sqlite3_vsnprintf(p->nAlloc-p->nUsed, p->z+p->nUsed, zFormat, ap); + va_end(ap); + nNew = (int)strlen(p->z + p->nUsed); + }else{ + nNew = p->nAlloc; + } + if( p->nUsed+nNew < p->nAlloc-1 ){ + p->nUsed += nNew; + break; + } + p->nAlloc = p->nAlloc*2 + 1000; + p->z = sqlite3_realloc(p->z, p->nAlloc); + if( p->z==0 ) runtimeError("out of memory"); + } +} + + + +/* Safely quote an SQL identifier. Use the minimum amount of transformation +** necessary to allow the string to be used with %s. +** +** Space to hold the returned string is obtained from sqlite3_malloc(). The +** caller is responsible for ensuring this space is freed when no longer +** needed. +*/ +static char *safeId(const char *zId){ + /* All SQLite keywords, in alphabetical order */ + static const char *azKeywords[] = { + "ABORT", "ACTION", "ADD", "AFTER", "ALL", "ALTER", "ANALYZE", "AND", "AS", + "ASC", "ATTACH", "AUTOINCREMENT", "BEFORE", "BEGIN", "BETWEEN", "BY", + "CASCADE", "CASE", "CAST", "CHECK", "COLLATE", "COLUMN", "COMMIT", + "CONFLICT", "CONSTRAINT", "CREATE", "CROSS", "CURRENT_DATE", + "CURRENT_TIME", "CURRENT_TIMESTAMP", "DATABASE", "DEFAULT", "DEFERRABLE", + "DEFERRED", "DELETE", "DESC", "DETACH", "DISTINCT", "DROP", "EACH", + "ELSE", "END", "ESCAPE", "EXCEPT", "EXCLUSIVE", "EXISTS", "EXPLAIN", + "FAIL", "FOR", "FOREIGN", "FROM", "FULL", "GLOB", "GROUP", "HAVING", "IF", + "IGNORE", "IMMEDIATE", "IN", "INDEX", "INDEXED", "INITIALLY", "INNER", + "INSERT", "INSTEAD", "INTERSECT", "INTO", "IS", "ISNULL", "JOIN", "KEY", + "LEFT", "LIKE", "LIMIT", "MATCH", "NATURAL", "NO", "NOT", "NOTNULL", + "NULL", "OF", "OFFSET", "ON", "OR", "ORDER", "OUTER", "PLAN", "PRAGMA", + "PRIMARY", "QUERY", "RAISE", "RECURSIVE", "REFERENCES", "REGEXP", + "REINDEX", "RELEASE", "RENAME", "REPLACE", "RESTRICT", "RIGHT", + "ROLLBACK", "ROW", "SAVEPOINT", "SELECT", "SET", "TABLE", "TEMP", + "TEMPORARY", "THEN", "TO", "TRANSACTION", "TRIGGER", "UNION", "UNIQUE", + "UPDATE", "USING", "VACUUM", "VALUES", "VIEW", "VIRTUAL", "WHEN", "WHERE", + "WITH", "WITHOUT", + }; + int lwr, upr, mid, c, i, x; + for(i=x=0; (c = zId[i])!=0; i++){ + if( !isalpha(c) && c!='_' ){ + if( i>0 && isdigit(c) ){ + x++; + }else{ + return sqlite3_mprintf("\"%w\"", zId); + } + } + } + if( x ) return sqlite3_mprintf("%s", zId); + lwr = 0; + upr = sizeof(azKeywords)/sizeof(azKeywords[0]) - 1; + while( lwr<=upr ){ + mid = (lwr+upr)/2; + c = sqlite3_stricmp(azKeywords[mid], zId); + if( c==0 ) return sqlite3_mprintf("\"%w\"", zId); + if( c<0 ){ + lwr = mid+1; + }else{ + upr = mid-1; + } + } + return sqlite3_mprintf("%s", zId); +} + +/* +** Prepare a new SQL statement. Print an error and abort if anything +** goes wrong. +*/ +static sqlite3_stmt *db_vprepare(const char *zFormat, va_list ap){ + char *zSql; + int rc; + sqlite3_stmt *pStmt; + + zSql = sqlite3_vmprintf(zFormat, ap); + if( zSql==0 ) runtimeError("out of memory"); + rc = sqlite3_prepare_v2(g.db, zSql, -1, &pStmt, 0); + if( rc ){ + runtimeError("SQL statement error: %s\n\"%s\"", sqlite3_errmsg(g.db), + zSql); + } + sqlite3_free(zSql); + return pStmt; +} +static sqlite3_stmt *db_prepare(const char *zFormat, ...){ + va_list ap; + sqlite3_stmt *pStmt; + va_start(ap, zFormat); + pStmt = db_vprepare(zFormat, ap); + va_end(ap); + return pStmt; +} + +/* +** Free a list of strings +*/ +static void namelistFree(char **az){ + if( az ){ + int i; + for(i=0; az[i]; i++) sqlite3_free(az[i]); + sqlite3_free(az); + } +} + +/* +** Return a list of column names for the table zDb.zTab. Space to +** old the list is obtained from malloc() and should released by calling +** namelistFree() when no longer needed. +** +** Primary key columns are listed first, followed by data columns. The +** "primary key" in the previous sentence is the true primary key - the +** rowid or INTEGER PRIMARY KEY for ordinary tables or the declared +** PRIMARY KEY for WITHOUT ROWID tables. The number of columns in the +** primary key is returned in *pNPkey. +** +** If the table is a rowid table for which the rowid is inaccessible, +** then this routine returns a NULL pointer. +** +** Examples: +** CREATE TABLE t1(a INT UNIQUE, b INTEGER, c TEXT, PRIMARY KEY(c)); +** *pnPKey = 1; +** az = { "rowid", "a", "b", "c", 0 } +** +** CREATE TABLE t2(a INT UNIQUE, b INTEGER, c TEXT, PRIMARY KEY(b)); +** *pnPKey = 1; +** az = { "b", "a", "c", 0 } +** +** CREATE TABLE t3(x,y,z,PRIMARY KEY(y,z)); +** *pnPKey = 1 +** az = { "rowid", "x", "y", "z", 0 } +** +** CREATE TABLE t4(x,y,z,PRIMARY KEY(y,z)) WITHOUT ROWID; +** *pnPKey = 2 +** az = { "y", "z", "x", 0 } +** +** CREATE TABLE t5(rowid,_rowid_,oid); +** az = 0 // The rowid is not accessible +*/ +static char **columnNames(const char *zDb, const char *zTab, int *pnPKey){ + char **az = 0; + int naz = 0; + sqlite3_stmt *pStmt; + char *zPkIdxName = 0; /* Name of the PRIMARY KEY index */ + int truePk = 0; /* PRAGMA table_info indentifies the true PK */ + int nPK = 0; /* Number of PRIMARY KEY columns */ + int i, j; + + pStmt = db_prepare("PRAGMA %s.index_list=%Q", zDb, zTab); + while( SQLITE_ROW==sqlite3_step(pStmt) ){ + if( sqlite3_stricmp((const char*)sqlite3_column_text(pStmt,3),"pk")==0 ){ + zPkIdxName = sqlite3_mprintf("%s", sqlite3_column_text(pStmt, 1)); + break; + } + } + sqlite3_finalize(pStmt); + if( zPkIdxName ){ + int nKey = 0; + int nCol = 0; + truePk = 0; + pStmt = db_prepare("PRAGMA %s.index_xinfo=%Q", zDb, zPkIdxName); + while( SQLITE_ROW==sqlite3_step(pStmt) ){ + nCol++; + if( sqlite3_column_int(pStmt,5) ){ nKey++; continue; } + if( sqlite3_column_int(pStmt,1)>=0 ) truePk = 1; + } + if( nCol==nKey ) truePk = 1; + if( truePk ){ + nPK = nKey; + }else{ + nPK = 1; + } + sqlite3_finalize(pStmt); + sqlite3_free(zPkIdxName); + }else{ + truePk = 1; + nPK = 1; + } + *pnPKey = nPK; + naz = nPK; + az = sqlite3_malloc( sizeof(char*)*(nPK+1) ); + if( az==0 ) runtimeError("out of memory"); + memset(az, 0, sizeof(char*)*(nPK+1)); + pStmt = db_prepare("PRAGMA %s.table_info=%Q", zDb, zTab); + while( SQLITE_ROW==sqlite3_step(pStmt) ){ + int iPKey; + if( truePk && (iPKey = sqlite3_column_int(pStmt,5))>0 ){ + az[iPKey-1] = safeId((char*)sqlite3_column_text(pStmt,1)); + }else{ + az = sqlite3_realloc(az, sizeof(char*)*(naz+2) ); + if( az==0 ) runtimeError("out of memory"); + az[naz++] = safeId((char*)sqlite3_column_text(pStmt,1)); + } + } + sqlite3_finalize(pStmt); + if( az ) az[naz] = 0; + if( az[0]==0 ){ + const char *azRowid[] = { "rowid", "_rowid_", "oid" }; + for(i=0; i=naz ){ + az[0] = sqlite3_mprintf("%s", azRowid[i]); + break; + } + } + if( az[0]==0 ){ + for(i=1; inPk2 ){ + zSep = "SELECT "; + for(i=0; i Date: Thu, 9 Apr 2015 13:40:18 +0000 Subject: [PATCH 075/181] Fix comment typos in the sqldiff.c utility program. FossilOrigin-Name: 32ab2bb990746a84f5944e3cf428fb2dff3628da --- manifest | 12 ++++++------ manifest.uuid | 2 +- tool/sqldiff.c | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index bcddd8c661..f4f4fa2b88 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sthe\s"sqldiff"\sutility\sprogram. -D 2015-04-09T13:34:29.580 +C Fix\scomment\stypos\sin\sthe\ssqldiff.c\sutility\sprogram. +D 2015-04-09T13:40:18.767 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5f78b1ab81b64e7c57a75d170832443e66c0880a F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -1239,7 +1239,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/split-sqlite3c.tcl d9be87f1c340285a3e081eb19b4a247981ed290c -F tool/sqldiff.c 9c1c1e0aef974f1ad52aa720440a8a105d24d6f0 +F tool/sqldiff.c a28d17d824bc80940c2d67b2cf85a387c461dc97 F tool/stack_usage.tcl f8e71b92cdb099a147dad572375595eae55eca43 F tool/symbols-mingw.sh 4dbcea7e74768305384c9fd2ed2b41bbf9f0414d F tool/symbols.sh fec58532668296d7c7dc48be9c87f75ccdb5814f @@ -1250,7 +1250,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 79861adbef8998c0f23e160543af8212d5546cd0 -R 55392413d804c3fa91206c94bb3d11f7 +P 88da5bf5d2c4f848dbd4b5ffb1539abfbbdaff18 +R df929ff4fd13763291be7acc0214ee00 U drh -Z a808bd48a859f116c92ef95210be5fe3 +Z 41493ba4ef878730b46175333abd9329 diff --git a/manifest.uuid b/manifest.uuid index 32da2f232b..91e566d270 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -88da5bf5d2c4f848dbd4b5ffb1539abfbbdaff18 \ No newline at end of file +32ab2bb990746a84f5944e3cf428fb2dff3628da \ No newline at end of file diff --git a/tool/sqldiff.c b/tool/sqldiff.c index 9aa68caaa9..2b982e914a 100644 --- a/tool/sqldiff.c +++ b/tool/sqldiff.c @@ -214,14 +214,14 @@ static void namelistFree(char **az){ /* ** Return a list of column names for the table zDb.zTab. Space to -** old the list is obtained from malloc() and should released by calling -** namelistFree() when no longer needed. +** hold the list is obtained from sqlite3_malloc() and should released +** using namelistFree() when no longer needed. ** ** Primary key columns are listed first, followed by data columns. The ** "primary key" in the previous sentence is the true primary key - the ** rowid or INTEGER PRIMARY KEY for ordinary tables or the declared ** PRIMARY KEY for WITHOUT ROWID tables. The number of columns in the -** primary key is returned in *pNPkey. +** primary key is returned in *pnPkey. ** ** If the table is a rowid table for which the rowid is inaccessible, ** then this routine returns a NULL pointer. From 3875becf3559a1129da2eca84491f11ab7b308d8 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 9 Apr 2015 16:30:56 +0000 Subject: [PATCH 076/181] Remove two pointless assert() statements. This should silence harmless compiler warnings reported at [https://bugzilla.mozilla.org/show_bug.cgi?id=1152845] FossilOrigin-Name: 83b342a44ffc9ea07dc4d59f2866cefc68ee4f13 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/build.c | 1 - src/trigger.c | 1 - 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index f4f4fa2b88..a4817bdb6c 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\scomment\stypos\sin\sthe\ssqldiff.c\sutility\sprogram. -D 2015-04-09T13:40:18.767 +C Remove\stwo\spointless\sassert()\sstatements.\s\sThis\sshould\ssilence\sharmless\ncompiler\swarnings\sreported\sat\s\n[https://bugzilla.mozilla.org/show_bug.cgi?id=1152845] +D 2015-04-09T16:30:56.502 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5f78b1ab81b64e7c57a75d170832443e66c0880a F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -176,7 +176,7 @@ F src/btmutex.c 45a968cc85afed9b5e6cf55bf1f42f8d18107f79 F src/btree.c 2caf598165f3608fde8abac2b243826616ce54b7 F src/btree.h 969adc948e89e449220ff0ff724c94bb2a52e9f1 F src/btreeInt.h 973a22a6fd61350b454ad614832b1f0a5e25a1e4 -F src/build.c 0419bba592c22f6d00e6d57a2ca7136720d02c1a +F src/build.c 4a6d573cd5f77812f32d343134b429046946d560 F src/callback.c 7b44ce59674338ad48b0e84e7b72f935ea4f68b0 F src/complete.c a5cf5b4b56390cfb7b8636e8f7ddef90258dd575 F src/ctime.c 98f89724adc891a1a4c655bee04e33e716e05887 @@ -288,7 +288,7 @@ F src/test_vfstrace.c bab9594adc976cbe696ff3970728830b4c5ed698 F src/test_wsd.c 41cadfd9d97fe8e3e4e44f61a4a8ccd6f7ca8fe9 F src/threads.c 6bbcc9fe50c917864d48287b4792d46d6e873481 F src/tokenize.c a8d270b06e5f709930f7b67cf70a847969cb5bf3 -F src/trigger.c 25571661fdeae8c7f975ff40ffec205520a3f92f +F src/trigger.c 69a91bed7c94e46223e37ffccfeeb35e34b999ac F src/update.c 3c4ecc282accf12d39edb8d524cf089645e55a13 F src/utf.c fc6b889ba0779b7722634cdeaa25f1930d93820c F src/util.c 98a7627ca48ad3265b6940915a1d08355eb3fc7e @@ -1250,7 +1250,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 88da5bf5d2c4f848dbd4b5ffb1539abfbbdaff18 -R df929ff4fd13763291be7acc0214ee00 +P 32ab2bb990746a84f5944e3cf428fb2dff3628da +R 37f01a89c55b4805b0a5cf101a377c7c U drh -Z 41493ba4ef878730b46175333abd9329 +Z 80169060600c5dd4d547a3dab7f7d969 diff --git a/manifest.uuid b/manifest.uuid index 91e566d270..341851e55f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -32ab2bb990746a84f5944e3cf428fb2dff3628da \ No newline at end of file +83b342a44ffc9ea07dc4d59f2866cefc68ee4f13 \ No newline at end of file diff --git a/src/build.c b/src/build.c index fcf96bd42c..e01e2427f1 100644 --- a/src/build.c +++ b/src/build.c @@ -3776,7 +3776,6 @@ void sqlite3SrcListIndexedBy(Parse *pParse, SrcList *p, Token *pIndexedBy){ void sqlite3SrcListShiftJoinType(SrcList *p){ if( p ){ int i; - assert( p->a || p->nSrc==0 ); for(i=p->nSrc-1; i>0; i--){ p->a[i].jointype = p->a[i-1].jointype; } diff --git a/src/trigger.c b/src/trigger.c index d2e7b5a1e6..ed152d2a8a 100644 --- a/src/trigger.c +++ b/src/trigger.c @@ -680,7 +680,6 @@ static SrcList *targetSrcList( pSrc = sqlite3SrcListAppend(pParse->db, 0, &pStep->target, 0); if( pSrc ){ assert( pSrc->nSrc>0 ); - assert( pSrc->a!=0 ); iDb = sqlite3SchemaToIndex(pParse->db, pStep->pTrig->pSchema); if( iDb==0 || iDb>=2 ){ sqlite3 *db = pParse->db; From a37591cdd10ead51ed87a43aeeb9f83312636fd1 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 9 Apr 2015 18:14:03 +0000 Subject: [PATCH 077/181] Add the --primarykey option to the sqldiff tool, which causes it to use the schema-defined PRIMARY KEY. FossilOrigin-Name: 5063f9070afde9374ea0f2bc338fee840d8b3dd4 --- manifest | 12 +++--- manifest.uuid | 2 +- tool/sqldiff.c | 112 ++++++++++++++++++++++++++++++++----------------- 3 files changed, 80 insertions(+), 46 deletions(-) diff --git a/manifest b/manifest index a4817bdb6c..d6f8442010 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Remove\stwo\spointless\sassert()\sstatements.\s\sThis\sshould\ssilence\sharmless\ncompiler\swarnings\sreported\sat\s\n[https://bugzilla.mozilla.org/show_bug.cgi?id=1152845] -D 2015-04-09T16:30:56.502 +C Add\sthe\s--primarykey\soption\sto\sthe\ssqldiff\stool,\swhich\scauses\sit\sto\suse\sthe\nschema-defined\sPRIMARY\sKEY. +D 2015-04-09T18:14:03.130 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5f78b1ab81b64e7c57a75d170832443e66c0880a F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -1239,7 +1239,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/split-sqlite3c.tcl d9be87f1c340285a3e081eb19b4a247981ed290c -F tool/sqldiff.c a28d17d824bc80940c2d67b2cf85a387c461dc97 +F tool/sqldiff.c 9334ebc767dda9e02b904d4cbbd31cf8aaba3ca5 F tool/stack_usage.tcl f8e71b92cdb099a147dad572375595eae55eca43 F tool/symbols-mingw.sh 4dbcea7e74768305384c9fd2ed2b41bbf9f0414d F tool/symbols.sh fec58532668296d7c7dc48be9c87f75ccdb5814f @@ -1250,7 +1250,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 32ab2bb990746a84f5944e3cf428fb2dff3628da -R 37f01a89c55b4805b0a5cf101a377c7c +P 83b342a44ffc9ea07dc4d59f2866cefc68ee4f13 +R 80b4d61d5d12e62d07bcaa502c23a21f U drh -Z 80169060600c5dd4d547a3dab7f7d969 +Z 965913d93d231505652de01e91883fad diff --git a/manifest.uuid b/manifest.uuid index 341851e55f..fda938f72a 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -83b342a44ffc9ea07dc4d59f2866cefc68ee4f13 \ No newline at end of file +5063f9070afde9374ea0f2bc338fee840d8b3dd4 \ No newline at end of file diff --git a/tool/sqldiff.c b/tool/sqldiff.c index 2b982e914a..28b66b2c37 100644 --- a/tool/sqldiff.c +++ b/tool/sqldiff.c @@ -26,6 +26,7 @@ struct GlobalVars { const char *zArgv0; /* Name of program */ int bSchemaOnly; /* Only show schema differences */ + int bSchemaPK; /* Use the schema-defined PK, not the true PK */ unsigned fDebug; /* Debug flags */ sqlite3 *db; /* The database connection */ } g; @@ -217,27 +218,34 @@ static void namelistFree(char **az){ ** hold the list is obtained from sqlite3_malloc() and should released ** using namelistFree() when no longer needed. ** -** Primary key columns are listed first, followed by data columns. The -** "primary key" in the previous sentence is the true primary key - the -** rowid or INTEGER PRIMARY KEY for ordinary tables or the declared -** PRIMARY KEY for WITHOUT ROWID tables. The number of columns in the -** primary key is returned in *pnPkey. +** Primary key columns are listed first, followed by data columns. +** The number of columns in the primary key is returned in *pnPkey. ** -** If the table is a rowid table for which the rowid is inaccessible, +** Normally, the "primary key" in the previous sentence is the true +** primary key - the rowid or INTEGER PRIMARY KEY for ordinary tables +** or the declared PRIMARY KEY for WITHOUT ROWID tables. However, if +** the g.bSchemaPK flag is set, then the schema-defined PRIMARY KEY is +** used in all cases. In that case, entries that have NULL values in +** any of their primary key fields will be excluded from the analysis. +** +** If the primary key for a table is the rowid but rowid is inaccessible, ** then this routine returns a NULL pointer. ** ** Examples: ** CREATE TABLE t1(a INT UNIQUE, b INTEGER, c TEXT, PRIMARY KEY(c)); ** *pnPKey = 1; -** az = { "rowid", "a", "b", "c", 0 } +** az = { "rowid", "a", "b", "c", 0 } // Normal case +** az = { "c", "a", "b", 0 } // g.bSchemaPK==1 ** ** CREATE TABLE t2(a INT UNIQUE, b INTEGER, c TEXT, PRIMARY KEY(b)); ** *pnPKey = 1; ** az = { "b", "a", "c", 0 } ** ** CREATE TABLE t3(x,y,z,PRIMARY KEY(y,z)); -** *pnPKey = 1 -** az = { "rowid", "x", "y", "z", 0 } +** *pnPKey = 1 // Normal case +** az = { "rowid", "x", "y", "z", 0 } // Normal case +** *pnPKey = 2 // g.bSchemaPK==1 +** az = { "y", "x", "z", 0 } // g.bSchemaPK==1 ** ** CREATE TABLE t4(x,y,z,PRIMARY KEY(y,z)) WITHOUT ROWID; ** *pnPKey = 2 @@ -247,50 +255,72 @@ static void namelistFree(char **az){ ** az = 0 // The rowid is not accessible */ static char **columnNames(const char *zDb, const char *zTab, int *pnPKey){ - char **az = 0; - int naz = 0; - sqlite3_stmt *pStmt; + char **az = 0; /* List of column names to be returned */ + int naz = 0; /* Number of entries in az[] */ + sqlite3_stmt *pStmt; /* SQL statement being run */ char *zPkIdxName = 0; /* Name of the PRIMARY KEY index */ - int truePk = 0; /* PRAGMA table_info indentifies the true PK */ + int truePk = 0; /* PRAGMA table_info indentifies the PK to use */ int nPK = 0; /* Number of PRIMARY KEY columns */ - int i, j; + int i, j; /* Loop counters */ - pStmt = db_prepare("PRAGMA %s.index_list=%Q", zDb, zTab); - while( SQLITE_ROW==sqlite3_step(pStmt) ){ - if( sqlite3_stricmp((const char*)sqlite3_column_text(pStmt,3),"pk")==0 ){ - zPkIdxName = sqlite3_mprintf("%s", sqlite3_column_text(pStmt, 1)); - break; - } - } - sqlite3_finalize(pStmt); - if( zPkIdxName ){ - int nKey = 0; - int nCol = 0; - truePk = 0; - pStmt = db_prepare("PRAGMA %s.index_xinfo=%Q", zDb, zPkIdxName); + if( g.bSchemaPK==0 ){ + /* Normal case: Figure out what the true primary key is for the table. + ** * For WITHOUT ROWID tables, the true primary key is the same as + ** the schema PRIMARY KEY, which is guaranteed to be present. + ** * For rowid tables with an INTEGER PRIMARY KEY, the true primary + ** key is the INTEGER PRIMARY KEY. + ** * For all other rowid tables, the rowid is the true primary key. + */ + pStmt = db_prepare("PRAGMA %s.index_list=%Q", zDb, zTab); while( SQLITE_ROW==sqlite3_step(pStmt) ){ - nCol++; - if( sqlite3_column_int(pStmt,5) ){ nKey++; continue; } - if( sqlite3_column_int(pStmt,1)>=0 ) truePk = 1; - } - if( nCol==nKey ) truePk = 1; - if( truePk ){ - nPK = nKey; - }else{ - nPK = 1; + if( sqlite3_stricmp((const char*)sqlite3_column_text(pStmt,3),"pk")==0 ){ + zPkIdxName = sqlite3_mprintf("%s", sqlite3_column_text(pStmt, 1)); + break; + } } sqlite3_finalize(pStmt); - sqlite3_free(zPkIdxName); + if( zPkIdxName ){ + int nKey = 0; + int nCol = 0; + truePk = 0; + pStmt = db_prepare("PRAGMA %s.index_xinfo=%Q", zDb, zPkIdxName); + while( SQLITE_ROW==sqlite3_step(pStmt) ){ + nCol++; + if( sqlite3_column_int(pStmt,5) ){ nKey++; continue; } + if( sqlite3_column_int(pStmt,1)>=0 ) truePk = 1; + } + if( nCol==nKey ) truePk = 1; + if( truePk ){ + nPK = nKey; + }else{ + nPK = 1; + } + sqlite3_finalize(pStmt); + sqlite3_free(zPkIdxName); + }else{ + truePk = 1; + nPK = 1; + } + pStmt = db_prepare("PRAGMA %s.table_info=%Q", zDb, zTab); }else{ + /* The g.bSchemaPK==1 case: Use whatever primary key is declared + ** in the schema. The "rowid" will still be used as the primary key + ** if the table definition does not contain a PRIMARY KEY. + */ + nPK = 0; + pStmt = db_prepare("PRAGMA %s.table_info=%Q", zDb, zTab); + while( SQLITE_ROW==sqlite3_step(pStmt) ){ + if( sqlite3_column_int(pStmt,5)>0 ) nPK++; + } + sqlite3_reset(pStmt); + if( nPK==0 ) nPK = 1; truePk = 1; - nPK = 1; } *pnPKey = nPK; naz = nPK; az = sqlite3_malloc( sizeof(char*)*(nPK+1) ); if( az==0 ) runtimeError("out of memory"); memset(az, 0, sizeof(char*)*(nPK+1)); - pStmt = db_prepare("PRAGMA %s.table_info=%Q", zDb, zTab); while( SQLITE_ROW==sqlite3_step(pStmt) ){ int iPKey; if( truePk && (iPKey = sqlite3_column_int(pStmt,5))>0 ){ @@ -692,6 +722,7 @@ static void showHelp(void){ printf( "Output SQL text that would transform DB1 into DB2.\n" "Options:\n" +" --primarykey Use schema-defined PRIMARY KEYs\n" " --schema Show only differences in the schema\n" " --table TAB Show only differences in table TAB\n" ); @@ -720,6 +751,9 @@ int main(int argc, char **argv){ showHelp(); return 0; }else + if( strcmp(z,"primarykey")==0 ){ + g.bSchemaPK = 1; + }else if( strcmp(z,"schema")==0 ){ g.bSchemaOnly = 1; }else From 2139d252ddcaeb2e162b04694b912cb0b2148d4f Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 9 Apr 2015 19:39:54 +0000 Subject: [PATCH 078/181] Fix incorrect column names in UPDATE statements generated by the sqldiff utility. FossilOrigin-Name: ee53b46011852e27db23708387fe1e918cc8284c --- manifest | 12 ++++++------ manifest.uuid | 2 +- tool/sqldiff.c | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index d6f8442010..5b339e5c39 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sthe\s--primarykey\soption\sto\sthe\ssqldiff\stool,\swhich\scauses\sit\sto\suse\sthe\nschema-defined\sPRIMARY\sKEY. -D 2015-04-09T18:14:03.130 +C Fix\sincorrect\scolumn\snames\sin\sUPDATE\sstatements\sgenerated\sby\sthe\ssqldiff\nutility. +D 2015-04-09T19:39:54.853 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5f78b1ab81b64e7c57a75d170832443e66c0880a F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -1239,7 +1239,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/split-sqlite3c.tcl d9be87f1c340285a3e081eb19b4a247981ed290c -F tool/sqldiff.c 9334ebc767dda9e02b904d4cbbd31cf8aaba3ca5 +F tool/sqldiff.c 050763654cb28d23c4d9516deb348c8632e432cd F tool/stack_usage.tcl f8e71b92cdb099a147dad572375595eae55eca43 F tool/symbols-mingw.sh 4dbcea7e74768305384c9fd2ed2b41bbf9f0414d F tool/symbols.sh fec58532668296d7c7dc48be9c87f75ccdb5814f @@ -1250,7 +1250,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 83b342a44ffc9ea07dc4d59f2866cefc68ee4f13 -R 80b4d61d5d12e62d07bcaa502c23a21f +P 5063f9070afde9374ea0f2bc338fee840d8b3dd4 +R b81a13af06affec3f4deb7b3b6092ef8 U drh -Z 965913d93d231505652de01e91883fad +Z 7a24354f8d3816810c976cc3a62d01ee diff --git a/manifest.uuid b/manifest.uuid index fda938f72a..56fcea9bbf 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -5063f9070afde9374ea0f2bc338fee840d8b3dd4 \ No newline at end of file +ee53b46011852e27db23708387fe1e918cc8284c \ No newline at end of file diff --git a/tool/sqldiff.c b/tool/sqldiff.c index 28b66b2c37..53c5977ed4 100644 --- a/tool/sqldiff.c +++ b/tool/sqldiff.c @@ -658,7 +658,7 @@ static void diff_one_table(const char *zTab){ zSep = " SET"; for(i=nPk+1; i Date: Fri, 10 Apr 2015 07:55:07 +0000 Subject: [PATCH 079/181] Do not allow virtual table constructors to be called recursively. FossilOrigin-Name: 0a72726da21581ab16cb3e964bd825b8f2e931e4 --- ext/fts3/fts3.c | 8 ++++++-- manifest | 18 +++++++++--------- manifest.uuid | 2 +- src/vtab.c | 33 +++++++++++++++++++++++++-------- test/fts4content.test | 18 ++++++++++++++++-- 5 files changed, 57 insertions(+), 22 deletions(-) diff --git a/ext/fts3/fts3.c b/ext/fts3/fts3.c index 7a15379b83..42b9663a1b 100644 --- a/ext/fts3/fts3.c +++ b/ext/fts3/fts3.c @@ -1019,7 +1019,8 @@ static int fts3ContentColumns( const char *zTbl, /* Name of content table */ const char ***pazCol, /* OUT: Malloc'd array of column names */ int *pnCol, /* OUT: Size of array *pazCol */ - int *pnStr /* OUT: Bytes of string content */ + int *pnStr, /* OUT: Bytes of string content */ + char **pzErr /* OUT: error message */ ){ int rc = SQLITE_OK; /* Return code */ char *zSql; /* "SELECT *" statement on zTbl */ @@ -1030,6 +1031,9 @@ static int fts3ContentColumns( rc = SQLITE_NOMEM; }else{ rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0); + if( rc!=SQLITE_OK ){ + *pzErr = sqlite3_mprintf("%s", sqlite3_errmsg(db)); + } } sqlite3_free(zSql); @@ -1281,7 +1285,7 @@ static int fts3InitVtab( if( nCol==0 ){ sqlite3_free((void*)aCol); aCol = 0; - rc = fts3ContentColumns(db, argv[1], zContent, &aCol, &nCol, &nString); + rc = fts3ContentColumns(db, argv[1], zContent,&aCol,&nCol,&nString,pzErr); /* If a languageid= option was specified, remove the language id ** column from the aCol[] array. */ diff --git a/manifest b/manifest index 5b339e5c39..b5170f2282 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sincorrect\scolumn\snames\sin\sUPDATE\sstatements\sgenerated\sby\sthe\ssqldiff\nutility. -D 2015-04-09T19:39:54.853 +C Do\snot\sallow\svirtual\stable\sconstructors\sto\sbe\scalled\srecursively. +D 2015-04-10T07:55:07.186 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5f78b1ab81b64e7c57a75d170832443e66c0880a F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -78,7 +78,7 @@ F ext/fts3/README.content fdc666a70d5257a64fee209f97cf89e0e6e32b51 F ext/fts3/README.syntax a19711dc5458c20734b8e485e75fb1981ec2427a F ext/fts3/README.tokenizers e0a8b81383ea60d0334d274fadf305ea14a8c314 F ext/fts3/README.txt 8c18f41574404623b76917b9da66fcb0ab38328d -F ext/fts3/fts3.c 23bd9d37a777342f5c22a648e9b4b005dde9e58f +F ext/fts3/fts3.c 57d863c3bd360e575ecc293570af7c9b0bdd2209 F ext/fts3/fts3.h 3a10a0af180d502cecc50df77b1b22df142817fe F ext/fts3/fts3Int.h 394858c12a17740f7a1f6bd372c4606d4425a8d1 F ext/fts3/fts3_aux.c 5c211e17a64885faeb16b9ba7772f9d5445c2365 @@ -302,7 +302,7 @@ F src/vdbeblob.c 4f2e8e075d238392df98c5e03a64342465b03f90 F src/vdbemem.c c0dc81285b7571b0a31c40f17846fe2397ec1cd9 F src/vdbesort.c 919717d7599fa31d343ec28bffd0f9e91a4ff5f6 F src/vdbetrace.c 7e4222955e07dd707a2f360c0eb73452be1cb010 -F src/vtab.c 62d49237bd8f3be4863815a39387b0f9897fa5e1 +F src/vtab.c ff722a886ed61e2e2889ee221b0a4f6dcaabb8e1 F src/vxworks.h c18586c8edc1bddbc15c004fa16aeb1e1342b4fb F src/wal.c 878c8e1a51cb2ec45c395d26b7d5cd9e1a098e4a F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4 @@ -606,7 +606,7 @@ F test/fts3tok_err.test 52273cd193b9036282f7bacb43da78c6be87418d F test/fts3varint.test 752c08ed5d32c5d7dc211b056f4ed68a76b7e36e F test/fts4aa.test 10aac8e9d62c7357590acfabe3fad01e9a9ce1cb F test/fts4check.test 74d77f6cdb768ac49df5afda575cef14ae3d239a -F test/fts4content.test 2e7252557d6d24afa101d9ba1de710d6140e6d06 +F test/fts4content.test abb0c77bc3da3df64fec72e00844d2257a90025d F test/fts4docid.test e33c383cfbdff0284685604d256f347a18fdbf01 F test/fts4growth.test df10fde9f47cf5c71861e63fd8efcd573c4f7e53 F test/fts4growth2.test 2f063be1902a73cd087355837c52fed42ac11a5d @@ -1250,7 +1250,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 5063f9070afde9374ea0f2bc338fee840d8b3dd4 -R b81a13af06affec3f4deb7b3b6092ef8 -U drh -Z 7a24354f8d3816810c976cc3a62d01ee +P ee53b46011852e27db23708387fe1e918cc8284c +R 7e9242555b174ae9f2c42129917fe80c +U dan +Z a71357da8ab26f740f6d9ebc28389132 diff --git a/manifest.uuid b/manifest.uuid index 56fcea9bbf..6d3ce3f223 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ee53b46011852e27db23708387fe1e918cc8284c \ No newline at end of file +0a72726da21581ab16cb3e964bd825b8f2e931e4 \ No newline at end of file diff --git a/src/vtab.c b/src/vtab.c index 23f49bafce..d17aa147de 100644 --- a/src/vtab.c +++ b/src/vtab.c @@ -24,6 +24,8 @@ struct VtabCtx { VTable *pVTable; /* The virtual table being constructed */ Table *pTab; /* The Table object to which the virtual table belongs */ + VtabCtx *pPrior; /* Parent context (if any) */ + int bDeclared; /* True after sqlite3_declare_vtab() is called */ }; /* @@ -487,15 +489,27 @@ static int vtabCallConstructor( int (*xConstruct)(sqlite3*,void*,int,const char*const*,sqlite3_vtab**,char**), char **pzErr ){ - VtabCtx sCtx, *pPriorCtx; + VtabCtx sCtx; VTable *pVTable; int rc; const char *const*azArg = (const char *const*)pTab->azModuleArg; int nArg = pTab->nModuleArg; char *zErr = 0; - char *zModuleName = sqlite3MPrintf(db, "%s", pTab->zName); + char *zModuleName; int iDb; + VtabCtx *pCtx; + /* Check that the virtual-table is not already being initialized */ + for(pCtx=db->pVtabCtx; pCtx; pCtx=pCtx->pPrior){ + if( pCtx->pTab==pTab ){ + *pzErr = sqlite3MPrintf(db, + "vtable constructor called recursively: %s", pTab->zName + ); + return SQLITE_LOCKED; + } + } + + zModuleName = sqlite3MPrintf(db, "%s", pTab->zName); if( !zModuleName ){ return SQLITE_NOMEM; } @@ -516,11 +530,13 @@ static int vtabCallConstructor( assert( xConstruct ); sCtx.pTab = pTab; sCtx.pVTable = pVTable; - pPriorCtx = db->pVtabCtx; + sCtx.pPrior = db->pVtabCtx; + sCtx.bDeclared = 0; db->pVtabCtx = &sCtx; rc = xConstruct(db, pMod->pAux, nArg, azArg, &pVTable->pVtab, &zErr); - db->pVtabCtx = pPriorCtx; + db->pVtabCtx = sCtx.pPrior; if( rc==SQLITE_NOMEM ) db->mallocFailed = 1; + assert( sCtx.pTab==pTab ); if( SQLITE_OK!=rc ){ if( zErr==0 ){ @@ -536,7 +552,7 @@ static int vtabCallConstructor( memset(pVTable->pVtab, 0, sizeof(pVTable->pVtab[0])); pVTable->pVtab->pModule = pMod->pModule; pVTable->nRef = 1; - if( sCtx.pTab ){ + if( sCtx.bDeclared==0 ){ const char *zFormat = "vtable constructor did not declare schema: %s"; *pzErr = sqlite3MPrintf(db, zFormat, pTab->zName); sqlite3VtabUnlock(pVTable); @@ -706,8 +722,8 @@ int sqlite3VtabCallCreate(sqlite3 *db, int iDb, const char *zTab, char **pzErr){ ** virtual table module. */ int sqlite3_declare_vtab(sqlite3 *db, const char *zCreateTable){ + VtabCtx *pCtx = db->pVtabCtx; Parse *pParse; - int rc = SQLITE_OK; Table *pTab; char *zErr = 0; @@ -718,11 +734,12 @@ int sqlite3_declare_vtab(sqlite3 *db, const char *zCreateTable){ } #endif sqlite3_mutex_enter(db->mutex); - if( !db->pVtabCtx || !(pTab = db->pVtabCtx->pTab) ){ + if( !pCtx || pCtx->bDeclared ){ sqlite3Error(db, SQLITE_MISUSE); sqlite3_mutex_leave(db->mutex); return SQLITE_MISUSE_BKPT; } + pTab = pCtx->pTab; assert( (pTab->tabFlags & TF_Virtual)!=0 ); pParse = sqlite3StackAllocZero(db, sizeof(*pParse)); @@ -745,7 +762,7 @@ int sqlite3_declare_vtab(sqlite3 *db, const char *zCreateTable){ pParse->pNewTable->nCol = 0; pParse->pNewTable->aCol = 0; } - db->pVtabCtx->pTab = 0; + pCtx->bDeclared = 1; }else{ sqlite3ErrorWithMsg(db, SQLITE_ERROR, (zErr ? "%s" : 0), zErr); sqlite3DbFree(db, zErr); diff --git a/test/fts4content.test b/test/fts4content.test index 6b2cd3cc8e..481c6ec008 100644 --- a/test/fts4content.test +++ b/test/fts4content.test @@ -48,6 +48,9 @@ ifcapable !fts3 { # # 9.* - Test using content=xxx where xxx is a virtual table. # +# 11.* - Test that circular references (e.g. "t1(content=t1)") are +# detected. +# do_execsql_test 1.1.1 { CREATE TABLE t1(a, b, c); @@ -406,7 +409,7 @@ do_execsql_test 5.1.7 { # do_catchsql_test 6.1.1 { CREATE VIRTUAL TABLE ft7 USING fts4(content=t7); -} {1 {vtable constructor failed: ft7}} +} {1 {no such table: main.t7}} do_execsql_test 6.2.1 { CREATE TABLE t7(one, two); @@ -433,7 +436,7 @@ do_execsql_test 6.2.3 { } do_catchsql_test 6.2.4 { SELECT * FROM ft7; -} {1 {vtable constructor failed: ft7}} +} {1 {no such table: main.t7}} do_execsql_test 6.2.5 { CREATE TABLE t7(x, y); INSERT INTO t7 VALUES('A B', 'B A'); @@ -622,4 +625,15 @@ do_execsql_test 10.7 { {...c d [e] f g...} } +#------------------------------------------------------------------------- +# Test cases 11.* +# +reset_db + +do_catchsql_test 11.1 { + CREATE VIRTUAL TABLE x1 USING fts4(content=x1); +} {1 {vtable constructor called recursively: x1}} + + finish_test + From e918aaba981efb7ec5cca88ca8ae4d509ca84367 Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 10 Apr 2015 12:04:57 +0000 Subject: [PATCH 080/181] Fix foreign key CASCADE for cases where the parent key is an INTEGER PRIMARY KEY and the parent table contains other columns named "rowid", "_rowid_", and "oid". FossilOrigin-Name: ed3cbaab6ad49b0cb5b17e44def26c866919387a --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/fkey.c | 3 ++- test/fkey2.test | 4 ++-- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/manifest b/manifest index b5170f2282..b70c671a51 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Do\snot\sallow\svirtual\stable\sconstructors\sto\sbe\scalled\srecursively. -D 2015-04-10T07:55:07.186 +C Fix\sforeign\skey\sCASCADE\sfor\scases\swhere\sthe\sparent\skey\sis\san\sINTEGER\sPRIMARY\nKEY\sand\sthe\sparent\stable\scontains\sother\scolumns\snamed\s"rowid",\s"_rowid_",\nand\s"oid". +D 2015-04-10T12:04:57.414 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5f78b1ab81b64e7c57a75d170832443e66c0880a F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -184,7 +184,7 @@ F src/date.c e4d50b3283696836ec1036b695ead9a19e37a5ac F src/delete.c 37964e6c1d73ff49cbea9ff690c9605fb15f600e F src/expr.c d09dac67d53c78880ba31d56e8ba2be3a6490553 F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb -F src/fkey.c e0444b61bed271a76840cbe6182df93a9baa3f12 +F src/fkey.c 3343d551a8d810782257244fb33f2ce191493c39 F src/func.c 1414c24c873c48796ad45942257a179a423ba42f F src/global.c 4f77cadbc5427d00139ba43d0f3979804cbb700e F src/hash.c 4263fbc955f26c2e8cdc0cf214bc42435aa4e4f5 @@ -505,7 +505,7 @@ F test/fallocate.test 3e979af17dfa7e5e9dda5eba1a696c04fa9d47f7 F test/filectrl.test 14fa712e42c4cb791e09dfd58a6a03efb47ef13a F test/filefmt.test cb34663f126cbc2d358af552dcaf5c72769b0146 F test/fkey1.test e1d1fa84cde579185ea01358436839703e415a5b -F test/fkey2.test 1db212cda86b0d3ce72714001f7b6381c321341c +F test/fkey2.test 223c624e7eccee21e89c98d4d127ac88d774b940 F test/fkey3.test 76d475c80b84ee7a5d062e56ccb6ea68882e2b49 F test/fkey4.test 86446017011273aad8f9a99c1a65019e7bd9ca9d F test/fkey5.test 56bcb5a6e8b725b17febc267fb041a6695e86853 @@ -1250,7 +1250,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 ee53b46011852e27db23708387fe1e918cc8284c -R 7e9242555b174ae9f2c42129917fe80c -U dan -Z a71357da8ab26f740f6d9ebc28389132 +P 0a72726da21581ab16cb3e964bd825b8f2e931e4 +R b2dde8f542352409005b61e29f91d905 +U drh +Z 7c6c1370c12f07a8520590c209ac9901 diff --git a/manifest.uuid b/manifest.uuid index 6d3ce3f223..33b43c8925 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -0a72726da21581ab16cb3e964bd825b8f2e931e4 \ No newline at end of file +ed3cbaab6ad49b0cb5b17e44def26c866919387a \ No newline at end of file diff --git a/src/fkey.c b/src/fkey.c index fa148ba6a3..3e4b752e86 100644 --- a/src/fkey.c +++ b/src/fkey.c @@ -1184,7 +1184,8 @@ static Trigger *fkActionTrigger( iFromCol = aiCol ? aiCol[i] : pFKey->aCol[0].iFrom; assert( iFromCol>=0 ); - tToCol.z = pIdx ? pTab->aCol[pIdx->aiColumn[i]].zName : "oid"; + assert( pIdx!=0 || (pTab->iPKey>=0 && pTab->iPKeynCol) ); + tToCol.z = pTab->aCol[pIdx ? pIdx->aiColumn[i] : pTab->iPKey].zName; tFromCol.z = pFKey->pFrom->aCol[iFromCol].zName; tToCol.n = sqlite3Strlen30(tToCol.z); diff --git a/test/fkey2.test b/test/fkey2.test index 53b90dc91c..8b2871e5a6 100644 --- a/test/fkey2.test +++ b/test/fkey2.test @@ -746,10 +746,10 @@ do_test fkey2-10.2.2 { drop_all_tables do_test fkey2-11.1.1 { execsql { - CREATE TABLE t1(a INTEGER PRIMARY KEY, b); + CREATE TABLE t1(a INTEGER PRIMARY KEY, b, rowid, _rowid_, oid); CREATE TABLE t2(c, d, FOREIGN KEY(c) REFERENCES t1(a) ON UPDATE CASCADE); - INSERT INTO t1 VALUES(10, 100); + INSERT INTO t1 VALUES(10, 100, 'abc', 'def', 'ghi'); INSERT INTO t2 VALUES(10, 100); UPDATE t1 SET a = 15; SELECT * FROM t2; From 4e23536e56f283bd8cf0d787dd9e76e7176435f0 Mon Sep 17 00:00:00 2001 From: dan Date: Fri, 10 Apr 2015 16:05:33 +0000 Subject: [PATCH 081/181] In sqlite3_declare_vtab(), avoid accessing the database structure until after the "api-armour" safety-check has completed and the db mutex has been obtained. FossilOrigin-Name: 860e4f8a94901d451fac3954960c1d2f589e8882 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/vtab.c | 3 ++- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index b70c671a51..a4b1b68367 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sforeign\skey\sCASCADE\sfor\scases\swhere\sthe\sparent\skey\sis\san\sINTEGER\sPRIMARY\nKEY\sand\sthe\sparent\stable\scontains\sother\scolumns\snamed\s"rowid",\s"_rowid_",\nand\s"oid". -D 2015-04-10T12:04:57.414 +C In\ssqlite3_declare_vtab(),\savoid\saccessing\sthe\sdatabase\sstructure\suntil\safter\sthe\s"api-armour"\ssafety-check\shas\scompleted\sand\sthe\sdb\smutex\shas\sbeen\sobtained. +D 2015-04-10T16:05:33.033 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5f78b1ab81b64e7c57a75d170832443e66c0880a F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -302,7 +302,7 @@ F src/vdbeblob.c 4f2e8e075d238392df98c5e03a64342465b03f90 F src/vdbemem.c c0dc81285b7571b0a31c40f17846fe2397ec1cd9 F src/vdbesort.c 919717d7599fa31d343ec28bffd0f9e91a4ff5f6 F src/vdbetrace.c 7e4222955e07dd707a2f360c0eb73452be1cb010 -F src/vtab.c ff722a886ed61e2e2889ee221b0a4f6dcaabb8e1 +F src/vtab.c 9ca557215e8591ceb66e0b7c0a579c6df1e54b2d F src/vxworks.h c18586c8edc1bddbc15c004fa16aeb1e1342b4fb F src/wal.c 878c8e1a51cb2ec45c395d26b7d5cd9e1a098e4a F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4 @@ -1250,7 +1250,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 0a72726da21581ab16cb3e964bd825b8f2e931e4 -R b2dde8f542352409005b61e29f91d905 -U drh -Z 7c6c1370c12f07a8520590c209ac9901 +P ed3cbaab6ad49b0cb5b17e44def26c866919387a +R f962720dd8c90d63a1a200cd065fa312 +U dan +Z 666766483214acd3a759f5cb43f45fc3 diff --git a/manifest.uuid b/manifest.uuid index 33b43c8925..909c5925c5 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ed3cbaab6ad49b0cb5b17e44def26c866919387a \ No newline at end of file +860e4f8a94901d451fac3954960c1d2f589e8882 \ No newline at end of file diff --git a/src/vtab.c b/src/vtab.c index d17aa147de..9629a00dcb 100644 --- a/src/vtab.c +++ b/src/vtab.c @@ -722,7 +722,7 @@ int sqlite3VtabCallCreate(sqlite3 *db, int iDb, const char *zTab, char **pzErr){ ** virtual table module. */ int sqlite3_declare_vtab(sqlite3 *db, const char *zCreateTable){ - VtabCtx *pCtx = db->pVtabCtx; + VtabCtx *pCtx; Parse *pParse; int rc = SQLITE_OK; Table *pTab; @@ -734,6 +734,7 @@ int sqlite3_declare_vtab(sqlite3 *db, const char *zCreateTable){ } #endif sqlite3_mutex_enter(db->mutex); + pCtx = db->pVtabCtx; if( !pCtx || pCtx->bDeclared ){ sqlite3Error(db, SQLITE_MISUSE); sqlite3_mutex_leave(db->mutex); From 83e63dc3857dbb2220090ef0cd3541cef2189aa3 Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 10 Apr 2015 19:41:18 +0000 Subject: [PATCH 082/181] Work toward adding the --changeset option to the sqldiff utility program. Changes are incomplete. This is an incremental check-in. FossilOrigin-Name: 463e38d765f9d055b63792a8ea15c3782657b07f --- manifest | 17 ++++--- manifest.uuid | 2 +- tool/sqldiff.c | 126 ++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 135 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index a4b1b68367..c7c3d03725 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C In\ssqlite3_declare_vtab(),\savoid\saccessing\sthe\sdatabase\sstructure\suntil\safter\sthe\s"api-armour"\ssafety-check\shas\scompleted\sand\sthe\sdb\smutex\shas\sbeen\sobtained. -D 2015-04-10T16:05:33.033 +C Work\stoward\sadding\sthe\s--changeset\soption\sto\sthe\ssqldiff\sutility\sprogram.\nChanges\sare\sincomplete.\s\sThis\sis\san\sincremental\scheck-in. +D 2015-04-10T19:41:18.818 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5f78b1ab81b64e7c57a75d170832443e66c0880a F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -1239,7 +1239,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/split-sqlite3c.tcl d9be87f1c340285a3e081eb19b4a247981ed290c -F tool/sqldiff.c 050763654cb28d23c4d9516deb348c8632e432cd +F tool/sqldiff.c 3e6f54359a070089ed0d11456e8868dcd3f20e94 F tool/stack_usage.tcl f8e71b92cdb099a147dad572375595eae55eca43 F tool/symbols-mingw.sh 4dbcea7e74768305384c9fd2ed2b41bbf9f0414d F tool/symbols.sh fec58532668296d7c7dc48be9c87f75ccdb5814f @@ -1250,7 +1250,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 ed3cbaab6ad49b0cb5b17e44def26c866919387a -R f962720dd8c90d63a1a200cd065fa312 -U dan -Z 666766483214acd3a759f5cb43f45fc3 +P 860e4f8a94901d451fac3954960c1d2f589e8882 +R 6c8da3b8e133d42c3c0048f2d2a47a98 +T *branch * sqldiff-changeset +T *sym-sqldiff-changeset * +T -sym-trunk * +U drh +Z b58ac33ed90e0dd7edcdd56b18b68a1d diff --git a/manifest.uuid b/manifest.uuid index 909c5925c5..324240a04b 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -860e4f8a94901d451fac3954960c1d2f589e8882 \ No newline at end of file +463e38d765f9d055b63792a8ea15c3782657b07f \ No newline at end of file diff --git a/tool/sqldiff.c b/tool/sqldiff.c index 53c5977ed4..2b46353535 100644 --- a/tool/sqldiff.c +++ b/tool/sqldiff.c @@ -714,6 +714,113 @@ end_diff_one_table: return; } +/* +** Generate a CHANGESET for all differences from main.zTab to aux.zTab. +*/ +static void changeset_one_table(const char *zTab, FILE *out){ + sqlite3_stmt *pStmt; /* SQL statment */ + char *zId = safeId(zTab); /* Escaped name of the table */ + char **azCol = 0; /* List of escaped column names */ + int nCol = 0; /* Number of columns */ + int *aiFlg = 0; /* 0 if column is not part of PK */ + int *aiPk = 0; /* Column numbers for each PK column */ + int nPk = 0; /* Number of PRIMARY KEY columns */ + Str sql; /* SQL for the diff query */ + int i; /* Loop counter */ + const char *zSep; /* List separator */ + + pStmt = db_prepare( + "SELECT A.sql=B.sql FROM main.sqlite_master A, aux.sqlite_master B" + " WHERE A.name=%Q AND B.name=%Q", zTab, zTab + ); + if( SQLITE_ROW==sqlite3_step(pStmt) ){ + if( sqlite3_column_int(pStmt,0)==0 ){ + runtimeError("schema changes for table %s", safeId(zTab)); + } + }else{ + runtimeError("table %s missing from one or both databases", safeId(zTab)); + } + sqlite3_finalize(pStmt); + pStmt = db_prepare("PRAGMA main.table_info=%Q", zTab); + while( SQLITE_ROW==sqlite3_step(pStmt) ){ + nCol++; + azCol = sqlite3_realloc(azCol, sizeof(char*)*nCol); + if( azCol==0 ) runtimeError("out of memory"); + aiFlg = sqlite3_realloc(aiFlg, sizeof(int)*nCol); + if( aiFlg==0 ) runtimeError("out of memory"); + azCol[nCol-1] = safeId((const char*)sqlite3_column_text(pStmt,1)); + aiFlg[nCol-1] = i = sqlite3_column_int(pStmt,5); + if( i>0 ){ + if( i>nPk ){ + nPk = i; + aiPk = sqlite3_realloc(aiPk, sizeof(int)*nPk); + if( aiPk==0 ) runtimeError("out of memory"); + } + aiPk[i-1] = nCol-1; + } + } + sqlite3_finalize(pStmt); + if( nPk==0 ) goto end_changeset_one_table; + strInit(&sql); + if( nCol>nPk ){ + strPrintf(&sql, "SELECT 1"); /* Changes to non-PK columns */ + for(i=0; i0 ) sqlite3_free(azCol[--nCol]); + sqlite3_free(azCol); + sqlite3_free(aiPk); + sqlite3_free(zId); +} + /* ** Print sketchy documentation for this utility program */ @@ -722,6 +829,7 @@ static void showHelp(void){ printf( "Output SQL text that would transform DB1 into DB2.\n" "Options:\n" +" --changeset FILE Write a CHANGESET into FILE\n" " --primarykey Use schema-defined PRIMARY KEYs\n" " --schema Show only differences in the schema\n" " --table TAB Show only differences in table TAB\n" @@ -737,6 +845,7 @@ int main(int argc, char **argv){ char *zSql; sqlite3_stmt *pStmt; char *zTab = 0; + FILE *out = 0; g.zArgv0 = argv[0]; for(i=1; i Date: Fri, 10 Apr 2015 21:16:11 +0000 Subject: [PATCH 083/181] Minor build enhancements for MSVC. FossilOrigin-Name: 40c417a7efb17221cec4a0a703863854bcab8db2 --- Makefile.msc | 6 ++++-- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/msvc.h | 1 + 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/Makefile.msc b/Makefile.msc index b49a3eb0e1..7ea110e7dd 100644 --- a/Makefile.msc +++ b/Makefile.msc @@ -42,8 +42,8 @@ DYNAMIC_SHELL = 0 # !IFNDEF NO_WARN !IF $(USE_FULLWARN)!=0 -NO_WARN = -wd4054 -wd4055 -wd4100 -wd4127 -wd4152 -wd4189 -wd4206 -wd4210 -NO_WARN = $(NO_WARN) -wd4232 -wd4244 -wd4305 -wd4306 -wd4702 -wd4706 +NO_WARN = -wd4054 -wd4055 -wd4100 -wd4127 -wd4130 -wd4152 -wd4189 -wd4206 +NO_WARN = $(NO_WARN) -wd4210 -wd4232 -wd4244 -wd4305 -wd4306 -wd4702 -wd4706 !ENDIF !ENDIF @@ -453,11 +453,13 @@ RCC = $(RCC) -I$(TOP)\ext\rtree # options are necessary in order to allow debugging symbols to # work correctly with Visual Studio when using the amalgamation. # +!IFNDEF MKSQLITE3C_ARGS !IF $(DEBUG)>1 MKSQLITE3C_ARGS = --linemacros !ELSE MKSQLITE3C_ARGS = !ENDIF +!ENDIF # Define -DNDEBUG to compile without debugging (i.e., for production usage) # Omitting the define will cause extra debugging code to be inserted and diff --git a/manifest b/manifest index a4b1b68367..d9f7505d75 100644 --- a/manifest +++ b/manifest @@ -1,9 +1,9 @@ -C In\ssqlite3_declare_vtab(),\savoid\saccessing\sthe\sdatabase\sstructure\suntil\safter\sthe\s"api-armour"\ssafety-check\shas\scompleted\sand\sthe\sdb\smutex\shas\sbeen\sobtained. -D 2015-04-10T16:05:33.033 +C Minor\sbuild\senhancements\sfor\sMSVC. +D 2015-04-10T21:16:11.659 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5f78b1ab81b64e7c57a75d170832443e66c0880a F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 -F Makefile.msc fa6a6de11af800d89f86e8a4266fd40a46008347 +F Makefile.msc 0078f5781538e07ea38683439f38d5f5ab79ab6e F Makefile.vxworks e1b65dea203f054e71653415bd8f96dcaed47858 F README.md d58e3bebc0a4145e0f2a87994015fdb575a8e866 F VERSION 319eb1ced4b4d17a67730f2b7b85f15c1346cb60 @@ -203,7 +203,7 @@ F src/mem2.c f1940d9e91948dd6a908fbb9ce3835c36b5d83c3 F src/mem3.c 61c9d47b792908c532ca3a62b999cf21795c6534 F src/mem5.c 61eeb90134f9a5be6c2e68d8daae7628b25953fb F src/memjournal.c 3eb2c0b51adbd869cb6a44780323f05fa904dc85 -F src/msvc.h e78002098966e39b2fd9915bd70b7bc3ec8398b7 +F src/msvc.h d9ba56c6851227ab44b3f228a35f3f5772296495 F src/mutex.c 19bf9acba69ca2f367c3761080f8a9f0cf4670a8 F src/mutex.h 779d588e3b7756ec3ecf7d78cde1d84aba414f85 F src/mutex_noop.c 529bab0743c3321c940f32c3464de494fd38cfa9 @@ -1250,7 +1250,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 ed3cbaab6ad49b0cb5b17e44def26c866919387a -R f962720dd8c90d63a1a200cd065fa312 -U dan -Z 666766483214acd3a759f5cb43f45fc3 +P 860e4f8a94901d451fac3954960c1d2f589e8882 +R d724f3837aa2139b84d99a7758232948 +U mistachkin +Z add6515d666dc387abaf063a7b8f0157 diff --git a/manifest.uuid b/manifest.uuid index 909c5925c5..5d2f5e3cb5 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -860e4f8a94901d451fac3954960c1d2f589e8882 \ No newline at end of file +40c417a7efb17221cec4a0a703863854bcab8db2 \ No newline at end of file diff --git a/src/msvc.h b/src/msvc.h index 4508e6941f..01ebf2b46f 100644 --- a/src/msvc.h +++ b/src/msvc.h @@ -20,6 +20,7 @@ #pragma warning(disable : 4055) #pragma warning(disable : 4100) #pragma warning(disable : 4127) +#pragma warning(disable : 4130) #pragma warning(disable : 4152) #pragma warning(disable : 4189) #pragma warning(disable : 4206) From 4a33507f60067a91786065a082a28fd781753aa3 Mon Sep 17 00:00:00 2001 From: drh Date: Sat, 11 Apr 2015 02:08:48 +0000 Subject: [PATCH 084/181] Detect and report oversized records constructed from multiple zeroblobs. FossilOrigin-Name: 9e139afd92116ebc593114ed63b57c8f469653f6 --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/vdbe.c | 4 ++-- test/zeroblob.test | 9 +++++++++ 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index d9f7505d75..71aafa2cb1 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Minor\sbuild\senhancements\sfor\sMSVC. -D 2015-04-10T21:16:11.659 +C Detect\sand\sreport\soversized\srecords\sconstructed\sfrom\smultiple\szeroblobs. +D 2015-04-11T02:08:48.265 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5f78b1ab81b64e7c57a75d170832443e66c0880a F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -293,7 +293,7 @@ F src/update.c 3c4ecc282accf12d39edb8d524cf089645e55a13 F src/utf.c fc6b889ba0779b7722634cdeaa25f1930d93820c F src/util.c 98a7627ca48ad3265b6940915a1d08355eb3fc7e F src/vacuum.c 9460b9de7b2d4e34b0d374894aa6c8a0632be8ec -F src/vdbe.c 86ae6f4774410868af41bd839b72b7081ff03e78 +F src/vdbe.c 06cc2cf42daf8b0c397f69a6fb1818124f3cd93a F src/vdbe.h 6fc69d9c5e146302c56e163cb4b31d1ee64a18c3 F src/vdbeInt.h 9cbaa84f53ddd2d09a0cf61a94337a3a035d08a0 F src/vdbeapi.c 583d56b129dd27f12bed518270de9ebe521e6a75 @@ -1194,7 +1194,7 @@ F test/without_rowid4.test 4e08bcbaee0399f35d58b5581881e7a6243d458a F test/without_rowid5.test 61256715b686359df48ca1742db50cc7e3e7b862 F test/without_rowid6.test db0dbf03c49030aa3c1ba5f618620334bd2baf5f F test/wordcount.c 9915e06cb33d8ca8109b8700791afe80d305afda -F test/zeroblob.test caaecfb4f908f7bc086ed238668049f96774d688 +F test/zeroblob.test fb3c0e4ab172d386954deda24c03f500e121d80d F test/zerodamage.test cf6748bad89553cc1632be51a6f54e487e4039ac F tool/build-all-msvc.bat 72e05bc8deca39a547884485c086b915f50a91ed x F tool/build-shell.sh 950f47c6174f1eea171319438b93ba67ff5bf367 @@ -1250,7 +1250,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 860e4f8a94901d451fac3954960c1d2f589e8882 -R d724f3837aa2139b84d99a7758232948 -U mistachkin -Z add6515d666dc387abaf063a7b8f0157 +P 40c417a7efb17221cec4a0a703863854bcab8db2 +R fd7ff5723f566045f2ba0751ddce0467 +U drh +Z f6419661cff2a502b477cceb45bb8fdd diff --git a/manifest.uuid b/manifest.uuid index 5d2f5e3cb5..c8b77b78ce 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -40c417a7efb17221cec4a0a703863854bcab8db2 \ No newline at end of file +9e139afd92116ebc593114ed63b57c8f469653f6 \ No newline at end of file diff --git a/src/vdbe.c b/src/vdbe.c index f2de90d14c..8e7247a1e8 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -2578,7 +2578,7 @@ case OP_MakeRecord: { u64 nData; /* Number of bytes of data space */ int nHdr; /* Number of bytes of header space */ i64 nByte; /* Data space required for this record */ - int nZero; /* Number of zero bytes at the end of the record */ + i64 nZero; /* Number of zero bytes at the end of the record */ int nVarint; /* Number of bytes in a varint */ u32 serial_type; /* Type field */ Mem *pData0; /* First field to be combined into the record */ @@ -2670,7 +2670,7 @@ case OP_MakeRecord: { if( nVarintdb->aLimit[SQLITE_LIMIT_LENGTH] ){ + if( nByte+nZero>db->aLimit[SQLITE_LIMIT_LENGTH] ){ goto too_big; } diff --git a/test/zeroblob.test b/test/zeroblob.test index f4a1950836..e70fd0b748 100644 --- a/test/zeroblob.test +++ b/test/zeroblob.test @@ -255,5 +255,14 @@ do_test zeroblob-9.8 { db eval {SELECT zeroblob(2) IN (zeroblob(2))} } {1} +# Oversized zeroblob records +# +do_test zeroblob-10.1 { + db eval { + CREATE TABLE t10(a,b,c); + } + catchsql {INSERT INTO t10 VALUES(zeroblob(1e9),zeroblob(1e9),zeroblob(1e9))} +} {1 {string or blob too big}} + finish_test From 2813bde0280a022b7adb2f1d79033aa8de7358a5 Mon Sep 17 00:00:00 2001 From: dan Date: Sat, 11 Apr 2015 11:44:27 +0000 Subject: [PATCH 085/181] Do not assume an index contains unique entries unless it is declared UNIQUE and NOT NULL is specified for all columns. Fix for [7b4fee9f6c]. FossilOrigin-Name: e3b1f625518edc0e925116668dca5d25c3232b59 --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/where.c | 2 +- test/null.test | 17 +++++++++++++++++ 4 files changed, 27 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index 71aafa2cb1..55283a01c9 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Detect\sand\sreport\soversized\srecords\sconstructed\sfrom\smultiple\szeroblobs. -D 2015-04-11T02:08:48.265 +C Do\snot\sassume\san\sindex\scontains\sunique\sentries\sunless\sit\sis\sdeclared\sUNIQUE\sand\sNOT\sNULL\sis\sspecified\sfor\sall\scolumns.\sFix\sfor\s[7b4fee9f6c]. +D 2015-04-11T11:44:27.202 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5f78b1ab81b64e7c57a75d170832443e66c0880a F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -307,7 +307,7 @@ F src/vxworks.h c18586c8edc1bddbc15c004fa16aeb1e1342b4fb F src/wal.c 878c8e1a51cb2ec45c395d26b7d5cd9e1a098e4a F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4 F src/walker.c c253b95b4ee44b21c406e2a1052636c31ea27804 -F src/where.c 85d832efa5ef57de542db7f430b72fecd3af8b38 +F src/where.c bd435b75b9de53e11b5eb561540e395041ac0cba F src/whereInt.h cbe4aa57326998d89e7698ca65bb7c28541d483c F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2 @@ -768,7 +768,7 @@ F test/notify1.test 669b2b743618efdc18ca4b02f45423d5d2304abf F test/notify2.test 2ecabaa1305083856b7c39cf32816b612740c161 F test/notify3.test 10ff25cde502e72a92053a2f215d64bece4ef934 F test/notnull.test f8fcf58669ddba79274daa2770d61dfad8274f62 -F test/null.test a8b09b8ed87852742343b33441a9240022108993 +F test/null.test 0dcce4f04284ec66108c503327ad6d224c0752b3 F test/numcast.test 5d126f7f581432e86a90d1e35cac625164aec4a1 F test/openv2.test 0d3040974bf402e19b7df4b783e447289d7ab394 F test/orderby1.test eb246e377612b21a418fbea57047ba8ea88aaa6b @@ -1250,7 +1250,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 40c417a7efb17221cec4a0a703863854bcab8db2 -R fd7ff5723f566045f2ba0751ddce0467 -U drh -Z f6419661cff2a502b477cceb45bb8fdd +P 9e139afd92116ebc593114ed63b57c8f469653f6 +R cb22563425ec3fdd92f04af95791ab8d +U dan +Z a8ae95b3c171e79da5c1dd8c91dd053d diff --git a/manifest.uuid b/manifest.uuid index c8b77b78ce..1f18603ac6 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -9e139afd92116ebc593114ed63b57c8f469653f6 \ No newline at end of file +e3b1f625518edc0e925116668dca5d25c3232b59 \ No newline at end of file diff --git a/src/where.c b/src/where.c index 921e683d98..a96d9e5add 100644 --- a/src/where.c +++ b/src/where.c @@ -4781,7 +4781,7 @@ static int whereLoopAddBtreeIndex( }else if( eOp & (WO_EQ) ){ pNew->wsFlags |= WHERE_COLUMN_EQ; if( iCol<0 || (nInMul==0 && pNew->u.btree.nEq==pProbe->nKeyCol-1) ){ - if( iCol>=0 && !IsUniqueIndex(pProbe) ){ + if( iCol>=0 && pProbe->uniqNotNull==0 ){ pNew->wsFlags |= WHERE_UNQ_WANTED; }else{ pNew->wsFlags |= WHERE_ONEROW; diff --git a/test/null.test b/test/null.test index f3782a7531..e8eeb9740b 100644 --- a/test/null.test +++ b/test/null.test @@ -278,6 +278,23 @@ do_test null-8.15 { } } {1} +do_execsql_test null-9.1 { + CREATE TABLE t5(a, b, c); + CREATE UNIQUE INDEX t5ab ON t5(a, b); + + INSERT INTO t5 VALUES(1, NULL, 'one'); + INSERT INTO t5 VALUES(1, NULL, 'i'); + INSERT INTO t5 VALUES(NULL, 'x', 'two'); + INSERT INTO t5 VALUES(NULL, 'x', 'ii'); +} + +do_execsql_test null-9.2 { + SELECT * FROM t5 WHERE a = 1 AND b IS NULL; +} {1 {} one 1 {} i} + +do_execsql_test null-9.3 { + SELECT * FROM t5 WHERE a IS NULL AND b = 'x'; +} {{} x two {} x ii} finish_test From 8aad8c482ce0eac0fb9245722d2a63ea490d6818 Mon Sep 17 00:00:00 2001 From: dan Date: Sat, 11 Apr 2015 11:53:39 +0000 Subject: [PATCH 086/181] Update tests in whereD.test to account for the change in the previous commit. FossilOrigin-Name: da49700ca148d91e1b8863c2eb6ee79144e83ac9 --- manifest | 12 ++++++------ manifest.uuid | 2 +- test/whereD.test | 14 +++++++------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/manifest b/manifest index 55283a01c9..378036e42a 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Do\snot\sassume\san\sindex\scontains\sunique\sentries\sunless\sit\sis\sdeclared\sUNIQUE\sand\sNOT\sNULL\sis\sspecified\sfor\sall\scolumns.\sFix\sfor\s[7b4fee9f6c]. -D 2015-04-11T11:44:27.202 +C Update\stests\sin\swhereD.test\sto\saccount\sfor\sthe\schange\sin\sthe\sprevious\scommit. +D 2015-04-11T11:53:39.984 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5f78b1ab81b64e7c57a75d170832443e66c0880a F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -1171,7 +1171,7 @@ F test/where9.test 729c3ba9b47e8f9f1aab96bae7dad2a524f1d1a2 F test/whereA.test 4d253178d135ec46d1671e440cd8f2b916aa6e6b F test/whereB.test 0def95db3bdec220a731c7e4bec5930327c1d8c5 F test/whereC.test d6f4ecd4fa2d9429681a5b22a25d2bda8e86ab8a -F test/whereD.test fd9120e262f9da3c45940f52aefeef4d15b904e5 +F test/whereD.test 9eba1f9b18e5b19a0b0bcaae5e8c037260195f2b F test/whereE.test b3a055eef928c992b0a33198a7b8dc10eea5ad2f F test/whereF.test 5b2ba0dbe8074aa13e416b37c753991f0a2492d7 F test/whereG.test 69f5ec4b15760a8c860f80e2d55525669390aab3 @@ -1250,7 +1250,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 9e139afd92116ebc593114ed63b57c8f469653f6 -R cb22563425ec3fdd92f04af95791ab8d +P e3b1f625518edc0e925116668dca5d25c3232b59 +R 7890e1f1fdfc32123135ecc1b57978ea U dan -Z a8ae95b3c171e79da5c1dd8c91dd053d +Z 68688658f813a09121106ccdd49ce975 diff --git a/manifest.uuid b/manifest.uuid index 1f18603ac6..f330c7ddcf 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -e3b1f625518edc0e925116668dca5d25c3232b59 \ No newline at end of file +da49700ca148d91e1b8863c2eb6ee79144e83ac9 \ No newline at end of file diff --git a/test/whereD.test b/test/whereD.test index db993040b0..17fdac7017 100644 --- a/test/whereD.test +++ b/test/whereD.test @@ -129,11 +129,11 @@ do_execsql_test 3.0 { do_searchcount_test 3.1 { SELECT a, b FROM t3 WHERE (a=1 AND b='one') OR (a=2 AND b='two') -} {1 one 2 two search 2} +} {1 one 2 two search 4} do_searchcount_test 3.2 { SELECT a, c FROM t3 WHERE (a=1 AND b='one') OR (a=2 AND b='two') -} {1 i 2 ii search 4} +} {1 i 2 ii search 6} do_searchcount_test 3.4.1 { SELECT y FROM t4 WHERE x='a' @@ -142,24 +142,24 @@ do_searchcount_test 3.4.2 { SELECT a, b FROM t3 WHERE (a=1 AND b=(SELECT y FROM t4 WHERE x='a')) OR (a=2 AND b='two') -} {1 one 2 two search 4} +} {1 one 2 two search 6} do_searchcount_test 3.4.3 { SELECT a, b FROM t3 WHERE (a=2 AND b='two') OR (a=1 AND b=(SELECT y FROM t4 WHERE x='a')) -} {2 two 1 one search 4} +} {2 two 1 one search 6} do_searchcount_test 3.4.4 { SELECT a, b FROM t3 WHERE (a=2 AND b=(SELECT y FROM t4 WHERE x='b')) OR (a=1 AND b=(SELECT y FROM t4 WHERE x='a')) -} {2 two 1 one search 6} +} {2 two 1 one search 8} do_searchcount_test 3.5.1 { SELECT a, b FROM t3 WHERE (a=1 AND b='one') OR rowid=4 -} {1 one 2 two search 2} +} {1 one 2 two search 3} do_searchcount_test 3.5.2 { SELECT a, c FROM t3 WHERE (a=1 AND b='one') OR rowid=4 -} {1 i 2 ii search 2} +} {1 i 2 ii search 3} # Ticket [d02e1406a58ea02d] (2012-10-04) # LEFT JOIN with an OR in the ON clause causes segfault From 697e5dba801332f9e412868c593b8f58fc713844 Mon Sep 17 00:00:00 2001 From: drh Date: Sat, 11 Apr 2015 12:07:40 +0000 Subject: [PATCH 087/181] First complete attempt to generate a working changeset. Still contains bugs. FossilOrigin-Name: 5611fa9bd5b8fd762d16ce9b0853c2e779a1a1b7 --- manifest | 15 ++++----- manifest.uuid | 2 +- tool/sqldiff.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 87 insertions(+), 17 deletions(-) diff --git a/manifest b/manifest index c7c3d03725..f2c0b806d6 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Work\stoward\sadding\sthe\s--changeset\soption\sto\sthe\ssqldiff\sutility\sprogram.\nChanges\sare\sincomplete.\s\sThis\sis\san\sincremental\scheck-in. -D 2015-04-10T19:41:18.818 +C First\scomplete\sattempt\sto\sgenerate\sa\sworking\schangeset.\s\sStill\scontains\sbugs. +D 2015-04-11T12:07:40.414 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5f78b1ab81b64e7c57a75d170832443e66c0880a F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -1239,7 +1239,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/split-sqlite3c.tcl d9be87f1c340285a3e081eb19b4a247981ed290c -F tool/sqldiff.c 3e6f54359a070089ed0d11456e8868dcd3f20e94 +F tool/sqldiff.c ed945df30d962d15d26188e33f7c5431cf197487 F tool/stack_usage.tcl f8e71b92cdb099a147dad572375595eae55eca43 F tool/symbols-mingw.sh 4dbcea7e74768305384c9fd2ed2b41bbf9f0414d F tool/symbols.sh fec58532668296d7c7dc48be9c87f75ccdb5814f @@ -1250,10 +1250,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 860e4f8a94901d451fac3954960c1d2f589e8882 -R 6c8da3b8e133d42c3c0048f2d2a47a98 -T *branch * sqldiff-changeset -T *sym-sqldiff-changeset * -T -sym-trunk * +P 463e38d765f9d055b63792a8ea15c3782657b07f +R c7ffcaee222b675f0ec3e43f31931e14 U drh -Z b58ac33ed90e0dd7edcdd56b18b68a1d +Z c4472641aefb50d8b597b0b444fecd27 diff --git a/manifest.uuid b/manifest.uuid index 324240a04b..4657a0c7e9 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -463e38d765f9d055b63792a8ea15c3782657b07f \ No newline at end of file +5611fa9bd5b8fd762d16ce9b0853c2e779a1a1b7 \ No newline at end of file diff --git a/tool/sqldiff.c b/tool/sqldiff.c index 2b46353535..d166174440 100644 --- a/tool/sqldiff.c +++ b/tool/sqldiff.c @@ -714,6 +714,31 @@ end_diff_one_table: return; } +/* +** Write a 64-bit signed integer as a varint onto out +*/ +static void putsVarint(FILE *out, sqlite3_uint64 v){ + int i, n; + unsigned char buf[12], p[12]; + if( v & (((sqlite3_uint64)0xff000000)<<32) ){ + p[8] = (unsigned char)v; + v >>= 8; + for(i=7; i>=0; i--){ + p[i] = (unsigned char)((v & 0x7f) | 0x80); + v >>= 7; + } + fwrite(p, 8, 1, out); + }else{ + n = 9; + do{ + p[n--] = (unsigned char)((v & 0x7f) | 0x80); + v >>= 7; + }while( v!=0 ); + buf[9] &= 0x7f; + fwrite(buf+n+1, 9-n, 1, out); + } +} + /* ** Generate a CHANGESET for all differences from main.zTab to aux.zTab. */ @@ -726,7 +751,7 @@ static void changeset_one_table(const char *zTab, FILE *out){ int *aiPk = 0; /* Column numbers for each PK column */ int nPk = 0; /* Number of PRIMARY KEY columns */ Str sql; /* SQL for the diff query */ - int i; /* Loop counter */ + int i, j; /* Loop counters */ const char *zSep; /* List separator */ pStmt = db_prepare( @@ -763,7 +788,7 @@ static void changeset_one_table(const char *zTab, FILE *out){ if( nPk==0 ) goto end_changeset_one_table; strInit(&sql); if( nCol>nPk ){ - strPrintf(&sql, "SELECT 1"); /* Changes to non-PK columns */ + strPrintf(&sql, "SELECT %d", SQLITE_UPDATE); for(i=0; i=0; j-=8) putc((uX>>j)&0xff, out); + break; + case SQLITE_FLOAT: + rX = sqlite3_column_int64(pStmt,i); + memcpy(&uX, &rX, 8); + for(j=56; j>=0; j-=8) putc((uX>>j)&0xff, out); + break; + case SQLITE_TEXT: + iX = sqlite3_column_bytes(pStmt,i); + putsVarint(out, (sqlite3_uint64)iX); + fwrite(sqlite3_column_text(pStmt,i),1,iX,out); + break; + case SQLITE_BLOB: + iX = sqlite3_column_bytes(pStmt,i); + putsVarint(out, (sqlite3_uint64)iX); + fwrite(sqlite3_column_blob(pStmt,i),1,iX,out); + break; + case SQLITE_NULL: + break; + } + } + } + sqlite3_finalize(pStmt); end_changeset_one_table: while( nCol>0 ) sqlite3_free(azCol[--nCol]); From 6e42ce44db4d367c64c704f953e575d0f42310e5 Mon Sep 17 00:00:00 2001 From: drh Date: Sat, 11 Apr 2015 13:48:01 +0000 Subject: [PATCH 088/181] The --changeset option now appears to be working. FossilOrigin-Name: 1a2e2803920dcf64190d81d8a487d6c3c9bb28ee --- manifest | 12 ++-- manifest.uuid | 2 +- tool/sqldiff.c | 161 +++++++++++++++++++++++++++++++++++-------------- 3 files changed, 124 insertions(+), 51 deletions(-) diff --git a/manifest b/manifest index f2c0b806d6..336a1877e9 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C First\scomplete\sattempt\sto\sgenerate\sa\sworking\schangeset.\s\sStill\scontains\sbugs. -D 2015-04-11T12:07:40.414 +C The\s--changeset\soption\snow\sappears\sto\sbe\sworking. +D 2015-04-11T13:48:01.693 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5f78b1ab81b64e7c57a75d170832443e66c0880a F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -1239,7 +1239,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/split-sqlite3c.tcl d9be87f1c340285a3e081eb19b4a247981ed290c -F tool/sqldiff.c ed945df30d962d15d26188e33f7c5431cf197487 +F tool/sqldiff.c 51c05cc1435507736b8b5a41a0498016041b3e48 F tool/stack_usage.tcl f8e71b92cdb099a147dad572375595eae55eca43 F tool/symbols-mingw.sh 4dbcea7e74768305384c9fd2ed2b41bbf9f0414d F tool/symbols.sh fec58532668296d7c7dc48be9c87f75ccdb5814f @@ -1250,7 +1250,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 463e38d765f9d055b63792a8ea15c3782657b07f -R c7ffcaee222b675f0ec3e43f31931e14 +P 5611fa9bd5b8fd762d16ce9b0853c2e779a1a1b7 +R 907cf695d8fcffe3003a321f9aace7fc U drh -Z c4472641aefb50d8b597b0b444fecd27 +Z 3b5f839006775d8054dcfb8aab08f0fa diff --git a/manifest.uuid b/manifest.uuid index 4657a0c7e9..a5255d3652 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -5611fa9bd5b8fd762d16ce9b0853c2e779a1a1b7 \ No newline at end of file +1a2e2803920dcf64190d81d8a487d6c3c9bb28ee \ No newline at end of file diff --git a/tool/sqldiff.c b/tool/sqldiff.c index d166174440..4455c582ef 100644 --- a/tool/sqldiff.c +++ b/tool/sqldiff.c @@ -719,7 +719,7 @@ end_diff_one_table: */ static void putsVarint(FILE *out, sqlite3_uint64 v){ int i, n; - unsigned char buf[12], p[12]; + unsigned char p[12]; if( v & (((sqlite3_uint64)0xff000000)<<32) ){ p[8] = (unsigned char)v; v >>= 8; @@ -734,8 +734,45 @@ static void putsVarint(FILE *out, sqlite3_uint64 v){ p[n--] = (unsigned char)((v & 0x7f) | 0x80); v >>= 7; }while( v!=0 ); - buf[9] &= 0x7f; - fwrite(buf+n+1, 9-n, 1, out); + p[9] &= 0x7f; + fwrite(p+n+1, 9-n, 1, out); + } +} + +/* +** Write an SQLite value onto out. +*/ +static void putValue(FILE *out, sqlite3_value *pVal){ + int iDType = sqlite3_value_type(pVal); + sqlite3_int64 iX; + double rX; + sqlite3_uint64 uX; + int j; + + putc(iDType, out); + switch( iDType ){ + case SQLITE_INTEGER: + iX = sqlite3_value_int64(pVal); + memcpy(&uX, &iX, 8); + for(j=56; j>=0; j-=8) putc((uX>>j)&0xff, out); + break; + case SQLITE_FLOAT: + rX = sqlite3_value_int64(pVal); + memcpy(&uX, &rX, 8); + for(j=56; j>=0; j-=8) putc((uX>>j)&0xff, out); + break; + case SQLITE_TEXT: + iX = sqlite3_value_bytes(pVal); + putsVarint(out, (sqlite3_uint64)iX); + fwrite(sqlite3_value_text(pVal),1,iX,out); + break; + case SQLITE_BLOB: + iX = sqlite3_value_bytes(pVal); + putsVarint(out, (sqlite3_uint64)iX); + fwrite(sqlite3_value_blob(pVal),1,iX,out); + break; + case SQLITE_NULL: + break; } } @@ -751,7 +788,7 @@ static void changeset_one_table(const char *zTab, FILE *out){ int *aiPk = 0; /* Column numbers for each PK column */ int nPk = 0; /* Number of PRIMARY KEY columns */ Str sql; /* SQL for the diff query */ - int i, j; /* Loop counters */ + int i, k; /* Loop counters */ const char *zSep; /* List separator */ pStmt = db_prepare( @@ -789,8 +826,14 @@ static void changeset_one_table(const char *zTab, FILE *out){ strInit(&sql); if( nCol>nPk ){ strPrintf(&sql, "SELECT %d", SQLITE_UPDATE); - for(i=0; i=0; j-=8) putc((uX>>j)&0xff, out); - break; - case SQLITE_FLOAT: - rX = sqlite3_column_int64(pStmt,i); - memcpy(&uX, &rX, 8); - for(j=56; j>=0; j-=8) putc((uX>>j)&0xff, out); - break; - case SQLITE_TEXT: - iX = sqlite3_column_bytes(pStmt,i); - putsVarint(out, (sqlite3_uint64)iX); - fwrite(sqlite3_column_text(pStmt,i),1,iX,out); - break; - case SQLITE_BLOB: - iX = sqlite3_column_bytes(pStmt,i); - putsVarint(out, (sqlite3_uint64)iX); - fwrite(sqlite3_column_blob(pStmt,i),1,iX,out); - break; - case SQLITE_NULL: - break; + switch( sqlite3_column_int(pStmt,0) ){ + case SQLITE_UPDATE: { + for(k=1, i=0; i Date: Sat, 11 Apr 2015 20:20:29 +0000 Subject: [PATCH 089/181] Fix a problem with sorting large amounts of partially ordered data. FossilOrigin-Name: acca97efda86a0c020854d2dd9da16f5879986b1 --- manifest | 17 ++++++++--------- manifest.uuid | 2 +- src/vdbesort.c | 9 ++------- test/orderby1.test | 29 +++++++++++++++++++++++++++++ 4 files changed, 40 insertions(+), 17 deletions(-) diff --git a/manifest b/manifest index 871fd87da4..e73c590925 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sthe\s--changeset\soption\sto\sthe\ssqldiff\sutility\sprogram,\sfor\sgenerating\na\ssessions\schangeset\sfile\sinstead\sof\san\sSQL\sdiff. -D 2015-04-11T13:49:16.216 +C Fix\sa\sproblem\swith\ssorting\slarge\samounts\sof\spartially\sordered\sdata. +D 2015-04-11T20:20:29.810 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5f78b1ab81b64e7c57a75d170832443e66c0880a F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -300,7 +300,7 @@ F src/vdbeapi.c 583d56b129dd27f12bed518270de9ebe521e6a75 F src/vdbeaux.c 413dc496248ac18eb0c19e35e86bb1ffd47b8907 F src/vdbeblob.c 4f2e8e075d238392df98c5e03a64342465b03f90 F src/vdbemem.c c0dc81285b7571b0a31c40f17846fe2397ec1cd9 -F src/vdbesort.c 919717d7599fa31d343ec28bffd0f9e91a4ff5f6 +F src/vdbesort.c a9d39d99969462908f50d09918791883c5b067ab F src/vdbetrace.c 7e4222955e07dd707a2f360c0eb73452be1cb010 F src/vtab.c 9ca557215e8591ceb66e0b7c0a579c6df1e54b2d F src/vxworks.h c18586c8edc1bddbc15c004fa16aeb1e1342b4fb @@ -771,7 +771,7 @@ F test/notnull.test f8fcf58669ddba79274daa2770d61dfad8274f62 F test/null.test 0dcce4f04284ec66108c503327ad6d224c0752b3 F test/numcast.test 5d126f7f581432e86a90d1e35cac625164aec4a1 F test/openv2.test 0d3040974bf402e19b7df4b783e447289d7ab394 -F test/orderby1.test eb246e377612b21a418fbea57047ba8ea88aaa6b +F test/orderby1.test d69a2c99c023c85b014ece2cf691caec16a40d6d F test/orderby2.test bc11009f7cd99d96b1b11e57b199b00633eb5b04 F test/orderby3.test 8619d06a3debdcd80a27c0fdea5c40b468854b99 F test/orderby4.test 4d39bfbaaa3ae64d026ca2ff166353d2edca4ba4 @@ -1250,8 +1250,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 da49700ca148d91e1b8863c2eb6ee79144e83ac9 1a2e2803920dcf64190d81d8a487d6c3c9bb28ee -R c078ada2bdea31973177a0bd82842009 -T +closed 1a2e2803920dcf64190d81d8a487d6c3c9bb28ee -U drh -Z 157b78d075c326a9e01bf8b58e910074 +P f9a3a8391c28cf13d76ec54f471735d35059acea +R 20d1ab6a886883435eefbe113ce65f82 +U dan +Z 26f0ad0889bc54d15cfec6237366d6c5 diff --git a/manifest.uuid b/manifest.uuid index 76f7b8530a..89b4e6fdf1 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -f9a3a8391c28cf13d76ec54f471735d35059acea \ No newline at end of file +acca97efda86a0c020854d2dd9da16f5879986b1 \ No newline at end of file diff --git a/src/vdbesort.c b/src/vdbesort.c index bbdafa8230..869ff4f2a3 100644 --- a/src/vdbesort.c +++ b/src/vdbesort.c @@ -887,30 +887,24 @@ static void vdbeSorterRecordFree(sqlite3 *db, SorterRecord *pRecord){ */ static void vdbeSortSubtaskCleanup(sqlite3 *db, SortSubtask *pTask){ sqlite3DbFree(db, pTask->pUnpacked); - pTask->pUnpacked = 0; #if SQLITE_MAX_WORKER_THREADS>0 /* pTask->list.aMemory can only be non-zero if it was handed memory ** from the main thread. That only occurs SQLITE_MAX_WORKER_THREADS>0 */ if( pTask->list.aMemory ){ sqlite3_free(pTask->list.aMemory); - pTask->list.aMemory = 0; }else #endif { assert( pTask->list.aMemory==0 ); vdbeSorterRecordFree(0, pTask->list.pList); } - pTask->list.pList = 0; if( pTask->file.pFd ){ sqlite3OsCloseFree(pTask->file.pFd); - pTask->file.pFd = 0; - pTask->file.iEof = 0; } if( pTask->file2.pFd ){ sqlite3OsCloseFree(pTask->file2.pFd); - pTask->file2.pFd = 0; - pTask->file2.iEof = 0; } + memset(pTask, 0, sizeof(SortSubtask)); } #ifdef SQLITE_DEBUG_SORTER_THREADS @@ -1090,6 +1084,7 @@ void sqlite3VdbeSorterReset(sqlite3 *db, VdbeSorter *pSorter){ for(i=0; inTask; i++){ SortSubtask *pTask = &pSorter->aTask[i]; vdbeSortSubtaskCleanup(db, pTask); + pTask->pSorter = pSorter; } if( pSorter->list.aMemory==0 ){ vdbeSorterRecordFree(0, pSorter->list.pList); diff --git a/test/orderby1.test b/test/orderby1.test index 6674e32220..164c3f25db 100644 --- a/test/orderby1.test +++ b/test/orderby1.test @@ -495,5 +495,34 @@ do_execsql_test 7.0 { SELECT * FROM t7 WHERE a=?1 ORDER BY rowid; } {~/ORDER BY/} +#------------------------------------------------------------------------- +# Test a partial sort large enough to cause the sorter to spill data +# to disk. +# +reset_db +do_execsql_test 8.0 { + PRAGMA cache_size = 5; + CREATE TABLE t1(a, b); + CREATE INDEX i1 ON t1(a); +} + +do_eqp_test 8.1 { + SELECT * FROM t1 ORDER BY a, b; +} { + 0 0 0 {SCAN TABLE t1 USING INDEX i1} + 0 0 0 {USE TEMP B-TREE FOR RIGHT PART OF ORDER BY} +} + +do_execsql_test 8.2 { + WITH cnt(i) AS ( + SELECT 1 UNION ALL SELECT i+1 FROM cnt WHERE i<10000 + ) + INSERT INTO t1 SELECT i%2, randomblob(500) FROM cnt; +} + +do_test 8.3 { + db eval { SELECT * FROM t1 ORDER BY a, b } { incr res $a } + set res +} 5000 finish_test From 11b04817785a3d23789ca80829cc598840878946 Mon Sep 17 00:00:00 2001 From: drh Date: Sun, 12 Apr 2015 01:22:04 +0000 Subject: [PATCH 090/181] Avoid problems when a query has a GROUP BY and an ORDER BY but no FROM clause. FossilOrigin-Name: e527d96a1e098ade4e9d124b630a8c2ea2ac9b36 --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/where.c | 2 +- test/orderby1.test | 3 +++ 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index 17f4391705..7967b35884 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Optimizations\sfor\sVACUUM,\sCREATE\sINDEX\sand\ssome\scases\sof\sORDER\sBY. -D 2015-04-11T20:44:28.726 +C Avoid\sproblems\swhen\sa\squery\shas\sa\sGROUP\sBY\sand\san\sORDER\sBY\sbut\sno\sFROM\sclause. +D 2015-04-12T01:22:04.580 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5f78b1ab81b64e7c57a75d170832443e66c0880a F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -307,7 +307,7 @@ F src/vxworks.h c18586c8edc1bddbc15c004fa16aeb1e1342b4fb F src/wal.c 878c8e1a51cb2ec45c395d26b7d5cd9e1a098e4a F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4 F src/walker.c c253b95b4ee44b21c406e2a1052636c31ea27804 -F src/where.c bd435b75b9de53e11b5eb561540e395041ac0cba +F src/where.c 9952e4749f481707595692f2f13d3ce3b64ffdc8 F src/whereInt.h cbe4aa57326998d89e7698ca65bb7c28541d483c F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2 @@ -771,7 +771,7 @@ F test/notnull.test f8fcf58669ddba79274daa2770d61dfad8274f62 F test/null.test 0dcce4f04284ec66108c503327ad6d224c0752b3 F test/numcast.test 5d126f7f581432e86a90d1e35cac625164aec4a1 F test/openv2.test 0d3040974bf402e19b7df4b783e447289d7ab394 -F test/orderby1.test d69a2c99c023c85b014ece2cf691caec16a40d6d +F test/orderby1.test 870e150450437d3980badbde3d0166b81d9e33f6 F test/orderby2.test bc11009f7cd99d96b1b11e57b199b00633eb5b04 F test/orderby3.test 8619d06a3debdcd80a27c0fdea5c40b468854b99 F test/orderby4.test 4d39bfbaaa3ae64d026ca2ff166353d2edca4ba4 @@ -1250,7 +1250,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 acca97efda86a0c020854d2dd9da16f5879986b1 cf7590f607d94a120385576b538484ca738349e2 -R 4a3267783e1ce12038a61c7c4ca15ba8 -U dan -Z 05508ac040af16f75cf3f23dcdb1072a +P 79326d6eece926fd1c148b29f0b726208d8b44c0 +R b8a99417c5276ad65ad7b525e5ae16a3 +U drh +Z ba0a0070ee213de4cf49a8279f3da0ad diff --git a/manifest.uuid b/manifest.uuid index 695e755462..df7dea6773 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -79326d6eece926fd1c148b29f0b726208d8b44c0 \ No newline at end of file +e527d96a1e098ade4e9d124b630a8c2ea2ac9b36 \ No newline at end of file diff --git a/src/where.c b/src/where.c index a96d9e5add..42e950e41e 100644 --- a/src/where.c +++ b/src/where.c @@ -6241,7 +6241,7 @@ static int wherePathSolver(WhereInfo *pWInfo, LogEst nRowEst){ pWInfo->revMask = pFrom->revLoop; } if( (pWInfo->wctrlFlags & WHERE_SORTBYGROUP) - && pWInfo->nOBSat==pWInfo->pOrderBy->nExpr + && pWInfo->nOBSat==pWInfo->pOrderBy->nExpr && nLoop>0 ){ Bitmask revMask = 0; int nOrder = wherePathSatisfiesOrderBy(pWInfo, pWInfo->pOrderBy, diff --git a/test/orderby1.test b/test/orderby1.test index 164c3f25db..3e785c54e4 100644 --- a/test/orderby1.test +++ b/test/orderby1.test @@ -463,6 +463,9 @@ do_execsql_test 5.1 { do_execsql_test 5.2 { SELECT 5 UNION ALL SELECT 3 ORDER BY 1 } {3 5} +do_execsql_test 5.3 { + SELECT 986 AS x GROUP BY X ORDER BY X +} {986} # The following test (originally derived from a single test within fuzz.test) # verifies that a PseudoTable cursor is not closed prematurely in a deeply From f932f7145ede311a79a15197841c2706af5bc71c Mon Sep 17 00:00:00 2001 From: drh Date: Sun, 12 Apr 2015 17:35:27 +0000 Subject: [PATCH 091/181] Fix a problem with a stale Select.pWith pointer when a CTE is used together with a compound query and an ORDER BY clause. FossilOrigin-Name: 9a453f52a2b30595891604ede7d4acf61c2736a1 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/select.c | 1 + test/with1.test | 6 ++++++ 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 7967b35884..5478452884 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Avoid\sproblems\swhen\sa\squery\shas\sa\sGROUP\sBY\sand\san\sORDER\sBY\sbut\sno\sFROM\sclause. -D 2015-04-12T01:22:04.580 +C Fix\sa\sproblem\swith\sa\sstale\sSelect.pWith\spointer\swhen\sa\sCTE\sis\sused\stogether\nwith\sa\scompound\squery\sand\san\sORDER\sBY\sclause. +D 2015-04-12T17:35:27.113 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5f78b1ab81b64e7c57a75d170832443e66c0880a F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -230,7 +230,7 @@ F src/printf.c 8ae1fa9d30c1200a9268a390ba9e9cea9197b27a F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c 41aa91af56d960e9414ce1d7c17cfb68e0d1c6cb F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e -F src/select.c c28c52e353287434fac8473e56ee4be848d12c9d +F src/select.c 117e0f9ac9254a6f7472fac5144eba21ba0b2ec1 F src/shell.c 84a1593bd86aaa14f4da8a8f9b16fbc239d262aa F src/sqlite.h.in 278602140d49575e8708e643161f4263e428a02a F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad @@ -1184,7 +1184,7 @@ F test/wild001.test bca33f499866f04c24510d74baf1e578d4e44b1c F test/win32heap.test ea19770974795cff26e11575e12d422dbd16893c F test/win32lock.test fbf107c91d8f5512be5a5b87c4c42ab9fdd54972 F test/win32longpath.test 169c75a3b2e43481f4a62122510210c67b08f26d -F test/with1.test 9df5cd8a62148b3d9ef8597aea563e3863018bcd +F test/with1.test a86bf7f9288ba759a25ee57221d3bffaca36032a F test/with2.test ee227a663586aa09771cafd4fa269c5217eaf775 F test/withM.test e97f2a8c506ab3ea9eab94e6f6072f6cc924c991 F test/without_rowid1.test 7862e605753c8d25329f665fa09072e842183151 @@ -1250,7 +1250,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 79326d6eece926fd1c148b29f0b726208d8b44c0 -R b8a99417c5276ad65ad7b525e5ae16a3 +P e527d96a1e098ade4e9d124b630a8c2ea2ac9b36 +R f469da7981f7e5a80ef00c68d565b4fb U drh -Z ba0a0070ee213de4cf49a8279f3da0ad +Z 637f476e29fbab1d809f7d30402eeba5 diff --git a/manifest.uuid b/manifest.uuid index df7dea6773..cdf3e1131c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -e527d96a1e098ade4e9d124b630a8c2ea2ac9b36 \ No newline at end of file +9a453f52a2b30595891604ede7d4acf61c2736a1 \ No newline at end of file diff --git a/src/select.c b/src/select.c index 90aaa842a6..930a099e80 100644 --- a/src/select.c +++ b/src/select.c @@ -3883,6 +3883,7 @@ static int convertCompoundSelectToSubquery(Walker *pWalker, Select *p){ pNew->pOrderBy = 0; p->pPrior = 0; p->pNext = 0; + p->pWith = 0; p->selFlags &= ~SF_Compound; assert( (p->selFlags & SF_Converted)==0 ); p->selFlags |= SF_Converted; diff --git a/test/with1.test b/test/with1.test index ad88a67c22..80892d2642 100644 --- a/test/with1.test +++ b/test/with1.test @@ -843,4 +843,10 @@ do_catchsql_test 13.3 { SELECT i FROM c; } {1 {table c has 1 values for 2 columns}} +# 2015-04-12 +# +do_execsql_test 14.1 { + WITH x AS (SELECT * FROM t) SELECT 0 EXCEPT SELECT 0 ORDER BY 1 COLLATE binary; +} {} + finish_test From 9dc225ef1c4ad4db3e518b1ba6a2ce4480865f98 Mon Sep 17 00:00:00 2001 From: drh Date: Sun, 12 Apr 2015 21:28:50 +0000 Subject: [PATCH 092/181] Update the version number to 3.8.10 because of the new sort optimizations from check-in [79326d6eec]. FossilOrigin-Name: bd2cfa1d72368db91064bace298df3d77d9963e6 --- VERSION | 2 +- configure | 18 +++++++++--------- manifest | 14 +++++++------- manifest.uuid | 2 +- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/VERSION b/VERSION index 203e6d5c9a..d20cc2bf02 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.8.9 +3.8.10 diff --git a/configure b/configure index d259324bdd..9a3d102a8a 100755 --- a/configure +++ b/configure @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.62 for sqlite 3.8.9. +# Generated by GNU Autoconf 2.62 for sqlite 3.8.10. # # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, # 2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. @@ -743,8 +743,8 @@ SHELL=${CONFIG_SHELL-/bin/sh} # Identity of this package. PACKAGE_NAME='sqlite' PACKAGE_TARNAME='sqlite' -PACKAGE_VERSION='3.8.9' -PACKAGE_STRING='sqlite 3.8.9' +PACKAGE_VERSION='3.8.10' +PACKAGE_STRING='sqlite 3.8.10' PACKAGE_BUGREPORT='' # Factoring default headers for most tests. @@ -1481,7 +1481,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures sqlite 3.8.9 to adapt to many kinds of systems. +\`configure' configures sqlite 3.8.10 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1546,7 +1546,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of sqlite 3.8.9:";; + short | recursive ) echo "Configuration of sqlite 3.8.10:";; esac cat <<\_ACEOF @@ -1660,7 +1660,7 @@ fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -sqlite configure 3.8.9 +sqlite configure 3.8.10 generated by GNU Autoconf 2.62 Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, @@ -1674,7 +1674,7 @@ cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by sqlite $as_me 3.8.9, which was +It was created by sqlite $as_me 3.8.10, which was generated by GNU Autoconf 2.62. Invocation command line was $ $0 $@ @@ -13953,7 +13953,7 @@ exec 6>&1 # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by sqlite $as_me 3.8.9, which was +This file was extended by sqlite $as_me 3.8.10, which was generated by GNU Autoconf 2.62. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -14006,7 +14006,7 @@ Report bugs to ." _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_version="\\ -sqlite config.status 3.8.9 +sqlite config.status 3.8.10 configured by $0, generated by GNU Autoconf 2.62, with options \\"`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`\\" diff --git a/manifest b/manifest index 5478452884..4a1c19474e 100644 --- a/manifest +++ b/manifest @@ -1,12 +1,12 @@ -C Fix\sa\sproblem\swith\sa\sstale\sSelect.pWith\spointer\swhen\sa\sCTE\sis\sused\stogether\nwith\sa\scompound\squery\sand\san\sORDER\sBY\sclause. -D 2015-04-12T17:35:27.113 +C Update\sthe\sversion\snumber\sto\s3.8.10\sbecause\sof\sthe\snew\ssort\soptimizations\sfrom\scheck-in\s[79326d6eec]. +D 2015-04-12T21:28:50.540 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5f78b1ab81b64e7c57a75d170832443e66c0880a F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 F Makefile.msc 0078f5781538e07ea38683439f38d5f5ab79ab6e F Makefile.vxworks e1b65dea203f054e71653415bd8f96dcaed47858 F README.md d58e3bebc0a4145e0f2a87994015fdb575a8e866 -F VERSION 319eb1ced4b4d17a67730f2b7b85f15c1346cb60 +F VERSION 2e244662b71e6e68a5c29b014ebc5b7564f4cc5a F aclocal.m4 a5c22d164aff7ed549d53a90fa56d56955281f50 F addopcodes.awk 9eb448a552d5c0185cf62c463f9c173cedae3811 F art/sqlite370.eps aa97a671332b432a54e1d74ff5e8775be34200c2 @@ -38,7 +38,7 @@ F autoconf/tea/win/rules.vc c511f222b80064096b705dbeb97060ee1d6b6d63 F config.guess 226d9a188c6196f3033ffc651cbc9dcee1a42977 F config.h.in 42b71ad3fe21c9e88fa59e8458ca1a6bc72eb0c0 F config.sub 9ebe4c3b3dab6431ece34f16828b594fb420da55 -F configure 8b18c2378805a1d8aaca85d293671f450dd3c723 x +F configure 2ea5f5b58dd106da449ab598ab6e515339d7fa2a x F configure.ac 0b775d383c536bbaafc1e46dd3cbb81a7ea11aeb F contrib/sqlitecon.tcl 210a913ad63f9f991070821e599d600bd913e0ad F doc/lemon.html 334dbf6621b8fb8790297ec1abf3cfa4621709d1 @@ -1250,7 +1250,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 e527d96a1e098ade4e9d124b630a8c2ea2ac9b36 -R f469da7981f7e5a80ef00c68d565b4fb +P 9a453f52a2b30595891604ede7d4acf61c2736a1 +R 4a2a023e9382e5658a5d290bebd20330 U drh -Z 637f476e29fbab1d809f7d30402eeba5 +Z 3fe3cb8d2199de920836663cd4df5373 diff --git a/manifest.uuid b/manifest.uuid index cdf3e1131c..d0ccf9d2b0 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -9a453f52a2b30595891604ede7d4acf61c2736a1 \ No newline at end of file +bd2cfa1d72368db91064bace298df3d77d9963e6 \ No newline at end of file From 4a614e9013478d98c1bfe1014f8d7a978c3c378d Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 13 Apr 2015 12:45:58 +0000 Subject: [PATCH 093/181] Remove an unreachable branch from the vdbeSorterCompareInt() routine. FossilOrigin-Name: f666ef06869f4fb655c43daacf5034c17575d951 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/vdbesort.c | 3 ++- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 4a1c19474e..40ccc22361 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Update\sthe\sversion\snumber\sto\s3.8.10\sbecause\sof\sthe\snew\ssort\soptimizations\sfrom\scheck-in\s[79326d6eec]. -D 2015-04-12T21:28:50.540 +C Remove\san\sunreachable\sbranch\sfrom\sthe\svdbeSorterCompareInt()\sroutine. +D 2015-04-13T12:45:58.929 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5f78b1ab81b64e7c57a75d170832443e66c0880a F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -300,7 +300,7 @@ F src/vdbeapi.c 583d56b129dd27f12bed518270de9ebe521e6a75 F src/vdbeaux.c a20504ae52392459fa08402fda3f195f19d7c79d F src/vdbeblob.c 4f2e8e075d238392df98c5e03a64342465b03f90 F src/vdbemem.c c0dc81285b7571b0a31c40f17846fe2397ec1cd9 -F src/vdbesort.c 5a729a15fb46b1759e13be49a10441172628e593 +F src/vdbesort.c 2e7f683464fd5db3be4beaa1ff2d39e24fcb64b8 F src/vdbetrace.c 7e4222955e07dd707a2f360c0eb73452be1cb010 F src/vtab.c 9ca557215e8591ceb66e0b7c0a579c6df1e54b2d F src/vxworks.h c18586c8edc1bddbc15c004fa16aeb1e1342b4fb @@ -1250,7 +1250,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 9a453f52a2b30595891604ede7d4acf61c2736a1 -R 4a2a023e9382e5658a5d290bebd20330 +P bd2cfa1d72368db91064bace298df3d77d9963e6 +R b8f08800d49097dd7ac4eb07d7ead02a U drh -Z 3fe3cb8d2199de920836663cd4df5373 +Z b7397c89c618aad1f80f88c7af5c800c diff --git a/manifest.uuid b/manifest.uuid index d0ccf9d2b0..660e0945e6 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -bd2cfa1d72368db91064bace298df3d77d9963e6 \ No newline at end of file +f666ef06869f4fb655c43daacf5034c17575d951 \ No newline at end of file diff --git a/src/vdbesort.c b/src/vdbesort.c index 14803c0b3e..4d9ef90cdc 100644 --- a/src/vdbesort.c +++ b/src/vdbesort.c @@ -882,10 +882,11 @@ static int vdbeSorterCompareInt( }else{ res = s1 - s2; } + assert( res!=0 ); if( res>0 ){ if( *v1 & 0x80 ) res = -1; - }else if( res<0 ){ + }else{ if( *v2 & 0x80 ) res = +1; } } From ab06b0e5be8377fc510fcde3c2d1de773a97942d Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 13 Apr 2015 14:03:54 +0000 Subject: [PATCH 094/181] Remove an unreachable branch from the VACUUM logic. FossilOrigin-Name: 65ace4b062d9454a296c5a1aa7ea7316b1507ad4 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/insert.c | 3 ++- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 40ccc22361..cf166dc945 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Remove\san\sunreachable\sbranch\sfrom\sthe\svdbeSorterCompareInt()\sroutine. -D 2015-04-13T12:45:58.929 +C Remove\san\sunreachable\sbranch\sfrom\sthe\sVACUUM\slogic. +D 2015-04-13T14:03:54.116 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5f78b1ab81b64e7c57a75d170832443e66c0880a F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -190,7 +190,7 @@ F src/global.c 4f77cadbc5427d00139ba43d0f3979804cbb700e F src/hash.c 4263fbc955f26c2e8cdc0cf214bc42435aa4e4f5 F src/hash.h c8f3c31722cf3277d03713909761e152a5b81094 F src/hwtime.h d32741c8f4df852c7d959236615444e2b1063b08 -F src/insert.c 1cc9dc4e939b5dd4a74ac4a3222b89e66b074210 +F src/insert.c 305dd3f9539d0affa4bf1c14cc7dffb34867e040 F src/journal.c b4124532212b6952f42eb2c12fa3c25701d8ba8d F src/legacy.c ba1863ea58c4c840335a84ec276fc2b25e22bc4e F src/lempar.c 7274c97d24bb46631e504332ccd3bd1b37841770 @@ -1250,7 +1250,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 bd2cfa1d72368db91064bace298df3d77d9963e6 -R b8f08800d49097dd7ac4eb07d7ead02a +P f666ef06869f4fb655c43daacf5034c17575d951 +R 13ae6f8a2a03926d32aaccc1e7fe4f0a U drh -Z b7397c89c618aad1f80f88c7af5c800c +Z 18a3bd532998a4429c86c5536067680b diff --git a/manifest.uuid b/manifest.uuid index 660e0945e6..c6033ca289 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -f666ef06869f4fb655c43daacf5034c17575d951 \ No newline at end of file +65ace4b062d9454a296c5a1aa7ea7316b1507ad4 \ No newline at end of file diff --git a/src/insert.c b/src/insert.c index f8ae4d7d3c..fc8895bbd6 100644 --- a/src/insert.c +++ b/src/insert.c @@ -2024,7 +2024,8 @@ static int xferOptimization( int i; for(i=0; inColumn; i++){ char *zColl = pSrcIdx->azColl[i]; - if( zColl && sqlite3_stricmp("BINARY", zColl) ) break; + assert( zColl!=0 ); + if( sqlite3_stricmp("BINARY", zColl) ) break; } if( i==pSrcIdx->nColumn ){ useSeekResult = OPFLAG_USESEEKRESULT; From 481ecd95d0e4386094e1eaa2d1512998d6d7fbdd Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 13 Apr 2015 14:08:27 +0000 Subject: [PATCH 095/181] Test that if the definition of a collation sequence is changed and VACUUM run, the new database contains records sorted in the (new) correct order. FossilOrigin-Name: ce6eaac10a190b26b87bfe75918e2ef58fd7a3f9 --- manifest | 14 +++++++------- manifest.uuid | 2 +- test/vacuum2.test | 20 ++++++++++++++++++++ 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index cf166dc945..1207568ae7 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Remove\san\sunreachable\sbranch\sfrom\sthe\sVACUUM\slogic. -D 2015-04-13T14:03:54.116 +C Test\sthat\sif\sthe\sdefinition\sof\sa\scollation\ssequence\sis\schanged\sand\sVACUUM\srun,\sthe\snew\sdatabase\scontains\srecords\ssorted\sin\sthe\s(new)\scorrect\sorder. +D 2015-04-13T14:08:27.490 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5f78b1ab81b64e7c57a75d170832443e66c0880a F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -1107,7 +1107,7 @@ F test/uri.test 23662b7b61958b0f0e47082de7d06341ccf85d5b F test/userauth01.test e740a2697a7b40d7c5003a7d7edaee16acd349a9 F test/utf16align.test 54cd35a27c005a9b6e7815d887718780b6a462ae F test/vacuum.test ce91c39f7f91a4273bf620efad21086b5aa6ef1d -F test/vacuum2.test af432e6e3bfc0ea20a80cb86a03c7d9876d38324 +F test/vacuum2.test aa048abee196c16c9ba308465494009057b79f9b F test/vacuum3.test 77ecdd54592b45a0bcb133339f99f1ae0ae94d0d F test/vacuum4.test d3f8ecff345f166911568f397d2432c16d2867d9 F test/varint.test ab7b110089a08b9926ed7390e7e97bdefeb74102 @@ -1250,7 +1250,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 f666ef06869f4fb655c43daacf5034c17575d951 -R 13ae6f8a2a03926d32aaccc1e7fe4f0a -U drh -Z 18a3bd532998a4429c86c5536067680b +P 65ace4b062d9454a296c5a1aa7ea7316b1507ad4 +R 10297fb20a52d4dc7c571adcebaddc36 +U dan +Z 0a6c3062817beaba9c93ab9bd5dcc5e3 diff --git a/manifest.uuid b/manifest.uuid index c6033ca289..fcea990f8f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -65ace4b062d9454a296c5a1aa7ea7316b1507ad4 \ No newline at end of file +ce6eaac10a190b26b87bfe75918e2ef58fd7a3f9 \ No newline at end of file diff --git a/test/vacuum2.test b/test/vacuum2.test index b3bfab3022..0350c8ec42 100644 --- a/test/vacuum2.test +++ b/test/vacuum2.test @@ -15,6 +15,7 @@ set testdir [file dirname $argv0] source $testdir/tester.tcl +set testprefix vacuum2 # Do not use a codec for tests in this file, as the database file is # manipulated directly using tcl scripts (using the [hexio_write] command). @@ -227,5 +228,24 @@ do_test vacuum2-5.4 { lappend res2 $res } {1 2 3 4 5 6 7 8 9 10 {1 {cannot VACUUM - SQL statements in progress}}} +#------------------------------------------------------------------------- +# Check that if the definition of a collation sequence is changed and +# VACUUM run, records are store in the (new) correct order following the +# VACUUM. Even if the modified collation is attached to a PK of a WITHOUT +# ROWID table. + +proc cmp {lhs rhs} { string compare $lhs $rhs } +db collate cmp cmp +do_execsql_test 6.0 { + CREATE TABLE t6(x PRIMARY KEY COLLATE cmp, y) WITHOUT ROWID; + CREATE INDEX t6y ON t6(y); + INSERT INTO t6 VALUES('i', 'one'); + INSERT INTO t6 VALUES('ii', 'one'); + INSERT INTO t6 VALUES('iii', 'one'); +} +integrity_check 6.1 +proc cmp {lhs rhs} { string compare $rhs $lhs } +do_execsql_test 6.2 VACUUM +integrity_check 6.3 finish_test From c01501a3861944d8027a5e620e420238db9bcc2c Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 13 Apr 2015 14:44:01 +0000 Subject: [PATCH 096/181] Remove a faulty assert() from the btree balancing logic. FossilOrigin-Name: d06669d968c8f6af8799fbfeabadaab68b9b8db8 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/btree.c | 1 - 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 1207568ae7..bddc4cadc4 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Test\sthat\sif\sthe\sdefinition\sof\sa\scollation\ssequence\sis\schanged\sand\sVACUUM\srun,\sthe\snew\sdatabase\scontains\srecords\ssorted\sin\sthe\s(new)\scorrect\sorder. -D 2015-04-13T14:08:27.490 +C Remove\sa\sfaulty\sassert()\sfrom\sthe\sbtree\sbalancing\slogic. +D 2015-04-13T14:44:01.870 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5f78b1ab81b64e7c57a75d170832443e66c0880a F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -173,7 +173,7 @@ F src/auth.c b56c78ebe40a2110fd361379f7e8162d23f92240 F src/backup.c ff743689c4d6c5cb55ad42ed9d174b2b3e71f1e3 F src/bitvec.c 19a4ba637bd85f8f63fc8c9bae5ade9fb05ec1cb F src/btmutex.c 45a968cc85afed9b5e6cf55bf1f42f8d18107f79 -F src/btree.c 2caf598165f3608fde8abac2b243826616ce54b7 +F src/btree.c 67648f6532c2da79d3b3fb6853aa1a0c3ba0e1ad F src/btree.h 969adc948e89e449220ff0ff724c94bb2a52e9f1 F src/btreeInt.h 973a22a6fd61350b454ad614832b1f0a5e25a1e4 F src/build.c fa4795bc795077388aa4e746e1b25ef97bc10489 @@ -1250,7 +1250,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 65ace4b062d9454a296c5a1aa7ea7316b1507ad4 -R 10297fb20a52d4dc7c571adcebaddc36 -U dan -Z 0a6c3062817beaba9c93ab9bd5dcc5e3 +P ce6eaac10a190b26b87bfe75918e2ef58fd7a3f9 +R bac46adba95b910001781f1715fe4531 +U drh +Z 344080508147bb8eb54111c6b1e074c7 diff --git a/manifest.uuid b/manifest.uuid index fcea990f8f..3daf8bbf88 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ce6eaac10a190b26b87bfe75918e2ef58fd7a3f9 \ No newline at end of file +d06669d968c8f6af8799fbfeabadaab68b9b8db8 \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index 789796d55a..9faf624235 100644 --- a/src/btree.c +++ b/src/btree.c @@ -6735,7 +6735,6 @@ static int balance_nonroot( }else if( iParentIdx==i ){ nxDiv = i-2+bBulk; }else{ - assert( bBulk==0 ); nxDiv = iParentIdx-1; } i = 2-bBulk; From 1fe0af200db60257a744104e7f264e8fd29729ac Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 13 Apr 2015 17:43:43 +0000 Subject: [PATCH 097/181] Add a comment to wal.c to explain why a race condition is safe. FossilOrigin-Name: bc33af866403c23d548dd4705675315810d52d7f --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/wal.c | 8 ++++++++ 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index bddc4cadc4..12b1e15e95 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Remove\sa\sfaulty\sassert()\sfrom\sthe\sbtree\sbalancing\slogic. -D 2015-04-13T14:44:01.870 +C Add\sa\scomment\sto\swal.c\sto\sexplain\swhy\sa\srace\scondition\sis\ssafe. +D 2015-04-13T17:43:43.335 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5f78b1ab81b64e7c57a75d170832443e66c0880a F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -304,7 +304,7 @@ F src/vdbesort.c 2e7f683464fd5db3be4beaa1ff2d39e24fcb64b8 F src/vdbetrace.c 7e4222955e07dd707a2f360c0eb73452be1cb010 F src/vtab.c 9ca557215e8591ceb66e0b7c0a579c6df1e54b2d F src/vxworks.h c18586c8edc1bddbc15c004fa16aeb1e1342b4fb -F src/wal.c 878c8e1a51cb2ec45c395d26b7d5cd9e1a098e4a +F src/wal.c 753995db83247f20361a8e8a874990b21a75abd9 F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4 F src/walker.c c253b95b4ee44b21c406e2a1052636c31ea27804 F src/where.c 9952e4749f481707595692f2f13d3ce3b64ffdc8 @@ -1250,7 +1250,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 ce6eaac10a190b26b87bfe75918e2ef58fd7a3f9 -R bac46adba95b910001781f1715fe4531 -U drh -Z 344080508147bb8eb54111c6b1e074c7 +P d06669d968c8f6af8799fbfeabadaab68b9b8db8 +R 90c9a3885d268edb8b0fe9dee7687f08 +U dan +Z a7fde54970dc241049366741c468ca23 diff --git a/manifest.uuid b/manifest.uuid index 3daf8bbf88..c0be3fa5e7 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -d06669d968c8f6af8799fbfeabadaab68b9b8db8 \ No newline at end of file +bc33af866403c23d548dd4705675315810d52d7f \ No newline at end of file diff --git a/src/wal.c b/src/wal.c index 558adbcad2..df3c8cb94e 100644 --- a/src/wal.c +++ b/src/wal.c @@ -1730,6 +1730,14 @@ static int walCheckpoint( mxSafeFrame = pWal->hdr.mxFrame; mxPage = pWal->hdr.nPage; for(i=1; iaReadMark[i]; if( mxSafeFrame>y ){ assert( y<=pWal->hdr.mxFrame ); From 27a348c7a0f26ea3037d0e8256f73a62dab84d31 Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 13 Apr 2015 19:14:06 +0000 Subject: [PATCH 098/181] Remove the out2-prerelease VDBE opcode property and its associated code, for a 0.5% performance improvement. FossilOrigin-Name: e29c7f2c910dac07f0f92dfef5e0e743141954eb --- manifest | 16 ++++----- manifest.uuid | 2 +- mkopcodeh.awk | 27 ++++++-------- src/vdbe.c | 97 +++++++++++++++++++++++++++++++-------------------- 4 files changed, 79 insertions(+), 63 deletions(-) diff --git a/manifest b/manifest index 12b1e15e95..acc5ea4f99 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sa\scomment\sto\swal.c\sto\sexplain\swhy\sa\srace\scondition\sis\ssafe. -D 2015-04-13T17:43:43.335 +C Remove\sthe\sout2-prerelease\sVDBE\sopcode\sproperty\sand\sits\sassociated\scode,\nfor\sa\s0.5%\sperformance\simprovement. +D 2015-04-13T19:14:06.003 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5f78b1ab81b64e7c57a75d170832443e66c0880a F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -154,7 +154,7 @@ F ltmain.sh 3ff0879076df340d2e23ae905484d8c15d5fdea8 F magic.txt 8273bf49ba3b0c8559cb2774495390c31fd61c60 F main.mk ddffac494a82d42772df9fe30d3a78acf4f7cb41 F mkopcodec.awk c2ff431854d702cdd2d779c9c0d1f58fa16fa4ea -F mkopcodeh.awk c6b3fa301db6ef7ac916b14c60868aeaec1337b5 +F mkopcodeh.awk d5e22023b5238985bb54a72d33e0ac71fe4f8a32 F mkso.sh fd21c06b063bb16a5d25deea1752c2da6ac3ed83 F mptest/config01.test 3c6adcbc50b991866855f1977ff172eb6d901271 F mptest/config02.test 4415dfe36c48785f751e16e32c20b077c28ae504 @@ -293,7 +293,7 @@ F src/update.c 3c4ecc282accf12d39edb8d524cf089645e55a13 F src/utf.c fc6b889ba0779b7722634cdeaa25f1930d93820c F src/util.c 98a7627ca48ad3265b6940915a1d08355eb3fc7e F src/vacuum.c 2ddd5cad2a7b9cef7f9e431b8c7771634c6b1701 -F src/vdbe.c c4bd96912f8837777bfe5762d310767ed628b442 +F src/vdbe.c 584abb81e4abf9dd51a9a2e71f680289bd0c019b F src/vdbe.h 7e538ecf47dccb307ea2d087c3ddc2dd8d70e79d F src/vdbeInt.h 9cbaa84f53ddd2d09a0cf61a94337a3a035d08a0 F src/vdbeapi.c 583d56b129dd27f12bed518270de9ebe521e6a75 @@ -1250,7 +1250,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 d06669d968c8f6af8799fbfeabadaab68b9b8db8 -R 90c9a3885d268edb8b0fe9dee7687f08 -U dan -Z a7fde54970dc241049366741c468ca23 +P bc33af866403c23d548dd4705675315810d52d7f +R 6ac0695a2f1b9d518c2805dcc9a01314 +U drh +Z 453362d5fdffab6ea02dce6dd25e18dd diff --git a/manifest.uuid b/manifest.uuid index c0be3fa5e7..5adaa0dcc9 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -bc33af866403c23d548dd4705675315810d52d7f \ No newline at end of file +e29c7f2c910dac07f0f92dfef5e0e743141954eb \ No newline at end of file diff --git a/mkopcodeh.awk b/mkopcodeh.awk index babfdc68d3..94db75e607 100644 --- a/mkopcodeh.awk +++ b/mkopcodeh.awk @@ -72,7 +72,6 @@ sub("\r","",name) op[name] = -1 # op[x] holds the numeric value for OP symbol x jump[name] = 0 - out2_prerelease[name] = 0 in1[name] = 0 in2[name] = 0 in3[name] = 0 @@ -92,8 +91,6 @@ sub(",","",x) if(x=="jump"){ jump[name] = 1 - }else if(x=="out2-prerelease"){ - out2_prerelease[name] = 1 }else if(x=="in1"){ in1[name] = 1 }else if(x=="in2"){ @@ -194,13 +191,12 @@ END { name = def[i] a0 = a1 = a2 = a3 = a4 = a5 = a6 = a7 = 0 if( jump[name] ) a0 = 1; - if( out2_prerelease[name] ) a1 = 2; - if( in1[name] ) a2 = 4; - if( in2[name] ) a3 = 8; - if( in3[name] ) a4 = 16; - if( out2[name] ) a5 = 32; - if( out3[name] ) a6 = 64; - bv[i] = a0+a1+a2+a3+a4+a5+a6+a7; + if( in1[name] ) a2 = 2; + if( in2[name] ) a3 = 4; + if( in3[name] ) a4 = 8; + if( out2[name] ) a5 = 16; + if( out3[name] ) a6 = 32; + bv[i] = a0+a1+a2+a3+a4+a5+a6; } print "\n" print "/* Properties such as \"out2\" or \"jump\" that are specified in" @@ -208,12 +204,11 @@ END { print "** are encoded into bitvectors as follows:" print "*/" print "#define OPFLG_JUMP 0x0001 /* jump: P2 holds jmp target */" - print "#define OPFLG_OUT2_PRERELEASE 0x0002 /* out2-prerelease: */" - print "#define OPFLG_IN1 0x0004 /* in1: P1 is an input */" - print "#define OPFLG_IN2 0x0008 /* in2: P2 is an input */" - print "#define OPFLG_IN3 0x0010 /* in3: P3 is an input */" - print "#define OPFLG_OUT2 0x0020 /* out2: P2 is an output */" - print "#define OPFLG_OUT3 0x0040 /* out3: P3 is an output */" + print "#define OPFLG_IN1 0x0002 /* in1: P1 is an input */" + print "#define OPFLG_IN2 0x0004 /* in2: P2 is an input */" + print "#define OPFLG_IN3 0x0008 /* in3: P3 is an input */" + print "#define OPFLG_OUT2 0x0010 /* out2: P2 is an output */" + print "#define OPFLG_OUT3 0x0020 /* out3: P3 is an output */" print "#define OPFLG_INITIALIZER {\\" for(i=0; i<=max; i++){ if( i%8==0 ) printf("/* %3d */",i) diff --git a/src/vdbe.c b/src/vdbe.c index 22b313756c..8492f8cc09 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -514,6 +514,21 @@ static int checkSavepointCount(sqlite3 *db){ } #endif +/* +** Return the register of pOp->p2 after first preparing it to be +** overwritten with an integer value. +*/ +static Mem *out2Prerelease(Vdbe *p, VdbeOp *pOp){ + Mem *pOut; + assert( pOp->p2>0 ); + assert( pOp->p2<=(p->nMem-p->nCursor) ); + pOut = &p->aMem[pOp->p2]; + memAboutToChange(p, pOut); + if( VdbeMemDynamic(pOut) ) sqlite3VdbeMemSetNull(pOut); + pOut->flags = MEM_Int; + return pOut; +} + /* ** Execute as much of a VDBE program as we can. @@ -633,23 +648,9 @@ int sqlite3VdbeExec( } #endif - /* On any opcode with the "out2-prerelease" tag, free any - ** external allocations out of mem[p2] and set mem[p2] to be - ** an undefined integer. Opcodes will either fill in the integer - ** value or convert mem[p2] to a different type. - */ - assert( pOp->opflags==sqlite3OpcodeProperty[pOp->opcode] ); - if( pOp->opflags & OPFLG_OUT2_PRERELEASE ){ - assert( pOp->p2>0 ); - assert( pOp->p2<=(p->nMem-p->nCursor) ); - pOut = &aMem[pOp->p2]; - memAboutToChange(p, pOut); - if( VdbeMemDynamic(pOut) ) sqlite3VdbeMemSetNull(pOut); - pOut->flags = MEM_Int; - } - /* Sanity checking on other operands */ #ifdef SQLITE_DEBUG + assert( pOp->opflags==sqlite3OpcodeProperty[pOp->opcode] ); if( (pOp->opflags & OPFLG_IN1)!=0 ){ assert( pOp->p1>0 ); assert( pOp->p1<=(p->nMem-p->nCursor) ); @@ -705,7 +706,7 @@ int sqlite3VdbeExec( ** ** Other keywords in the comment that follows each case are used to ** construct the OPFLG_INITIALIZER value that initializes opcodeProperty[]. -** Keywords include: in1, in2, in3, out2_prerelease, out2, out3. See +** Keywords include: in1, in2, in3, out2, out3. See ** the mkopcodeh.awk script for additional information. ** ** Documentation about VDBE opcodes is generated by scanning this file @@ -979,7 +980,8 @@ case OP_Halt: { ** ** The 32-bit integer value P1 is written into register P2. */ -case OP_Integer: { /* out2-prerelease */ +case OP_Integer: { /* out2 */ + pOut = out2Prerelease(p, pOp); pOut->u.i = pOp->p1; break; } @@ -990,7 +992,8 @@ case OP_Integer: { /* out2-prerelease */ ** P4 is a pointer to a 64-bit integer value. ** Write that value into register P2. */ -case OP_Int64: { /* out2-prerelease */ +case OP_Int64: { /* out2 */ + pOut = out2Prerelease(p, pOp); assert( pOp->p4.pI64!=0 ); pOut->u.i = *pOp->p4.pI64; break; @@ -1003,7 +1006,8 @@ case OP_Int64: { /* out2-prerelease */ ** P4 is a pointer to a 64-bit floating point value. ** Write that value into register P2. */ -case OP_Real: { /* same as TK_FLOAT, out2-prerelease */ +case OP_Real: { /* same as TK_FLOAT, out2 */ + pOut = out2Prerelease(p, pOp); pOut->flags = MEM_Real; assert( !sqlite3IsNaN(*pOp->p4.pReal) ); pOut->u.r = *pOp->p4.pReal; @@ -1019,8 +1023,9 @@ case OP_Real: { /* same as TK_FLOAT, out2-prerelease */ ** this transformation, the length of string P4 is computed and stored ** as the P1 parameter. */ -case OP_String8: { /* same as TK_STRING, out2-prerelease */ +case OP_String8: { /* same as TK_STRING, out2 */ assert( pOp->p4.z!=0 ); + pOut = out2Prerelease(p, pOp); pOp->opcode = OP_String; pOp->p1 = sqlite3Strlen30(pOp->p4.z); @@ -1057,8 +1062,9 @@ case OP_String8: { /* same as TK_STRING, out2-prerelease */ ** the same sequence of bytes, it is merely interpreted as a BLOB instead ** of a string, as if it had been CAST. */ -case OP_String: { /* out2-prerelease */ +case OP_String: { /* out2 */ assert( pOp->p4.z!=0 ); + pOut = out2Prerelease(p, pOp); pOut->flags = MEM_Str|MEM_Static|MEM_Term; pOut->z = pOp->p4.z; pOut->n = pOp->p1; @@ -1086,9 +1092,10 @@ case OP_String: { /* out2-prerelease */ ** NULL values will not compare equal even if SQLITE_NULLEQ is set on ** OP_Ne or OP_Eq. */ -case OP_Null: { /* out2-prerelease */ +case OP_Null: { /* out2 */ int cnt; u16 nullFlag; + pOut = out2Prerelease(p, pOp); cnt = pOp->p3-pOp->p2; assert( pOp->p3<=(p->nMem-p->nCursor) ); pOut->flags = nullFlag = pOp->p1 ? (MEM_Null|MEM_Cleared) : MEM_Null; @@ -1123,8 +1130,9 @@ case OP_SoftNull: { ** P4 points to a blob of data P1 bytes long. Store this ** blob in register P2. */ -case OP_Blob: { /* out2-prerelease */ +case OP_Blob: { /* out2 */ assert( pOp->p1 <= SQLITE_MAX_LENGTH ); + pOut = out2Prerelease(p, pOp); sqlite3VdbeMemSetStr(pOut, pOp->p4.z, pOp->p1, 0, 0); pOut->enc = encoding; UPDATE_MAX_BLOBSIZE(pOut); @@ -1139,7 +1147,7 @@ case OP_Blob: { /* out2-prerelease */ ** If the parameter is named, then its name appears in P4. ** The P4 value is used by sqlite3_bind_parameter_name(). */ -case OP_Variable: { /* out2-prerelease */ +case OP_Variable: { /* out2 */ Mem *pVar; /* Value being transferred */ assert( pOp->p1>0 && pOp->p1<=p->nVar ); @@ -1148,6 +1156,7 @@ case OP_Variable: { /* out2-prerelease */ if( sqlite3VdbeMemTooBig(pVar) ){ goto too_big; } + pOut = out2Prerelease(p, pOp); sqlite3VdbeMemShallowCopy(pOut, pVar, MEM_Static); UPDATE_MAX_BLOBSIZE(pOut); break; @@ -2721,7 +2730,7 @@ case OP_MakeRecord: { ** opened by cursor P1 in register P2 */ #ifndef SQLITE_OMIT_BTREECOUNT -case OP_Count: { /* out2-prerelease */ +case OP_Count: { /* out2 */ i64 nEntry; BtCursor *pCrsr; @@ -2729,6 +2738,7 @@ case OP_Count: { /* out2-prerelease */ assert( pCrsr ); nEntry = 0; /* Not needed. Only used to silence a warning. */ rc = sqlite3BtreeCount(pCrsr, &nEntry); + pOut = out2Prerelease(p, pOp); pOut->u.i = nEntry; break; } @@ -3117,7 +3127,7 @@ case OP_Transaction: { ** must be started or there must be an open cursor) before ** executing this instruction. */ -case OP_ReadCookie: { /* out2-prerelease */ +case OP_ReadCookie: { /* out2 */ int iMeta; int iDb; int iCookie; @@ -3131,6 +3141,7 @@ case OP_ReadCookie: { /* out2-prerelease */ assert( DbMaskTest(p->btreeMask, iDb) ); sqlite3BtreeGetMeta(db->aDb[iDb].pBt, iCookie, (u32 *)&iMeta); + pOut = out2Prerelease(p, pOp); pOut->u.i = iMeta; break; } @@ -3951,9 +3962,10 @@ case OP_NotExists: { /* jump, in3 */ ** The sequence number on the cursor is incremented after this ** instruction. */ -case OP_Sequence: { /* out2-prerelease */ +case OP_Sequence: { /* out2 */ assert( pOp->p1>=0 && pOp->p1nCursor ); assert( p->apCsr[pOp->p1]!=0 ); + pOut = out2Prerelease(p, pOp); pOut->u.i = p->apCsr[pOp->p1]->seqCount++; break; } @@ -3974,7 +3986,7 @@ case OP_Sequence: { /* out2-prerelease */ ** generated record number. This P3 mechanism is used to help implement the ** AUTOINCREMENT feature. */ -case OP_NewRowid: { /* out2-prerelease */ +case OP_NewRowid: { /* out2 */ i64 v; /* The new rowid */ VdbeCursor *pC; /* Cursor of table to get the new rowid */ int res; /* Result of an sqlite3BtreeLast() */ @@ -3984,6 +3996,7 @@ case OP_NewRowid: { /* out2-prerelease */ v = 0; res = 0; + pOut = out2Prerelease(p, pOp); assert( pOp->p1>=0 && pOp->p1nCursor ); pC = p->apCsr[pOp->p1]; assert( pC!=0 ); @@ -4428,12 +4441,13 @@ case OP_RowData: { ** be a separate OP_VRowid opcode for use with virtual tables, but this ** one opcode now works for both table types. */ -case OP_Rowid: { /* out2-prerelease */ +case OP_Rowid: { /* out2 */ VdbeCursor *pC; i64 v; sqlite3_vtab *pVtab; const sqlite3_module *pModule; + pOut = out2Prerelease(p, pOp); assert( pOp->p1>=0 && pOp->p1nCursor ); pC = p->apCsr[pOp->p1]; assert( pC!=0 ); @@ -4808,11 +4822,12 @@ case OP_IdxDelete: { ** ** See also: Rowid, MakeRecord. */ -case OP_IdxRowid: { /* out2-prerelease */ +case OP_IdxRowid: { /* out2 */ BtCursor *pCrsr; VdbeCursor *pC; i64 rowid; + pOut = out2Prerelease(p, pOp); assert( pOp->p1>=0 && pOp->p1nCursor ); pC = p->apCsr[pOp->p1]; assert( pC!=0 ); @@ -4951,11 +4966,12 @@ case OP_IdxGE: { /* jump */ ** ** See also: Clear */ -case OP_Destroy: { /* out2-prerelease */ +case OP_Destroy: { /* out2 */ int iMoved; int iDb; assert( p->readOnly==0 ); + pOut = out2Prerelease(p, pOp); pOut->flags = MEM_Null; if( db->nVdbeRead > db->nVDestroy+1 ){ rc = SQLITE_LOCKED; @@ -5064,12 +5080,13 @@ case OP_ResetSorter: { ** ** See documentation on OP_CreateTable for additional information. */ -case OP_CreateIndex: /* out2-prerelease */ -case OP_CreateTable: { /* out2-prerelease */ +case OP_CreateIndex: /* out2 */ +case OP_CreateTable: { /* out2 */ int pgno; int flags; Db *pDb; + pOut = out2Prerelease(p, pOp); pgno = 0; assert( pOp->p1>=0 && pOp->p1nDb ); assert( DbMaskTest(p->btreeMask, pOp->p1) ); @@ -5505,9 +5522,10 @@ case OP_Program: { /* jump */ ** the value of the P1 argument to the value of the P1 argument to the ** calling OP_Program instruction. */ -case OP_Param: { /* out2-prerelease */ +case OP_Param: { /* out2 */ VdbeFrame *pFrame; Mem *pIn; + pOut = out2Prerelease(p, pOp); pFrame = p->pFrame; pIn = &pFrame->aMem[pOp->p1 + pFrame->aOp[pFrame->pc].p1]; sqlite3VdbeMemShallowCopy(pOut, pIn, MEM_Ephem); @@ -5814,7 +5832,7 @@ case OP_Checkpoint: { ** ** Write a string containing the final journal-mode to register P2. */ -case OP_JournalMode: { /* out2-prerelease */ +case OP_JournalMode: { /* out2 */ Btree *pBt; /* Btree to change journal mode of */ Pager *pPager; /* Pager associated with pBt */ int eNew; /* New journal mode */ @@ -5823,6 +5841,7 @@ case OP_JournalMode: { /* out2-prerelease */ const char *zFilename; /* Name of database file for pPager */ #endif + pOut = out2Prerelease(p, pOp); eNew = pOp->p3; assert( eNew==PAGER_JOURNALMODE_DELETE || eNew==PAGER_JOURNALMODE_TRUNCATE @@ -6378,7 +6397,8 @@ case OP_VUpdate: { ** ** Write the current number of pages in database P1 to memory cell P2. */ -case OP_Pagecount: { /* out2-prerelease */ +case OP_Pagecount: { /* out2 */ + pOut = out2Prerelease(p, pOp); pOut->u.i = sqlite3BtreeLastPage(db->aDb[pOp->p1].pBt); break; } @@ -6394,10 +6414,11 @@ case OP_Pagecount: { /* out2-prerelease */ ** ** Store the maximum page count after the change in register P2. */ -case OP_MaxPgcnt: { /* out2-prerelease */ +case OP_MaxPgcnt: { /* out2 */ unsigned int newMax; Btree *pBt; + pOut = out2Prerelease(p, pOp); pBt = db->aDb[pOp->p1].pBt; newMax = 0; if( pOp->p3 ){ @@ -6503,7 +6524,7 @@ default: { /* This is really OP_Noop and OP_Explain */ #ifdef SQLITE_DEBUG if( db->flags & SQLITE_VdbeTrace ){ if( rc!=0 ) printf("rc=%d\n",rc); - if( pOp->opflags & (OPFLG_OUT2_PRERELEASE|OPFLG_OUT2) ){ + if( pOp->opflags & (OPFLG_OUT2) ){ registerTrace(pOp->p2, &aMem[pOp->p2]); } if( pOp->opflags & OPFLG_OUT3 ){ From f56fa4676e26c07b9ae45248e987e380743ce623 Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 13 Apr 2015 21:39:54 +0000 Subject: [PATCH 099/181] Omit the "pc" or "program counter" variable from the VDBE loop for 0.6% performance increase. FossilOrigin-Name: d2f10c41a832f520de13cf8315be22e66552f8e1 --- manifest | 12 +-- manifest.uuid | 2 +- src/vdbe.c | 215 +++++++++++++++++++++++--------------------------- 3 files changed, 105 insertions(+), 124 deletions(-) diff --git a/manifest b/manifest index acc5ea4f99..9ca1e537a7 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Remove\sthe\sout2-prerelease\sVDBE\sopcode\sproperty\sand\sits\sassociated\scode,\nfor\sa\s0.5%\sperformance\simprovement. -D 2015-04-13T19:14:06.003 +C Omit\sthe\s"pc"\sor\s"program\scounter"\svariable\sfrom\sthe\sVDBE\sloop\sfor\s0.6%\nperformance\sincrease. +D 2015-04-13T21:39:54.858 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5f78b1ab81b64e7c57a75d170832443e66c0880a F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -293,7 +293,7 @@ F src/update.c 3c4ecc282accf12d39edb8d524cf089645e55a13 F src/utf.c fc6b889ba0779b7722634cdeaa25f1930d93820c F src/util.c 98a7627ca48ad3265b6940915a1d08355eb3fc7e F src/vacuum.c 2ddd5cad2a7b9cef7f9e431b8c7771634c6b1701 -F src/vdbe.c 584abb81e4abf9dd51a9a2e71f680289bd0c019b +F src/vdbe.c 3f3afd12d4794cb51fe13dc948b1172a5eb71a94 F src/vdbe.h 7e538ecf47dccb307ea2d087c3ddc2dd8d70e79d F src/vdbeInt.h 9cbaa84f53ddd2d09a0cf61a94337a3a035d08a0 F src/vdbeapi.c 583d56b129dd27f12bed518270de9ebe521e6a75 @@ -1250,7 +1250,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 bc33af866403c23d548dd4705675315810d52d7f -R 6ac0695a2f1b9d518c2805dcc9a01314 +P e29c7f2c910dac07f0f92dfef5e0e743141954eb +R 264d755a27d6975322da35a6d51f72d4 U drh -Z 453362d5fdffab6ea02dce6dd25e18dd +Z 01e6d8b5894e3dcd9945571fd6cd1cd0 diff --git a/manifest.uuid b/manifest.uuid index 5adaa0dcc9..28f820dc76 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -e29c7f2c910dac07f0f92dfef5e0e743141954eb \ No newline at end of file +d2f10c41a832f520de13cf8315be22e66552f8e1 \ No newline at end of file diff --git a/src/vdbe.c b/src/vdbe.c index 8492f8cc09..3bd4222c8b 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -537,9 +537,8 @@ static Mem *out2Prerelease(Vdbe *p, VdbeOp *pOp){ int sqlite3VdbeExec( Vdbe *p /* The VDBE */ ){ - int pc=0; /* The program counter */ Op *aOp = p->aOp; /* Copy of p->aOp */ - Op *pOp; /* Current operation */ + Op *pOp = aOp; /* Current operation */ int rc = SQLITE_OK; /* Value to return */ sqlite3 *db = p->db; /* The database */ u8 resetSchemaOnFault = 0; /* Reset schema after an error if positive */ @@ -615,23 +614,22 @@ int sqlite3VdbeExec( } sqlite3EndBenignMalloc(); #endif - for(pc=p->pc; rc==SQLITE_OK; pc++){ - assert( pc>=0 && pcnOp ); + for(pOp=&aOp[p->pc]; rc==SQLITE_OK; pOp++){ + assert( pOp>=aOp && pOp<&aOp[p->nOp]); if( db->mallocFailed ) goto no_mem; #ifdef VDBE_PROFILE start = sqlite3Hwtime(); #endif nVmStep++; - pOp = &aOp[pc]; #ifdef SQLITE_ENABLE_STMT_SCANSTATUS - if( p->anExec ) p->anExec[pc]++; + if( p->anExec ) p->anExec[(int)(pOp-aOp)]++; #endif /* Only allow tracing if SQLITE_DEBUG is defined. */ #ifdef SQLITE_DEBUG if( db->flags & SQLITE_VdbeTrace ){ - sqlite3VdbePrintOp(stdout, pc, pOp); + sqlite3VdbePrintOp(stdout, (int)(pOp - aOp), pOp); } #endif @@ -734,7 +732,8 @@ int sqlite3VdbeExec( ** to the current line should be indented for EXPLAIN output. */ case OP_Goto: { /* jump */ - pc = pOp->p2 - 1; +jump_to_p2_and_check_for_interrupt: + pOp = &aOp[pOp->p2 - 1]; /* Opcodes that are used as the bottom of a loop (OP_Next, OP_Prev, ** OP_VNext, OP_RowSetNext, or OP_SorterNext) all jump here upon @@ -779,9 +778,13 @@ case OP_Gosub: { /* jump */ assert( VdbeMemDynamic(pIn1)==0 ); memAboutToChange(p, pIn1); pIn1->flags = MEM_Int; - pIn1->u.i = pc; + pIn1->u.i = (int)(pOp-aOp); REGISTER_TRACE(pOp->p1, pIn1); - pc = pOp->p2 - 1; + + /* Most jump operations do a goto to this spot in order to update + ** the pOp pointer. */ +jump_to_p2: + pOp = &aOp[pOp->p2 - 1]; break; } @@ -793,7 +796,7 @@ case OP_Gosub: { /* jump */ case OP_Return: { /* in1 */ pIn1 = &aMem[pOp->p1]; assert( pIn1->flags==MEM_Int ); - pc = (int)pIn1->u.i; + pOp = &aOp[pIn1->u.i]; pIn1->flags = MEM_Undefined; break; } @@ -817,7 +820,7 @@ case OP_InitCoroutine: { /* jump */ assert( !VdbeMemDynamic(pOut) ); pOut->u.i = pOp->p3 - 1; pOut->flags = MEM_Int; - if( pOp->p2 ) pc = pOp->p2 - 1; + if( pOp->p2 ) goto jump_to_p2; break; } @@ -837,7 +840,7 @@ case OP_EndCoroutine: { /* in1 */ pCaller = &aOp[pIn1->u.i]; assert( pCaller->opcode==OP_Yield ); assert( pCaller->p2>=0 && pCaller->p2nOp ); - pc = pCaller->p2 - 1; + pOp = &aOp[pCaller->p2 - 1]; pIn1->flags = MEM_Undefined; break; } @@ -861,9 +864,9 @@ case OP_Yield: { /* in1, jump */ assert( VdbeMemDynamic(pIn1)==0 ); pIn1->flags = MEM_Int; pcDest = (int)pIn1->u.i; - pIn1->u.i = pc; + pIn1->u.i = (int)(pOp - aOp); REGISTER_TRACE(pOp->p1, pIn1); - pc = pcDest; + pOp = &aOp[pcDest]; break; } @@ -914,30 +917,34 @@ case OP_HaltIfNull: { /* in3 */ case OP_Halt: { const char *zType; const char *zLogFmt; + VdbeFrame *pFrame; + int pcx; + pcx = (int)(pOp - aOp); if( pOp->p1==SQLITE_OK && p->pFrame ){ /* Halt the sub-program. Return control to the parent frame. */ - VdbeFrame *pFrame = p->pFrame; + pFrame = p->pFrame; p->pFrame = pFrame->pParent; p->nFrame--; sqlite3VdbeSetChanges(db, p->nChange); - pc = sqlite3VdbeFrameRestore(pFrame); + pcx = sqlite3VdbeFrameRestore(pFrame); lastRowid = db->lastRowid; if( pOp->p2==OE_Ignore ){ - /* Instruction pc is the OP_Program that invoked the sub-program + /* Instruction pcx is the OP_Program that invoked the sub-program ** currently being halted. If the p2 instruction of this OP_Halt ** instruction is set to OE_Ignore, then the sub-program is throwing ** an IGNORE exception. In this case jump to the address specified ** as the p2 of the calling OP_Program. */ - pc = p->aOp[pc].p2-1; + pcx = p->aOp[pcx].p2-1; } aOp = p->aOp; aMem = p->aMem; + pOp = &aOp[pcx]; break; } p->rc = pOp->p1; p->errorAction = (u8)pOp->p2; - p->pc = pc; + p->pc = pcx; if( p->rc ){ if( pOp->p5 ){ static const char * const azType[] = { "NOT NULL", "UNIQUE", "CHECK", @@ -961,7 +968,7 @@ case OP_Halt: { }else{ sqlite3SetString(&p->zErrMsg, db, "%s constraint failed", zType); } - sqlite3_log(pOp->p1, zLogFmt, pc, p->zSql, p->zErrMsg); + sqlite3_log(pOp->p1, zLogFmt, pcx, p->zSql, p->zErrMsg); } rc = sqlite3VdbeHalt(p); assert( rc==SQLITE_BUSY || rc==SQLITE_OK || rc==SQLITE_ERROR ); @@ -972,6 +979,7 @@ case OP_Halt: { assert( rc==SQLITE_OK || db->nDeferredCons>0 || db->nDeferredImmCons>0 ); rc = p->rc ? SQLITE_ERROR : SQLITE_DONE; } + pOp = &aOp[pcx]; goto vdbe_return; } @@ -1333,7 +1341,7 @@ case OP_ResultRow: { /* Return SQLITE_ROW */ - p->pc = pc + 1; + p->pc = (int)(pOp - aOp) + 1; rc = SQLITE_ROW; goto vdbe_return; } @@ -1579,7 +1587,7 @@ case OP_Function: { assert( pOp->p4type==P4_FUNCDEF ); ctx.pFunc = pOp->p4.pFunc; - ctx.iOp = pc; + ctx.iOp = (int)(pOp - aOp); ctx.pVdbe = p; MemSetTypeFlag(ctx.pOut, MEM_Null); ctx.fErrorOrAux = 0; @@ -1593,7 +1601,7 @@ case OP_Function: { sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(ctx.pOut)); rc = ctx.isError; } - sqlite3VdbeDeleteAuxData(p, pc, pOp->p1); + sqlite3VdbeDeleteAuxData(p, (int)(pOp - aOp), pOp->p1); } /* Copy the result of the function into register P3 */ @@ -1722,8 +1730,7 @@ case OP_MustBeInt: { /* jump, in1 */ rc = SQLITE_MISMATCH; goto abort_due_to_error; }else{ - pc = pOp->p2 - 1; - break; + goto jump_to_p2; } } } @@ -1909,7 +1916,7 @@ case OP_Ge: { /* same as TK_GE, jump, in1, in3 */ }else{ VdbeBranchTaken(2,3); if( pOp->p5 & SQLITE_JUMPIFNULL ){ - pc = pOp->p2-1; + goto jump_to_p2; } } break; @@ -1961,6 +1968,12 @@ case OP_Ge: { /* same as TK_GE, jump, in1, in3 */ default: res = res>=0; break; } + /* Undo any changes made by applyAffinity() to the input registers. */ + assert( (pIn1->flags & MEM_Dyn) == (flags1 & MEM_Dyn) ); + pIn1->flags = flags1; + assert( (pIn3->flags & MEM_Dyn) == (flags3 & MEM_Dyn) ); + pIn3->flags = flags3; + if( pOp->p5 & SQLITE_STOREP2 ){ pOut = &aMem[pOp->p2]; memAboutToChange(p, pOut); @@ -1970,14 +1983,9 @@ case OP_Ge: { /* same as TK_GE, jump, in1, in3 */ }else{ VdbeBranchTaken(res!=0, (pOp->p5 & SQLITE_NULLEQ)?2:3); if( res ){ - pc = pOp->p2-1; + goto jump_to_p2; } } - /* Undo any changes made by applyAffinity() to the input registers. */ - assert( (pIn1->flags & MEM_Dyn) == (flags1 & MEM_Dyn) ); - pIn1->flags = flags1; - assert( (pIn3->flags & MEM_Dyn) == (flags3 & MEM_Dyn) ); - pIn3->flags = flags3; break; } @@ -2072,11 +2080,11 @@ case OP_Compare: { */ case OP_Jump: { /* jump */ if( iCompare<0 ){ - pc = pOp->p1 - 1; VdbeBranchTaken(0,3); + VdbeBranchTaken(0,3); pOp = &aOp[pOp->p1 - 1]; }else if( iCompare==0 ){ - pc = pOp->p2 - 1; VdbeBranchTaken(1,3); + VdbeBranchTaken(1,3); pOp = &aOp[pOp->p2 - 1]; }else{ - pc = pOp->p3 - 1; VdbeBranchTaken(2,3); + VdbeBranchTaken(2,3); pOp = &aOp[pOp->p3 - 1]; } break; } @@ -2186,7 +2194,7 @@ case OP_Once: { /* jump */ assert( pOp->p1nOnceFlag ); VdbeBranchTaken(p->aOnceFlag[pOp->p1]!=0, 2); if( p->aOnceFlag[pOp->p1] ){ - pc = pOp->p2-1; + goto jump_to_p2; }else{ p->aOnceFlag[pOp->p1] = 1; } @@ -2221,7 +2229,7 @@ case OP_IfNot: { /* jump, in1 */ } VdbeBranchTaken(c!=0, 2); if( c ){ - pc = pOp->p2-1; + goto jump_to_p2; } break; } @@ -2235,7 +2243,7 @@ case OP_IsNull: { /* same as TK_ISNULL, jump, in1 */ pIn1 = &aMem[pOp->p1]; VdbeBranchTaken( (pIn1->flags & MEM_Null)!=0, 2); if( (pIn1->flags & MEM_Null)!=0 ){ - pc = pOp->p2 - 1; + goto jump_to_p2; } break; } @@ -2249,7 +2257,7 @@ case OP_NotNull: { /* same as TK_NOTNULL, jump, in1 */ pIn1 = &aMem[pOp->p1]; VdbeBranchTaken( (pIn1->flags & MEM_Null)==0, 2); if( (pIn1->flags & MEM_Null)==0 ){ - pc = pOp->p2 - 1; + goto jump_to_p2; } break; } @@ -2852,7 +2860,7 @@ case OP_Savepoint: { } db->autoCommit = 1; if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){ - p->pc = pc; + p->pc = (int)(pOp - aOp); db->autoCommit = 0; p->rc = rc = SQLITE_BUSY; goto vdbe_return; @@ -2971,7 +2979,7 @@ case OP_AutoCommit: { }else{ db->autoCommit = (u8)desiredAutoCommit; if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){ - p->pc = pc; + p->pc = (int)(pOp - aOp); db->autoCommit = (u8)(1-desiredAutoCommit); p->rc = rc = SQLITE_BUSY; goto vdbe_return; @@ -3048,7 +3056,7 @@ case OP_Transaction: { if( pBt ){ rc = sqlite3BtreeBeginTrans(pBt, pOp->p2); if( rc==SQLITE_BUSY ){ - p->pc = pc; + p->pc = (int)(pOp - aOp); p->rc = rc = SQLITE_BUSY; goto vdbe_return; } @@ -3463,7 +3471,7 @@ case OP_SequenceTest: { pC = p->apCsr[pOp->p1]; assert( pC->pSorter ); if( (pC->seqCount++)==0 ){ - pc = pOp->p2 - 1; + goto jump_to_p2; } break; } @@ -3640,7 +3648,7 @@ case OP_SeekGT: { /* jump, in3 */ if( (pIn3->flags & MEM_Real)==0 ){ /* If the P3 value cannot be converted into any kind of a number, ** then the seek is not possible, so jump to P2 */ - pc = pOp->p2 - 1; VdbeBranchTaken(1,2); + VdbeBranchTaken(1,2); goto jump_to_p2; break; } @@ -3731,7 +3739,7 @@ case OP_SeekGT: { /* jump, in3 */ assert( pOp->p2>0 ); VdbeBranchTaken(res!=0,2); if( res ){ - pc = pOp->p2 - 1; + goto jump_to_p2; } break; } @@ -3825,6 +3833,7 @@ case OP_NoConflict: /* jump, in3 */ case OP_NotFound: /* jump, in3 */ case OP_Found: { /* jump, in3 */ int alreadyExists; + int takeJump; int ii; VdbeCursor *pC; int res; @@ -3847,7 +3856,7 @@ case OP_Found: { /* jump, in3 */ pIn3 = &aMem[pOp->p3]; assert( pC->pCursor!=0 ); assert( pC->isTable==0 ); - pFree = 0; /* Not needed. Only used to suppress a compiler warning. */ + pFree = 0; if( pOp->p4.i>0 ){ r.pKeyInfo = pC->pKeyInfo; r.nField = (u16)pOp->p4.i; @@ -3870,21 +3879,20 @@ case OP_Found: { /* jump, in3 */ sqlite3VdbeRecordUnpack(pC->pKeyInfo, pIn3->n, pIn3->z, pIdxKey); } pIdxKey->default_rc = 0; + takeJump = 0; if( pOp->opcode==OP_NoConflict ){ /* For the OP_NoConflict opcode, take the jump if any of the ** input fields are NULL, since any key with a NULL will not ** conflict */ for(ii=0; iinField; ii++){ if( pIdxKey->aMem[ii].flags & MEM_Null ){ - pc = pOp->p2 - 1; VdbeBranchTaken(1,2); + takeJump = 1; break; } } } rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, pIdxKey, 0, 0, &res); - if( pOp->p4.i==0 ){ - sqlite3DbFree(db, pFree); - } + sqlite3DbFree(db, pFree); if( rc!=SQLITE_OK ){ break; } @@ -3895,10 +3903,10 @@ case OP_Found: { /* jump, in3 */ pC->cacheStatus = CACHE_STALE; if( pOp->opcode==OP_Found ){ VdbeBranchTaken(alreadyExists!=0,2); - if( alreadyExists ) pc = pOp->p2 - 1; + if( alreadyExists ) goto jump_to_p2; }else{ - VdbeBranchTaken(alreadyExists==0,2); - if( !alreadyExists ) pc = pOp->p2 - 1; + VdbeBranchTaken(takeJump||alreadyExists==0,2); + if( takeJump || !alreadyExists ) goto jump_to_p2; } break; } @@ -3947,10 +3955,8 @@ case OP_NotExists: { /* jump, in3 */ pC->cacheStatus = CACHE_STALE; pC->deferredMoveto = 0; VdbeBranchTaken(res!=0,2); - if( res!=0 ){ - pc = pOp->p2 - 1; - } pC->seekResult = res; + if( res!=0 ) goto jump_to_p2; break; } @@ -4310,9 +4316,7 @@ case OP_SorterCompare: { res = 0; rc = sqlite3VdbeSorterCompare(pC, pIn3, nKeyCol, &res); VdbeBranchTaken(res!=0,2); - if( res ){ - pc = pOp->p2-1; - } + if( res ) goto jump_to_p2; break; }; @@ -4533,7 +4537,7 @@ case OP_Last: { /* jump */ #endif if( pOp->p2>0 ){ VdbeBranchTaken(res!=0,2); - if( res ) pc = pOp->p2 - 1; + if( res ) goto jump_to_p2; } break; } @@ -4597,9 +4601,7 @@ case OP_Rewind: { /* jump */ pC->nullRow = (u8)res; assert( pOp->p2>0 && pOp->p2nOp ); VdbeBranchTaken(res!=0,2); - if( res ){ - pc = pOp->p2 - 1; - } + if( res ) goto jump_to_p2; break; } @@ -4710,11 +4712,11 @@ next_tail: VdbeBranchTaken(res==0,2); if( res==0 ){ pC->nullRow = 0; - pc = pOp->p2 - 1; p->aCounter[pOp->p5]++; #ifdef SQLITE_TEST sqlite3_search_count++; #endif + goto jump_to_p2_and_check_for_interrupt; }else{ pC->nullRow = 1; } @@ -4940,9 +4942,7 @@ case OP_IdxGE: { /* jump */ res++; } VdbeBranchTaken(res>0,2); - if( res>0 ){ - pc = pOp->p2 - 1 ; - } + if( res>0 ) goto jump_to_p2; break; } @@ -5312,12 +5312,12 @@ case OP_RowSetRead: { /* jump, in1, out3 */ ){ /* The boolean index is empty */ sqlite3VdbeMemSetNull(pIn1); - pc = pOp->p2 - 1; VdbeBranchTaken(1,2); + goto jump_to_p2_and_check_for_interrupt; }else{ /* A value was pulled from the index */ - sqlite3VdbeMemSetInt64(&aMem[pOp->p3], val); VdbeBranchTaken(0,2); + sqlite3VdbeMemSetInt64(&aMem[pOp->p3], val); } goto check_for_interrupt; } @@ -5368,10 +5368,7 @@ case OP_RowSetTest: { /* jump, in1, in3 */ if( iSet ){ exists = sqlite3RowSetTest(pIn1->u.pRowSet, iSet, pIn3->u.i); VdbeBranchTaken(exists!=0,2); - if( exists ){ - pc = pOp->p2 - 1; - break; - } + if( exists ) goto jump_to_p2; } if( iSet>=0 ){ sqlite3RowSetInsert(pIn1->u.pRowSet, pIn3->u.i); @@ -5460,7 +5457,7 @@ case OP_Program: { /* jump */ pFrame->v = p; pFrame->nChildMem = nMem; pFrame->nChildCsr = pProgram->nCsr; - pFrame->pc = pc; + pFrame->pc = (int)(pOp - aOp); pFrame->aMem = p->aMem; pFrame->nMem = p->nMem; pFrame->apCsr = p->apCsr; @@ -5483,7 +5480,7 @@ case OP_Program: { /* jump */ pFrame = pRt->u.pFrame; assert( pProgram->nMem+pProgram->nCsr==pFrame->nChildMem ); assert( pProgram->nCsr==pFrame->nChildCsr ); - assert( pc==pFrame->pc ); + assert( (int)(pOp - aOp)==pFrame->pc ); } p->nFrame++; @@ -5504,7 +5501,7 @@ case OP_Program: { /* jump */ #ifdef SQLITE_ENABLE_STMT_SCANSTATUS p->anExec = 0; #endif - pc = -1; + pOp = &aOp[-1]; memset(p->aOnceFlag, 0, p->nOnceFlag); break; @@ -5569,10 +5566,10 @@ case OP_FkCounter: { case OP_FkIfZero: { /* jump */ if( pOp->p1 ){ VdbeBranchTaken(db->nDeferredCons==0 && db->nDeferredImmCons==0, 2); - if( db->nDeferredCons==0 && db->nDeferredImmCons==0 ) pc = pOp->p2-1; + if( db->nDeferredCons==0 && db->nDeferredImmCons==0 ) goto jump_to_p2; }else{ VdbeBranchTaken(p->nFkConstraint==0 && db->nDeferredImmCons==0, 2); - if( p->nFkConstraint==0 && db->nDeferredImmCons==0 ) pc = pOp->p2-1; + if( p->nFkConstraint==0 && db->nDeferredImmCons==0 ) goto jump_to_p2; } break; } @@ -5623,9 +5620,7 @@ case OP_IfPos: { /* jump, in1 */ pIn1 = &aMem[pOp->p1]; assert( pIn1->flags&MEM_Int ); VdbeBranchTaken( pIn1->u.i>0, 2); - if( pIn1->u.i>0 ){ - pc = pOp->p2 - 1; - } + if( pIn1->u.i>0 ) goto jump_to_p2; break; } @@ -5640,9 +5635,7 @@ case OP_IfNeg: { /* jump, in1 */ assert( pIn1->flags&MEM_Int ); pIn1->u.i += pOp->p3; VdbeBranchTaken(pIn1->u.i<0, 2); - if( pIn1->u.i<0 ){ - pc = pOp->p2 - 1; - } + if( pIn1->u.i<0 ) goto jump_to_p2; break; } @@ -5659,7 +5652,7 @@ case OP_IfNotZero: { /* jump, in1 */ VdbeBranchTaken(pIn1->u.i<0, 2); if( pIn1->u.i ){ pIn1->u.i += pOp->p3; - pc = pOp->p2 - 1; + goto jump_to_p2; } break; } @@ -5675,9 +5668,7 @@ case OP_DecrJumpZero: { /* jump, in1 */ assert( pIn1->flags&MEM_Int ); pIn1->u.i--; VdbeBranchTaken(pIn1->u.i==0, 2); - if( pIn1->u.i==0 ){ - pc = pOp->p2 - 1; - } + if( pIn1->u.i==0 ) goto jump_to_p2; break; } @@ -5693,9 +5684,7 @@ case OP_JumpZeroIncr: { /* jump, in1 */ pIn1 = &aMem[pOp->p1]; assert( pIn1->flags&MEM_Int ); VdbeBranchTaken(pIn1->u.i==0, 2); - if( (pIn1->u.i++)==0 ){ - pc = pOp->p2 - 1; - } + if( (pIn1->u.i++)==0 ) goto jump_to_p2; break; } @@ -5737,7 +5726,7 @@ case OP_AggStep: { ctx.pOut = &t; ctx.isError = 0; ctx.pVdbe = p; - ctx.iOp = pc; + ctx.iOp = (int)(pOp - aOp); ctx.skipFlag = 0; (ctx.pFunc->xStep)(&ctx, n, apVal); /* IMP: R-24505-23230 */ if( ctx.isError ){ @@ -5958,8 +5947,8 @@ case OP_IncrVacuum: { /* jump */ rc = sqlite3BtreeIncrVacuum(pBt); VdbeBranchTaken(rc==SQLITE_DONE,2); if( rc==SQLITE_DONE ){ - pc = pOp->p2 - 1; rc = SQLITE_OK; + goto jump_to_p2; } break; } @@ -6169,25 +6158,19 @@ case OP_VFilter: { /* jump */ iQuery = (int)pQuery->u.i; /* Invoke the xFilter method */ - { - res = 0; - apArg = p->apArg; - for(i = 0; ixFilter(pVtabCursor, iQuery, pOp->p4.z, nArg, apArg); - sqlite3VtabImportErrmsg(p, pVtab); - if( rc==SQLITE_OK ){ - res = pModule->xEof(pVtabCursor); - } - VdbeBranchTaken(res!=0,2); - if( res ){ - pc = pOp->p2 - 1; - } + res = 0; + apArg = p->apArg; + for(i = 0; ixFilter(pVtabCursor, iQuery, pOp->p4.z, nArg, apArg); + sqlite3VtabImportErrmsg(p, pVtab); + if( rc==SQLITE_OK ){ + res = pModule->xEof(pVtabCursor); } pCur->nullRow = 0; - + VdbeBranchTaken(res!=0,2); + if( res ) goto jump_to_p2; break; } #endif /* SQLITE_OMIT_VIRTUALTABLE */ @@ -6274,7 +6257,7 @@ case OP_VNext: { /* jump */ VdbeBranchTaken(!res,2); if( !res ){ /* If there is data, jump to P2 */ - pc = pOp->p2 - 1; + goto jump_to_p2_and_check_for_interrupt; } goto check_for_interrupt; } @@ -6447,9 +6430,6 @@ case OP_Init: { /* jump */ char *zTrace; char *z; - if( pOp->p2 ){ - pc = pOp->p2 - 1; - } #ifndef SQLITE_OMIT_TRACE if( db->xTrace && !p->doingRerun @@ -6477,6 +6457,7 @@ case OP_Init: { /* jump */ } #endif /* SQLITE_DEBUG */ #endif /* SQLITE_OMIT_TRACE */ + if( pOp->p2 ) goto jump_to_p2; break; } @@ -6519,7 +6500,7 @@ default: { /* This is really OP_Noop and OP_Explain */ ** the evaluator loop. So we can leave it out when NDEBUG is defined. */ #ifndef NDEBUG - assert( pc>=-1 && pcnOp ); + assert( pOp>=&aOp[-1] && pOp<&aOp[p->nOp] ); #ifdef SQLITE_DEBUG if( db->flags & SQLITE_VdbeTrace ){ @@ -6543,7 +6524,7 @@ vdbe_error_halt: p->rc = rc; testcase( sqlite3GlobalConfig.xLog!=0 ); sqlite3_log(rc, "statement aborts at %d: [%s] %s", - pc, p->zSql, p->zErrMsg); + (int)(pOp - aOp), p->zSql, p->zErrMsg); sqlite3VdbeHalt(p); if( rc==SQLITE_IOERR_NOMEM ) db->mallocFailed = 1; rc = SQLITE_ERROR; From 2647dfa2928aaa3907680d55c1df94b1d8c40eea Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 13 Apr 2015 22:26:55 +0000 Subject: [PATCH 100/181] On a DETACH statement, keep all schemas intact except fo the one that is being detached, and thus avoid unnecessary schema reparsing. FossilOrigin-Name: 661db19b34566642dd44ee4cff4ebc093cb8a552 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/attach.c | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 9ca1e537a7..924612731f 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Omit\sthe\s"pc"\sor\s"program\scounter"\svariable\sfrom\sthe\sVDBE\sloop\sfor\s0.6%\nperformance\sincrease. -D 2015-04-13T21:39:54.858 +C On\sa\sDETACH\sstatement,\skeep\sall\sschemas\sintact\sexcept\sfo\sthe\sone\sthat\sis\nbeing\sdetached,\sand\sthus\savoid\sunnecessary\sschema\sreparsing. +D 2015-04-13T22:26:55.617 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5f78b1ab81b64e7c57a75d170832443e66c0880a F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -168,7 +168,7 @@ F sqlite3.1 fc7ad8990fc8409983309bb80de8c811a7506786 F sqlite3.pc.in 48fed132e7cb71ab676105d2a4dc77127d8c1f3a F src/alter.c d23d6b6991f66b383934f137fd4384d93fb98c81 F src/analyze.c 91540f835163d5369ccbae78e2e6c74d0dd53c1d -F src/attach.c 880f9b8641a829c563e52dd13c452ce457ae4dd8 +F src/attach.c 3c1053a4cf1c3ca05c8c1d74a94cb688d763cef2 F src/auth.c b56c78ebe40a2110fd361379f7e8162d23f92240 F src/backup.c ff743689c4d6c5cb55ad42ed9d174b2b3e71f1e3 F src/bitvec.c 19a4ba637bd85f8f63fc8c9bae5ade9fb05ec1cb @@ -1250,7 +1250,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 e29c7f2c910dac07f0f92dfef5e0e743141954eb -R 264d755a27d6975322da35a6d51f72d4 +P d2f10c41a832f520de13cf8315be22e66552f8e1 +R 49212af07046904ea6b82f6ec3cc0926 U drh -Z 01e6d8b5894e3dcd9945571fd6cd1cd0 +Z b2d6c204725accd9dcc524641d192884 diff --git a/manifest.uuid b/manifest.uuid index 28f820dc76..c643643efb 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -d2f10c41a832f520de13cf8315be22e66552f8e1 \ No newline at end of file +661db19b34566642dd44ee4cff4ebc093cb8a552 \ No newline at end of file diff --git a/src/attach.c b/src/attach.c index 7e35fa67c6..11296d02ad 100644 --- a/src/attach.c +++ b/src/attach.c @@ -298,7 +298,7 @@ static void detachFunc( sqlite3BtreeClose(pDb->pBt); pDb->pBt = 0; pDb->pSchema = 0; - sqlite3ResetAllSchemasOfConnection(db); + sqlite3CollapseDatabaseArray(db); return; detach_error: From 6bca6511666674870a081f05eec9f708ac1ce072 Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 13 Apr 2015 23:05:28 +0000 Subject: [PATCH 101/181] Add #ifdef magic for HAVE_GETHOSTUUID so that the build will hopefully now work on more verions of MacOS with SQLITE_ENABLE_LOCKING_STYLE turned on. FossilOrigin-Name: 211411d02c0729c9af0e3cc7e4910db2e7e0d08e --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/os_unix.c | 16 ++++++++++++++-- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 924612731f..148ae45ff6 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C On\sa\sDETACH\sstatement,\skeep\sall\sschemas\sintact\sexcept\sfo\sthe\sone\sthat\sis\nbeing\sdetached,\sand\sthus\savoid\sunnecessary\sschema\sreparsing. -D 2015-04-13T22:26:55.617 +C Add\s#ifdef\smagic\sfor\sHAVE_GETHOSTUUID\sso\sthat\sthe\sbuild\swill\shopefully\snow\nwork\son\smore\sverions\sof\sMacOS\swith\sSQLITE_ENABLE_LOCKING_STYLE\sturned\son. +D 2015-04-13T23:05:28.978 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5f78b1ab81b64e7c57a75d170832443e66c0880a F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -214,7 +214,7 @@ F src/os.c 8fd25588eeba74068d41102d26810e216999b6c8 F src/os.h 3e57a24e2794a94d3cf2342c6d9a884888cd96bf F src/os_common.h 92815ed65f805560b66166e3583470ff94478f04 F src/os_setup.h c9d4553b5aaa6f73391448b265b89bed0b890faa -F src/os_unix.c 25b80a3d167da44226a2084dc9e89a6cb1f02e2e +F src/os_unix.c 5ed7e2e453c2980909a6b2c80dc55764b50819a8 F src/os_win.c 03d27be3a20048ef52a648d5f0a15f5edda9f2a3 F src/os_win.h eb7a47aa17b26b77eb97e4823f20a00b8bda12ca F src/pager.c 4120a49ecd37697e28f5ed807f470b9c0b88410c @@ -1250,7 +1250,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 d2f10c41a832f520de13cf8315be22e66552f8e1 -R 49212af07046904ea6b82f6ec3cc0926 +P 661db19b34566642dd44ee4cff4ebc093cb8a552 +R 8591357f8b00a438bdaa3b5a16ff0e3f U drh -Z b2d6c204725accd9dcc524641d192884 +Z d2025877377cf6ead9db7636c81d5974 diff --git a/manifest.uuid b/manifest.uuid index c643643efb..8657041788 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -661db19b34566642dd44ee4cff4ebc093cb8a552 \ No newline at end of file +211411d02c0729c9af0e3cc7e4910db2e7e0d08e \ No newline at end of file diff --git a/src/os_unix.c b/src/os_unix.c index 1d867d7cd8..188c025336 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -91,6 +91,17 @@ # include #endif /* SQLITE_ENABLE_LOCKING_STYLE */ +#if defined(__APPLE__) && ((__MAC_OS_X_VERSION_MIN_REQUIRED > 1050) || \ + (__IPHONE_OS_VERSION_MIN_REQUIRED > 2000)) +# if (!defined(TARGET_OS_EMBEDDED) || (TARGET_OS_EMBEDDED==0)) \ + && (!defined(TARGET_IPHONE_SIMULATOR) || (TARGET_IPHONE_SIMULATOR==0)) +# define HAVE_GETHOSTUUID 1 +# else +# warning "gethostuuid() is disabled." +# endif +#endif + + #if OS_VXWORKS # include # include @@ -6602,8 +6613,10 @@ int sqlite3_hostid_num = 0; #define PROXY_HOSTIDLEN 16 /* conch file host id length */ +#ifdef HAVE_GETHOSTUUID /* Not always defined in the headers as it ought to be */ extern int gethostuuid(uuid_t id, const struct timespec *wait); +#endif /* get the host ID via gethostuuid(), pHostID must point to PROXY_HOSTIDLEN ** bytes of writable memory. @@ -6611,8 +6624,7 @@ extern int gethostuuid(uuid_t id, const struct timespec *wait); static int proxyGetHostID(unsigned char *pHostID, int *pError){ assert(PROXY_HOSTIDLEN == sizeof(uuid_t)); memset(pHostID, 0, PROXY_HOSTIDLEN); -# if defined(__APPLE__) && ((__MAC_OS_X_VERSION_MIN_REQUIRED > 1050) || \ - (__IPHONE_OS_VERSION_MIN_REQUIRED > 2000)) +#ifdef HAVE_GETHOSTUUID { struct timespec timeout = {1, 0}; /* 1 sec timeout */ if( gethostuuid(pHostID, &timeout) ){ From d9a0a9a0c6db9ac1d224ff886f89a09af720088f Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 14 Apr 2015 15:14:06 +0000 Subject: [PATCH 102/181] Update API documentation to identify many functions as methods on objects. No changes to code. FossilOrigin-Name: b549cbcee1c11f9ffedf763ca672b125eac87bfe --- manifest | 12 +++--- manifest.uuid | 2 +- src/sqlite.h.in | 100 ++++++++++++++++++++++++++++++++++++++++++------ 3 files changed, 95 insertions(+), 19 deletions(-) diff --git a/manifest b/manifest index 148ae45ff6..c795bef110 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\s#ifdef\smagic\sfor\sHAVE_GETHOSTUUID\sso\sthat\sthe\sbuild\swill\shopefully\snow\nwork\son\smore\sverions\sof\sMacOS\swith\sSQLITE_ENABLE_LOCKING_STYLE\sturned\son. -D 2015-04-13T23:05:28.978 +C Update\sAPI\sdocumentation\sto\sidentify\smany\sfunctions\sas\smethods\son\sobjects.\nNo\schanges\sto\scode. +D 2015-04-14T15:14:06.177 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5f78b1ab81b64e7c57a75d170832443e66c0880a F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -232,7 +232,7 @@ F src/resolve.c 41aa91af56d960e9414ce1d7c17cfb68e0d1c6cb F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e F src/select.c 117e0f9ac9254a6f7472fac5144eba21ba0b2ec1 F src/shell.c 84a1593bd86aaa14f4da8a8f9b16fbc239d262aa -F src/sqlite.h.in 278602140d49575e8708e643161f4263e428a02a +F src/sqlite.h.in ca27603a36fcacdaac5a19d8ee35aaff8ce8516f F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h 17d487c3c91b0b8c584a32fbeb393f6f795eea7d F src/sqliteInt.h 90b7bfd89d7307cd0750663da419ba4bb81e7379 @@ -1250,7 +1250,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 661db19b34566642dd44ee4cff4ebc093cb8a552 -R 8591357f8b00a438bdaa3b5a16ff0e3f +P 211411d02c0729c9af0e3cc7e4910db2e7e0d08e +R 32297e2ca295bdee2feb4a534c04bc42 U drh -Z d2025877377cf6ead9db7636c81d5974 +Z 358af9cd25fc843b833aaa97a1900951 diff --git a/manifest.uuid b/manifest.uuid index 8657041788..5721ce9565 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -211411d02c0729c9af0e3cc7e4910db2e7e0d08e \ No newline at end of file +b549cbcee1c11f9ffedf763ca672b125eac87bfe \ No newline at end of file diff --git a/src/sqlite.h.in b/src/sqlite.h.in index acc3c51404..163bc69fe7 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -270,6 +270,7 @@ typedef sqlite_uint64 sqlite3_uint64; /* ** CAPI3REF: Closing A Database Connection +** DESTRUCTOR: sqlite3 ** ** ^The sqlite3_close() and sqlite3_close_v2() routines are destructors ** for the [sqlite3] object. @@ -321,6 +322,7 @@ typedef int (*sqlite3_callback)(void*,int,char**, char**); /* ** CAPI3REF: One-Step Query Execution Interface +** METHOD: sqlite3 ** ** The sqlite3_exec() interface is a convenience wrapper around ** [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()], @@ -1378,6 +1380,7 @@ int sqlite3_config(int, ...); /* ** CAPI3REF: Configure database connections +** METHOD: sqlite3 ** ** The sqlite3_db_config() interface is used to make configuration ** changes to a [database connection]. The interface is similar to @@ -1875,6 +1878,7 @@ struct sqlite3_mem_methods { /* ** CAPI3REF: Enable Or Disable Extended Result Codes +** METHOD: sqlite3 ** ** ^The sqlite3_extended_result_codes() routine enables or disables the ** [extended result codes] feature of SQLite. ^The extended result @@ -1884,6 +1888,7 @@ int sqlite3_extended_result_codes(sqlite3*, int onoff); /* ** CAPI3REF: Last Insert Rowid +** METHOD: sqlite3 ** ** ^Each entry in most SQLite tables (except for [WITHOUT ROWID] tables) ** has a unique 64-bit signed @@ -1935,6 +1940,7 @@ sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*); /* ** CAPI3REF: Count The Number Of Rows Modified +** METHOD: sqlite3 ** ** ^This function returns the number of rows modified, inserted or ** deleted by the most recently completed INSERT, UPDATE or DELETE @@ -1987,6 +1993,7 @@ int sqlite3_changes(sqlite3*); /* ** CAPI3REF: Total Number Of Rows Modified +** METHOD: sqlite3 ** ** ^This function returns the total number of rows inserted, modified or ** deleted by all [INSERT], [UPDATE] or [DELETE] statements completed @@ -2010,6 +2017,7 @@ int sqlite3_total_changes(sqlite3*); /* ** CAPI3REF: Interrupt A Long-Running Query +** METHOD: sqlite3 ** ** ^This function causes any pending database operation to abort and ** return at its earliest opportunity. This routine is typically @@ -2086,6 +2094,7 @@ int sqlite3_complete16(const void *sql); /* ** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors ** KEYWORDS: {busy-handler callback} {busy handler} +** METHOD: sqlite3 ** ** ^The sqlite3_busy_handler(D,X,P) routine sets a callback function X ** that might be invoked with argument P whenever @@ -2145,6 +2154,7 @@ int sqlite3_busy_handler(sqlite3*, int(*)(void*,int), void*); /* ** CAPI3REF: Set A Busy Timeout +** METHOD: sqlite3 ** ** ^This routine sets a [sqlite3_busy_handler | busy handler] that sleeps ** for a specified amount of time when a table is locked. ^The handler @@ -2167,6 +2177,7 @@ int sqlite3_busy_timeout(sqlite3*, int ms); /* ** CAPI3REF: Convenience Routines For Running Queries +** METHOD: sqlite3 ** ** This is a legacy interface that is preserved for backwards compatibility. ** Use of this interface is not recommended. @@ -2502,6 +2513,7 @@ void sqlite3_randomness(int N, void *P); /* ** CAPI3REF: Compile-Time Authorization Callbacks +** METHOD: sqlite3 ** ** ^This routine registers an authorizer callback with a particular ** [database connection], supplied in the first argument. @@ -2658,6 +2670,7 @@ int sqlite3_set_authorizer( /* ** CAPI3REF: Tracing And Profiling Functions +** METHOD: sqlite3 ** ** These routines register callback functions that can be used for ** tracing and profiling the execution of SQL statements. @@ -2690,6 +2703,7 @@ SQLITE_EXPERIMENTAL void *sqlite3_profile(sqlite3*, /* ** CAPI3REF: Query Progress Callbacks +** METHOD: sqlite3 ** ** ^The sqlite3_progress_handler(D,N,X,P) interface causes the callback ** function X to be invoked periodically during long running calls to @@ -2723,6 +2737,7 @@ void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*); /* ** CAPI3REF: Opening A New Database Connection +** CONSTRUCTOR: sqlite3 ** ** ^These routines open an SQLite database file as specified by the ** filename argument. ^The filename argument is interpreted as UTF-8 for @@ -3008,6 +3023,7 @@ sqlite3_int64 sqlite3_uri_int64(const char*, const char*, sqlite3_int64); /* ** CAPI3REF: Error Codes And Messages +** METHOD: sqlite3 ** ** ^If the most recent sqlite3_* API call associated with ** [database connection] D failed, then the sqlite3_errcode(D) interface @@ -3053,33 +3069,34 @@ const void *sqlite3_errmsg16(sqlite3*); const char *sqlite3_errstr(int); /* -** CAPI3REF: SQL Statement Object +** CAPI3REF: Prepared Statement Object ** KEYWORDS: {prepared statement} {prepared statements} ** -** An instance of this object represents a single SQL statement. -** This object is variously known as a "prepared statement" or a -** "compiled SQL statement" or simply as a "statement". +** An instance of this object represents a single SQL statement that +** has been compiled into binary form and is ready to be evaluated. ** -** The life of a statement object goes something like this: +** Think of each SQL statement as a separate computer program. The +** original SQL text is source code. A prepared statement object +** is the compiled object code. All SQL must be converted into a +** prepared statement before it can be run. +** +** The life-cycle of a prepared statement object usually goes like this: ** **
      -**
    1. Create the object using [sqlite3_prepare_v2()] or a related -** function. -**
    2. Bind values to [host parameters] using the sqlite3_bind_*() +**
    3. Create the prepared statement object using [sqlite3_prepare_v2()]. +**
    4. Bind values to [parameters] using the sqlite3_bind_*() ** interfaces. **
    5. Run the SQL by calling [sqlite3_step()] one or more times. -**
    6. Reset the statement using [sqlite3_reset()] then go back +**
    7. Reset the prepared statement using [sqlite3_reset()] then go back ** to step 2. Do this zero or more times. **
    8. Destroy the object using [sqlite3_finalize()]. **
    -** -** Refer to documentation on individual methods above for additional -** information. */ typedef struct sqlite3_stmt sqlite3_stmt; /* ** CAPI3REF: Run-time Limits +** METHOD: sqlite3 ** ** ^(This interface allows the size of various constructs to be limited ** on a connection by connection basis. The first parameter is the @@ -3191,6 +3208,8 @@ int sqlite3_limit(sqlite3*, int id, int newVal); /* ** CAPI3REF: Compiling An SQL Statement ** KEYWORDS: {SQL statement compiler} +** METHOD: sqlite3 +** CONSTRUCTOR: sqlite3_stmt ** ** To execute an SQL query, it must first be compiled into a byte-code ** program using one of these routines. @@ -3298,6 +3317,7 @@ int sqlite3_prepare16_v2( /* ** CAPI3REF: Retrieving Statement SQL +** METHOD: sqlite3_stmt ** ** ^This interface can be used to retrieve a saved copy of the original ** SQL text used to create a [prepared statement] if that statement was @@ -3307,6 +3327,7 @@ const char *sqlite3_sql(sqlite3_stmt *pStmt); /* ** CAPI3REF: Determine If An SQL Statement Writes The Database +** METHOD: sqlite3_stmt ** ** ^The sqlite3_stmt_readonly(X) interface returns true (non-zero) if ** and only if the [prepared statement] X makes no direct changes to @@ -3338,6 +3359,7 @@ int sqlite3_stmt_readonly(sqlite3_stmt *pStmt); /* ** CAPI3REF: Determine If A Prepared Statement Has Been Reset +** METHOD: sqlite3_stmt ** ** ^The sqlite3_stmt_busy(S) interface returns true (non-zero) if the ** [prepared statement] S has been stepped at least once using @@ -3412,6 +3434,7 @@ typedef struct sqlite3_context sqlite3_context; ** CAPI3REF: Binding Values To Prepared Statements ** KEYWORDS: {host parameter} {host parameters} {host parameter name} ** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding} +** METHOD: sqlite3_stmt ** ** ^(In the SQL statement text input to [sqlite3_prepare_v2()] and its variants, ** literals may be replaced by a [parameter] that matches one of following @@ -3530,6 +3553,7 @@ int sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n); /* ** CAPI3REF: Number Of SQL Parameters +** METHOD: sqlite3_stmt ** ** ^This routine can be used to find the number of [SQL parameters] ** in a [prepared statement]. SQL parameters are tokens of the @@ -3550,6 +3574,7 @@ int sqlite3_bind_parameter_count(sqlite3_stmt*); /* ** CAPI3REF: Name Of A Host Parameter +** METHOD: sqlite3_stmt ** ** ^The sqlite3_bind_parameter_name(P,N) interface returns ** the name of the N-th [SQL parameter] in the [prepared statement] P. @@ -3577,6 +3602,7 @@ const char *sqlite3_bind_parameter_name(sqlite3_stmt*, int); /* ** CAPI3REF: Index Of A Parameter With A Given Name +** METHOD: sqlite3_stmt ** ** ^Return the index of an SQL parameter given its name. ^The ** index value returned is suitable for use as the second @@ -3593,6 +3619,7 @@ int sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName); /* ** CAPI3REF: Reset All Bindings On A Prepared Statement +** METHOD: sqlite3_stmt ** ** ^Contrary to the intuition of many, [sqlite3_reset()] does not reset ** the [sqlite3_bind_blob | bindings] on a [prepared statement]. @@ -3602,6 +3629,7 @@ int sqlite3_clear_bindings(sqlite3_stmt*); /* ** CAPI3REF: Number Of Columns In A Result Set +** METHOD: sqlite3_stmt ** ** ^Return the number of columns in the result set returned by the ** [prepared statement]. ^This routine returns 0 if pStmt is an SQL @@ -3613,6 +3641,7 @@ int sqlite3_column_count(sqlite3_stmt *pStmt); /* ** CAPI3REF: Column Names In A Result Set +** METHOD: sqlite3_stmt ** ** ^These routines return the name assigned to a particular column ** in the result set of a [SELECT] statement. ^The sqlite3_column_name() @@ -3642,6 +3671,7 @@ const void *sqlite3_column_name16(sqlite3_stmt*, int N); /* ** CAPI3REF: Source Of Data In A Query Result +** METHOD: sqlite3_stmt ** ** ^These routines provide a means to determine the database, table, and ** table column that is the origin of a particular result column in @@ -3694,6 +3724,7 @@ const void *sqlite3_column_origin_name16(sqlite3_stmt*,int); /* ** CAPI3REF: Declared Datatype Of A Query Result +** METHOD: sqlite3_stmt ** ** ^(The first parameter is a [prepared statement]. ** If this statement is a [SELECT] statement and the Nth column of the @@ -3726,6 +3757,7 @@ const void *sqlite3_column_decltype16(sqlite3_stmt*,int); /* ** CAPI3REF: Evaluate An SQL Statement +** METHOD: sqlite3_stmt ** ** After a [prepared statement] has been prepared using either ** [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] or one of the legacy @@ -3805,6 +3837,7 @@ int sqlite3_step(sqlite3_stmt*); /* ** CAPI3REF: Number of columns in a result set +** METHOD: sqlite3_stmt ** ** ^The sqlite3_data_count(P) interface returns the number of columns in the ** current row of the result set of [prepared statement] P. @@ -3858,6 +3891,7 @@ int sqlite3_data_count(sqlite3_stmt *pStmt); /* ** CAPI3REF: Result Values From A Query ** KEYWORDS: {column access functions} +** METHOD: sqlite3_stmt ** ** These routines form the "result set" interface. ** @@ -4030,6 +4064,7 @@ sqlite3_value *sqlite3_column_value(sqlite3_stmt*, int iCol); /* ** CAPI3REF: Destroy A Prepared Statement Object +** DESTRUCTOR: sqlite3_stmt ** ** ^The sqlite3_finalize() function is called to delete a [prepared statement]. ** ^If the most recent evaluation of the statement encountered no errors @@ -4057,6 +4092,7 @@ int sqlite3_finalize(sqlite3_stmt *pStmt); /* ** CAPI3REF: Reset A Prepared Statement Object +** METHOD: sqlite3_stmt ** ** The sqlite3_reset() function is called to reset a [prepared statement] ** object back to its initial state, ready to be re-executed. @@ -4086,6 +4122,7 @@ int sqlite3_reset(sqlite3_stmt *pStmt); ** KEYWORDS: {function creation routines} ** KEYWORDS: {application-defined SQL function} ** KEYWORDS: {application-defined SQL functions} +** METHOD: sqlite3 ** ** ^These functions (collectively known as "function creation routines") ** are used to add SQL functions or aggregates or to redefine the behavior @@ -4255,6 +4292,7 @@ SQLITE_DEPRECATED int sqlite3_memory_alarm(void(*)(void*,sqlite3_int64,int), /* ** CAPI3REF: Obtaining SQL Function Parameter Values +** METHOD: sqlite3_value ** ** The C-language implementation of SQL functions and aggregates uses ** this set of interface routines to access the parameter values on @@ -4313,6 +4351,7 @@ int sqlite3_value_numeric_type(sqlite3_value*); /* ** CAPI3REF: Obtain Aggregate Function Context +** METHOD: sqlite3_context ** ** Implementations of aggregate SQL functions use this ** routine to allocate memory for storing their state. @@ -4357,6 +4396,7 @@ void *sqlite3_aggregate_context(sqlite3_context*, int nBytes); /* ** CAPI3REF: User Data For Functions +** METHOD: sqlite3_context ** ** ^The sqlite3_user_data() interface returns a copy of ** the pointer that was the pUserData parameter (the 5th parameter) @@ -4371,6 +4411,7 @@ void *sqlite3_user_data(sqlite3_context*); /* ** CAPI3REF: Database Connection For Functions +** METHOD: sqlite3_context ** ** ^The sqlite3_context_db_handle() interface returns a copy of ** the pointer to the [database connection] (the 1st parameter) @@ -4382,6 +4423,7 @@ sqlite3 *sqlite3_context_db_handle(sqlite3_context*); /* ** CAPI3REF: Function Auxiliary Data +** METHOD: sqlite3_context ** ** These functions may be used by (non-aggregate) SQL functions to ** associate metadata with argument values. If the same value is passed to @@ -4454,6 +4496,7 @@ typedef void (*sqlite3_destructor_type)(void*); /* ** CAPI3REF: Setting The Result Of An SQL Function +** METHOD: sqlite3_context ** ** These routines are used by the xFunc or xFinal callbacks that ** implement SQL functions and aggregates. See @@ -4589,6 +4632,7 @@ void sqlite3_result_zeroblob(sqlite3_context*, int n); /* ** CAPI3REF: Define New Collating Sequences +** METHOD: sqlite3 ** ** ^These functions add, remove, or modify a [collation] associated ** with the [database connection] specified as the first argument. @@ -4691,6 +4735,7 @@ int sqlite3_create_collation16( /* ** CAPI3REF: Collation Needed Callbacks +** METHOD: sqlite3 ** ** ^To avoid having to register all collation sequences before a database ** can be used, a single callback function may be registered with the @@ -4898,6 +4943,7 @@ SQLITE_EXTERN char *sqlite3_data_directory; /* ** CAPI3REF: Test For Auto-Commit Mode ** KEYWORDS: {autocommit mode} +** METHOD: sqlite3 ** ** ^The sqlite3_get_autocommit() interface returns non-zero or ** zero if the given database connection is or is not in autocommit mode, @@ -4920,6 +4966,7 @@ int sqlite3_get_autocommit(sqlite3*); /* ** CAPI3REF: Find The Database Handle Of A Prepared Statement +** METHOD: sqlite3_stmt ** ** ^The sqlite3_db_handle interface returns the [database connection] handle ** to which a [prepared statement] belongs. ^The [database connection] @@ -4932,6 +4979,7 @@ sqlite3 *sqlite3_db_handle(sqlite3_stmt*); /* ** CAPI3REF: Return The Filename For A Database Connection +** METHOD: sqlite3 ** ** ^The sqlite3_db_filename(D,N) interface returns a pointer to a filename ** associated with database N of connection D. ^The main database file @@ -4948,6 +4996,7 @@ const char *sqlite3_db_filename(sqlite3 *db, const char *zDbName); /* ** CAPI3REF: Determine if a database is read-only +** METHOD: sqlite3 ** ** ^The sqlite3_db_readonly(D,N) interface returns 1 if the database N ** of connection D is read-only, 0 if it is read/write, or -1 if N is not @@ -4957,6 +5006,7 @@ int sqlite3_db_readonly(sqlite3 *db, const char *zDbName); /* ** CAPI3REF: Find the next prepared statement +** METHOD: sqlite3 ** ** ^This interface returns a pointer to the next [prepared statement] after ** pStmt associated with the [database connection] pDb. ^If pStmt is NULL @@ -4972,6 +5022,7 @@ sqlite3_stmt *sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt); /* ** CAPI3REF: Commit And Rollback Notification Callbacks +** METHOD: sqlite3 ** ** ^The sqlite3_commit_hook() interface registers a callback ** function to be invoked whenever a transaction is [COMMIT | committed]. @@ -5021,6 +5072,7 @@ void *sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*); /* ** CAPI3REF: Data Change Notification Callbacks +** METHOD: sqlite3 ** ** ^The sqlite3_update_hook() interface registers a callback function ** with the [database connection] identified by the first argument @@ -5127,6 +5179,7 @@ int sqlite3_release_memory(int); /* ** CAPI3REF: Free Memory Used By A Database Connection +** METHOD: sqlite3 ** ** ^The sqlite3_db_release_memory(D) interface attempts to free as much heap ** memory as possible from database connection D. Unlike the @@ -5204,6 +5257,7 @@ SQLITE_DEPRECATED void sqlite3_soft_heap_limit(int N); /* ** CAPI3REF: Extract Metadata About A Column Of A Table +** METHOD: sqlite3 ** ** ^(The sqlite3_table_column_metadata(X,D,T,C,....) routine returns ** information about column C of table T in database D @@ -5282,6 +5336,7 @@ int sqlite3_table_column_metadata( /* ** CAPI3REF: Load An Extension +** METHOD: sqlite3 ** ** ^This interface loads an SQLite extension library from the named file. ** @@ -5323,6 +5378,7 @@ int sqlite3_load_extension( /* ** CAPI3REF: Enable Or Disable Extension Loading +** METHOD: sqlite3 ** ** ^So as not to open security holes in older applications that are ** unprepared to deal with [extension loading], and as a means of disabling @@ -5572,6 +5628,7 @@ struct sqlite3_index_info { /* ** CAPI3REF: Register A Virtual Table Implementation +** METHOD: sqlite3 ** ** ^These routines are used to register a new [virtual table module] name. ** ^Module names must be registered before @@ -5668,6 +5725,7 @@ int sqlite3_declare_vtab(sqlite3*, const char *zSQL); /* ** CAPI3REF: Overload A Function For A Virtual Table +** METHOD: sqlite3 ** ** ^(Virtual tables can provide alternative implementations of functions ** using the [xFindFunction] method of the [virtual table module]. @@ -5710,6 +5768,8 @@ typedef struct sqlite3_blob sqlite3_blob; /* ** CAPI3REF: Open A BLOB For Incremental I/O +** METHOD: sqlite3 +** CONSTRUCTOR: sqlite3_blob ** ** ^(This interfaces opens a [BLOB handle | handle] to the BLOB located ** in row iRow, column zColumn, table zTable in database zDb; @@ -5791,6 +5851,7 @@ int sqlite3_blob_open( /* ** CAPI3REF: Move a BLOB Handle to a New Row +** METHOD: sqlite3_blob ** ** ^This function is used to move an existing blob handle so that it points ** to a different row of the same database table. ^The new row is identified @@ -5815,6 +5876,7 @@ SQLITE_EXPERIMENTAL int sqlite3_blob_reopen(sqlite3_blob *, sqlite3_int64); /* ** CAPI3REF: Close A BLOB Handle +** DESTRUCTOR: sqlite3_blob ** ** ^This function closes an open [BLOB handle]. ^(The BLOB handle is closed ** unconditionally. Even if this routine returns an error code, the @@ -5837,6 +5899,7 @@ int sqlite3_blob_close(sqlite3_blob *); /* ** CAPI3REF: Return The Size Of An Open BLOB +** METHOD: sqlite3_blob ** ** ^Returns the size in bytes of the BLOB accessible via the ** successfully opened [BLOB handle] in its only argument. ^The @@ -5852,6 +5915,7 @@ int sqlite3_blob_bytes(sqlite3_blob *); /* ** CAPI3REF: Read Data From A BLOB Incrementally +** METHOD: sqlite3_blob ** ** ^(This function is used to read data from an open [BLOB handle] into a ** caller-supplied buffer. N bytes of data are copied into buffer Z @@ -5880,6 +5944,7 @@ int sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset); /* ** CAPI3REF: Write Data Into A BLOB Incrementally +** METHOD: sqlite3_blob ** ** ^(This function is used to write data into an open [BLOB handle] from a ** caller-supplied buffer. N bytes of data are copied from the buffer Z @@ -6207,6 +6272,7 @@ int sqlite3_mutex_notheld(sqlite3_mutex*); /* ** CAPI3REF: Retrieve the mutex for a database connection +** METHOD: sqlite3 ** ** ^This interface returns a pointer the [sqlite3_mutex] object that ** serializes access to the [database connection] given in the argument @@ -6218,6 +6284,7 @@ sqlite3_mutex *sqlite3_db_mutex(sqlite3*); /* ** CAPI3REF: Low-Level Control Of Database Files +** METHOD: sqlite3 ** ** ^The [sqlite3_file_control()] interface makes a direct call to the ** xFileControl method for the [sqlite3_io_methods] object associated @@ -6434,6 +6501,7 @@ int sqlite3_status64( /* ** CAPI3REF: Database Connection Status +** METHOD: sqlite3 ** ** ^This interface is used to retrieve runtime status information ** about a single [database connection]. ^The first argument is the @@ -6562,6 +6630,7 @@ int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg); /* ** CAPI3REF: Prepared Statement Status +** METHOD: sqlite3_stmt ** ** ^(Each prepared statement maintains various ** [SQLITE_STMTSTATUS counters] that measure the number @@ -7065,6 +7134,7 @@ int sqlite3_backup_pagecount(sqlite3_backup *p); /* ** CAPI3REF: Unlock Notification +** METHOD: sqlite3 ** ** ^When running in shared-cache mode, a database operation may fail with ** an [SQLITE_LOCKED] error if the required locks on the shared-cache or @@ -7235,6 +7305,7 @@ void sqlite3_log(int iErrCode, const char *zFormat, ...); /* ** CAPI3REF: Write-Ahead Log Commit Hook +** METHOD: sqlite3 ** ** ^The [sqlite3_wal_hook()] function is used to register a callback that ** is invoked each time data is committed to a database in wal mode. @@ -7274,6 +7345,7 @@ void *sqlite3_wal_hook( /* ** CAPI3REF: Configure an auto-checkpoint +** METHOD: sqlite3 ** ** ^The [sqlite3_wal_autocheckpoint(D,N)] is a wrapper around ** [sqlite3_wal_hook()] that causes any database on [database connection] D @@ -7304,6 +7376,7 @@ int sqlite3_wal_autocheckpoint(sqlite3 *db, int N); /* ** CAPI3REF: Checkpoint a database +** METHOD: sqlite3 ** ** ^(The sqlite3_wal_checkpoint(D,X) is equivalent to ** [sqlite3_wal_checkpoint_v2](D,X,[SQLITE_CHECKPOINT_PASSIVE],0,0).)^ @@ -7325,6 +7398,7 @@ int sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb); /* ** CAPI3REF: Checkpoint a database +** METHOD: sqlite3 ** ** ^(The sqlite3_wal_checkpoint_v2(D,X,M,L,C) interface runs a checkpoint ** operation on database X of [database connection] D in mode M. Status @@ -7579,6 +7653,7 @@ int sqlite3_vtab_on_conflict(sqlite3 *); /* ** CAPI3REF: Prepared Statement Scan Status +** METHOD: sqlite3_stmt ** ** This interface returns information about the predicted and measured ** performance for pStmt. Advanced applications can use this @@ -7616,6 +7691,7 @@ SQLITE_EXPERIMENTAL int sqlite3_stmt_scanstatus( /* ** CAPI3REF: Zero Scan-Status Counters +** METHOD: sqlite3_stmt ** ** ^Zero all [sqlite3_stmt_scanstatus()] related event counters. ** From 8a1cd765dfae89bb23a8ce61101f299d8a225334 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 14 Apr 2015 19:01:08 +0000 Subject: [PATCH 103/181] Add the --summary option to the sqldiff command-line tool. FossilOrigin-Name: 88b22761c59b06fa86c57f8d22a46046ad17d5d5 --- manifest | 12 +-- manifest.uuid | 2 +- tool/sqldiff.c | 238 ++++++++++++++++++++++++++++++++++++++----------- 3 files changed, 192 insertions(+), 60 deletions(-) diff --git a/manifest b/manifest index c795bef110..821eb96f29 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Update\sAPI\sdocumentation\sto\sidentify\smany\sfunctions\sas\smethods\son\sobjects.\nNo\schanges\sto\scode. -D 2015-04-14T15:14:06.177 +C Add\sthe\s--summary\soption\sto\sthe\ssqldiff\scommand-line\stool. +D 2015-04-14T19:01:08.549 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5f78b1ab81b64e7c57a75d170832443e66c0880a F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -1239,7 +1239,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/split-sqlite3c.tcl d9be87f1c340285a3e081eb19b4a247981ed290c -F tool/sqldiff.c 51c05cc1435507736b8b5a41a0498016041b3e48 +F tool/sqldiff.c 5c16cf3a1f566873abbdecac0d13a6691437564f F tool/stack_usage.tcl f8e71b92cdb099a147dad572375595eae55eca43 F tool/symbols-mingw.sh 4dbcea7e74768305384c9fd2ed2b41bbf9f0414d F tool/symbols.sh fec58532668296d7c7dc48be9c87f75ccdb5814f @@ -1250,7 +1250,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 211411d02c0729c9af0e3cc7e4910db2e7e0d08e -R 32297e2ca295bdee2feb4a534c04bc42 +P b549cbcee1c11f9ffedf763ca672b125eac87bfe +R 64950626ad311356247b51bbef2cd09d U drh -Z 358af9cd25fc843b833aaa97a1900951 +Z 2d35d7a2b23bff60413bdff46818cee3 diff --git a/manifest.uuid b/manifest.uuid index 5721ce9565..674f6cdaa2 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -b549cbcee1c11f9ffedf763ca672b125eac87bfe \ No newline at end of file +88b22761c59b06fa86c57f8d22a46046ad17d5d5 \ No newline at end of file diff --git a/tool/sqldiff.c b/tool/sqldiff.c index 4455c582ef..c7b59400df 100644 --- a/tool/sqldiff.c +++ b/tool/sqldiff.c @@ -356,18 +356,18 @@ static char **columnNames(const char *zDb, const char *zTab, int *pnPKey){ /* ** Print the sqlite3_value X as an SQL literal. */ -static void printQuoted(sqlite3_value *X){ +static void printQuoted(FILE *out, sqlite3_value *X){ switch( sqlite3_value_type(X) ){ case SQLITE_FLOAT: { double r1; char zBuf[50]; r1 = sqlite3_value_double(X); sqlite3_snprintf(sizeof(zBuf), zBuf, "%!.15g", r1); - printf("%s", zBuf); + fprintf(out, "%s", zBuf); break; } case SQLITE_INTEGER: { - printf("%lld", sqlite3_value_int64(X)); + fprintf(out, "%lld", sqlite3_value_int64(X)); break; } case SQLITE_BLOB: { @@ -375,13 +375,13 @@ static void printQuoted(sqlite3_value *X){ int nBlob = sqlite3_value_bytes(X); if( zBlob ){ int i; - printf("x'"); + fprintf(out, "x'"); for(i=0; i Date: Wed, 15 Apr 2015 04:10:50 +0000 Subject: [PATCH 104/181] An oversize hex literal can cause a parsing error while generating code for constants that are factored out of the main body of the VDBE program. So allow for that case. FossilOrigin-Name: a084690b4fcabba20d9770ebf3a014dda84e2954 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/build.c | 2 +- test/hexlit.test | 5 +++++ 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 821eb96f29..70d58da81f 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sthe\s--summary\soption\sto\sthe\ssqldiff\scommand-line\stool. -D 2015-04-14T19:01:08.549 +C An\soversize\shex\sliteral\scan\scause\sa\sparsing\serror\swhile\sgenerating\scode\sfor\nconstants\sthat\sare\sfactored\sout\sof\sthe\smain\sbody\sof\sthe\sVDBE\sprogram.\s\sSo\nallow\sfor\sthat\scase. +D 2015-04-15T04:10:50.814 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5f78b1ab81b64e7c57a75d170832443e66c0880a F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -176,7 +176,7 @@ F src/btmutex.c 45a968cc85afed9b5e6cf55bf1f42f8d18107f79 F src/btree.c 67648f6532c2da79d3b3fb6853aa1a0c3ba0e1ad F src/btree.h 969adc948e89e449220ff0ff724c94bb2a52e9f1 F src/btreeInt.h 973a22a6fd61350b454ad614832b1f0a5e25a1e4 -F src/build.c fa4795bc795077388aa4e746e1b25ef97bc10489 +F src/build.c 01b969b20a44a3d9620e597d9af8242348123540 F src/callback.c 7b44ce59674338ad48b0e84e7b72f935ea4f68b0 F src/complete.c a5cf5b4b56390cfb7b8636e8f7ddef90258dd575 F src/ctime.c 98f89724adc891a1a4c655bee04e33e716e05887 @@ -633,7 +633,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 f9ecde8145bfc2341573473256c74ae37a200497 +F test/hexlit.test 1d312fa816dfd3650a3bb488093bc09a0c927f67 F test/hook.test 162d7cef7a2d2b04839fe14402934e6a1b79442f F test/icu.test 70df4faca133254c042d02ae342c0a141f2663f4 F test/imposter1.test c3f1db2d3db2c24611a6596a3fc0ffc14f1466c8 @@ -1250,7 +1250,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 b549cbcee1c11f9ffedf763ca672b125eac87bfe -R 64950626ad311356247b51bbef2cd09d +P 88b22761c59b06fa86c57f8d22a46046ad17d5d5 +R a0a6eb36c09cbd9c15f1359867fe74af U drh -Z 2d35d7a2b23bff60413bdff46818cee3 +Z 7045f923a68da4f66662aff61189246b diff --git a/manifest.uuid b/manifest.uuid index 674f6cdaa2..81075d42b9 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -88b22761c59b06fa86c57f8d22a46046ad17d5d5 \ No newline at end of file +a084690b4fcabba20d9770ebf3a014dda84e2954 \ No newline at end of file diff --git a/src/build.c b/src/build.c index 9d8465561f..3021ad4e51 100644 --- a/src/build.c +++ b/src/build.c @@ -226,7 +226,7 @@ void sqlite3FinishCoding(Parse *pParse){ /* Get the VDBE program ready for execution */ - if( v && ALWAYS(pParse->nErr==0) && !db->mallocFailed ){ + if( v && pParse->nErr==0 && !db->mallocFailed ){ assert( pParse->iCacheLevel==0 ); /* Disables and re-enables match */ /* A minimum of one cursor is required if autoincrement is used * See ticket [a696379c1f08866] */ diff --git a/test/hexlit.test b/test/hexlit.test index 10909e6f4c..2edd458e89 100644 --- a/test/hexlit.test +++ b/test/hexlit.test @@ -109,6 +109,11 @@ do_execsql_test hexlit-301 { do_catchsql_test hexlist-400 { SELECT 0x10000000000000000; } {1 {hex literal too big: 0x10000000000000000}} +do_catchsql_test hexlist-410 { + DROP TABLE IF EXISTS t1; + CREATE TABLE t1(x); + INSERT INTO t1 VALUES(1+0x10000000000000000); +} {1 {hex literal too big: 0x10000000000000000}} finish_test From 311efc70a74a01d22b4d90c87490cda41b0b110a Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 15 Apr 2015 04:20:58 +0000 Subject: [PATCH 105/181] Add a test case for what was formerly thought to be an unreachable condition: when the LHS of an OR operator contains an error and the RHS contains an IN operator. FossilOrigin-Name: 3872742591add4e94033484c2844e7d7ab69674b --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/expr.c | 2 +- test/in.test | 6 ++++++ 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 70d58da81f..8ac7986648 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C An\soversize\shex\sliteral\scan\scause\sa\sparsing\serror\swhile\sgenerating\scode\sfor\nconstants\sthat\sare\sfactored\sout\sof\sthe\smain\sbody\sof\sthe\sVDBE\sprogram.\s\sSo\nallow\sfor\sthat\scase. -D 2015-04-15T04:10:50.814 +C Add\sa\stest\scase\sfor\swhat\swas\sformerly\sthought\sto\sbe\san\sunreachable\scondition:\nwhen\sthe\sLHS\sof\san\sOR\soperator\scontains\san\serror\sand\sthe\sRHS\scontains\san\sIN\noperator. +D 2015-04-15T04:20:58.065 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5f78b1ab81b64e7c57a75d170832443e66c0880a F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -182,7 +182,7 @@ F src/complete.c a5cf5b4b56390cfb7b8636e8f7ddef90258dd575 F src/ctime.c 98f89724adc891a1a4c655bee04e33e716e05887 F src/date.c e4d50b3283696836ec1036b695ead9a19e37a5ac F src/delete.c 37964e6c1d73ff49cbea9ff690c9605fb15f600e -F src/expr.c d09dac67d53c78880ba31d56e8ba2be3a6490553 +F src/expr.c aba4f0547aac1fcbd965d548ab2e36efd5a4481c F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb F src/fkey.c 3343d551a8d810782257244fb33f2ce191493c39 F src/func.c 1414c24c873c48796ad45942257a179a423ba42f @@ -637,7 +637,7 @@ F test/hexlit.test 1d312fa816dfd3650a3bb488093bc09a0c927f67 F test/hook.test 162d7cef7a2d2b04839fe14402934e6a1b79442f F test/icu.test 70df4faca133254c042d02ae342c0a141f2663f4 F test/imposter1.test c3f1db2d3db2c24611a6596a3fc0ffc14f1466c8 -F test/in.test 047c4671328e9032ab95666a67021adbbd36e98e +F test/in.test b52fa96bcf6cebc5c8829c822315d0f87af9c6c2 F test/in2.test 5d4c61d17493c832f7d2d32bef785119e87bde75 F test/in3.test 3cbf58c87f4052cee3a58b37b6389777505aa0c0 F test/in4.test d2b38cba404bc4320f4fe1b595b3d163f212c068 @@ -1250,7 +1250,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 88b22761c59b06fa86c57f8d22a46046ad17d5d5 -R a0a6eb36c09cbd9c15f1359867fe74af +P a084690b4fcabba20d9770ebf3a014dda84e2954 +R fcf0b4147f04a74e05def15e3b1a56b8 U drh -Z 7045f923a68da4f66662aff61189246b +Z 041867bd4c7c23a09c20a9ae6f8ff29f diff --git a/manifest.uuid b/manifest.uuid index 81075d42b9..f94b10f78e 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -a084690b4fcabba20d9770ebf3a014dda84e2954 \ No newline at end of file +3872742591add4e94033484c2844e7d7ab69674b \ No newline at end of file diff --git a/src/expr.c b/src/expr.c index e6ac0f6796..6a30755aa5 100644 --- a/src/expr.c +++ b/src/expr.c @@ -1691,7 +1691,7 @@ int sqlite3FindInIndex(Parse *pParse, Expr *pX, u32 inFlags, int *prRhsHasNull){ ** ephemeral table. */ p = (ExprHasProperty(pX, EP_xIsSelect) ? pX->x.pSelect : 0); - if( ALWAYS(pParse->nErr==0) && isCandidateForInOpt(p) ){ + if( pParse->nErr==0 && isCandidateForInOpt(p) ){ sqlite3 *db = pParse->db; /* Database connection */ Table *pTab; /* Table . */ Expr *pExpr; /* Expression */ diff --git a/test/in.test b/test/in.test index 515e598c12..de38c22456 100644 --- a/test/in.test +++ b/test/in.test @@ -615,6 +615,12 @@ do_test in-13.14 { } } {} +do_test in-13.15 { + catchsql { + SELECT 0 WHERE (SELECT 0,0) OR (0 IN (1,2)); + } +} {1 {only a single result allowed for a SELECT that is part of an expression}} + do_test in-13.X { db nullvalue "" From 0ec68f845c1ab87995f8956c2617c7017809a963 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 15 Apr 2015 04:51:28 +0000 Subject: [PATCH 106/181] When doing the (dubious) conversion of double-quoted identifier into string literal for MySQL compatibility, be sure to also clear the iTable value from the Expr entry to avoid an assert. FossilOrigin-Name: d7211b68107ea669de39e0aa81a1be40901e1487 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/resolve.c | 1 + test/misc1.test | 5 +++++ 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 8ac7986648..c64b26440d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sa\stest\scase\sfor\swhat\swas\sformerly\sthought\sto\sbe\san\sunreachable\scondition:\nwhen\sthe\sLHS\sof\san\sOR\soperator\scontains\san\serror\sand\sthe\sRHS\scontains\san\sIN\noperator. -D 2015-04-15T04:20:58.065 +C When\sdoing\sthe\s(dubious)\sconversion\sof\sdouble-quoted\sidentifier\sinto\sstring\nliteral\sfor\sMySQL\scompatibility,\sbe\ssure\sto\salso\sclear\sthe\siTable\svalue\sfrom\nthe\sExpr\sentry\sto\savoid\san\sassert. +D 2015-04-15T04:51:28.676 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5f78b1ab81b64e7c57a75d170832443e66c0880a F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -228,7 +228,7 @@ F src/pragma.h 09c89bca58e9a44de2116cc8272b8d454657129f F src/prepare.c 173a5a499138451b2561614ecb87d78f9f4644b9 F src/printf.c 8ae1fa9d30c1200a9268a390ba9e9cea9197b27a F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 -F src/resolve.c 41aa91af56d960e9414ce1d7c17cfb68e0d1c6cb +F src/resolve.c 7bd67ded824a2fe8b356cd45e053d9c94b1874c2 F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e F src/select.c 117e0f9ac9254a6f7472fac5144eba21ba0b2ec1 F src/shell.c 84a1593bd86aaa14f4da8a8f9b16fbc239d262aa @@ -743,7 +743,7 @@ F test/minmax.test 42fbad0e81afaa6e0de41c960329f2b2c3526efd F test/minmax2.test b44bae787fc7b227597b01b0ca5575c7cb54d3bc F test/minmax3.test cc1e8b010136db0d01a6f2a29ba5a9f321034354 F test/minmax4.test 936941484ebdceb8adec7c86b6cd9b6e5e897c1f -F test/misc1.test f3f59b3941c84a10860c06c07e86ad367a74ec92 +F test/misc1.test 9abcae9a0b8785d6fa92925dbb19c309ae9ea077 F test/misc2.test 00d7de54eda90e237fc9a38b9e5ccc769ebf6d4d F test/misc3.test cf3dda47d5dda3e53fc5804a100d3c82be736c9d F test/misc4.test 9c078510fbfff05a9869a0b6d8b86a623ad2c4f6 @@ -1250,7 +1250,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 a084690b4fcabba20d9770ebf3a014dda84e2954 -R fcf0b4147f04a74e05def15e3b1a56b8 +P 3872742591add4e94033484c2844e7d7ab69674b +R 3d936303913ff5357294410059be6467 U drh -Z 041867bd4c7c23a09c20a9ae6f8ff29f +Z adb676b9f25e7eed8c83dbf9762c49f4 diff --git a/manifest.uuid b/manifest.uuid index f94b10f78e..f2359bbae0 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -3872742591add4e94033484c2844e7d7ab69674b \ No newline at end of file +d7211b68107ea669de39e0aa81a1be40901e1487 \ No newline at end of file diff --git a/src/resolve.c b/src/resolve.c index a7b14cd005..d66de27958 100644 --- a/src/resolve.c +++ b/src/resolve.c @@ -460,6 +460,7 @@ static int lookupName( if( cnt==0 && zTab==0 && ExprHasProperty(pExpr,EP_DblQuoted) ){ pExpr->op = TK_STRING; pExpr->pTab = 0; + pExpr->iTable = -1; return WRC_Prune; } diff --git a/test/misc1.test b/test/misc1.test index 0f4881fb61..1b98eafc6a 100644 --- a/test/misc1.test +++ b/test/misc1.test @@ -639,4 +639,9 @@ do_catchsql_test misc1-21.2 { VALUES(0,0x0MATCH#0; } {1 {near ";": syntax error}} +# 2015-04-15 +do_execsql_test misc1-22.1 { + SELECT ""+3 FROM (SELECT ""+5); +} {3} + finish_test From 1978d171cb1f64765b18c81ad3d8bde62c2d434c Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 15 Apr 2015 05:20:44 +0000 Subject: [PATCH 107/181] When adding the implied "LIMIT 1" to the end of a scalar subquery, make sure that subquery is not a VALUES-only query as such queries cannot deal with LIMIT clauses. FossilOrigin-Name: 7c27310bdf6b4af44a0811a2787ed64966d720d2 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/expr.c | 1 + test/select4.test | 7 +++++++ 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index c64b26440d..3a48ca3967 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C When\sdoing\sthe\s(dubious)\sconversion\sof\sdouble-quoted\sidentifier\sinto\sstring\nliteral\sfor\sMySQL\scompatibility,\sbe\ssure\sto\salso\sclear\sthe\siTable\svalue\sfrom\nthe\sExpr\sentry\sto\savoid\san\sassert. -D 2015-04-15T04:51:28.676 +C When\sadding\sthe\simplied\s"LIMIT\s1"\sto\sthe\send\sof\sa\sscalar\ssubquery,\smake\ssure\nthat\ssubquery\sis\snot\sa\sVALUES-only\squery\sas\ssuch\squeries\scannot\sdeal\swith\nLIMIT\sclauses. +D 2015-04-15T05:20:44.109 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5f78b1ab81b64e7c57a75d170832443e66c0880a F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -182,7 +182,7 @@ F src/complete.c a5cf5b4b56390cfb7b8636e8f7ddef90258dd575 F src/ctime.c 98f89724adc891a1a4c655bee04e33e716e05887 F src/date.c e4d50b3283696836ec1036b695ead9a19e37a5ac F src/delete.c 37964e6c1d73ff49cbea9ff690c9605fb15f600e -F src/expr.c aba4f0547aac1fcbd965d548ab2e36efd5a4481c +F src/expr.c 8800584340a9b4f4c0ca55c360de751c6da0b11a F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb F src/fkey.c 3343d551a8d810782257244fb33f2ce191493c39 F src/func.c 1414c24c873c48796ad45942257a179a423ba42f @@ -839,7 +839,7 @@ F test/securedel2.test 2d54c28e46eb1fd6902089958b20b1b056c6f1c5 F test/select1.test fc2a61f226a649393664ad54bc5376631801517c F test/select2.test 352480e0e9c66eda9c3044e412abdf5be0215b56 F test/select3.test 2ce595f8fb8e2ac10071d3b4e424cadd4634a054 -F test/select4.test e20e8ce47b558de80616102ef273704cf0d48a3b +F test/select4.test af938bb5f55c6f3925047fc7cd837c894566f5db F test/select5.test e758b8ef94f69b111df4cb819008856655dcd535 F test/select6.test 39eac4a5c03650b2b473c532882273283ee8b7a0 F test/select7.test 7fd2ef598cfabb6b9ff6ac13973b91d0527df49d @@ -1250,7 +1250,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 3872742591add4e94033484c2844e7d7ab69674b -R 3d936303913ff5357294410059be6467 +P d7211b68107ea669de39e0aa81a1be40901e1487 +R 880c9defd1fb09406a80bcc7ed2c9c3e U drh -Z adb676b9f25e7eed8c83dbf9762c49f4 +Z 868124641765b45b984dc6b337325865 diff --git a/manifest.uuid b/manifest.uuid index f2359bbae0..783f8ed725 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -d7211b68107ea669de39e0aa81a1be40901e1487 \ No newline at end of file +7c27310bdf6b4af44a0811a2787ed64966d720d2 \ No newline at end of file diff --git a/src/expr.c b/src/expr.c index 6a30755aa5..77eb35aa74 100644 --- a/src/expr.c +++ b/src/expr.c @@ -2016,6 +2016,7 @@ int sqlite3CodeSubselect( pSel->pLimit = sqlite3PExpr(pParse, TK_INTEGER, 0, 0, &sqlite3IntTokens[1]); pSel->iLimit = 0; + pSel->selFlags &= ~SF_AllValues; if( sqlite3Select(pParse, pSel, &dest) ){ return 0; } diff --git a/test/select4.test b/test/select4.test index 47a44081f4..71171def33 100644 --- a/test/select4.test +++ b/test/select4.test @@ -863,5 +863,12 @@ do_execsql_test select4-14.8 { do_execsql_test select4-14.9 { SELECT * FROM t14 UNION ALL VALUES(3,2,1),(2,3,1),(1,2,3),(2,1,3); } {1 2 3 4 5 6 3 2 1 2 3 1 1 2 3 2 1 3} +do_execsql_test select4-14.10 { + SELECT (VALUES(1),(2),(3),(4)) +} {1} +do_execsql_test select4-14.11 { + SELECT (SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4) +} {1} + finish_test From 65df68e8c56bf3b79a31a7a1e853f4067998e207 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 15 Apr 2015 05:31:02 +0000 Subject: [PATCH 108/181] Correctly deal with an unknown collating sequence on an indexed DISTINCT query. FossilOrigin-Name: a0b6e2fed3e95cf78ed0515c6e4da7510af4e86a --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/where.c | 2 +- test/collate3.test | 7 ++++++- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index 3a48ca3967..2b31601281 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C When\sadding\sthe\simplied\s"LIMIT\s1"\sto\sthe\send\sof\sa\sscalar\ssubquery,\smake\ssure\nthat\ssubquery\sis\snot\sa\sVALUES-only\squery\sas\ssuch\squeries\scannot\sdeal\swith\nLIMIT\sclauses. -D 2015-04-15T05:20:44.109 +C Correctly\sdeal\swith\san\sunknown\scollating\ssequence\son\san\sindexed\sDISTINCT\squery. +D 2015-04-15T05:31:02.899 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5f78b1ab81b64e7c57a75d170832443e66c0880a F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -307,7 +307,7 @@ F src/vxworks.h c18586c8edc1bddbc15c004fa16aeb1e1342b4fb F src/wal.c 753995db83247f20361a8e8a874990b21a75abd9 F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4 F src/walker.c c253b95b4ee44b21c406e2a1052636c31ea27804 -F src/where.c 9952e4749f481707595692f2f13d3ce3b64ffdc8 +F src/where.c 8a05434f5a75a38c64c45e316b00167ba0fd7ad3 F src/whereInt.h cbe4aa57326998d89e7698ca65bb7c28541d483c F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2 @@ -401,7 +401,7 @@ F test/closure01.test b1703ba40639cfc9b295cf478d70739415eec6a4 F test/coalesce.test cee0dccb9fbd2d494b77234bccf9dc6c6786eb91 F test/collate1.test 7fcfe78f9613dc4a7e247d6bd27749955f108741 F test/collate2.test 9aaa410a00734e48bcb27f3872617d6f69b2a621 -F test/collate3.test 79558a286362cb9ed603c6fa543f1cda7f563f0f +F test/collate3.test 89defc49983ddfbf0a0555aca8c0521a676f56a5 F test/collate4.test f04d5168685f2eef637ecfa2d4ddf8ec0d600177 F test/collate5.test 65d928034d30d2d263a80f6359f7549ee1598ec6 F test/collate6.test 8be65a182abaac8011a622131486dafb8076e907 @@ -1250,7 +1250,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 d7211b68107ea669de39e0aa81a1be40901e1487 -R 880c9defd1fb09406a80bcc7ed2c9c3e +P 7c27310bdf6b4af44a0811a2787ed64966d720d2 +R 97d8aa531c1ae9c06ffcd147c2fe4f6f U drh -Z 868124641765b45b984dc6b337325865 +Z 3a34d92eb0e2b45ff65d57bcfcec8b05 diff --git a/manifest.uuid b/manifest.uuid index 783f8ed725..4b837de064 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -7c27310bdf6b4af44a0811a2787ed64966d720d2 \ No newline at end of file +a0b6e2fed3e95cf78ed0515c6e4da7510af4e86a \ No newline at end of file diff --git a/src/where.c b/src/where.c index 42e950e41e..e1c5f4ecaa 100644 --- a/src/where.c +++ b/src/where.c @@ -1532,7 +1532,7 @@ static int findIndexCol( && p->iTable==iBase ){ CollSeq *pColl = sqlite3ExprCollSeq(pParse, pList->a[i].pExpr); - if( ALWAYS(pColl) && 0==sqlite3StrICmp(pColl->zName, zColl) ){ + if( pColl && 0==sqlite3StrICmp(pColl->zName, zColl) ){ return i; } } diff --git a/test/collate3.test b/test/collate3.test index 2c051cb9a7..99640d05b8 100644 --- a/test/collate3.test +++ b/test/collate3.test @@ -32,7 +32,7 @@ source $testdir/tester.tcl # do_test collate3-1.0 { execsql { - CREATE TABLE collate3t1(c1); + CREATE TABLE collate3t1(c1 UNIQUE); } } {} do_test collate3-1.1 { @@ -40,6 +40,11 @@ do_test collate3-1.1 { SELECT * FROM collate3t1 ORDER BY 1 collate garbage; } } {1 {no such collation sequence: garbage}} +do_test collate3-1.1.2 { + catchsql { + SELECT DISTINCT c1 COLLATE garbage FROM collate3t1; + } +} {1 {no such collation sequence: garbage}} do_test collate3-1.2 { catchsql { CREATE TABLE collate3t2(c1 collate garbage); From 3457338ced7a521be2fb0aab1808648128a3d43e Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 15 Apr 2015 05:38:35 +0000 Subject: [PATCH 109/181] Fix a faulty assert() in the sqlite3StrAccumAppend() routine. FossilOrigin-Name: 998cfdb8dcda2cac94b83326751e16dcef8b267f --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/printf.c | 2 +- test/printf2.test | 3 +++ 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 2b31601281..94e960af32 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Correctly\sdeal\swith\san\sunknown\scollating\ssequence\son\san\sindexed\sDISTINCT\squery. -D 2015-04-15T05:31:02.899 +C Fix\sa\sfaulty\sassert()\sin\sthe\ssqlite3StrAccumAppend()\sroutine. +D 2015-04-15T05:38:35.928 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5f78b1ab81b64e7c57a75d170832443e66c0880a F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -226,7 +226,7 @@ F src/pcache1.c 69d137620a305f814398bd29a0c998038c0695e9 F src/pragma.c ac4f3f856b4234e85f55b0f069698a4766011100 F src/pragma.h 09c89bca58e9a44de2116cc8272b8d454657129f F src/prepare.c 173a5a499138451b2561614ecb87d78f9f4644b9 -F src/printf.c 8ae1fa9d30c1200a9268a390ba9e9cea9197b27a +F src/printf.c 08fa675c200aac29e561c6153f91f909ed17612f F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c 7bd67ded824a2fe8b356cd45e053d9c94b1874c2 F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e @@ -798,7 +798,7 @@ F test/pragma.test ad99d05e411c7687302124be56f3b362204be041 F test/pragma2.test f624a496a95ee878e81e59961eade66d5c00c028 F test/pragma3.test 6f849ccffeee7e496d2f2b5e74152306c0b8757c F test/printf.test b3ff34e73d59124140eaf89f7672e21bc2ca5fcc -F test/printf2.test b4acd4bf8734243257f01ddefa17c4fb090acc8a +F test/printf2.test 0b61566dd1c0f0b802f59dffa228c5dc5aa6b054 F test/progress.test a282973d1d17f08071bc58a77d6b80f2a81c354d F test/ptrchng.test ef1aa72d6cf35a2bbd0869a649b744e9d84977fc F test/queryonly.test 5f653159e0f552f0552d43259890c1089391dcca @@ -1250,7 +1250,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 7c27310bdf6b4af44a0811a2787ed64966d720d2 -R 97d8aa531c1ae9c06ffcd147c2fe4f6f +P a0b6e2fed3e95cf78ed0515c6e4da7510af4e86a +R bd008e3cfd1613a5e1f1a28458fbfaad U drh -Z 3a34d92eb0e2b45ff65d57bcfcec8b05 +Z cf565eb6ae4e94564c05e7f944eb18e5 diff --git a/manifest.uuid b/manifest.uuid index 4b837de064..1adef81d5f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -a0b6e2fed3e95cf78ed0515c6e4da7510af4e86a \ No newline at end of file +998cfdb8dcda2cac94b83326751e16dcef8b267f \ No newline at end of file diff --git a/src/printf.c b/src/printf.c index 9714fa1565..1a978dc5ca 100644 --- a/src/printf.c +++ b/src/printf.c @@ -826,7 +826,7 @@ static void SQLITE_NOINLINE enlargeAndAppend(StrAccum *p, const char *z, int N){ ** size of the memory allocation for StrAccum if necessary. */ void sqlite3StrAccumAppend(StrAccum *p, const char *z, int N){ - assert( z!=0 ); + assert( z!=0 || N==0 ); assert( p->zText!=0 || p->nChar==0 || p->accError ); assert( N>=0 ); assert( p->accError==0 || p->nAlloc==0 ); diff --git a/test/printf2.test b/test/printf2.test index 21deeb779d..fb031bd68f 100644 --- a/test/printf2.test +++ b/test/printf2.test @@ -58,6 +58,9 @@ do_execsql_test printf2-1.10 { do_execsql_test printf2-1.11 { SELECT printf('%lld%n',314159.2653,'hi'); } {314159} +do_execsql_test printf2-1.12 { + SELECT printf('%n',0); +} {{}} # EVIDENCE-OF: R-17002-27534 The %z format is interchangeable with %s. # From 6456b7710c1ff87a5a6b6f58a8d1471a16553434 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 15 Apr 2015 05:57:50 +0000 Subject: [PATCH 110/181] Correctly handle COLLATE operators applied to COLLATE operators in an ORDER BY clause. FossilOrigin-Name: 9e1f837b08facbc7a2b6196770599a58233e725c --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/resolve.c | 8 +++++--- test/collate1.test | 18 ++++++++++++++++-- 4 files changed, 29 insertions(+), 13 deletions(-) diff --git a/manifest b/manifest index 94e960af32..355bd09e61 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sfaulty\sassert()\sin\sthe\ssqlite3StrAccumAppend()\sroutine. -D 2015-04-15T05:38:35.928 +C Correctly\shandle\sCOLLATE\soperators\sapplied\sto\sCOLLATE\soperators\sin\san\nORDER\sBY\sclause. +D 2015-04-15T05:57:50.327 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5f78b1ab81b64e7c57a75d170832443e66c0880a F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -228,7 +228,7 @@ F src/pragma.h 09c89bca58e9a44de2116cc8272b8d454657129f F src/prepare.c 173a5a499138451b2561614ecb87d78f9f4644b9 F src/printf.c 08fa675c200aac29e561c6153f91f909ed17612f F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 -F src/resolve.c 7bd67ded824a2fe8b356cd45e053d9c94b1874c2 +F src/resolve.c 03fe2a8640b7f1477e6cbca6f3bc1b5549263a47 F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e F src/select.c 117e0f9ac9254a6f7472fac5144eba21ba0b2ec1 F src/shell.c 84a1593bd86aaa14f4da8a8f9b16fbc239d262aa @@ -399,7 +399,7 @@ F test/check.test 5831ddb6f2c687782eaf2e1a07b6e17f24c4f763 F test/close.test 340bd24cc58b16c6bc01967402755027c37eb815 F test/closure01.test b1703ba40639cfc9b295cf478d70739415eec6a4 F test/coalesce.test cee0dccb9fbd2d494b77234bccf9dc6c6786eb91 -F test/collate1.test 7fcfe78f9613dc4a7e247d6bd27749955f108741 +F test/collate1.test 08c18e7512a5a32c97938854263fa15362eeb846 F test/collate2.test 9aaa410a00734e48bcb27f3872617d6f69b2a621 F test/collate3.test 89defc49983ddfbf0a0555aca8c0521a676f56a5 F test/collate4.test f04d5168685f2eef637ecfa2d4ddf8ec0d600177 @@ -1250,7 +1250,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 a0b6e2fed3e95cf78ed0515c6e4da7510af4e86a -R bd008e3cfd1613a5e1f1a28458fbfaad +P 998cfdb8dcda2cac94b83326751e16dcef8b267f +R 365a6b3d3d3943322095f384b9ee1504 U drh -Z cf565eb6ae4e94564c05e7f944eb18e5 +Z eaf1d275b82a1bdf74f8de064c4444e7 diff --git a/manifest.uuid b/manifest.uuid index 1adef81d5f..a0184f5e23 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -998cfdb8dcda2cac94b83326751e16dcef8b267f \ No newline at end of file +9e1f837b08facbc7a2b6196770599a58233e725c \ No newline at end of file diff --git a/src/resolve.c b/src/resolve.c index d66de27958..aa4cddfef2 100644 --- a/src/resolve.c +++ b/src/resolve.c @@ -994,9 +994,11 @@ static int resolveCompoundOrderBy( if( pItem->pExpr==pE ){ pItem->pExpr = pNew; }else{ - assert( pItem->pExpr->op==TK_COLLATE ); - assert( pItem->pExpr->pLeft==pE ); - pItem->pExpr->pLeft = pNew; + Expr *pParent = pItem->pExpr; + assert( pParent->op==TK_COLLATE ); + while( pParent->pLeft->op==TK_COLLATE ) pParent = pParent->pLeft; + assert( pParent->pLeft==pE ); + pParent->pLeft = pNew; } sqlite3ExprDelete(db, pE); pItem->u.x.iOrderByCol = (u16)iCol; diff --git a/test/collate1.test b/test/collate1.test index 0716ac743f..7cf5698454 100644 --- a/test/collate1.test +++ b/test/collate1.test @@ -385,6 +385,20 @@ do_execsql_test 6.8 { SELECT x, y FROM c1 ORDER BY y COLLATE """"""""; } {2 abb 1 ABC 4 WXY 3 wxz} +# 2015-04-15: Nested COLLATE operators +# +do_execsql_test 7.0 { + SELECT 'abc' UNION ALL SELECT 'DEF' + ORDER BY 1 COLLATE nocase COLLATE nocase COLLATE nocase COLLATE nocase; +} {abc DEF} +do_execsql_test 7.1 { + SELECT 'abc' UNION ALL SELECT 'DEF' + ORDER BY 1 COLLATE nocase COLLATE nocase COLLATE nocase COLLATE binary; +} {DEF abc} +do_execsql_test 7.2 { + SELECT 'abc' UNION ALL SELECT 'DEF' + ORDER BY 1 COLLATE binary COLLATE binary COLLATE binary COLLATE nocase; +} {abc DEF} + + finish_test - - From a43f02efc613826511132be78c9445e239f91ddd Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 15 Apr 2015 06:45:13 +0000 Subject: [PATCH 111/181] Fix a faulty assert() statement in the name resolver associated with the optimization that converts compound selects with ORDER BY COLLATE into subqueries. FossilOrigin-Name: c72324ef9243946550ae3d974826502b1cc5eb10 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/resolve.c | 2 +- test/selectE.test | 5 +++++ 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 355bd09e61..b179c36ad3 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Correctly\shandle\sCOLLATE\soperators\sapplied\sto\sCOLLATE\soperators\sin\san\nORDER\sBY\sclause. -D 2015-04-15T05:57:50.327 +C Fix\sa\sfaulty\sassert()\sstatement\sin\sthe\sname\sresolver\sassociated\swith\sthe\noptimization\sthat\sconverts\scompound\sselects\swith\sORDER\sBY\sCOLLATE\sinto\nsubqueries. +D 2015-04-15T06:45:13.856 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5f78b1ab81b64e7c57a75d170832443e66c0880a F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -228,7 +228,7 @@ F src/pragma.h 09c89bca58e9a44de2116cc8272b8d454657129f F src/prepare.c 173a5a499138451b2561614ecb87d78f9f4644b9 F src/printf.c 08fa675c200aac29e561c6153f91f909ed17612f F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 -F src/resolve.c 03fe2a8640b7f1477e6cbca6f3bc1b5549263a47 +F src/resolve.c 66cfe49a9c3b449ef13b89a8c47036a4ed167eab F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e F src/select.c 117e0f9ac9254a6f7472fac5144eba21ba0b2ec1 F src/shell.c 84a1593bd86aaa14f4da8a8f9b16fbc239d262aa @@ -849,7 +849,7 @@ F test/selectA.test e452bdb975f488ea46d091382a9185b5853ed2c7 F test/selectB.test 954e4e49cf1f896d61794e440669e03a27ceea25 F test/selectC.test 871fb55d884d3de5943c4057ebd22c2459e71977 F test/selectD.test b0f02a04ef7737decb24e08be2c39b9664b43394 -F test/selectE.test fc02a1eb04c8eb537091482644b7d778ae8759b7 +F test/selectE.test a8730ca330fcf40ace158f134f4fe0eb00c7edbf F test/selectF.test 21c94e6438f76537b72532fa9fd4710cdd455fc3 F test/selectG.test e8600e379589e85e9fefd2fe4d44a4cdd63f6982 F test/server1.test 46803bd3fe8b99b30dbc5ff38ffc756f5c13a118 @@ -1250,7 +1250,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 998cfdb8dcda2cac94b83326751e16dcef8b267f -R 365a6b3d3d3943322095f384b9ee1504 +P 9e1f837b08facbc7a2b6196770599a58233e725c +R d99053241fb4278349e47e2aa3bd86a0 U drh -Z eaf1d275b82a1bdf74f8de064c4444e7 +Z d2955d105f5f67e57ae3e9b26664c585 diff --git a/manifest.uuid b/manifest.uuid index a0184f5e23..3d0d30286b 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -9e1f837b08facbc7a2b6196770599a58233e725c \ No newline at end of file +c72324ef9243946550ae3d974826502b1cc5eb10 \ No newline at end of file diff --git a/src/resolve.c b/src/resolve.c index aa4cddfef2..6294ba26e1 100644 --- a/src/resolve.c +++ b/src/resolve.c @@ -1198,7 +1198,7 @@ static int resolveSelectStep(Walker *pWalker, Select *p){ ** after the names have been resolved. */ if( p->selFlags & SF_Converted ){ Select *pSub = p->pSrc->a[0].pSelect; - assert( p->pSrc->nSrc==1 && isCompound==0 && p->pOrderBy ); + assert( p->pSrc->nSrc==1 && p->pOrderBy ); assert( pSub->pPrior && pSub->pOrderBy==0 ); pSub->pOrderBy = p->pOrderBy; p->pOrderBy = 0; diff --git a/test/selectE.test b/test/selectE.test index d7592bbbc5..1cabeff370 100644 --- a/test/selectE.test +++ b/test/selectE.test @@ -92,4 +92,9 @@ do_test selectE-2.2 { } } {} +do_catchsql_test selectE-3.1 { + SELECT 1 EXCEPT SELECT 2 ORDER BY 1 COLLATE nocase EXCEPT SELECT 3; +} {1 {ORDER BY clause should come after EXCEPT not before}} + + finish_test From 3dc4cc66b3a7ff48cff042751a5e9eee41b08f24 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 15 Apr 2015 07:10:25 +0000 Subject: [PATCH 112/181] Change the multiSelectOrderBy() routine to return non-zero if there has been any prior error. FossilOrigin-Name: 14784c317bff05dd0a74e2596432dfd12c139391 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/select.c | 2 +- test/select4.test | 5 +++++ 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index b179c36ad3..8fb373a6c9 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sfaulty\sassert()\sstatement\sin\sthe\sname\sresolver\sassociated\swith\sthe\noptimization\sthat\sconverts\scompound\sselects\swith\sORDER\sBY\sCOLLATE\sinto\nsubqueries. -D 2015-04-15T06:45:13.856 +C Change\sthe\smultiSelectOrderBy()\sroutine\sto\sreturn\snon-zero\sif\sthere\shas\nbeen\sany\sprior\serror. +D 2015-04-15T07:10:25.034 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5f78b1ab81b64e7c57a75d170832443e66c0880a F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -230,7 +230,7 @@ F src/printf.c 08fa675c200aac29e561c6153f91f909ed17612f F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c 66cfe49a9c3b449ef13b89a8c47036a4ed167eab F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e -F src/select.c 117e0f9ac9254a6f7472fac5144eba21ba0b2ec1 +F src/select.c 93260bc9e7e0e6dfe1b7cb8815b0ed4cad8be9e3 F src/shell.c 84a1593bd86aaa14f4da8a8f9b16fbc239d262aa F src/sqlite.h.in ca27603a36fcacdaac5a19d8ee35aaff8ce8516f F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad @@ -839,7 +839,7 @@ F test/securedel2.test 2d54c28e46eb1fd6902089958b20b1b056c6f1c5 F test/select1.test fc2a61f226a649393664ad54bc5376631801517c F test/select2.test 352480e0e9c66eda9c3044e412abdf5be0215b56 F test/select3.test 2ce595f8fb8e2ac10071d3b4e424cadd4634a054 -F test/select4.test af938bb5f55c6f3925047fc7cd837c894566f5db +F test/select4.test 16fa1cafb942f42294ec85cbb78954c2f2d15a44 F test/select5.test e758b8ef94f69b111df4cb819008856655dcd535 F test/select6.test 39eac4a5c03650b2b473c532882273283ee8b7a0 F test/select7.test 7fd2ef598cfabb6b9ff6ac13973b91d0527df49d @@ -1250,7 +1250,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 9e1f837b08facbc7a2b6196770599a58233e725c -R d99053241fb4278349e47e2aa3bd86a0 +P c72324ef9243946550ae3d974826502b1cc5eb10 +R a18a17a9c69cd2c9e7e0fb3024e1e22e U drh -Z d2955d105f5f67e57ae3e9b26664c585 +Z 56fd45c34ac20b50b5d25609e083b049 diff --git a/manifest.uuid b/manifest.uuid index 3d0d30286b..b9b981e38f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c72324ef9243946550ae3d974826502b1cc5eb10 \ No newline at end of file +14784c317bff05dd0a74e2596432dfd12c139391 \ No newline at end of file diff --git a/src/select.c b/src/select.c index 930a099e80..bed1f80be0 100644 --- a/src/select.c +++ b/src/select.c @@ -3071,7 +3071,7 @@ static int multiSelectOrderBy( /*** TBD: Insert subroutine calls to close cursors on incomplete **** subqueries ****/ explainComposite(pParse, p->op, iSub1, iSub2, 0); - return SQLITE_OK; + return pParse->nErr!=0; } #endif diff --git a/test/select4.test b/test/select4.test index 71171def33..2f3ddbe96a 100644 --- a/test/select4.test +++ b/test/select4.test @@ -799,6 +799,11 @@ do_test select4-11.15 { SELECT x FROM t2 } } {1 {SELECTs to the left and right of UNION do not have the same number of result columns}} +do_test select4-11.16 { + catchsql { + INSERT INTO t2(rowid) VALUES(2) UNION SELECT 3,4 UNION SELECT 5,6 ORDER BY 1; + } +} {1 {SELECTs to the left and right of UNION do not have the same number of result columns}} do_test select4-12.1 { sqlite3 db2 :memory: From 1b6789697d13ab232b99f8064b0d106c6b5184a0 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 15 Apr 2015 07:19:27 +0000 Subject: [PATCH 113/181] Remove an incorrect ALWAYS() from the table_info pragma. FossilOrigin-Name: 0e087c0183bc7a758cf2a1d39158bc24fde833a2 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/pragma.c | 2 +- test/pragma.test | 10 ++++++++++ 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 8fb373a6c9..82ef7926f4 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Change\sthe\smultiSelectOrderBy()\sroutine\sto\sreturn\snon-zero\sif\sthere\shas\nbeen\sany\sprior\serror. -D 2015-04-15T07:10:25.034 +C Remove\san\sincorrect\sALWAYS()\sfrom\sthe\stable_info\spragma. +D 2015-04-15T07:19:27.406 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5f78b1ab81b64e7c57a75d170832443e66c0880a F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -223,7 +223,7 @@ F src/parse.y 1299c66e7b1707322ccd8af43a359b8fb0d46d72 F src/pcache.c 10539fb959849ad6efff80050541cab3d25089d4 F src/pcache.h b44658c9c932d203510279439d891a2a83e12ba8 F src/pcache1.c 69d137620a305f814398bd29a0c998038c0695e9 -F src/pragma.c ac4f3f856b4234e85f55b0f069698a4766011100 +F src/pragma.c 3965ae4e82bed39fb97ce04c5fe18c9bc3ee6a88 F src/pragma.h 09c89bca58e9a44de2116cc8272b8d454657129f F src/prepare.c 173a5a499138451b2561614ecb87d78f9f4644b9 F src/printf.c 08fa675c200aac29e561c6153f91f909ed17612f @@ -794,7 +794,7 @@ F test/pcache.test b09104b03160aca0d968d99e8cd2c5b1921a993d F test/pcache2.test a83efe2dec0d392f814bfc998def1d1833942025 F test/percentile.test 4243af26b8f3f4555abe166f723715a1f74c77ff F test/permutations.test f9cc1dd987986c9d4949211c7a4ed55ec9aecba1 -F test/pragma.test ad99d05e411c7687302124be56f3b362204be041 +F test/pragma.test e6605ce89c66db930aef561e43a22281a09ffc66 F test/pragma2.test f624a496a95ee878e81e59961eade66d5c00c028 F test/pragma3.test 6f849ccffeee7e496d2f2b5e74152306c0b8757c F test/printf.test b3ff34e73d59124140eaf89f7672e21bc2ca5fcc @@ -1250,7 +1250,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 c72324ef9243946550ae3d974826502b1cc5eb10 -R a18a17a9c69cd2c9e7e0fb3024e1e22e +P 14784c317bff05dd0a74e2596432dfd12c139391 +R 275812afa820df20388de5de5b05e3ce U drh -Z 56fd45c34ac20b50b5d25609e083b049 +Z c974cc37b6f1891bf4b4ede9ca413ca2 diff --git a/manifest.uuid b/manifest.uuid index b9b981e38f..a860fba913 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -14784c317bff05dd0a74e2596432dfd12c139391 \ No newline at end of file +0e087c0183bc7a758cf2a1d39158bc24fde833a2 \ No newline at end of file diff --git a/src/pragma.c b/src/pragma.c index ef11d5840f..8f6ac64754 100644 --- a/src/pragma.c +++ b/src/pragma.c @@ -1041,7 +1041,7 @@ void sqlite3Pragma( }else if( pPk==0 ){ k = 1; }else{ - for(k=1; ALWAYS(k<=pTab->nCol) && pPk->aiColumn[k-1]!=i; k++){} + for(k=1; k<=pTab->nCol && pPk->aiColumn[k-1]!=i; k++){} } sqlite3VdbeAddOp2(v, OP_Integer, k, 6); sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 6); diff --git a/test/pragma.test b/test/pragma.test index d164702643..e8a53f442d 100644 --- a/test/pragma.test +++ b/test/pragma.test @@ -752,6 +752,16 @@ do_test pragma-6.7 { {3 four REAL 0 X'abcdef' 0} \ {4 five {} 0 CURRENT_TIME 0} \ ] +do_test pragma-6.8 { + execsql { + CREATE TABLE t68(a,b,c,PRIMARY KEY(a,b,a,c)); + PRAGMA table_info(t68); + } +} [concat \ + {0 a {} 0 {} 1} \ + {1 b {} 0 {} 2} \ + {2 c {} 0 {} 4} \ +] } ;# ifcapable schema_pragmas # Miscellaneous tests # From 29031837c19e371ae6056e2dc3efb03f3f7895b4 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 15 Apr 2015 07:34:25 +0000 Subject: [PATCH 114/181] Remove an incorrect ALWAYS() from the automatic index generator. FossilOrigin-Name: eeb4bd06bf69e411736cc6077d1d64af6bd8fb09 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/where.c | 2 +- test/autoindex1.test | 7 +++++++ 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 82ef7926f4..f61d8e0c34 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Remove\san\sincorrect\sALWAYS()\sfrom\sthe\stable_info\spragma. -D 2015-04-15T07:19:27.406 +C Remove\san\sincorrect\sALWAYS()\sfrom\sthe\sautomatic\sindex\sgenerator. +D 2015-04-15T07:34:25.165 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5f78b1ab81b64e7c57a75d170832443e66c0880a F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -307,7 +307,7 @@ F src/vxworks.h c18586c8edc1bddbc15c004fa16aeb1e1342b4fb F src/wal.c 753995db83247f20361a8e8a874990b21a75abd9 F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4 F src/walker.c c253b95b4ee44b21c406e2a1052636c31ea27804 -F src/where.c 8a05434f5a75a38c64c45e316b00167ba0fd7ad3 +F src/where.c 8ba8ff31dc9bf1b69fe771d35d8764d5a1efd310 F src/whereInt.h cbe4aa57326998d89e7698ca65bb7c28541d483c F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2 @@ -349,7 +349,7 @@ F test/auth.test 855233ef26eb3601b6886567ea4e326c72959360 F test/auth2.test 264c6af53cad9aba5218c68bbe18036e39007bfa F test/auth3.test 5cfa94ed90c6617c42b7ba4b133fd79678b251c7 F test/autoinc.test c58912526998a39e11f66b533e23cfabea7f25b7 -F test/autoindex1.test 7008c9f604141fdabe31b7bb95b5ff31b518251f +F test/autoindex1.test 14b63a9f1e405fe6d5bfc8c8d00249c2ebaf13ea F test/autoindex2.test af7e595c6864cc6ef5fc38d5db579a3e34940cb8 F test/autoindex3.test a3be0d1a53a7d2edff208a5e442312957047e972 F test/autoindex4.test 49d3cd791a9baa16fb461d7ea3de80d019a819cf @@ -1250,7 +1250,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 14784c317bff05dd0a74e2596432dfd12c139391 -R 275812afa820df20388de5de5b05e3ce +P 0e087c0183bc7a758cf2a1d39158bc24fde833a2 +R 45168c2ae417f665e937b47961f47d47 U drh -Z c974cc37b6f1891bf4b4ede9ca413ca2 +Z fe2feaff56a77a679eecea2f54332501 diff --git a/manifest.uuid b/manifest.uuid index a860fba913..2e89d53bd1 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -0e087c0183bc7a758cf2a1d39158bc24fde833a2 \ No newline at end of file +eeb4bd06bf69e411736cc6077d1d64af6bd8fb09 \ No newline at end of file diff --git a/src/where.c b/src/where.c index e1c5f4ecaa..3467a68626 100644 --- a/src/where.c +++ b/src/where.c @@ -1806,7 +1806,7 @@ static void constructAutomaticIndex( idxCols |= cMask; pIdx->aiColumn[n] = pTerm->u.leftColumn; pColl = sqlite3BinaryCompareCollSeq(pParse, pX->pLeft, pX->pRight); - pIdx->azColl[n] = ALWAYS(pColl) ? pColl->zName : "BINARY"; + pIdx->azColl[n] = pColl ? pColl->zName : "BINARY"; n++; } } diff --git a/test/autoindex1.test b/test/autoindex1.test index c5ce42c1d4..e2b8b1529e 100644 --- a/test/autoindex1.test +++ b/test/autoindex1.test @@ -512,5 +512,12 @@ do_execsql_test autoindex1-901 { WHERE t1.x IN (1,2,3); } {/USING AUTOMATIC COVERING INDEX/} +# 2015-04-15: A NULL CollSeq pointer in automatic index creation. +# +do_execsql_test autoindex1-920 { + CREATE TABLE t920(x); + INSERT INTO t920 VALUES(3),(4),(5); + SELECT * FROM t920,(SELECT 0 FROM t920),(VALUES(9)) WHERE 5 IN (x); +} {5 0 9 5 0 9 5 0 9} finish_test From 347bdc39a70e092247a3fc0c3e4e99aef24d92fe Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 15 Apr 2015 07:57:27 +0000 Subject: [PATCH 115/181] Fix the error message generator for illegal token errors so that it does not leak memory if it immediately follows another erroneous SQL statement. FossilOrigin-Name: 3576973f8b88b6109fbefdebfa53468ffa137009 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/tokenize.c | 4 +--- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index f61d8e0c34..983d068c58 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Remove\san\sincorrect\sALWAYS()\sfrom\sthe\sautomatic\sindex\sgenerator. -D 2015-04-15T07:34:25.165 +C Fix\sthe\serror\smessage\sgenerator\sfor\sillegal\stoken\serrors\sso\sthat\sit\sdoes\snot\nleak\smemory\sif\sit\simmediately\sfollows\sanother\serroneous\sSQL\sstatement. +D 2015-04-15T07:57:27.369 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5f78b1ab81b64e7c57a75d170832443e66c0880a F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -287,7 +287,7 @@ F src/test_vfs.c b7e6831e6fcf04c5090accff30640ec5c9630739 F src/test_vfstrace.c bab9594adc976cbe696ff3970728830b4c5ed698 F src/test_wsd.c 41cadfd9d97fe8e3e4e44f61a4a8ccd6f7ca8fe9 F src/threads.c 6bbcc9fe50c917864d48287b4792d46d6e873481 -F src/tokenize.c a8d270b06e5f709930f7b67cf70a847969cb5bf3 +F src/tokenize.c 2b93d338833be43cba93644562e85a24ff3d97d1 F src/trigger.c 69a91bed7c94e46223e37ffccfeeb35e34b999ac F src/update.c 3c4ecc282accf12d39edb8d524cf089645e55a13 F src/utf.c fc6b889ba0779b7722634cdeaa25f1930d93820c @@ -1250,7 +1250,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 0e087c0183bc7a758cf2a1d39158bc24fde833a2 -R 45168c2ae417f665e937b47961f47d47 +P eeb4bd06bf69e411736cc6077d1d64af6bd8fb09 +R a12d30eac869033c520f48032e05590c U drh -Z fe2feaff56a77a679eecea2f54332501 +Z d83a0172461932509217291c59869b0d diff --git a/manifest.uuid b/manifest.uuid index 2e89d53bd1..ff52dd674e 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -eeb4bd06bf69e411736cc6077d1d64af6bd8fb09 \ No newline at end of file +3576973f8b88b6109fbefdebfa53468ffa137009 \ No newline at end of file diff --git a/src/tokenize.c b/src/tokenize.c index 5068742f31..a4d20c8641 100644 --- a/src/tokenize.c +++ b/src/tokenize.c @@ -430,10 +430,8 @@ int sqlite3RunParser(Parse *pParse, const char *zSql, char **pzErrMsg){ break; } case TK_ILLEGAL: { - sqlite3DbFree(db, *pzErrMsg); - *pzErrMsg = sqlite3MPrintf(db, "unrecognized token: \"%T\"", + sqlite3ErrorMsg(pParse, "unrecognized token: \"%T\"", &pParse->sLastToken); - nErr++; goto abort_parse; } case TK_SEMI: { From 2deb12be2beea8ef9f392db2bba6fab1239b9e0c Mon Sep 17 00:00:00 2001 From: dan Date: Wed, 15 Apr 2015 08:20:50 +0000 Subject: [PATCH 116/181] Fix a problem causing an assert() to fail if a snippet containing 0 tokens was requested from fts3. FossilOrigin-Name: eafd0a1e3f25f38d551603f177ff4634cf79de77 --- ext/fts3/fts3.c | 2 ++ manifest | 16 ++++++++-------- manifest.uuid | 2 +- test/fts3snippet.test | 19 +++++++++++++++++++ 4 files changed, 30 insertions(+), 9 deletions(-) diff --git a/ext/fts3/fts3.c b/ext/fts3/fts3.c index 42b9663a1b..eb62c195df 100644 --- a/ext/fts3/fts3.c +++ b/ext/fts3/fts3.c @@ -3527,6 +3527,8 @@ static void fts3SnippetFunc( } if( !zEllipsis || !zEnd || !zStart ){ sqlite3_result_error_nomem(pContext); + }else if( nToken==0 ){ + sqlite3_result_text(pContext, "", -1, SQLITE_STATIC); }else if( SQLITE_OK==fts3CursorSeek(pContext, pCsr) ){ sqlite3Fts3Snippet(pContext, pCsr, zStart, zEnd, zEllipsis, iCol, nToken); } diff --git a/manifest b/manifest index 983d068c58..f9c5dae3b3 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sthe\serror\smessage\sgenerator\sfor\sillegal\stoken\serrors\sso\sthat\sit\sdoes\snot\nleak\smemory\sif\sit\simmediately\sfollows\sanother\serroneous\sSQL\sstatement. -D 2015-04-15T07:57:27.369 +C Fix\sa\sproblem\scausing\san\sassert()\sto\sfail\sif\sa\ssnippet\scontaining\s0\stokens\swas\srequested\sfrom\sfts3. +D 2015-04-15T08:20:50.158 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5f78b1ab81b64e7c57a75d170832443e66c0880a F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -78,7 +78,7 @@ F ext/fts3/README.content fdc666a70d5257a64fee209f97cf89e0e6e32b51 F ext/fts3/README.syntax a19711dc5458c20734b8e485e75fb1981ec2427a F ext/fts3/README.tokenizers e0a8b81383ea60d0334d274fadf305ea14a8c314 F ext/fts3/README.txt 8c18f41574404623b76917b9da66fcb0ab38328d -F ext/fts3/fts3.c 57d863c3bd360e575ecc293570af7c9b0bdd2209 +F ext/fts3/fts3.c ed6624d7c5fb5aee5d47f884b2d184169fa7a7d4 F ext/fts3/fts3.h 3a10a0af180d502cecc50df77b1b22df142817fe F ext/fts3/fts3Int.h 394858c12a17740f7a1f6bd372c4606d4425a8d1 F ext/fts3/fts3_aux.c 5c211e17a64885faeb16b9ba7772f9d5445c2365 @@ -599,7 +599,7 @@ F test/fts3prefix2.test e1f0a822ca661dced7f12ce392e14eaf65609dce F test/fts3query.test c838b18f2b859e15fd31c64be3d79ef1556803ca F test/fts3rnd.test 1320d8826a845e38a96e769562bf83d7a92a15d0 F test/fts3shared.test 57e26a801f21027b7530da77db54286a6fe4997e -F test/fts3snippet.test 03c2f3be7d3b7c8bb105ed237f204833392bd57f +F test/fts3snippet.test 63dbd687d5bf5191f1b8e6a0977aa9c1e28a7004 F test/fts3sort.test ed34c716a11cc2009a35210e84ad5f9c102362ca F test/fts3tok1.test c551043de056b0b1582a54e878991f57bad074bc F test/fts3tok_err.test 52273cd193b9036282f7bacb43da78c6be87418d @@ -1250,7 +1250,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 eeb4bd06bf69e411736cc6077d1d64af6bd8fb09 -R a12d30eac869033c520f48032e05590c -U drh -Z d83a0172461932509217291c59869b0d +P 3576973f8b88b6109fbefdebfa53468ffa137009 +R 3265dd5ed99bf273b3517690abeeedc9 +U dan +Z a6b618f03dfa759db2c6c3b930aa2a83 diff --git a/manifest.uuid b/manifest.uuid index ff52dd674e..e0df72f85f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -3576973f8b88b6109fbefdebfa53468ffa137009 \ No newline at end of file +eafd0a1e3f25f38d551603f177ff4634cf79de77 \ No newline at end of file diff --git a/test/fts3snippet.test b/test/fts3snippet.test index e97db586e6..4e1d123b2f 100644 --- a/test/fts3snippet.test +++ b/test/fts3snippet.test @@ -538,6 +538,25 @@ do_execsql_test 3.4 { SELECT snippet(t3) FROM t3 WHERE t3 MATCH 'one OR two OR three'; } {{[one two three]}} +#------------------------------------------------------------------------- +# Request a snippet 0 tokens in size. This is always an empty string. +do_execsql_test 4.1 { + CREATE VIRTUAL TABLE t4 USING fts4; + INSERT INTO t4 VALUES('a b c d'); + SELECT snippet(t4, '[', ']', '...', 0, 0) FROM t4 WHERE t4 MATCH 'b'; +} {{}} + +do_test 4.2 { + set x35 [string trim [string repeat "x " 35]] + execsql "INSERT INTO t4 VALUES('$x35 E $x35 F $x35 G $x35');" + llength [db one { + SELECT snippet(t4, '', '', '', 0, 64) FROM t4 WHERE t4 MATCH 'E' + }] +} {64} + + + + set sqlite_fts3_enable_parentheses 0 finish_test From 0be0cf672183a6767439657e0312e4b388a2d7c8 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 15 Apr 2015 08:37:42 +0000 Subject: [PATCH 117/181] Remove a branch that became unreachable due to one of the earlier check-ins today. FossilOrigin-Name: fa0956edf866f48f448967836709a3ad822ff917 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/tokenize.c | 3 ++- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index f9c5dae3b3..5fed9110db 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sproblem\scausing\san\sassert()\sto\sfail\sif\sa\ssnippet\scontaining\s0\stokens\swas\srequested\sfrom\sfts3. -D 2015-04-15T08:20:50.158 +C Remove\sa\sbranch\sthat\sbecame\sunreachable\sdue\sto\sone\sof\sthe\searlier\scheck-ins\ntoday. +D 2015-04-15T08:37:42.853 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5f78b1ab81b64e7c57a75d170832443e66c0880a F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -287,7 +287,7 @@ F src/test_vfs.c b7e6831e6fcf04c5090accff30640ec5c9630739 F src/test_vfstrace.c bab9594adc976cbe696ff3970728830b4c5ed698 F src/test_wsd.c 41cadfd9d97fe8e3e4e44f61a4a8ccd6f7ca8fe9 F src/threads.c 6bbcc9fe50c917864d48287b4792d46d6e873481 -F src/tokenize.c 2b93d338833be43cba93644562e85a24ff3d97d1 +F src/tokenize.c a8234a67577308935cdf13e618cd66556f5f45d1 F src/trigger.c 69a91bed7c94e46223e37ffccfeeb35e34b999ac F src/update.c 3c4ecc282accf12d39edb8d524cf089645e55a13 F src/utf.c fc6b889ba0779b7722634cdeaa25f1930d93820c @@ -1250,7 +1250,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 3576973f8b88b6109fbefdebfa53468ffa137009 -R 3265dd5ed99bf273b3517690abeeedc9 -U dan -Z a6b618f03dfa759db2c6c3b930aa2a83 +P eafd0a1e3f25f38d551603f177ff4634cf79de77 +R cd3636389f675a46c2832548029faa61 +U drh +Z 0baf8e6f8836d6dbdde447c335370222 diff --git a/manifest.uuid b/manifest.uuid index e0df72f85f..0fa4f22d90 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -eafd0a1e3f25f38d551603f177ff4634cf79de77 \ No newline at end of file +fa0956edf866f48f448967836709a3ad822ff917 \ No newline at end of file diff --git a/src/tokenize.c b/src/tokenize.c index a4d20c8641..2f8fd98ede 100644 --- a/src/tokenize.c +++ b/src/tokenize.c @@ -449,7 +449,8 @@ int sqlite3RunParser(Parse *pParse, const char *zSql, char **pzErrMsg){ } } abort_parse: - if( zSql[i]==0 && nErr==0 && pParse->rc==SQLITE_OK ){ + assert( nErr==0 ); + if( zSql[i]==0 && pParse->rc==SQLITE_OK ){ if( lastTokenParsed!=TK_SEMI ){ sqlite3Parser(pEngine, TK_SEMI, pParse->sLastToken, pParse); pParse->zTail = &zSql[i]; From 0d01ec8de83b4e0d7523d67c5f92a44f0ba79b8e Mon Sep 17 00:00:00 2001 From: dan Date: Wed, 15 Apr 2015 09:16:39 +0000 Subject: [PATCH 118/181] Remove an incorrect assert() statement from sqlite3Fts3Dequote(). FossilOrigin-Name: bd06eeb8d06237dc2d54d8a03e8bf525cb811c9e --- ext/fts3/fts3.c | 9 ++++++++- ext/fts3/fts3Int.h | 5 +++++ manifest | 18 +++++++++--------- manifest.uuid | 2 +- test/fts3tok1.test | 10 ++++++++++ 5 files changed, 33 insertions(+), 11 deletions(-) diff --git a/ext/fts3/fts3.c b/ext/fts3/fts3.c index eb62c195df..eab8ad63ad 100644 --- a/ext/fts3/fts3.c +++ b/ext/fts3/fts3.c @@ -313,6 +313,13 @@ static int fts3EvalStart(Fts3Cursor *pCsr); static int fts3TermSegReaderCursor( Fts3Cursor *, const char *, int, int, Fts3MultiSegReader **); +#ifndef SQLITE_AMALGAMATION +# if defined(SQLITE_DEBUG) +int sqlite3Fts3Always(int b) { assert( b ); return b; } +int sqlite3Fts3Never(int b) { assert( !b ); return b; } +# endif +#endif + /* ** Write a 64-bit variable-length integer to memory starting at p[0]. ** The length of data written will be between 1 and FTS3_VARINT_MAX bytes. @@ -422,7 +429,7 @@ void sqlite3Fts3Dequote(char *z){ /* If the first byte was a '[', then the close-quote character is a ']' */ if( quote=='[' ) quote = ']'; - while( ALWAYS(z[iIn]) ){ + while( z[iIn] ){ if( z[iIn]==quote ){ if( z[iIn+1]!=quote ) break; z[iOut++] = quote; diff --git a/ext/fts3/fts3Int.h b/ext/fts3/fts3Int.h index 1b8b7bd97e..8285f8aaf5 100644 --- a/ext/fts3/fts3Int.h +++ b/ext/fts3/fts3Int.h @@ -134,6 +134,11 @@ SQLITE_EXTENSION_INIT3 #ifdef SQLITE_COVERAGE_TEST # define ALWAYS(x) (1) # define NEVER(X) (0) +#elif defined(SQLITE_DEBUG) +# define ALWAYS(x) sqlite3Fts3Always((x)!=0) +# define NEVER(x) sqlite3Fts3Never((x)!=0) +int sqlite3Fts3Always(int b); +int sqlite3Fts3Never(int b); #else # define ALWAYS(x) (x) # define NEVER(x) (x) diff --git a/manifest b/manifest index 5fed9110db..7337ec7673 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Remove\sa\sbranch\sthat\sbecame\sunreachable\sdue\sto\sone\sof\sthe\searlier\scheck-ins\ntoday. -D 2015-04-15T08:37:42.853 +C Remove\san\sincorrect\sassert()\sstatement\sfrom\ssqlite3Fts3Dequote(). +D 2015-04-15T09:16:39.633 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5f78b1ab81b64e7c57a75d170832443e66c0880a 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 ed6624d7c5fb5aee5d47f884b2d184169fa7a7d4 +F ext/fts3/fts3.c 4bd75289875b63c04f943d6ed7c31737da99cd74 F ext/fts3/fts3.h 3a10a0af180d502cecc50df77b1b22df142817fe -F ext/fts3/fts3Int.h 394858c12a17740f7a1f6bd372c4606d4425a8d1 +F ext/fts3/fts3Int.h 3626655d6ba903a3919bb44e1c38e5f0f9d6be82 F ext/fts3/fts3_aux.c 5c211e17a64885faeb16b9ba7772f9d5445c2365 F ext/fts3/fts3_expr.c 40123785eaa3ebd4c45c9b23407cc44ac0c49905 F ext/fts3/fts3_hash.c 29b986e43f4e9dd40110eafa377dc0d63c422c60 @@ -601,7 +601,7 @@ F test/fts3rnd.test 1320d8826a845e38a96e769562bf83d7a92a15d0 F test/fts3shared.test 57e26a801f21027b7530da77db54286a6fe4997e F test/fts3snippet.test 63dbd687d5bf5191f1b8e6a0977aa9c1e28a7004 F test/fts3sort.test ed34c716a11cc2009a35210e84ad5f9c102362ca -F test/fts3tok1.test c551043de056b0b1582a54e878991f57bad074bc +F test/fts3tok1.test 178c050199af8c05299b1ad572514ce1c54b7827 F test/fts3tok_err.test 52273cd193b9036282f7bacb43da78c6be87418d F test/fts3varint.test 752c08ed5d32c5d7dc211b056f4ed68a76b7e36e F test/fts4aa.test 10aac8e9d62c7357590acfabe3fad01e9a9ce1cb @@ -1250,7 +1250,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 eafd0a1e3f25f38d551603f177ff4634cf79de77 -R cd3636389f675a46c2832548029faa61 -U drh -Z 0baf8e6f8836d6dbdde447c335370222 +P fa0956edf866f48f448967836709a3ad822ff917 +R ae90fdb352a7af37163dde65a0adec8a +U dan +Z a5cd9462fba20ef05f7047cbd877b3d9 diff --git a/manifest.uuid b/manifest.uuid index 0fa4f22d90..6c106f0137 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -fa0956edf866f48f448967836709a3ad822ff917 \ No newline at end of file +bd06eeb8d06237dc2d54d8a03e8bf525cb811c9e \ No newline at end of file diff --git a/test/fts3tok1.test b/test/fts3tok1.test index e6fbbe10a2..09b07e9db1 100644 --- a/test/fts3tok1.test +++ b/test/fts3tok1.test @@ -110,5 +110,15 @@ do_catchsql_test 2.1 { SELECT * FROM t4; } {1 {SQL logic error or missing database}} +do_catchsql_test 2.2 { + CREATE VIRTUAL TABLE t USING fts4(tokenize=simple""); +} {0 {}} + +ifcapable fts3_unicode { + do_catchsql_test 2.3 { + CREATE VIRTUAL TABLE u USING fts4(tokenize=unicode61""); + } {1 {unknown tokenizer}} +} + finish_test From 748c7357ab3906c8a70c4fa53f247560c13c3411 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 15 Apr 2015 15:29:05 +0000 Subject: [PATCH 119/181] Enhance the showdb utility program so that it can read the last partial page of a truncated database file. FossilOrigin-Name: 61d72e17916bc043ce53c64e5ba7050a9bae554e --- manifest | 12 ++++++------ manifest.uuid | 2 +- tool/showdb.c | 6 ++++-- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index c374496704..35f1031e63 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sthe\s--msvc\scommand-line\soption\sto\sthe\sreleasetest.tcl\sscript.\s\sThis\sis\nonly\sa\spartial\smerge\sfrom\sthe\swinTest\sbranch\sas\sthe\sOS_TRACE\schanges\sare\nomitted. -D 2015-04-15T14:52:05.457 +C Enhance\sthe\sshowdb\sutility\sprogram\sso\sthat\sit\scan\sread\sthe\slast\spartial\spage\nof\sa\struncated\sdatabase\sfile. +D 2015-04-15T15:29:05.938 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5f78b1ab81b64e7c57a75d170832443e66c0880a F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -1225,7 +1225,7 @@ 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 63cdef19e7fbca0c164b096ef8aef3bb9e9dd222 +F tool/showdb.c 3b5d335d537e4dc44d0c86967023819453c87dc6 F tool/showjournal.c 053eb1cc774710c6890b7dd6293300cc297b16a5 F tool/showlocks.c 9920bcc64f58378ff1118caead34147201f48c68 F tool/showstat4.c 9515faa8ec176599d4a8288293ba8ec61f7b728a @@ -1250,7 +1250,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 bd06eeb8d06237dc2d54d8a03e8bf525cb811c9e f664bfdc82597a4530d4f4938bb96557b43b171b -R b50245239bcc99605991067d21ad645b +P b8768f124ef7d79e500b60a3ede288d46a0f529d +R ba09996f8bd767f4c42736f26f8bc5d1 U drh -Z 4acea00deaa3e67c61c8980097c82958 +Z aee37f07b2a30818108be904ab58fa7c diff --git a/manifest.uuid b/manifest.uuid index 89bd95a649..be87706afb 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -b8768f124ef7d79e500b60a3ede288d46a0f529d \ No newline at end of file +61d72e17916bc043ce53c64e5ba7050a9bae554e \ No newline at end of file diff --git a/tool/showdb.c b/tool/showdb.c index 7fdf7c91ad..c90f410d95 100644 --- a/tool/showdb.c +++ b/tool/showdb.c @@ -64,11 +64,13 @@ static void out_of_memory(void){ */ static unsigned char *getContent(int ofst, int nByte){ unsigned char *aData; + int got; aData = malloc(nByte+32); if( aData==0 ) out_of_memory(); memset(aData, 0, nByte+32); lseek(db, ofst, SEEK_SET); - if( read(db, aData, nByte)0 && got Date: Wed, 15 Apr 2015 17:26:55 +0000 Subject: [PATCH 120/181] Prevent the fetchPayload() routine from reporting a cell size that extends off the end of the page on a pathologically corrupted database file. FossilOrigin-Name: f71053cf658b3260a32ac06f8ba5c2cde0ea54dd --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/btree.c | 7 ++++++- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 35f1031e63..2bcb4fd1f2 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Enhance\sthe\sshowdb\sutility\sprogram\sso\sthat\sit\scan\sread\sthe\slast\spartial\spage\nof\sa\struncated\sdatabase\sfile. -D 2015-04-15T15:29:05.938 +C Prevent\sthe\sfetchPayload()\sroutine\sfrom\sreporting\sa\scell\ssize\sthat\sextends\noff\sthe\send\sof\sthe\spage\son\sa\spathologically\scorrupted\sdatabase\sfile. +D 2015-04-15T17:26:55.979 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5f78b1ab81b64e7c57a75d170832443e66c0880a F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -173,7 +173,7 @@ F src/auth.c b56c78ebe40a2110fd361379f7e8162d23f92240 F src/backup.c ff743689c4d6c5cb55ad42ed9d174b2b3e71f1e3 F src/bitvec.c 19a4ba637bd85f8f63fc8c9bae5ade9fb05ec1cb F src/btmutex.c 45a968cc85afed9b5e6cf55bf1f42f8d18107f79 -F src/btree.c 67648f6532c2da79d3b3fb6853aa1a0c3ba0e1ad +F src/btree.c c6e32d84442f79d5b96965265d65b3baa231dffc F src/btree.h 969adc948e89e449220ff0ff724c94bb2a52e9f1 F src/btreeInt.h 973a22a6fd61350b454ad614832b1f0a5e25a1e4 F src/build.c 01b969b20a44a3d9620e597d9af8242348123540 @@ -1250,7 +1250,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 b8768f124ef7d79e500b60a3ede288d46a0f529d -R ba09996f8bd767f4c42736f26f8bc5d1 +P 61d72e17916bc043ce53c64e5ba7050a9bae554e +R a75e3890d67000037a79bd4d7c9f248e U drh -Z aee37f07b2a30818108be904ab58fa7c +Z c0a93418012c7dd834fb5d24bb6e0682 diff --git a/manifest.uuid b/manifest.uuid index be87706afb..ec95ab78c0 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -61d72e17916bc043ce53c64e5ba7050a9bae554e \ No newline at end of file +f71053cf658b3260a32ac06f8ba5c2cde0ea54dd \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index 9faf624235..51fca4b4be 100644 --- a/src/btree.c +++ b/src/btree.c @@ -4451,13 +4451,18 @@ static const void *fetchPayload( BtCursor *pCur, /* Cursor pointing to entry to read from */ u32 *pAmt /* Write the number of available bytes here */ ){ + u32 amt; assert( pCur!=0 && pCur->iPage>=0 && pCur->apPage[pCur->iPage]); assert( pCur->eState==CURSOR_VALID ); assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) ); assert( cursorHoldsMutex(pCur) ); assert( pCur->aiIdx[pCur->iPage]apPage[pCur->iPage]->nCell ); assert( pCur->info.nSize>0 ); - *pAmt = pCur->info.nLocal; + assert( pCur->info.pPayload>pCur->apPage[pCur->iPage]->aData || CORRUPT_DB ); + assert( pCur->info.pPayloadapPage[pCur->iPage]->aDataEnd ||CORRUPT_DB); + amt = (int)(pCur->apPage[pCur->iPage]->aDataEnd - pCur->info.pPayload); + if( pCur->info.nLocalinfo.nLocal; + *pAmt = amt; return (void*)pCur->info.pPayload; } From 4b608038b0d3b00c42c84faa1414ae1d037027b5 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 15 Apr 2015 19:25:25 +0000 Subject: [PATCH 121/181] Fix a potential one-byte buffer overread in the command-line shell. FossilOrigin-Name: e018f4bf1f27f7838342940ad89a12d7f1536e8e --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/shell.c | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 2bcb4fd1f2..a7f5fc07e9 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Prevent\sthe\sfetchPayload()\sroutine\sfrom\sreporting\sa\scell\ssize\sthat\sextends\noff\sthe\send\sof\sthe\spage\son\sa\spathologically\scorrupted\sdatabase\sfile. -D 2015-04-15T17:26:55.979 +C Fix\sa\spotential\sone-byte\sbuffer\soverread\sin\sthe\scommand-line\sshell. +D 2015-04-15T19:25:25.409 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5f78b1ab81b64e7c57a75d170832443e66c0880a F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -231,7 +231,7 @@ F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c 66cfe49a9c3b449ef13b89a8c47036a4ed167eab F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e F src/select.c 93260bc9e7e0e6dfe1b7cb8815b0ed4cad8be9e3 -F src/shell.c 84a1593bd86aaa14f4da8a8f9b16fbc239d262aa +F src/shell.c 72b61a9d41ba12b67ea06fe9267abcc012c6c5bb F src/sqlite.h.in ca27603a36fcacdaac5a19d8ee35aaff8ce8516f F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h 17d487c3c91b0b8c584a32fbeb393f6f795eea7d @@ -1250,7 +1250,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 61d72e17916bc043ce53c64e5ba7050a9bae554e -R a75e3890d67000037a79bd4d7c9f248e +P f71053cf658b3260a32ac06f8ba5c2cde0ea54dd +R eab6e1273b6697560bfb82b228385932 U drh -Z c0a93418012c7dd834fb5d24bb6e0682 +Z 6d428eedf5ae6fc2d3dc612cb5905085 diff --git a/manifest.uuid b/manifest.uuid index ec95ab78c0..5482423efa 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -f71053cf658b3260a32ac06f8ba5c2cde0ea54dd \ No newline at end of file +e018f4bf1f27f7838342940ad89a12d7f1536e8e \ No newline at end of file diff --git a/src/shell.c b/src/shell.c index 7ff3eb6cb0..0f7234c47f 100644 --- a/src/shell.c +++ b/src/shell.c @@ -1944,7 +1944,7 @@ static void resolve_backslashes(char *z){ char c; while( *z && *z!='\\' ) z++; for(i=j=0; (c = z[i])!=0; i++, j++){ - if( c=='\\' ){ + if( c=='\\' && z[i+1]!=0 ){ c = z[++i]; if( c=='n' ){ c = '\n'; From 22ecef5c20e007ae5121d9febb3bb3d7f56097b0 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 16 Apr 2015 00:26:03 +0000 Subject: [PATCH 122/181] When parsing the schema, ignore any SQL that does not begin with "CREATE". FossilOrigin-Name: d3c00d61581c8ba6dce5618391432d3af8d324d4 --- manifest | 18 +++++++++--------- manifest.uuid | 2 +- src/prepare.c | 6 +++--- test/analyze.test | 2 +- test/index3.test | 2 +- test/trigger7.test | 2 +- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/manifest b/manifest index a7f5fc07e9..5e32fe4ffc 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\spotential\sone-byte\sbuffer\soverread\sin\sthe\scommand-line\sshell. -D 2015-04-15T19:25:25.409 +C When\sparsing\sthe\sschema,\signore\sany\sSQL\sthat\sdoes\snot\sbegin\swith\s"CREATE". +D 2015-04-16T00:26:03.247 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5f78b1ab81b64e7c57a75d170832443e66c0880a F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -225,7 +225,7 @@ F src/pcache.h b44658c9c932d203510279439d891a2a83e12ba8 F src/pcache1.c 69d137620a305f814398bd29a0c998038c0695e9 F src/pragma.c 3965ae4e82bed39fb97ce04c5fe18c9bc3ee6a88 F src/pragma.h 09c89bca58e9a44de2116cc8272b8d454657129f -F src/prepare.c 173a5a499138451b2561614ecb87d78f9f4644b9 +F src/prepare.c 1fffbdcd6f8a0173a8f70d71f22528f4c0e1e3d3 F src/printf.c 08fa675c200aac29e561c6153f91f909ed17612f F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c 66cfe49a9c3b449ef13b89a8c47036a4ed167eab @@ -320,7 +320,7 @@ F test/alter3.test 49c9d9fba2b8fcdce2dedeca97bbf1f369cc548d F test/alter4.test c461150723ac957f3b2214aa0b11552cd72023ec F test/altermalloc.test e81ac9657ed25c6c5bb09bebfa5a047cd8e4acfc F test/amatch1.test b5ae7065f042b7f4c1c922933f4700add50cdb9f -F test/analyze.test 1772936d66471c65221e437b6d1999c3a03166c4 +F test/analyze.test 3eb35a4af972f98422e5dc0586501b17d103d321 F test/analyze3.test 75b9e42ea1e4edc919250450dc5762186965d4e6 F test/analyze4.test eff2df19b8dd84529966420f29ea52edc6b56213 F test/analyze5.test 765c4e284aa69ca172772aa940946f55629bc8c4 @@ -655,7 +655,7 @@ F test/incrvacuum3.test 75256fb1377e7c39ef2de62bfc42bbff67be295a F test/incrvacuum_ioerr.test 6ae2f783424e47a0033304808fe27789cf93e635 F test/index.test 4d990005a67a36984e4f1a5f1bdccea8d08da4ee F test/index2.test ee83c6b5e3173a3d7137140d945d9a5d4fdfb9d6 -F test/index3.test 55a90cff99834305e8141df7afaef39674b57062 +F test/index3.test b6ec456cf3b81d9a32123fe7e449bde434db338b F test/index4.test ab92e736d5946840236cd61ac3191f91a7856bf6 F test/index5.test 25b0b451aceed4ac5f7d49f856f6de7257470b3e F test/index6.test 3ae54e53c53f2adcacda269237d8e52bdb05a481 @@ -1082,7 +1082,7 @@ F test/trigger3.test aa640bb2bbb03edd5ff69c055117ea088f121945 F test/trigger4.test 74700b76ebf3947b2f7a92405141eb2cf2a5d359 F test/trigger5.test 619391a3e9fc194081d22cefd830d811e7badf83 F test/trigger6.test 0e411654f122552da6590f0b4e6f781048a4a9b9 -F test/trigger7.test b39e6dee1debe0ff9c2ef66326668f149f07c9c4 +F test/trigger7.test 200dd51e728c9cdc20c72d99d9e9d45c667248f8 F test/trigger8.test 30cb0530bd7c4728055420e3f739aa00412eafa4 F test/trigger9.test 2226ec795a33b0460ab5cf8891e9054cc7edef41 F test/triggerA.test fe5597f47ee21bacb4936dc827994ed94161e332 @@ -1250,7 +1250,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 f71053cf658b3260a32ac06f8ba5c2cde0ea54dd -R eab6e1273b6697560bfb82b228385932 +P e018f4bf1f27f7838342940ad89a12d7f1536e8e +R 9772cd879deb52a3e48d7b6cb0b29092 U drh -Z 6d428eedf5ae6fc2d3dc612cb5905085 +Z 089490261a72224f9edd48b4acf9b866 diff --git a/manifest.uuid b/manifest.uuid index 5482423efa..e0b027b22a 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -e018f4bf1f27f7838342940ad89a12d7f1536e8e \ No newline at end of file +d3c00d61581c8ba6dce5618391432d3af8d324d4 \ No newline at end of file diff --git a/src/prepare.c b/src/prepare.c index 97be900d68..a55a0fee43 100644 --- a/src/prepare.c +++ b/src/prepare.c @@ -67,7 +67,7 @@ int sqlite3InitCallback(void *pInit, int argc, char **argv, char **NotUsed){ if( argv==0 ) return 0; /* Might happen if EMPTY_RESULT_CALLBACKS are on */ if( argv[1]==0 ){ corruptSchema(pData, argv[0], 0); - }else if( argv[2] && argv[2][0] ){ + }else if( sqlite3_strnicmp(argv[2],"create ",7)==0 ){ /* Call the parser to process a CREATE TABLE, INDEX or VIEW. ** But because db->init.busy is set to 1, no VDBE code is generated ** or executed. All the parser does is build the internal data @@ -98,8 +98,8 @@ int sqlite3InitCallback(void *pInit, int argc, char **argv, char **NotUsed){ } } sqlite3_finalize(pStmt); - }else if( argv[0]==0 ){ - corruptSchema(pData, 0, 0); + }else if( argv[0]==0 || (argv[2]!=0 && argv[2][0]!=0) ){ + corruptSchema(pData, argv[0], 0); }else{ /* If the SQL column is blank it means this is an index that ** was created to be the PRIMARY KEY or to fulfill a UNIQUE diff --git a/test/analyze.test b/test/analyze.test index c445084263..af277cc835 100644 --- a/test/analyze.test +++ b/test/analyze.test @@ -359,6 +359,6 @@ do_test analyze-99.1 { catchsql { ANALYZE } -} {1 {malformed database schema (sqlite_stat1) - near "nonsense": syntax error}} +} {1 {malformed database schema (sqlite_stat1)}} finish_test diff --git a/test/index3.test b/test/index3.test index a9f9b7ae6f..0cdc6e088d 100644 --- a/test/index3.test +++ b/test/index3.test @@ -51,6 +51,6 @@ do_test index3-99.1 { db close catch { sqlite3 db test.db } catchsql { DROP INDEX i1 } -} {1 {malformed database schema (t1) - near "nonsense": syntax error}} +} {1 {malformed database schema (t1)}} finish_test diff --git a/test/trigger7.test b/test/trigger7.test index 8fde2004f8..221962406b 100644 --- a/test/trigger7.test +++ b/test/trigger7.test @@ -114,6 +114,6 @@ do_test trigger7-99.1 { db close catch { sqlite3 db test.db } catchsql { DROP TRIGGER t2r5 } -} {1 {malformed database schema (t2r12) - near "nonsense": syntax error}} +} {1 {malformed database schema (t2r12)}} finish_test From 5b1c07e7fb84f3106276bcbd8c400b88f18aabff Mon Sep 17 00:00:00 2001 From: dan Date: Thu, 16 Apr 2015 07:19:23 +0000 Subject: [PATCH 123/181] Ensure the sqlite3Select() routine always returns non-zero if an error has occurred. FossilOrigin-Name: b51028ed2f57f4245a7ebd9bdb99d1bcfaf1a01b --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/select.c | 7 +++---- test/select1.test | 3 +++ 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/manifest b/manifest index 5e32fe4ffc..a26119df8c 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C When\sparsing\sthe\sschema,\signore\sany\sSQL\sthat\sdoes\snot\sbegin\swith\s"CREATE". -D 2015-04-16T00:26:03.247 +C Ensure\sthe\ssqlite3Select()\sroutine\salways\sreturns\snon-zero\sif\san\serror\shas\soccurred. +D 2015-04-16T07:19:23.819 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5f78b1ab81b64e7c57a75d170832443e66c0880a F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -230,7 +230,7 @@ F src/printf.c 08fa675c200aac29e561c6153f91f909ed17612f F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c 66cfe49a9c3b449ef13b89a8c47036a4ed167eab F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e -F src/select.c 93260bc9e7e0e6dfe1b7cb8815b0ed4cad8be9e3 +F src/select.c fdac71edb73206488b44cfc0f78708e83f99f591 F src/shell.c 72b61a9d41ba12b67ea06fe9267abcc012c6c5bb F src/sqlite.h.in ca27603a36fcacdaac5a19d8ee35aaff8ce8516f F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad @@ -836,7 +836,7 @@ F test/schema4.test e6a66e20cc69f0e306667c08be7fda3d11707dc5 F test/schema5.test 29699b4421f183c8f0e88bd28ce7d75d13ea653e F test/securedel.test 21749c32ccc30f1ea9e4b9f33295a6521ec20fa0 F test/securedel2.test 2d54c28e46eb1fd6902089958b20b1b056c6f1c5 -F test/select1.test fc2a61f226a649393664ad54bc5376631801517c +F test/select1.test 53c3a5228b099601eafc7f3cc0e9cd682b07d9d5 F test/select2.test 352480e0e9c66eda9c3044e412abdf5be0215b56 F test/select3.test 2ce595f8fb8e2ac10071d3b4e424cadd4634a054 F test/select4.test 16fa1cafb942f42294ec85cbb78954c2f2d15a44 @@ -1250,7 +1250,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 e018f4bf1f27f7838342940ad89a12d7f1536e8e -R 9772cd879deb52a3e48d7b6cb0b29092 -U drh -Z 089490261a72224f9edd48b4acf9b866 +P d3c00d61581c8ba6dce5618391432d3af8d324d4 +R 8123505062f70927e7be9214d0f6d5b6 +U dan +Z fd48a7f3e42fad2b9442aa5a1e6cf7ce diff --git a/manifest.uuid b/manifest.uuid index e0b027b22a..66f4c95a45 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -d3c00d61581c8ba6dce5618391432d3af8d324d4 \ No newline at end of file +b51028ed2f57f4245a7ebd9bdb99d1bcfaf1a01b \ No newline at end of file diff --git a/src/select.c b/src/select.c index bed1f80be0..8e85ebadbf 100644 --- a/src/select.c +++ b/src/select.c @@ -5483,10 +5483,9 @@ int sqlite3Select( */ sqlite3VdbeResolveLabel(v, iEnd); - /* The SELECT was successfully coded. Set the return code to 0 - ** to indicate no errors. - */ - rc = 0; + /* The SELECT has been coded. If there is an error in the Parse structure, + ** set the return code to 1. Otherwise 0. */ + rc = (pParse->nErr>0); /* Control jumps to here if an error is encountered above, or upon ** successful coding of the SELECT. diff --git a/test/select1.test b/test/select1.test index 875c87c84a..2ae91dc0fd 100644 --- a/test/select1.test +++ b/test/select1.test @@ -307,6 +307,9 @@ do_test select1-4.4 { set v [catch {execsql {SELECT f1 FROM test1 ORDER BY min(f1)}} msg] lappend v $msg } {1 {misuse of aggregate: min()}} +do_catchsql_test select1-4.5 { + INSERT INTO test1(f1) SELECT f1 FROM test1 ORDER BY min(f1); +} {1 {misuse of aggregate: min()}} # The restriction not allowing constants in the ORDER BY clause # has been removed. See ticket #1768 From 0d2e2f2b101a12d98ee147500a5bdd65b0fe945f Mon Sep 17 00:00:00 2001 From: dan Date: Thu, 16 Apr 2015 08:54:01 +0000 Subject: [PATCH 124/181] Fix a problem in test file e_reindex.test. FossilOrigin-Name: 5b3de9390f2ffc4c530fd47c71c70e87972cf74b --- manifest | 12 ++++++------ manifest.uuid | 2 +- test/e_reindex.test | 8 ++++++-- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index a26119df8c..5e08cf7fd9 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Ensure\sthe\ssqlite3Select()\sroutine\salways\sreturns\snon-zero\sif\san\serror\shas\soccurred. -D 2015-04-16T07:19:23.819 +C Fix\sa\sproblem\sin\stest\sfile\se_reindex.test. +D 2015-04-16T08:54:01.766 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5f78b1ab81b64e7c57a75d170832443e66c0880a F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -476,7 +476,7 @@ F test/e_expr.test 8f5fdd7261e2d746813b0c6a1c0e34824ad3c5ad F test/e_fkey.test a1783fe1f759e1990e6a11adfcf0702dac4d0707 F test/e_fts3.test 5c02288842e4f941896fd44afdef564dd5fc1459 F test/e_insert.test 0e63edc037afe738bb81a626a676811ed7862c90 -F test/e_reindex.test 396b7b4f0a66863b4e95116a67d93b227193e589 +F test/e_reindex.test 57d439f6c644befc8274ac93cf2f5449cf2736c1 F test/e_resolve.test dcce9308fb13b934ce29591105d031d3e14fbba6 F test/e_select.test 52692ff3849541e828ad4661fe3773a9b8711763 F test/e_select2.test aceb80ab927d46fba5ce7586ebabf23e2bb0604f @@ -1250,7 +1250,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 d3c00d61581c8ba6dce5618391432d3af8d324d4 -R 8123505062f70927e7be9214d0f6d5b6 +P b51028ed2f57f4245a7ebd9bdb99d1bcfaf1a01b +R 2161c4b29e95b81d422e85f30c2d6731 U dan -Z fd48a7f3e42fad2b9442aa5a1e6cf7ce +Z 154b9b38eeade2d6cb79a81e5bb9fb34 diff --git a/manifest.uuid b/manifest.uuid index 66f4c95a45..833d348a2f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -b51028ed2f57f4245a7ebd9bdb99d1bcfaf1a01b \ No newline at end of file +5b3de9390f2ffc4c530fd47c71c70e87972cf74b \ No newline at end of file diff --git a/test/e_reindex.test b/test/e_reindex.test index 4b86787a05..fa66aa7a1f 100644 --- a/test/e_reindex.test +++ b/test/e_reindex.test @@ -48,8 +48,11 @@ do_execsql_test e_reindex-1.1 { INSERT INTO t1 VALUES(1, 2); INSERT INTO t1 VALUES(3, 4); INSERT INTO t1 VALUES(5, 6); + + CREATE TABLE saved(a,b,c,d,e); + INSERT INTO saved SELECT * FROM sqlite_master WHERE type = 'index'; PRAGMA writable_schema = 1; - UPDATE sqlite_master SET sql = '-- ' || sql WHERE type = 'index'; + DELETE FROM sqlite_master WHERE type = 'index'; } {} db close @@ -59,7 +62,8 @@ do_execsql_test e_reindex-1.2 { INSERT INTO t1 VALUES(7, 8); INSERT INTO t1 VALUES(9, 10); PRAGMA writable_schema = 1; - UPDATE sqlite_master SET sql = substr(sql, 4) WHERE type = 'index'; + INSERT INTO sqlite_master SELECT * FROM saved; + DROP TABLE saved; } {} db close From 67731a97a25fda22915df3507e8802aee8a93a51 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 16 Apr 2015 11:56:03 +0000 Subject: [PATCH 125/181] Use a heap instead of a bitmap for cell overlap and coverage testing of btree pages in PRAGMA integrity_check. FossilOrigin-Name: 5619c959bf7babb19fd8ba8b228be7f090fe0ce3 --- manifest | 15 +++++---- manifest.uuid | 2 +- src/btree.c | 85 ++++++++++++++++++++++++++++++++++++++++++--------- 3 files changed, 81 insertions(+), 21 deletions(-) diff --git a/manifest b/manifest index 5e32fe4ffc..b0560fd036 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C When\sparsing\sthe\sschema,\signore\sany\sSQL\sthat\sdoes\snot\sbegin\swith\s"CREATE". -D 2015-04-16T00:26:03.247 +C Use\sa\sheap\sinstead\sof\sa\sbitmap\sfor\scell\soverlap\sand\scoverage\stesting\sof\nbtree\spages\sin\sPRAGMA\sintegrity_check. +D 2015-04-16T11:56:03.678 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5f78b1ab81b64e7c57a75d170832443e66c0880a F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -173,7 +173,7 @@ F src/auth.c b56c78ebe40a2110fd361379f7e8162d23f92240 F src/backup.c ff743689c4d6c5cb55ad42ed9d174b2b3e71f1e3 F src/bitvec.c 19a4ba637bd85f8f63fc8c9bae5ade9fb05ec1cb F src/btmutex.c 45a968cc85afed9b5e6cf55bf1f42f8d18107f79 -F src/btree.c c6e32d84442f79d5b96965265d65b3baa231dffc +F src/btree.c c0e7a97c1125b7b0791ced5fc7ab82adb1b47861 F src/btree.h 969adc948e89e449220ff0ff724c94bb2a52e9f1 F src/btreeInt.h 973a22a6fd61350b454ad614832b1f0a5e25a1e4 F src/build.c 01b969b20a44a3d9620e597d9af8242348123540 @@ -1250,7 +1250,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 e018f4bf1f27f7838342940ad89a12d7f1536e8e -R 9772cd879deb52a3e48d7b6cb0b29092 +P d3c00d61581c8ba6dce5618391432d3af8d324d4 +R 47f1d98f50d53f3c70bce340530e7599 +T *branch * integrity-check-heap +T *sym-integrity-check-heap * +T -sym-trunk * U drh -Z 089490261a72224f9edd48b4acf9b866 +Z 60d66e717d835dfb89af877c15f0d57c diff --git a/manifest.uuid b/manifest.uuid index e0b027b22a..025d2170ab 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -d3c00d61581c8ba6dce5618391432d3af8d324d4 \ No newline at end of file +5619c959bf7babb19fd8ba8b228be7f090fe0ce3 \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index 51fca4b4be..1383193982 100644 --- a/src/btree.c +++ b/src/btree.c @@ -8528,6 +8528,57 @@ static void checkList( } #endif /* SQLITE_OMIT_INTEGRITY_CHECK */ +/* +** An implementation of a min-heap. +** +** aHeap[0] is the number of elements on the heap. aHeap[1] is the +** root element. For element aHeap[N] the daughter nodes are aHeap[N*2] +** and aHeap[N*2+1]. +** +** The heap property is this: Every node is less than or equal to both +** of its daughter nodes. A consequence of the heap property is that the +** root node aHeap[1] is always the minimum value current in the heap. +** +** The btreeHeapInsert() routine inserts an unsigned 32-bit number onto +** the heap, preserving the heap property. The btreeHeapPull() routine +** removes the root element from the heap (the minimum value in the heap) +** and then move other nodes around as necessary to preserve the heap +** property. +** +** This heap is used for cell overlap and coverage testing. Each u32 +** entry represents the span of a cell or freeblock on a btree page. +** The upper 16 bits are the index of the first byte of a range and the +** lower 16 bits are the index of the last byte of that range. +*/ +static void btreeHeapInsert(u32 *aHeap, u32 x){ + u32 j, i = ++aHeap[0]; + aHeap[i] = x; + while( i>1 && aHeap[j=i/2]>aHeap[i] ){ + x = aHeap[j]; + aHeap[j] = aHeap[i]; + aHeap[i] = x; + i = j; + } +} +static int btreeHeapPull(u32 *aHeap, u32 *pOut){ + u32 j, i, x; + if( (x = aHeap[0])==0 ) return 0; + *pOut = aHeap[1]; + aHeap[1] = aHeap[x]; + aHeap[x] = 0xffffffff; + aHeap[0]--; + i = 1; + while( (j = i*2)<=aHeap[0] ){ + if( aHeap[j]>aHeap[j+1] ) j++; + if( aHeap[i]zPfx; @@ -8705,15 +8757,15 @@ static int checkTreePage( */ data = pPage->aData; hdr = pPage->hdrOffset; - hit = sqlite3PageMalloc( pBt->pageSize ); + heap = (u32*)sqlite3PageMalloc( pBt->pageSize ); pCheck->zPfx = 0; - if( hit==0 ){ + if( heap==0 ){ pCheck->mallocFailed = 1; }else{ int contentOffset = get2byteNotZero(&data[hdr+5]); assert( contentOffset<=usableSize ); /* Enforced by btreeInitPage() */ - memset(hit+contentOffset, 0, usableSize-contentOffset); - memset(hit, 1, contentOffset); + heap[0] = 0; + btreeHeapInsert(heap, contentOffset-1); /* EVIDENCE-OF: R-37002-32774 The two-byte integer at offset 3 gives the ** number of cells on the page. */ nCell = get2byte(&data[hdr+3]); @@ -8725,7 +8777,6 @@ static int checkTreePage( for(i=0; i=pc; j--) hit[j]++; + btreeHeapInsert(heap, (pc<<16)|(pc+size-1)); } } /* EVIDENCE-OF: R-20690-50594 The second field of the b-tree page header @@ -8746,7 +8797,7 @@ static int checkTreePage( assert( i<=usableSize-4 ); /* Enforced by btreeInitPage() */ size = get2byte(&data[i+2]); assert( i+size<=usableSize ); /* Enforced by btreeInitPage() */ - for(j=i+size-1; j>=i; j--) hit[j]++; + btreeHeapInsert(heap, (i<<16)|(i+size-1)); /* EVIDENCE-OF: R-58208-19414 The first 2 bytes of a freeblock are a ** big-endian integer which is the offset in the b-tree page of the next ** freeblock in the chain, or zero if the freeblock is the last on the @@ -8758,15 +8809,21 @@ static int checkTreePage( assert( j<=usableSize-4 ); /* Enforced by btreeInitPage() */ i = j; } - for(i=cnt=0; i1 ){ + cnt = 0; + assert( heap[0]>0 ); + assert( (heap[1]>>16)==0 ); + btreeHeapPull(heap,&prev); + while( btreeHeapPull(heap,&x) ){ + if( (prev&0xffff)+1>(x>>16) ){ checkAppendMsg(pCheck, - "Multiple uses for byte %d of page %d", i, iPage); + "Multiple uses for byte %u of page %d", x>>16, iPage); break; + }else{ + cnt += (x>>16) - (prev&0xffff) - 1; + prev = x; } } + cnt += usableSize - (prev&0xffff) - 1; /* EVIDENCE-OF: R-43263-13491 The total number of bytes in all fragments ** is stored in the fifth field of the b-tree page header. ** EVIDENCE-OF: R-07161-27322 The one-byte integer at offset 7 gives the @@ -8778,7 +8835,7 @@ static int checkTreePage( cnt, data[hdr+7], iPage); } } - sqlite3PageFree(hit); + sqlite3PageFree(heap); releasePage(pPage); end_of_check: From b073771cdfc16bfc781f400d3d518498e2690b83 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 16 Apr 2015 12:12:07 +0000 Subject: [PATCH 126/181] Fix the corruptC.test module due to a change in error message text. FossilOrigin-Name: 7c0deed25762a954c78d98412d8f4a265a437d06 --- manifest | 14 +++++++------- manifest.uuid | 2 +- test/corruptC.test | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 5e08cf7fd9..93195dbcb1 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sproblem\sin\stest\sfile\se_reindex.test. -D 2015-04-16T08:54:01.766 +C Fix\sthe\scorruptC.test\smodule\sdue\sto\sa\schange\sin\serror\smessage\stext. +D 2015-04-16T12:12:07.953 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5f78b1ab81b64e7c57a75d170832443e66c0880a F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -426,7 +426,7 @@ F test/corrupt8.test 2399dfe40d2c0c63af86706e30f3e6302a8d0516 F test/corrupt9.test 730a3db08d4ab9aa43392ea30d9c2b4879cbff85 F test/corruptA.test 53e56dafd180addcdadb402244b8cb9771d2ba26 F test/corruptB.test 73a8d6c0b9833697ecf16b63e3c5c05c945b5dec -F test/corruptC.test 02405cf7ed0c1e989060e1aab6d02ffbc3906fbb +F test/corruptC.test 3fcc0f73d2cf2d69befe2d96332b942426a6aae2 F test/corruptD.test b3c205fac7952b1de645ce44bb02335cd9e3e040 F test/corruptE.test 193b4ca4e927e77c1d5f4f56203ddc998432a7ee F test/corruptF.test be9fde98e4c93648f1ba52b74e5318edc8f59fe4 @@ -1250,7 +1250,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 b51028ed2f57f4245a7ebd9bdb99d1bcfaf1a01b -R 2161c4b29e95b81d422e85f30c2d6731 -U dan -Z 154b9b38eeade2d6cb79a81e5bb9fb34 +P 5b3de9390f2ffc4c530fd47c71c70e87972cf74b +R 52f7fd6b33b7cf36f49fd780c8e11ee8 +U drh +Z 89ad7719122c7a76b704b370103ce659 diff --git a/manifest.uuid b/manifest.uuid index 833d348a2f..c65ebcbe96 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -5b3de9390f2ffc4c530fd47c71c70e87972cf74b \ No newline at end of file +7c0deed25762a954c78d98412d8f4a265a437d06 \ No newline at end of file diff --git a/test/corruptC.test b/test/corruptC.test index adf6f44c44..a7f93c46d2 100644 --- a/test/corruptC.test +++ b/test/corruptC.test @@ -292,7 +292,7 @@ do_test corruptC-2.15 { hexio_write test.db 986 b9 sqlite3 db test.db catchsql {SELECT count(*) FROM sqlite_master;} -} {1 {malformed database schema (t1i1) - no such table: main.t1}} +} {1 {database disk image is malformed}} # # Now test for a series of quasi-random seeds. From 772460fd4c73cb810c11a12ea77f3d74602f4041 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 16 Apr 2015 14:13:12 +0000 Subject: [PATCH 127/181] Improvements to the way VALUES clauses are parsed. FossilOrigin-Name: ec5a493ad27593ca78899b3001630c1898b940ff --- manifest | 20 ++++++++++---------- manifest.uuid | 2 +- src/expr.c | 2 +- src/parse.y | 44 ++++++++++++++++++++++++++++---------------- src/select.c | 7 +++---- src/sqliteInt.h | 2 +- test/select4.test | 10 +++++++++- 7 files changed, 53 insertions(+), 34 deletions(-) diff --git a/manifest b/manifest index 93195dbcb1..e9c5d46443 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sthe\scorruptC.test\smodule\sdue\sto\sa\schange\sin\serror\smessage\stext. -D 2015-04-16T12:12:07.953 +C Improvements\sto\sthe\sway\sVALUES\sclauses\sare\sparsed. +D 2015-04-16T14:13:12.394 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5f78b1ab81b64e7c57a75d170832443e66c0880a F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -182,7 +182,7 @@ F src/complete.c a5cf5b4b56390cfb7b8636e8f7ddef90258dd575 F src/ctime.c 98f89724adc891a1a4c655bee04e33e716e05887 F src/date.c e4d50b3283696836ec1036b695ead9a19e37a5ac F src/delete.c 37964e6c1d73ff49cbea9ff690c9605fb15f600e -F src/expr.c 8800584340a9b4f4c0ca55c360de751c6da0b11a +F src/expr.c f37d5eb44a1fad4ca4faa6b0c4f1230f233e3835 F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb F src/fkey.c 3343d551a8d810782257244fb33f2ce191493c39 F src/func.c 1414c24c873c48796ad45942257a179a423ba42f @@ -219,7 +219,7 @@ F src/os_win.c 03d27be3a20048ef52a648d5f0a15f5edda9f2a3 F src/os_win.h eb7a47aa17b26b77eb97e4823f20a00b8bda12ca F src/pager.c 4120a49ecd37697e28f5ed807f470b9c0b88410c F src/pager.h c3476e7c89cdf1c6914e50a11f3714e30b4e0a77 -F src/parse.y 1299c66e7b1707322ccd8af43a359b8fb0d46d72 +F src/parse.y b5c16bc5aa5e59a7ceb0fe94defa9dce3a6b1d3c F src/pcache.c 10539fb959849ad6efff80050541cab3d25089d4 F src/pcache.h b44658c9c932d203510279439d891a2a83e12ba8 F src/pcache1.c 69d137620a305f814398bd29a0c998038c0695e9 @@ -230,12 +230,12 @@ F src/printf.c 08fa675c200aac29e561c6153f91f909ed17612f F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c 66cfe49a9c3b449ef13b89a8c47036a4ed167eab F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e -F src/select.c fdac71edb73206488b44cfc0f78708e83f99f591 +F src/select.c e24bd1a7b6bf2256cf8df115d01e308c94ad9c05 F src/shell.c 72b61a9d41ba12b67ea06fe9267abcc012c6c5bb F src/sqlite.h.in ca27603a36fcacdaac5a19d8ee35aaff8ce8516f F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h 17d487c3c91b0b8c584a32fbeb393f6f795eea7d -F src/sqliteInt.h 90b7bfd89d7307cd0750663da419ba4bb81e7379 +F src/sqliteInt.h af228df2a02bf1a608d678b312d46aa480470b3c F src/sqliteLimit.h 216557999cb45f2e3578ed53ebefe228d779cb46 F src/status.c f266ad8a2892d659b74f0f50cb6a88b6e7c12179 F src/table.c e7a09215315a978057fb42c640f890160dbcc45e @@ -839,7 +839,7 @@ F test/securedel2.test 2d54c28e46eb1fd6902089958b20b1b056c6f1c5 F test/select1.test 53c3a5228b099601eafc7f3cc0e9cd682b07d9d5 F test/select2.test 352480e0e9c66eda9c3044e412abdf5be0215b56 F test/select3.test 2ce595f8fb8e2ac10071d3b4e424cadd4634a054 -F test/select4.test 16fa1cafb942f42294ec85cbb78954c2f2d15a44 +F test/select4.test d4330ee0e24e52fa21c62c6bbf999dbfcbb7dfd0 F test/select5.test e758b8ef94f69b111df4cb819008856655dcd535 F test/select6.test 39eac4a5c03650b2b473c532882273283ee8b7a0 F test/select7.test 7fd2ef598cfabb6b9ff6ac13973b91d0527df49d @@ -1250,7 +1250,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 5b3de9390f2ffc4c530fd47c71c70e87972cf74b -R 52f7fd6b33b7cf36f49fd780c8e11ee8 +P 7c0deed25762a954c78d98412d8f4a265a437d06 +R 611a860661173119865e499e8c5f5052 U drh -Z 89ad7719122c7a76b704b370103ce659 +Z f1f791a01fc19f4f892a113c0900910a diff --git a/manifest.uuid b/manifest.uuid index c65ebcbe96..c43e827164 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -7c0deed25762a954c78d98412d8f4a265a437d06 \ No newline at end of file +ec5a493ad27593ca78899b3001630c1898b940ff \ No newline at end of file diff --git a/src/expr.c b/src/expr.c index 77eb35aa74..418881ffd9 100644 --- a/src/expr.c +++ b/src/expr.c @@ -2016,7 +2016,7 @@ int sqlite3CodeSubselect( pSel->pLimit = sqlite3PExpr(pParse, TK_INTEGER, 0, 0, &sqlite3IntTokens[1]); pSel->iLimit = 0; - pSel->selFlags &= ~SF_AllValues; + pSel->selFlags &= ~SF_MultiValue; if( sqlite3Select(pParse, pSel, &dest) ){ return 0; } diff --git a/src/parse.y b/src/parse.y index b8ef26810c..ac15c3ce71 100644 --- a/src/parse.y +++ b/src/parse.y @@ -409,28 +409,35 @@ cmd ::= select(X). { %type oneselect {Select*} %destructor oneselect {sqlite3SelectDelete(pParse->db, $$);} -select(A) ::= with(W) selectnowith(X). { - Select *p = X, *pNext, *pLoop; - if( p ){ - int cnt = 0, mxSelect; - p->pWith = W; +%include { + /* + ** For a compound SELECT statement, make sure p->pPrior->pNext==p for + ** all elements in the list. And make sure list length does not exceed + ** SQLITE_LIMIT_COMPOUND_SELECT. + */ + void parserDoubleLinkSelect(Parse *pParse, Select *p){ if( p->pPrior ){ - u16 allValues = SF_Values; - pNext = 0; + Select *pNext = 0, *pLoop; + int mxSelect, cnt = 0; for(pLoop=p; pLoop; pNext=pLoop, pLoop=pLoop->pPrior, cnt++){ pLoop->pNext = pNext; pLoop->selFlags |= SF_Compound; - allValues &= pLoop->selFlags; } - if( allValues ){ - p->selFlags |= SF_AllValues; - }else if( - (mxSelect = pParse->db->aLimit[SQLITE_LIMIT_COMPOUND_SELECT])>0 - && cnt>mxSelect + if( (p->selFlags & SF_MultiValue)==0 && + (mxSelect = pParse->db->aLimit[SQLITE_LIMIT_COMPOUND_SELECT])>0 && + cnt>mxSelect ){ sqlite3ErrorMsg(pParse, "too many terms in compound SELECT"); } } + } +} + +select(A) ::= with(W) selectnowith(X). { + Select *p = X; + if( p ){ + p->pWith = W; + parserDoubleLinkSelect(pParse, p); }else{ sqlite3WithDelete(pParse->db, W); } @@ -445,12 +452,14 @@ selectnowith(A) ::= selectnowith(X) multiselect_op(Y) oneselect(Z). { SrcList *pFrom; Token x; x.n = 0; + parserDoubleLinkSelect(pParse, pRhs); pFrom = sqlite3SrcListAppendFromTerm(pParse,0,0,0,&x,pRhs,0,0); pRhs = sqlite3SelectNew(pParse,0,pFrom,0,0,0,0,0,0,0); } if( pRhs ){ pRhs->op = (u8)Y; pRhs->pPrior = X; + pRhs->selFlags &= ~SF_MultiValue; if( Y!=TK_ALL ) pParse->hasCompound = 1; }else{ sqlite3SelectDelete(pParse->db, X); @@ -498,13 +507,16 @@ values(A) ::= VALUES LP nexprlist(X) RP. { A = sqlite3SelectNew(pParse,X,0,0,0,0,0,SF_Values,0,0); } values(A) ::= values(X) COMMA LP exprlist(Y) RP. { - Select *pRight = sqlite3SelectNew(pParse,Y,0,0,0,0,0,SF_Values,0,0); + Select *pRight, *pLeft = X; + pRight = sqlite3SelectNew(pParse,Y,0,0,0,0,0,SF_Values|SF_MultiValue,0,0); + if( pLeft ) pLeft->selFlags &= ~SF_MultiValue; if( pRight ){ pRight->op = TK_ALL; - pRight->pPrior = X; + pLeft = X; + pRight->pPrior = pLeft; A = pRight; }else{ - A = X; + A = pLeft; } } diff --git a/src/select.c b/src/select.c index 8e85ebadbf..298ad90a1c 100644 --- a/src/select.c +++ b/src/select.c @@ -2108,8 +2108,7 @@ static int multiSelectValues( int nExpr = p->pEList->nExpr; int nRow = 1; int rc = 0; - assert( p->pNext==0 ); - assert( p->selFlags & SF_AllValues ); + assert( p->selFlags & SF_MultiValue ); do{ assert( p->selFlags & SF_Values ); assert( p->op==TK_ALL || (p->op==TK_SELECT && p->pPrior==0) ); @@ -2218,7 +2217,7 @@ static int multiSelect( /* Special handling for a compound-select that originates as a VALUES clause. */ - if( p->selFlags & SF_AllValues ){ + if( p->selFlags & SF_MultiValue ){ rc = multiSelectValues(pParse, p, &dest); goto multi_select_end; } @@ -4422,7 +4421,7 @@ static void sqlite3SelectExpand(Parse *pParse, Select *pSelect){ sqlite3WalkSelect(&w, pSelect); } w.xSelectCallback = selectExpander; - if( (pSelect->selFlags & SF_AllValues)==0 ){ + if( (pSelect->selFlags & SF_MultiValue)==0 ){ w.xSelectCallback2 = selectPopWith; } sqlite3WalkSelect(&w, pSelect); diff --git a/src/sqliteInt.h b/src/sqliteInt.h index ee24342919..b1a2db3a28 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -2385,7 +2385,7 @@ struct Select { #define SF_HasTypeInfo 0x0020 /* FROM subqueries have Table metadata */ #define SF_Compound 0x0040 /* Part of a compound query */ #define SF_Values 0x0080 /* Synthesized from VALUES clause */ -#define SF_AllValues 0x0100 /* All terms of compound are VALUES */ +#define SF_MultiValue 0x0100 /* Single VALUES term with multiple rows */ #define SF_NestedFrom 0x0200 /* Part of a parenthesized FROM clause */ #define SF_MaybeConvert 0x0400 /* Need convertCompoundSelectToSubquery() */ #define SF_Recursive 0x0800 /* The recursive part of a recursive CTE */ diff --git a/test/select4.test b/test/select4.test index 2f3ddbe96a..ce09ba71d4 100644 --- a/test/select4.test +++ b/test/select4.test @@ -874,6 +874,14 @@ do_execsql_test select4-14.10 { do_execsql_test select4-14.11 { SELECT (SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4) } {1} - +do_execsql_test select4-14.12 { + VALUES(1) UNION VALUES(2); +} {1 2} +do_execsql_test select4-14.13 { + VALUES(1),(2),(3) EXCEPT VALUES(2); +} {1 3} +do_execsql_test select4-14.14 { + VALUES(1),(2),(3) EXCEPT VALUES(1),(3); +} {2} finish_test From 6736618a8f9368629a7d9510a549bb591d9d7d20 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 16 Apr 2015 14:33:35 +0000 Subject: [PATCH 128/181] Fix a faulty assert() in the compound select code generator. FossilOrigin-Name: 9d336be1b16aa9bd5c9e4132bb645874993c7d96 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/select.c | 6 ++++-- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index e9c5d46443..86969a411c 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Improvements\sto\sthe\sway\sVALUES\sclauses\sare\sparsed. -D 2015-04-16T14:13:12.394 +C Fix\sa\sfaulty\sassert()\sin\sthe\scompound\sselect\scode\sgenerator. +D 2015-04-16T14:33:35.359 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5f78b1ab81b64e7c57a75d170832443e66c0880a F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -230,7 +230,7 @@ F src/printf.c 08fa675c200aac29e561c6153f91f909ed17612f F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c 66cfe49a9c3b449ef13b89a8c47036a4ed167eab F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e -F src/select.c e24bd1a7b6bf2256cf8df115d01e308c94ad9c05 +F src/select.c b7b91db829464db6ebba4cd6a878a0ef688b847d F src/shell.c 72b61a9d41ba12b67ea06fe9267abcc012c6c5bb F src/sqlite.h.in ca27603a36fcacdaac5a19d8ee35aaff8ce8516f F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad @@ -1250,7 +1250,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 7c0deed25762a954c78d98412d8f4a265a437d06 -R 611a860661173119865e499e8c5f5052 +P ec5a493ad27593ca78899b3001630c1898b940ff +R 11ac4c431272562d678d3132e12f4ff6 U drh -Z f1f791a01fc19f4f892a113c0900910a +Z 9969aaea0bee219926e4d05bec4ccd67 diff --git a/manifest.uuid b/manifest.uuid index c43e827164..523f920fa3 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ec5a493ad27593ca78899b3001630c1898b940ff \ No newline at end of file +9d336be1b16aa9bd5c9e4132bb645874993c7d96 \ No newline at end of file diff --git a/src/select.c b/src/select.c index 298ad90a1c..c7c7095032 100644 --- a/src/select.c +++ b/src/select.c @@ -2859,8 +2859,10 @@ static int multiSelectOrderBy( if( aPermute ){ struct ExprList_item *pItem; for(i=0, pItem=pOrderBy->a; iu.x.iOrderByCol>0 - && pItem->u.x.iOrderByCol<=p->pEList->nExpr ); + assert( pItem->u.x.iOrderByCol>0 ); + /* assert( pItem->u.x.iOrderByCol<=p->pEList->nExpr ) is also true + ** but only for well-formed SELECT statements. */ + testcase( pItem->u.x.iOrderByCol > p->pEList->nExpr ); aPermute[i] = pItem->u.x.iOrderByCol - 1; } pKeyMerge = multiSelectOrderByKeyInfo(pParse, p, 1); From 9569f60e18282e33dd78c63c8b842c3392bb576d Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 16 Apr 2015 15:05:04 +0000 Subject: [PATCH 129/181] Add the --backslash option to the command-line shell for testing purposes. FossilOrigin-Name: dd96211e8022365637286b146120cc5db44a9923 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/shell.c | 9 +++++++++ 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/manifest b/manifest index 86969a411c..93103be3ba 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sfaulty\sassert()\sin\sthe\scompound\sselect\scode\sgenerator. -D 2015-04-16T14:33:35.359 +C Add\sthe\s--backslash\soption\sto\sthe\scommand-line\sshell\sfor\stesting\spurposes. +D 2015-04-16T15:05:04.946 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5f78b1ab81b64e7c57a75d170832443e66c0880a F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -231,7 +231,7 @@ F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c 66cfe49a9c3b449ef13b89a8c47036a4ed167eab F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e F src/select.c b7b91db829464db6ebba4cd6a878a0ef688b847d -F src/shell.c 72b61a9d41ba12b67ea06fe9267abcc012c6c5bb +F src/shell.c 28b3e1174a7fc00155d7d00880a33589a88508c9 F src/sqlite.h.in ca27603a36fcacdaac5a19d8ee35aaff8ce8516f F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h 17d487c3c91b0b8c584a32fbeb393f6f795eea7d @@ -1250,7 +1250,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 ec5a493ad27593ca78899b3001630c1898b940ff -R 11ac4c431272562d678d3132e12f4ff6 +P 9d336be1b16aa9bd5c9e4132bb645874993c7d96 +R 5fbffaa37b14ccf06bc3b95dfad9c618 U drh -Z 9969aaea0bee219926e4d05bec4ccd67 +Z e400cf12f450b0a1df16da05ddca199b diff --git a/manifest.uuid b/manifest.uuid index 523f920fa3..57720c5916 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -9d336be1b16aa9bd5c9e4132bb645874993c7d96 \ No newline at end of file +dd96211e8022365637286b146120cc5db44a9923 \ No newline at end of file diff --git a/src/shell.c b/src/shell.c index 0f7234c47f..0d83084741 100644 --- a/src/shell.c +++ b/src/shell.c @@ -527,6 +527,7 @@ struct ShellState { int autoEQP; /* Run EXPLAIN QUERY PLAN prior to seach SQL stmt */ int statsOn; /* True to display memory stats before each finalize */ int scanstatsOn; /* True to display scan stats before each finalize */ + int backslashOn; /* Resolve C-style \x escapes in SQL input text */ int outCount; /* Revert to stdout when reaching zero */ int cnt; /* Number of records displayed so far */ FILE *out; /* Write results here */ @@ -4111,6 +4112,7 @@ static int process_input(ShellState *p, FILE *in){ && sqlite3_complete(zSql) ){ p->cnt = 0; open_db(p, 0); + if( p->backslashOn ) resolve_backslashes(zSql); BEGIN_TIMER; rc = shell_exec(p->db, zSql, shell_callback, p, &zErrMsg); END_TIMER; @@ -4577,6 +4579,13 @@ int SQLITE_CDECL main(int argc, char **argv){ data.statsOn = 1; }else if( strcmp(z,"-scanstats")==0 ){ data.scanstatsOn = 1; + }else if( strcmp(z,"-backslash")==0 ){ + /* Undocumented command-line option: -backslash + ** Causes C-style backslash escapes to be evaluated in SQL statements + ** prior to sending the SQL into SQLite. Useful for injecting + ** crazy bytes in the middle of SQL statements for testing and debugging. + */ + data.backslashOn = 1; }else if( strcmp(z,"-bail")==0 ){ bail_on_error = 1; }else if( strcmp(z,"-version")==0 ){ From e06874eaa10b153add74507b0d6ad5027cee2dba Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 16 Apr 2015 15:47:06 +0000 Subject: [PATCH 130/181] Make sure errors in coding triggers are propagated back up to the parser. FossilOrigin-Name: 928f973ca9adc7933015b2fb6b6fcb8e3154cb9c --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/trigger.c | 1 + test/fkey2.test | 14 ++++++++++++++ 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 93103be3ba..d7954dddf7 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sthe\s--backslash\soption\sto\sthe\scommand-line\sshell\sfor\stesting\spurposes. -D 2015-04-16T15:05:04.946 +C Make\ssure\serrors\sin\scoding\striggers\sare\spropagated\sback\sup\sto\sthe\sparser. +D 2015-04-16T15:47:06.148 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5f78b1ab81b64e7c57a75d170832443e66c0880a F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -288,7 +288,7 @@ F src/test_vfstrace.c bab9594adc976cbe696ff3970728830b4c5ed698 F src/test_wsd.c 41cadfd9d97fe8e3e4e44f61a4a8ccd6f7ca8fe9 F src/threads.c 6bbcc9fe50c917864d48287b4792d46d6e873481 F src/tokenize.c a8234a67577308935cdf13e618cd66556f5f45d1 -F src/trigger.c 69a91bed7c94e46223e37ffccfeeb35e34b999ac +F src/trigger.c a261da05e2ba65035d6f4b85d1fe6d4f363c1f1f F src/update.c 3c4ecc282accf12d39edb8d524cf089645e55a13 F src/utf.c fc6b889ba0779b7722634cdeaa25f1930d93820c F src/util.c 98a7627ca48ad3265b6940915a1d08355eb3fc7e @@ -505,7 +505,7 @@ F test/fallocate.test 3e979af17dfa7e5e9dda5eba1a696c04fa9d47f7 F test/filectrl.test 14fa712e42c4cb791e09dfd58a6a03efb47ef13a F test/filefmt.test cb34663f126cbc2d358af552dcaf5c72769b0146 F test/fkey1.test e1d1fa84cde579185ea01358436839703e415a5b -F test/fkey2.test 223c624e7eccee21e89c98d4d127ac88d774b940 +F test/fkey2.test 043692a609d513f8f230ca3064e8074f8643b60e F test/fkey3.test 76d475c80b84ee7a5d062e56ccb6ea68882e2b49 F test/fkey4.test 86446017011273aad8f9a99c1a65019e7bd9ca9d F test/fkey5.test 56bcb5a6e8b725b17febc267fb041a6695e86853 @@ -1250,7 +1250,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 9d336be1b16aa9bd5c9e4132bb645874993c7d96 -R 5fbffaa37b14ccf06bc3b95dfad9c618 +P dd96211e8022365637286b146120cc5db44a9923 +R 046f14926b5af5dfc4416003fb47b3d1 U drh -Z e400cf12f450b0a1df16da05ddca199b +Z 6ea7be360982608826bd8c7c45584988 diff --git a/manifest.uuid b/manifest.uuid index 57720c5916..7832a2dde8 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -dd96211e8022365637286b146120cc5db44a9923 \ No newline at end of file +928f973ca9adc7933015b2fb6b6fcb8e3154cb9c \ No newline at end of file diff --git a/src/trigger.c b/src/trigger.c index ed152d2a8a..d29f509a8d 100644 --- a/src/trigger.c +++ b/src/trigger.c @@ -795,6 +795,7 @@ static void transferParseError(Parse *pTo, Parse *pFrom){ if( pTo->nErr==0 ){ pTo->zErrMsg = pFrom->zErrMsg; pTo->nErr = pFrom->nErr; + pTo->rc = pFrom->rc; }else{ sqlite3DbFree(pFrom->db, pFrom->zErrMsg); } diff --git a/test/fkey2.test b/test/fkey2.test index 8b2871e5a6..d0b284b780 100644 --- a/test/fkey2.test +++ b/test/fkey2.test @@ -2014,4 +2014,18 @@ do_test fkey2-ce7c13.1.6 { } } {1 {FOREIGN KEY constraint failed}} +# 2015-04-16: Foreign key errors propagate back up to the parser. +# +do_test fkey2-20150416-100 { + db close + sqlite3 db :memory: + catchsql { + PRAGMA foreign_keys=1; + CREATE TABLE t1(x PRIMARY KEY); + CREATE TABLE t(y REFERENCES t0(x)ON DELETE SET DEFAULT); + CREATE TABLE t0(y REFERENCES t1 ON DELETE SET NULL); + REPLACE INTO t1 SELECT(0);CREATE TABLE t2(x);CREATE TABLE t3; + } +} {1 {foreign key mismatch - "t" referencing "t0"}} + finish_test From 59ac655d028c744b13d079e8a06e8f56b6ae8092 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 16 Apr 2015 16:04:39 +0000 Subject: [PATCH 131/181] Silently ignore requests to change the PRAGMA synchronous setting to an illegal integer value, rather than raising an assertion. FossilOrigin-Name: e0a88176fcfbed7b554a036948261a332c920053 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/pragma.c | 4 +++- test/pragma.test | 12 ++++++++++++ 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index d7954dddf7..2370ea266a 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Make\ssure\serrors\sin\scoding\striggers\sare\spropagated\sback\sup\sto\sthe\sparser. -D 2015-04-16T15:47:06.148 +C Silently\signore\srequests\sto\schange\sthe\sPRAGMA\ssynchronous\ssetting\sto\san\nillegal\sinteger\svalue,\srather\sthan\sraising\san\sassertion. +D 2015-04-16T16:04:39.846 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5f78b1ab81b64e7c57a75d170832443e66c0880a F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -223,7 +223,7 @@ F src/parse.y b5c16bc5aa5e59a7ceb0fe94defa9dce3a6b1d3c F src/pcache.c 10539fb959849ad6efff80050541cab3d25089d4 F src/pcache.h b44658c9c932d203510279439d891a2a83e12ba8 F src/pcache1.c 69d137620a305f814398bd29a0c998038c0695e9 -F src/pragma.c 3965ae4e82bed39fb97ce04c5fe18c9bc3ee6a88 +F src/pragma.c 633cb355ab30b197d4e8e9976f94378199439b76 F src/pragma.h 09c89bca58e9a44de2116cc8272b8d454657129f F src/prepare.c 1fffbdcd6f8a0173a8f70d71f22528f4c0e1e3d3 F src/printf.c 08fa675c200aac29e561c6153f91f909ed17612f @@ -794,7 +794,7 @@ F test/pcache.test b09104b03160aca0d968d99e8cd2c5b1921a993d F test/pcache2.test a83efe2dec0d392f814bfc998def1d1833942025 F test/percentile.test 4243af26b8f3f4555abe166f723715a1f74c77ff F test/permutations.test f9cc1dd987986c9d4949211c7a4ed55ec9aecba1 -F test/pragma.test e6605ce89c66db930aef561e43a22281a09ffc66 +F test/pragma.test 2e3d20785e463d7eeed636cba16e742b5df88073 F test/pragma2.test f624a496a95ee878e81e59961eade66d5c00c028 F test/pragma3.test 6f849ccffeee7e496d2f2b5e74152306c0b8757c F test/printf.test b3ff34e73d59124140eaf89f7672e21bc2ca5fcc @@ -1250,7 +1250,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 dd96211e8022365637286b146120cc5db44a9923 -R 046f14926b5af5dfc4416003fb47b3d1 +P 928f973ca9adc7933015b2fb6b6fcb8e3154cb9c +R f9e99024211f275c6c5be92b169c1ffa U drh -Z 6ea7be360982608826bd8c7c45584988 +Z 092fd595f2813758c3267ca51aac5606 diff --git a/manifest.uuid b/manifest.uuid index 7832a2dde8..91ff8f2a2e 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -928f973ca9adc7933015b2fb6b6fcb8e3154cb9c \ No newline at end of file +e0a88176fcfbed7b554a036948261a332c920053 \ No newline at end of file diff --git a/src/pragma.c b/src/pragma.c index 8f6ac64754..3cecd8dda5 100644 --- a/src/pragma.c +++ b/src/pragma.c @@ -946,7 +946,9 @@ void sqlite3Pragma( sqlite3ErrorMsg(pParse, "Safety level may not be changed inside a transaction"); }else{ - pDb->safety_level = getSafetyLevel(zRight,0,1)+1; + testcase( (getSafetyLevel(zRight,0,1)+1) & ~PAGER_SYNCHRONOUS_MASK ); + pDb->safety_level = (getSafetyLevel(zRight,0,1)+1) + & PAGER_SYNCHRONOUS_MASK; setAllPagerFlags(db); } } diff --git a/test/pragma.test b/test/pragma.test index e8a53f442d..a45dc45a44 100644 --- a/test/pragma.test +++ b/test/pragma.test @@ -219,6 +219,18 @@ do_test pragma-1.14 { PRAGMA synchronous; } } {2} +do_test pragma-1.14.1 { + execsql { + PRAGMA synchronous=4; + PRAGMA synchronous; + } +} {0} +do_test pragma-1.14.2 { + execsql { + PRAGMA synchronous=10; + PRAGMA synchronous; + } +} {2} } ;# ifcapable pager_pragmas # Test turning "flag" pragmas on and off. From a276e3fd4d28adb49b39235b1f87d51ba406e673 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 16 Apr 2015 16:22:27 +0000 Subject: [PATCH 132/181] Fix a faulty assert() in the compound-SELECT code generator. FossilOrigin-Name: 10715b05f2201a63dca317f99ce39d3ce182e182 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/select.c | 2 +- test/select4.test | 4 ++++ 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 2370ea266a..8446774a73 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Silently\signore\srequests\sto\schange\sthe\sPRAGMA\ssynchronous\ssetting\sto\san\nillegal\sinteger\svalue,\srather\sthan\sraising\san\sassertion. -D 2015-04-16T16:04:39.846 +C Fix\sa\sfaulty\sassert()\sin\sthe\scompound-SELECT\scode\sgenerator. +D 2015-04-16T16:22:27.087 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5f78b1ab81b64e7c57a75d170832443e66c0880a F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -230,7 +230,7 @@ F src/printf.c 08fa675c200aac29e561c6153f91f909ed17612f F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c 66cfe49a9c3b449ef13b89a8c47036a4ed167eab F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e -F src/select.c b7b91db829464db6ebba4cd6a878a0ef688b847d +F src/select.c d66970749a9d5a5b04950c9a26d6d0ea1320f91b F src/shell.c 28b3e1174a7fc00155d7d00880a33589a88508c9 F src/sqlite.h.in ca27603a36fcacdaac5a19d8ee35aaff8ce8516f F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad @@ -839,7 +839,7 @@ F test/securedel2.test 2d54c28e46eb1fd6902089958b20b1b056c6f1c5 F test/select1.test 53c3a5228b099601eafc7f3cc0e9cd682b07d9d5 F test/select2.test 352480e0e9c66eda9c3044e412abdf5be0215b56 F test/select3.test 2ce595f8fb8e2ac10071d3b4e424cadd4634a054 -F test/select4.test d4330ee0e24e52fa21c62c6bbf999dbfcbb7dfd0 +F test/select4.test 4b2df48129369a2a426f0f710fb94c50f75b31fb F test/select5.test e758b8ef94f69b111df4cb819008856655dcd535 F test/select6.test 39eac4a5c03650b2b473c532882273283ee8b7a0 F test/select7.test 7fd2ef598cfabb6b9ff6ac13973b91d0527df49d @@ -1250,7 +1250,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 928f973ca9adc7933015b2fb6b6fcb8e3154cb9c -R f9e99024211f275c6c5be92b169c1ffa +P e0a88176fcfbed7b554a036948261a332c920053 +R 0b75ab69a90f92b9d27a639039ba6734 U drh -Z 092fd595f2813758c3267ca51aac5606 +Z 2a30576e418c5afefa31fbc64fb3a4fe diff --git a/manifest.uuid b/manifest.uuid index 91ff8f2a2e..7c6fbacdd3 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -e0a88176fcfbed7b554a036948261a332c920053 \ No newline at end of file +10715b05f2201a63dca317f99ce39d3ce182e182 \ No newline at end of file diff --git a/src/select.c b/src/select.c index c7c7095032..e4e5d6da8d 100644 --- a/src/select.c +++ b/src/select.c @@ -2628,7 +2628,7 @@ static int generateOutputSubroutine( ** of the scan loop. */ case SRT_Mem: { - assert( pIn->nSdst==1 ); + assert( pIn->nSdst==1 || pParse->nErr>0 ); testcase( pIn->nSdst!=1 ); sqlite3ExprCodeMove(pParse, pIn->iSdst, pDest->iSDParm, 1); /* The LIMIT clause will jump out of the loop for us */ break; diff --git a/test/select4.test b/test/select4.test index ce09ba71d4..7718901c0c 100644 --- a/test/select4.test +++ b/test/select4.test @@ -118,6 +118,10 @@ do_test select4-1.3 { }} msg] lappend v $msg } {1 {ORDER BY clause should come after UNION ALL not before}} +do_catchsql_test select4-1.4 { + SELECT (VALUES(0) INTERSECT SELECT(0) UNION SELECT(0) ORDER BY (0) UNION + SELECT 0 UNION SELECT 0 ORDER BY 1); +} {1 {ORDER BY clause should come after UNION not before}} # Union operator # From 6dc4148547a0e3e60b4688fb7d142ae55181460d Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 16 Apr 2015 17:31:02 +0000 Subject: [PATCH 133/181] Fix the VDBE so that it always uses the original opcode for profiling and debugging even after the pOp pointer has been updated due to a jump. FossilOrigin-Name: 647495cf12b656f6a2f028dc1fb459d667153cf2 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/vdbe.c | 20 +++++++++++++------- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/manifest b/manifest index 8446774a73..926e070400 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sfaulty\sassert()\sin\sthe\scompound-SELECT\scode\sgenerator. -D 2015-04-16T16:22:27.087 +C Fix\sthe\sVDBE\sso\sthat\sit\salways\suses\sthe\soriginal\sopcode\sfor\sprofiling\sand\ndebugging\seven\safter\sthe\spOp\spointer\shas\sbeen\supdated\sdue\sto\sa\sjump. +D 2015-04-16T17:31:02.931 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5f78b1ab81b64e7c57a75d170832443e66c0880a F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -293,7 +293,7 @@ F src/update.c 3c4ecc282accf12d39edb8d524cf089645e55a13 F src/utf.c fc6b889ba0779b7722634cdeaa25f1930d93820c F src/util.c 98a7627ca48ad3265b6940915a1d08355eb3fc7e F src/vacuum.c 2ddd5cad2a7b9cef7f9e431b8c7771634c6b1701 -F src/vdbe.c 3f3afd12d4794cb51fe13dc948b1172a5eb71a94 +F src/vdbe.c 55650cb03d26ce5955cffcdc6568e046680b1fd4 F src/vdbe.h 7e538ecf47dccb307ea2d087c3ddc2dd8d70e79d F src/vdbeInt.h 9cbaa84f53ddd2d09a0cf61a94337a3a035d08a0 F src/vdbeapi.c 583d56b129dd27f12bed518270de9ebe521e6a75 @@ -1250,7 +1250,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 e0a88176fcfbed7b554a036948261a332c920053 -R 0b75ab69a90f92b9d27a639039ba6734 +P 10715b05f2201a63dca317f99ce39d3ce182e182 +R a3daab05325b2d95fe679d302a2d11e4 U drh -Z 2a30576e418c5afefa31fbc64fb3a4fe +Z 9f3c109ab0871adbf8f7030a7a0d36ce diff --git a/manifest.uuid b/manifest.uuid index 7c6fbacdd3..e49cab3edf 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -10715b05f2201a63dca317f99ce39d3ce182e182 \ No newline at end of file +647495cf12b656f6a2f028dc1fb459d667153cf2 \ No newline at end of file diff --git a/src/vdbe.c b/src/vdbe.c index 3bd4222c8b..0890df11a5 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -539,6 +539,9 @@ int sqlite3VdbeExec( ){ Op *aOp = p->aOp; /* Copy of p->aOp */ Op *pOp = aOp; /* Current operation */ +#if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE) + Op *pOrigOp; /* Value of pOp at the top of the loop */ +#endif int rc = SQLITE_OK; /* Value to return */ sqlite3 *db = p->db; /* The database */ u8 resetSchemaOnFault = 0; /* Reset schema after an error if positive */ @@ -681,6 +684,9 @@ int sqlite3VdbeExec( memAboutToChange(p, &aMem[pOp->p3]); } #endif +#if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE) + pOrigOp = pOp; +#endif switch( pOp->opcode ){ @@ -6489,8 +6495,8 @@ default: { /* This is really OP_Noop and OP_Explain */ #ifdef VDBE_PROFILE { u64 endTime = sqlite3Hwtime(); - if( endTime>start ) pOp->cycles += endTime - start; - pOp->cnt++; + if( endTime>start ) pOrigOp->cycles += endTime - start; + pOrigOp->cnt++; } #endif @@ -6500,16 +6506,16 @@ default: { /* This is really OP_Noop and OP_Explain */ ** the evaluator loop. So we can leave it out when NDEBUG is defined. */ #ifndef NDEBUG - assert( pOp>=&aOp[-1] && pOp<&aOp[p->nOp] ); + assert( pOp>=&aOp[-1] && pOp<&aOp[p->nOp-1] ); #ifdef SQLITE_DEBUG if( db->flags & SQLITE_VdbeTrace ){ if( rc!=0 ) printf("rc=%d\n",rc); - if( pOp->opflags & (OPFLG_OUT2) ){ - registerTrace(pOp->p2, &aMem[pOp->p2]); + if( pOrigOp->opflags & (OPFLG_OUT2) ){ + registerTrace(pOrigOp->p2, &aMem[pOrigOp->p2]); } - if( pOp->opflags & OPFLG_OUT3 ){ - registerTrace(pOp->p3, &aMem[pOp->p3]); + if( pOrigOp->opflags & OPFLG_OUT3 ){ + registerTrace(pOrigOp->p3, &aMem[pOrigOp->p3]); } } #endif /* SQLITE_DEBUG */ From ab4e7f3337e8a7942492b09813826f6ae0cdc43f Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 16 Apr 2015 18:11:50 +0000 Subject: [PATCH 134/181] Make sure all cursors are closed when returning from a VDBE subprogram that implements a foreign-key construct. FossilOrigin-Name: d04d354d8e423961c3091b6ebcfbbbf10d3ecb04 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/vdbeaux.c | 29 ++++++++++++++++++----------- test/fkey2.test | 5 +++++ 4 files changed, 31 insertions(+), 19 deletions(-) diff --git a/manifest b/manifest index 926e070400..fbd6b0739e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sthe\sVDBE\sso\sthat\sit\salways\suses\sthe\soriginal\sopcode\sfor\sprofiling\sand\ndebugging\seven\safter\sthe\spOp\spointer\shas\sbeen\supdated\sdue\sto\sa\sjump. -D 2015-04-16T17:31:02.931 +C Make\ssure\sall\scursors\sare\sclosed\swhen\sreturning\sfrom\sa\sVDBE\ssubprogram\sthat\nimplements\sa\sforeign-key\sconstruct. +D 2015-04-16T18:11:50.067 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5f78b1ab81b64e7c57a75d170832443e66c0880a F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -297,7 +297,7 @@ F src/vdbe.c 55650cb03d26ce5955cffcdc6568e046680b1fd4 F src/vdbe.h 7e538ecf47dccb307ea2d087c3ddc2dd8d70e79d F src/vdbeInt.h 9cbaa84f53ddd2d09a0cf61a94337a3a035d08a0 F src/vdbeapi.c 583d56b129dd27f12bed518270de9ebe521e6a75 -F src/vdbeaux.c a20504ae52392459fa08402fda3f195f19d7c79d +F src/vdbeaux.c 03591cca98ec50e1493043f0ff7abbece0b9c83d F src/vdbeblob.c 4f2e8e075d238392df98c5e03a64342465b03f90 F src/vdbemem.c c0dc81285b7571b0a31c40f17846fe2397ec1cd9 F src/vdbesort.c 2e7f683464fd5db3be4beaa1ff2d39e24fcb64b8 @@ -505,7 +505,7 @@ F test/fallocate.test 3e979af17dfa7e5e9dda5eba1a696c04fa9d47f7 F test/filectrl.test 14fa712e42c4cb791e09dfd58a6a03efb47ef13a F test/filefmt.test cb34663f126cbc2d358af552dcaf5c72769b0146 F test/fkey1.test e1d1fa84cde579185ea01358436839703e415a5b -F test/fkey2.test 043692a609d513f8f230ca3064e8074f8643b60e +F test/fkey2.test f3d27ecba480a348c328965d154214719bb158a9 F test/fkey3.test 76d475c80b84ee7a5d062e56ccb6ea68882e2b49 F test/fkey4.test 86446017011273aad8f9a99c1a65019e7bd9ca9d F test/fkey5.test 56bcb5a6e8b725b17febc267fb041a6695e86853 @@ -1250,7 +1250,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 10715b05f2201a63dca317f99ce39d3ce182e182 -R a3daab05325b2d95fe679d302a2d11e4 +P 647495cf12b656f6a2f028dc1fb459d667153cf2 +R a757fbed701cb5d24ccca7b2844fe222 U drh -Z 9f3c109ab0871adbf8f7030a7a0d36ce +Z 3babb77db24db798d253708de47714ee diff --git a/manifest.uuid b/manifest.uuid index e49cab3edf..3c86d5dfe0 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -647495cf12b656f6a2f028dc1fb459d667153cf2 \ No newline at end of file +d04d354d8e423961c3091b6ebcfbbbf10d3ecb04 \ No newline at end of file diff --git a/src/vdbeaux.c b/src/vdbeaux.c index 1c10bab0b8..2c32038564 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -1789,6 +1789,22 @@ void sqlite3VdbeFreeCursor(Vdbe *p, VdbeCursor *pCx){ #endif } +/* +** Close all cursors in the current frame. +*/ +static void closeCursorsInFrame(Vdbe *p){ + if( p->apCsr ){ + int i; + for(i=0; inCursor; i++){ + VdbeCursor *pC = p->apCsr[i]; + if( pC ){ + sqlite3VdbeFreeCursor(p, pC); + p->apCsr[i] = 0; + } + } + } +} + /* ** Copy the values stored in the VdbeFrame structure to its Vdbe. This ** is used, for example, when a trigger sub-program is halted to restore @@ -1796,6 +1812,7 @@ void sqlite3VdbeFreeCursor(Vdbe *p, VdbeCursor *pCx){ */ int sqlite3VdbeFrameRestore(VdbeFrame *pFrame){ Vdbe *v = pFrame->v; + closeCursorsInFrame(v); #ifdef SQLITE_ENABLE_STMT_SCANSTATUS v->anExec = pFrame->anExec; #endif @@ -1830,17 +1847,7 @@ static void closeAllCursors(Vdbe *p){ p->nFrame = 0; } assert( p->nFrame==0 ); - - if( p->apCsr ){ - int i; - for(i=0; inCursor; i++){ - VdbeCursor *pC = p->apCsr[i]; - if( pC ){ - sqlite3VdbeFreeCursor(p, pC); - p->apCsr[i] = 0; - } - } - } + closeCursorsInFrame(p); if( p->aMem ){ releaseMemArray(&p->aMem[1], p->nMem); } diff --git a/test/fkey2.test b/test/fkey2.test index d0b284b780..aec75ed693 100644 --- a/test/fkey2.test +++ b/test/fkey2.test @@ -676,6 +676,11 @@ do_test fkey2-9.2.3 { SELECT * FROM cc; } } {{} A {} {} B {} 3 A 2 3 B 2} +do_execsql_test fkey2-9.3.0 { + CREATE TABLE t3(x PRIMARY KEY REFERENCES t3 ON DELETE SET NULL); + INSERT INTO t3(x) VALUES(12345); + DROP TABLE t3; +} {} #------------------------------------------------------------------------- # The following tests, fkey2-10.*, test "foreign key mismatch" and From a4bb7764fe5af31cd71215d17327aebd0c32417d Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 16 Apr 2015 20:10:17 +0000 Subject: [PATCH 135/181] Fix a boundry-value condition in the phrase poslist extractor of FTS3/4. FossilOrigin-Name: 55d10baf0bffdb1a34bf5627ed8f25e4a4efd942 --- ext/fts3/fts3.c | 3 ++- manifest | 12 ++++++------ manifest.uuid | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/ext/fts3/fts3.c b/ext/fts3/fts3.c index eab8ad63ad..0555025f1a 100644 --- a/ext/fts3/fts3.c +++ b/ext/fts3/fts3.c @@ -5765,7 +5765,8 @@ int sqlite3Fts3EvalPhrasePoslist( pIter = pPhrase->pOrPoslist; iDocid = pPhrase->iOrDocid; if( pCsr->bDesc==bDescDoclist ){ - bEof = (pIter >= (pPhrase->doclist.aAll + pPhrase->doclist.nAll)); + bEof = !pPhrase->doclist.nAll || + (pIter >= (pPhrase->doclist.aAll + pPhrase->doclist.nAll)); while( (pIter==0 || DOCID_CMP(iDocid, pCsr->iPrevId)<0 ) && bEof==0 ){ sqlite3Fts3DoclistNext( bDescDoclist, pPhrase->doclist.aAll, pPhrase->doclist.nAll, diff --git a/manifest b/manifest index fbd6b0739e..e2292c4541 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Make\ssure\sall\scursors\sare\sclosed\swhen\sreturning\sfrom\sa\sVDBE\ssubprogram\sthat\nimplements\sa\sforeign-key\sconstruct. -D 2015-04-16T18:11:50.067 +C Fix\sa\sboundry-value\scondition\sin\sthe\sphrase\sposlist\sextractor\sof\sFTS3/4. +D 2015-04-16T20:10:17.867 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5f78b1ab81b64e7c57a75d170832443e66c0880a F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -78,7 +78,7 @@ F ext/fts3/README.content fdc666a70d5257a64fee209f97cf89e0e6e32b51 F ext/fts3/README.syntax a19711dc5458c20734b8e485e75fb1981ec2427a F ext/fts3/README.tokenizers e0a8b81383ea60d0334d274fadf305ea14a8c314 F ext/fts3/README.txt 8c18f41574404623b76917b9da66fcb0ab38328d -F ext/fts3/fts3.c 4bd75289875b63c04f943d6ed7c31737da99cd74 +F ext/fts3/fts3.c cb5019020e1ca8e999beb2a63100563c17def8ae F ext/fts3/fts3.h 3a10a0af180d502cecc50df77b1b22df142817fe F ext/fts3/fts3Int.h 3626655d6ba903a3919bb44e1c38e5f0f9d6be82 F ext/fts3/fts3_aux.c 5c211e17a64885faeb16b9ba7772f9d5445c2365 @@ -1250,7 +1250,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 647495cf12b656f6a2f028dc1fb459d667153cf2 -R a757fbed701cb5d24ccca7b2844fe222 +P d04d354d8e423961c3091b6ebcfbbbf10d3ecb04 +R 7d25758eea33f4a370736317991c770a U drh -Z 3babb77db24db798d253708de47714ee +Z 4086867d1a0bc88e855064836598b64d diff --git a/manifest.uuid b/manifest.uuid index 3c86d5dfe0..7320463437 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -d04d354d8e423961c3091b6ebcfbbbf10d3ecb04 \ No newline at end of file +55d10baf0bffdb1a34bf5627ed8f25e4a4efd942 \ No newline at end of file From f3151f0a0d251d70a606aa25983d2261811e1e65 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 16 Apr 2015 20:27:09 +0000 Subject: [PATCH 136/181] Fix a couple of unreachable branches. FossilOrigin-Name: 8f391dffcfe068d48f854784648610d8a86f6bc8 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/parse.y | 2 +- src/tokenize.c | 4 +--- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/manifest b/manifest index e2292c4541..4eae8fd3c1 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sboundry-value\scondition\sin\sthe\sphrase\sposlist\sextractor\sof\sFTS3/4. -D 2015-04-16T20:10:17.867 +C Fix\sa\scouple\sof\sunreachable\sbranches. +D 2015-04-16T20:27:09.079 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5f78b1ab81b64e7c57a75d170832443e66c0880a F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -219,7 +219,7 @@ F src/os_win.c 03d27be3a20048ef52a648d5f0a15f5edda9f2a3 F src/os_win.h eb7a47aa17b26b77eb97e4823f20a00b8bda12ca F src/pager.c 4120a49ecd37697e28f5ed807f470b9c0b88410c F src/pager.h c3476e7c89cdf1c6914e50a11f3714e30b4e0a77 -F src/parse.y b5c16bc5aa5e59a7ceb0fe94defa9dce3a6b1d3c +F src/parse.y 5944031bd7660589a7bb340cef5e134b55f01ec0 F src/pcache.c 10539fb959849ad6efff80050541cab3d25089d4 F src/pcache.h b44658c9c932d203510279439d891a2a83e12ba8 F src/pcache1.c 69d137620a305f814398bd29a0c998038c0695e9 @@ -287,7 +287,7 @@ F src/test_vfs.c b7e6831e6fcf04c5090accff30640ec5c9630739 F src/test_vfstrace.c bab9594adc976cbe696ff3970728830b4c5ed698 F src/test_wsd.c 41cadfd9d97fe8e3e4e44f61a4a8ccd6f7ca8fe9 F src/threads.c 6bbcc9fe50c917864d48287b4792d46d6e873481 -F src/tokenize.c a8234a67577308935cdf13e618cd66556f5f45d1 +F src/tokenize.c b7fb584c2be5ec39b6fdf04b185e7c6f33f8dc15 F src/trigger.c a261da05e2ba65035d6f4b85d1fe6d4f363c1f1f F src/update.c 3c4ecc282accf12d39edb8d524cf089645e55a13 F src/utf.c fc6b889ba0779b7722634cdeaa25f1930d93820c @@ -1250,7 +1250,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 d04d354d8e423961c3091b6ebcfbbbf10d3ecb04 -R 7d25758eea33f4a370736317991c770a +P 55d10baf0bffdb1a34bf5627ed8f25e4a4efd942 +R 114fb2d7e0df7ea2622d3974dda61e5a U drh -Z 4086867d1a0bc88e855064836598b64d +Z 08da3cff84a49c68f76471919d394d1c diff --git a/manifest.uuid b/manifest.uuid index 7320463437..8ae628632f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -55d10baf0bffdb1a34bf5627ed8f25e4a4efd942 \ No newline at end of file +8f391dffcfe068d48f854784648610d8a86f6bc8 \ No newline at end of file diff --git a/src/parse.y b/src/parse.y index ac15c3ce71..a2ad10eb5f 100644 --- a/src/parse.y +++ b/src/parse.y @@ -509,7 +509,7 @@ values(A) ::= VALUES LP nexprlist(X) RP. { values(A) ::= values(X) COMMA LP exprlist(Y) RP. { Select *pRight, *pLeft = X; pRight = sqlite3SelectNew(pParse,Y,0,0,0,0,0,SF_Values|SF_MultiValue,0,0); - if( pLeft ) pLeft->selFlags &= ~SF_MultiValue; + if( ALWAYS(pLeft) ) pLeft->selFlags &= ~SF_MultiValue; if( pRight ){ pRight->op = TK_ALL; pLeft = X; diff --git a/src/tokenize.c b/src/tokenize.c index 2f8fd98ede..076acb0209 100644 --- a/src/tokenize.c +++ b/src/tokenize.c @@ -516,8 +516,6 @@ abort_parse: pParse->pZombieTab = p->pNextZombie; sqlite3DeleteTable(db, p); } - if( nErr>0 && pParse->rc==SQLITE_OK ){ - pParse->rc = SQLITE_ERROR; - } + assert( nErr==0 || pParse->rc!=SQLITE_OK ); return nErr; } From e318a7f84c90003309cf7b518524bad9b8d50492 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 16 Apr 2015 23:04:17 +0000 Subject: [PATCH 137/181] Restrict the scope of a local-use function in the parser. FossilOrigin-Name: cd6598f47480a6189df3e4283231833fd246d7fb --- manifest | 13 ++++++------- manifest.uuid | 2 +- src/parse.y | 2 +- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 7fd7cbd6c6..6bc57d0ca6 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Use\sa\sheap\srather\sthan\sa\sbitmap\sfor\scell\scoverage\sand\soverlap\stesting\son\nbtree\spages\sin\sPRAGMA\sintegrity_check. -D 2015-04-16T21:57:37.861 +C Restrict\sthe\sscope\sof\sa\slocal-use\sfunction\sin\sthe\sparser. +D 2015-04-16T23:04:17.948 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5f78b1ab81b64e7c57a75d170832443e66c0880a F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -219,7 +219,7 @@ F src/os_win.c 03d27be3a20048ef52a648d5f0a15f5edda9f2a3 F src/os_win.h eb7a47aa17b26b77eb97e4823f20a00b8bda12ca F src/pager.c 4120a49ecd37697e28f5ed807f470b9c0b88410c F src/pager.h c3476e7c89cdf1c6914e50a11f3714e30b4e0a77 -F src/parse.y 5944031bd7660589a7bb340cef5e134b55f01ec0 +F src/parse.y c4e0387bc88c8e21e5ba653e2578959a1f3cdbc7 F src/pcache.c 10539fb959849ad6efff80050541cab3d25089d4 F src/pcache.h b44658c9c932d203510279439d891a2a83e12ba8 F src/pcache1.c 69d137620a305f814398bd29a0c998038c0695e9 @@ -1250,8 +1250,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 8f391dffcfe068d48f854784648610d8a86f6bc8 5619c959bf7babb19fd8ba8b228be7f090fe0ce3 -R 72a6fa603587f85ee318933146285087 -T +closed 5619c959bf7babb19fd8ba8b228be7f090fe0ce3 +P e94b2ef2242d716379a35dba3d2df1ac512c8d30 +R 70b7123ef26fc35932871334bf1b767b U drh -Z e48be2bfe822e32604f22d78d2be1c02 +Z 97923746cc2f7b18a22c50ab5601a1cf diff --git a/manifest.uuid b/manifest.uuid index 9dea5b13da..7189dc2e98 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -e94b2ef2242d716379a35dba3d2df1ac512c8d30 \ No newline at end of file +cd6598f47480a6189df3e4283231833fd246d7fb \ No newline at end of file diff --git a/src/parse.y b/src/parse.y index a2ad10eb5f..6a64206ac0 100644 --- a/src/parse.y +++ b/src/parse.y @@ -415,7 +415,7 @@ cmd ::= select(X). { ** all elements in the list. And make sure list length does not exceed ** SQLITE_LIMIT_COMPOUND_SELECT. */ - void parserDoubleLinkSelect(Parse *pParse, Select *p){ + static void parserDoubleLinkSelect(Parse *pParse, Select *p){ if( p->pPrior ){ Select *pNext = 0, *pLoop; int mxSelect, cnt = 0; From 50be9c4b288a3d07b2ff11b377ce84bbd288dc26 Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 17 Apr 2015 12:16:09 +0000 Subject: [PATCH 138/181] Fix the header comment on the sqldiff utility program. No code changes. FossilOrigin-Name: b355ca3a3f617cd6d4c45c8e27ecd75d9e68b792 --- manifest | 12 ++++++------ manifest.uuid | 2 +- tool/sqldiff.c | 7 ++++++- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 6bc57d0ca6..319d197291 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Restrict\sthe\sscope\sof\sa\slocal-use\sfunction\sin\sthe\sparser. -D 2015-04-16T23:04:17.948 +C Fix\sthe\sheader\scomment\son\sthe\ssqldiff\sutility\sprogram.\s\sNo\scode\schanges. +D 2015-04-17T12:16:09.669 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5f78b1ab81b64e7c57a75d170832443e66c0880a F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -1239,7 +1239,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/split-sqlite3c.tcl d9be87f1c340285a3e081eb19b4a247981ed290c -F tool/sqldiff.c 5c16cf3a1f566873abbdecac0d13a6691437564f +F tool/sqldiff.c 393b0f5b17ef29341664563a90d40ee63a0a18f7 F tool/stack_usage.tcl f8e71b92cdb099a147dad572375595eae55eca43 F tool/symbols-mingw.sh 4dbcea7e74768305384c9fd2ed2b41bbf9f0414d F tool/symbols.sh fec58532668296d7c7dc48be9c87f75ccdb5814f @@ -1250,7 +1250,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 e94b2ef2242d716379a35dba3d2df1ac512c8d30 -R 70b7123ef26fc35932871334bf1b767b +P cd6598f47480a6189df3e4283231833fd246d7fb +R bfdce473d247dbaaedf4cb00e3a28380 U drh -Z 97923746cc2f7b18a22c50ab5601a1cf +Z c972653cce57a7491204b613b522cd75 diff --git a/manifest.uuid b/manifest.uuid index 7189dc2e98..e7fbfbeb71 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -cd6598f47480a6189df3e4283231833fd246d7fb \ No newline at end of file +b355ca3a3f617cd6d4c45c8e27ecd75d9e68b792 \ No newline at end of file diff --git a/tool/sqldiff.c b/tool/sqldiff.c index c7b59400df..ad19b8cf24 100644 --- a/tool/sqldiff.c +++ b/tool/sqldiff.c @@ -10,8 +10,13 @@ ** ************************************************************************* ** -** This is a utility problem that computes the differences in content +** This is a utility program that computes the differences in content ** between two SQLite databases. +** +** To compile, simply link against SQLite. +** +** See the showHelp() routine below for a brief description of how to +** run the utility. */ #include #include From 268e72f936f49fba9660e52d781085f515f2cf45 Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 17 Apr 2015 14:30:49 +0000 Subject: [PATCH 139/181] Add the tool/fuzzershell.c utility program. FossilOrigin-Name: db8d9af4d04ee862995ffa13ae6dcd9a1fc72855 --- Makefile.in | 3 + Makefile.msc | 3 + main.mk | 4 + manifest | 17 +-- manifest.uuid | 2 +- tool/fuzzershell.c | 294 +++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 314 insertions(+), 9 deletions(-) create mode 100644 tool/fuzzershell.c diff --git a/Makefile.in b/Makefile.in index 295a6bc9c1..6b3f18c35c 100644 --- a/Makefile.in +++ b/Makefile.in @@ -539,6 +539,9 @@ sqlite3$(TEXE): $(TOP)/src/shell.c libsqlite3.la sqlite3.h sqldiff$(EXE): $(TOP)/tool/sqldiff.c sqlite3.c sqlite3.h $(LTLINK) -o $@ $(TOP)/tool/sqldiff.c sqlite3.c $(TLIBS) +fuzzershell$(EXE): $(TOP)/tool/fuzzershell.c sqlite3.c sqlite3.h + $(LTLINK) -o $@ $(TOP)/tool/fuzzershell.c sqlite3.c $(TLIBS) + mptester$(EXE): sqlite3.c $(TOP)/mptest/mptest.c $(LTLINK) -o $@ -I. $(TOP)/mptest/mptest.c sqlite3.c \ $(TLIBS) -rpath "$(libdir)" diff --git a/Makefile.msc b/Makefile.msc index f13418ffb7..914bb1e7ad 100644 --- a/Makefile.msc +++ b/Makefile.msc @@ -1159,6 +1159,9 @@ sqlite3.exe: $(TOP)\src\shell.c $(SHELL_CORE_DEP) $(LIBRESOBJS) sqlite3.h sqldiff.exe: $(TOP)\tool\sqldiff.c sqlite3.c sqlite3.h $(LTLINK) $(TOP)\tool\sqldiff.c sqlite3.c +fuzzershell.exe: $(TOP)\tool\fuzzershell.c sqlite3.c sqlite3.h + $(LTLINK) $(TOP)\tool\fuzzershell.c sqlite3.c + mptester.exe: $(TOP)\mptest\mptest.c $(SHELL_CORE_DEP) $(LIBRESOBJS) sqlite3.h $(LTLINK) $(SHELL_COMPILE_OPTS) $(TOP)\mptest\mptest.c \ /link $(LTLINKOPTS) $(LTLIBPATHS) $(SHELL_LINK_OPTS) $(LIBRESOBJS) $(LIBREADLINE) $(LTLIBS) $(TLIBS) diff --git a/main.mk b/main.mk index c5328dc6c7..22c4f3e02d 100644 --- a/main.mk +++ b/main.mk @@ -408,6 +408,10 @@ sqldiff$(EXE): $(TOP)/tool/sqldiff.c sqlite3.c sqlite3.h $(TCCX) -o sqldiff$(EXE) -DSQLITE_THREADSAFE=0 \ $(TOP)/tool/sqldiff.c sqlite3.c $(TLIBS) $(THREADLIB) +fuzzershell$(EXE): $(TOP)/tool/fuzzershell.c sqlite3.c sqlite3.h + $(TCCX) -o fuzzershell$(EXE) -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION\ + $(TOP)/tool/fuzzershell.c sqlite3.c $(TLIBS) $(THREADLIB) + mptester$(EXE): sqlite3.c $(TOP)/mptest/mptest.c $(TCCX) -o $@ -I. $(TOP)/mptest/mptest.c sqlite3.c \ $(TLIBS) $(THREADLIB) diff --git a/manifest b/manifest index 319d197291..d8d547e501 100644 --- a/manifest +++ b/manifest @@ -1,9 +1,9 @@ -C Fix\sthe\sheader\scomment\son\sthe\ssqldiff\sutility\sprogram.\s\sNo\scode\schanges. -D 2015-04-17T12:16:09.669 +C Add\sthe\stool/fuzzershell.c\sutility\sprogram. +D 2015-04-17T14:30:49.931 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f -F Makefile.in 5f78b1ab81b64e7c57a75d170832443e66c0880a +F Makefile.in faaf75b89840659d74501bea269c7e33414761c1 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 -F Makefile.msc 11cb5361e34b80e9c5b417ed6a6deee099c5b5f3 +F Makefile.msc a19bceec468fa18bb54df52257b1a2211e69172d F Makefile.vxworks e1b65dea203f054e71653415bd8f96dcaed47858 F README.md d58e3bebc0a4145e0f2a87994015fdb575a8e866 F VERSION 2e244662b71e6e68a5c29b014ebc5b7564f4cc5a @@ -152,7 +152,7 @@ F ext/userauth/userauth.c 5fa3bdb492f481bbc1709fc83c91ebd13460c69e F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 x F ltmain.sh 3ff0879076df340d2e23ae905484d8c15d5fdea8 F magic.txt 8273bf49ba3b0c8559cb2774495390c31fd61c60 -F main.mk ddffac494a82d42772df9fe30d3a78acf4f7cb41 +F main.mk 60aba7d38b9bd73e249693344dd8405aa24ac02a F mkopcodec.awk c2ff431854d702cdd2d779c9c0d1f58fa16fa4ea F mkopcodeh.awk d5e22023b5238985bb54a72d33e0ac71fe4f8a32 F mkso.sh fd21c06b063bb16a5d25deea1752c2da6ac3ed83 @@ -1203,6 +1203,7 @@ F tool/diffdb.c 7524b1b5df217c20cd0431f6789851a4e0cb191b F tool/extract.c 054069d81b095fbdc189a6f5d4466e40380505e2 F tool/fast_vacuum.c 5ba0d6f5963a0a63bdc42840f678bad75b2ebce1 F tool/fragck.tcl 5265a95126abcf6ab357f7efa544787e5963f439 +F tool/fuzzershell.c 9e7e273da203037154b433bb67f10b0d9772b370 F tool/genfkey.README cf68fddd4643bbe3ff8e31b8b6d8b0a1b85e20f4 F tool/genfkey.test 4196a8928b78f51d54ef58e99e99401ab2f0a7e5 F tool/getlock.c f4c39b651370156cae979501a7b156bdba50e7ce @@ -1250,7 +1251,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 cd6598f47480a6189df3e4283231833fd246d7fb -R bfdce473d247dbaaedf4cb00e3a28380 +P b355ca3a3f617cd6d4c45c8e27ecd75d9e68b792 +R d4d32c82236775154903bd68de367067 U drh -Z c972653cce57a7491204b613b522cd75 +Z b7bf748b01ea8ab50dc7b538dea6204b diff --git a/manifest.uuid b/manifest.uuid index e7fbfbeb71..b1fc9a1168 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -b355ca3a3f617cd6d4c45c8e27ecd75d9e68b792 \ No newline at end of file +db8d9af4d04ee862995ffa13ae6dcd9a1fc72855 \ No newline at end of file diff --git a/tool/fuzzershell.c b/tool/fuzzershell.c new file mode 100644 index 0000000000..a44a722505 --- /dev/null +++ b/tool/fuzzershell.c @@ -0,0 +1,294 @@ +/* +** 2015-04-17 +** +** 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 is a utility program designed to aid running the SQLite library +** against an external fuzzer, such as American Fuzzy Lop (AFL) +** (http://lcamtuf.coredump.cx/afl/). Basically, this program reads +** SQL text from standard input and passes it through to SQLite for evaluation, +** just like the "sqlite3" command-line shell. Differences from the +** command-line shell: +** +** (1) The complex "dot-command" extensions are omitted. This +** prevents the fuzzer from discovering that it can run things +** like ".shell rm -rf ~" +** +** (2) The database is opened with the SQLITE_OPEN_MEMORY flag so that +** no disk I/O from the database is permitted. The ATTACH command +** with a filename still uses an in-memory database. +** +** (3) The main in-memory database can be initialized from a template +** disk database so that the fuzzer starts with a database containing +** content. +** +** (4) The eval() SQL function is added, allowing the fuzzer to do +** interesting recursive operations. +*/ +#include +#include +#include +#include +#include "sqlite3.h" + +/* +** All global variables are gathered into the "g" singleton. +*/ +struct GlobalVars { + const char *zArgv0; /* Name of program */ +} g; + + + +/* +** Print an error message and abort in such a way to indicate to the +** fuzzer that this counts as a crash. +*/ +static void abendError(const char *zFormat, ...){ + va_list ap; + fprintf(stderr, "%s: ", g.zArgv0); + va_start(ap, zFormat); + vfprintf(stderr, zFormat, ap); + va_end(ap); + fprintf(stderr, "\n"); + abort(); +} +/* +** Print an error message and quit, but not in a way that would look +** like a crash. +*/ +static void fatalError(const char *zFormat, ...){ + va_list ap; + fprintf(stderr, "%s: ", g.zArgv0); + va_start(ap, zFormat); + vfprintf(stderr, zFormat, ap); + va_end(ap); + fprintf(stderr, "\n"); + exit(1); +} + +/* +** This callback is invoked by sqlite3_log(). +*/ +static void shellLog(void *pNotUsed, int iErrCode, const char *zMsg){ + printf("LOG: (%d) %s\n", iErrCode, zMsg); +} + +/* +** This callback is invoked by sqlite3_exec() to return query results. +*/ +static int execCallback(void *NotUsed, int argc, char **argv, char **colv){ + int i; + static unsigned cnt = 0; + printf("ROW #%u:\n", ++cnt); + for(i=0; inUsed+p->szSep+1 > p->nAlloc ){ + char *zNew; + p->nAlloc = p->nAlloc*2 + sz + p->szSep + 1; + /* Using sqlite3_realloc64() would be better, but it is a recent + ** addition and will cause a segfault if loaded by an older version + ** of SQLite. */ + zNew = p->nAlloc<=0x7fffffff ? sqlite3_realloc(p->z, (int)p->nAlloc) : 0; + if( zNew==0 ){ + sqlite3_free(p->z); + memset(p, 0, sizeof(*p)); + return 1; + } + p->z = zNew; + } + if( p->nUsed>0 ){ + memcpy(&p->z[p->nUsed], p->zSep, p->szSep); + p->nUsed += p->szSep; + } + memcpy(&p->z[p->nUsed], z, sz); + p->nUsed += sz; + } + return 0; +} + +/* +** Implementation of the eval(X) and eval(X,Y) SQL functions. +** +** Evaluate the SQL text in X. Return the results, using string +** Y as the separator. If Y is omitted, use a single space character. +*/ +static void sqlEvalFunc( + sqlite3_context *context, + int argc, + sqlite3_value **argv +){ + const char *zSql; + sqlite3 *db; + char *zErr = 0; + int rc; + struct EvalResult x; + + memset(&x, 0, sizeof(x)); + x.zSep = " "; + zSql = (const char*)sqlite3_value_text(argv[0]); + if( zSql==0 ) return; + if( argc>1 ){ + x.zSep = (const char*)sqlite3_value_text(argv[1]); + if( x.zSep==0 ) return; + } + x.szSep = (int)strlen(x.zSep); + db = sqlite3_context_db_handle(context); + rc = sqlite3_exec(db, zSql, callback, &x, &zErr); + if( rc!=SQLITE_OK ){ + sqlite3_result_error(context, zErr, -1); + sqlite3_free(zErr); + }else if( x.zSep==0 ){ + sqlite3_result_error_nomem(context); + sqlite3_free(x.z); + }else{ + sqlite3_result_text(context, x.z, (int)x.nUsed, sqlite3_free); + } +} +/* End of the eval() implementation +******************************************************************************/ + +/* +** Print sketchy documentation for this utility program +*/ +static void showHelp(void){ + printf("Usage: %s [options]\n", g.zArgv0); + printf( +"Read SQL text from standard input and evaluate it.\n" +"Options:\n" +" -f FILE Read SQL text from FILE instead of standard input\n" +" --help Show this help text\n" +" --initdb DBFILE Initialize the in-memory database using template DBFILE\n" + ); +} + + +int main(int argc, char **argv){ + char *zIn = 0; /* Input text */ + int nAlloc = 0; /* Number of bytes allocated for zIn[] */ + int nIn = 0; /* Number of bytes of zIn[] used */ + size_t got; /* Bytes read from input */ + FILE *in = stdin; /* Where to read SQL text from */ + int rc = SQLITE_OK; /* Result codes from API functions */ + int i; /* Loop counter */ + sqlite3 *db; /* Open database */ + sqlite3 *dbInit; /* On-disk database used to initialize the in-memory db */ + const char *zInitDb = 0;/* Name of the initialization database file */ + char *zErrMsg = 0; /* Error message returned from sqlite3_exec() */ + + g.zArgv0 = argv[0]; + for(i=1; i Date: Fri, 17 Apr 2015 15:16:58 +0000 Subject: [PATCH 140/181] Fix a faulty assert() in sqlite3SelectNew(). FossilOrigin-Name: 620d19c3b462f5c4763ebd26513321431f21dd72 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/select.c | 3 +-- test/select1.test | 5 +++++ 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index d8d547e501..0fba60c8e9 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sthe\stool/fuzzershell.c\sutility\sprogram. -D 2015-04-17T14:30:49.931 +C Fix\sa\sfaulty\sassert()\sin\ssqlite3SelectNew(). +D 2015-04-17T15:16:58.290 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in faaf75b89840659d74501bea269c7e33414761c1 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -230,7 +230,7 @@ F src/printf.c 08fa675c200aac29e561c6153f91f909ed17612f F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c 66cfe49a9c3b449ef13b89a8c47036a4ed167eab F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e -F src/select.c d66970749a9d5a5b04950c9a26d6d0ea1320f91b +F src/select.c e7d3f26dd2bb513049c6c585919aa195c862a287 F src/shell.c 28b3e1174a7fc00155d7d00880a33589a88508c9 F src/sqlite.h.in ca27603a36fcacdaac5a19d8ee35aaff8ce8516f F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad @@ -836,7 +836,7 @@ F test/schema4.test e6a66e20cc69f0e306667c08be7fda3d11707dc5 F test/schema5.test 29699b4421f183c8f0e88bd28ce7d75d13ea653e F test/securedel.test 21749c32ccc30f1ea9e4b9f33295a6521ec20fa0 F test/securedel2.test 2d54c28e46eb1fd6902089958b20b1b056c6f1c5 -F test/select1.test 53c3a5228b099601eafc7f3cc0e9cd682b07d9d5 +F test/select1.test be62204d2bd9a5a8a149e9974cfddce893d8f686 F test/select2.test 352480e0e9c66eda9c3044e412abdf5be0215b56 F test/select3.test 2ce595f8fb8e2ac10071d3b4e424cadd4634a054 F test/select4.test 4b2df48129369a2a426f0f710fb94c50f75b31fb @@ -1251,7 +1251,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 b355ca3a3f617cd6d4c45c8e27ecd75d9e68b792 -R d4d32c82236775154903bd68de367067 +P db8d9af4d04ee862995ffa13ae6dcd9a1fc72855 +R a2d46793733766d02a97971b373ce378 U drh -Z b7bf748b01ea8ab50dc7b538dea6204b +Z 3bc04f03d72aa5c77d969deb6f174a4e diff --git a/manifest.uuid b/manifest.uuid index b1fc9a1168..bc2b8b9300 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -db8d9af4d04ee862995ffa13ae6dcd9a1fc72855 \ No newline at end of file +620d19c3b462f5c4763ebd26513321431f21dd72 \ No newline at end of file diff --git a/src/select.c b/src/select.c index e4e5d6da8d..fc5740e80f 100644 --- a/src/select.c +++ b/src/select.c @@ -111,7 +111,6 @@ Select *sqlite3SelectNew( Select standin; sqlite3 *db = pParse->db; pNew = sqlite3DbMallocZero(db, sizeof(*pNew) ); - assert( db->mallocFailed || !pOffset || pLimit ); /* OFFSET implies LIMIT */ if( pNew==0 ){ assert( db->mallocFailed ); pNew = &standin; @@ -131,7 +130,7 @@ Select *sqlite3SelectNew( pNew->op = TK_SELECT; pNew->pLimit = pLimit; pNew->pOffset = pOffset; - assert( pOffset==0 || pLimit!=0 ); + assert( pOffset==0 || pLimit!=0 || pParse->nErr>0 || db->mallocFailed!=0 ); pNew->addrOpenEphm[0] = -1; pNew->addrOpenEphm[1] = -1; if( db->mallocFailed ) { diff --git a/test/select1.test b/test/select1.test index 2ae91dc0fd..4d6c07f2d0 100644 --- a/test/select1.test +++ b/test/select1.test @@ -1075,5 +1075,10 @@ if {[db one {PRAGMA locking_mode}]=="normal"} { do_test select1-16.1 { catchsql {SELECT 1 FROM (SELECT *)} } {1 {no tables specified}} + +# 2015-04-17: assertion fix. +do_catchsql_test select1-16.2 { + SELECT 1 FROM sqlite_master LIMIT 1,#1; +} {1 {near "#1": syntax error}} finish_test From d99d28361eb6022b46e4e45924088913f082f6f7 Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 17 Apr 2015 15:58:33 +0000 Subject: [PATCH 141/181] Ensure that semantic SQL errors are always reported back up to the syntax parser. Also: Improve the defense against invalid PRAGMA synchronous settings. FossilOrigin-Name: 7aeade9a07f29bf26e50394042ea18d0121fe7a3 --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/build.c | 6 ++++-- src/pragma.c | 6 +++--- test/pragma.test | 6 ++++++ 5 files changed, 22 insertions(+), 14 deletions(-) diff --git a/manifest b/manifest index 0fba60c8e9..23cf01f4c5 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sfaulty\sassert()\sin\ssqlite3SelectNew(). -D 2015-04-17T15:16:58.290 +C Ensure\sthat\ssemantic\sSQL\serrors\sare\salways\sreported\sback\sup\sto\sthe\ssyntax\nparser.\s\sAlso:\s\sImprove\sthe\sdefense\sagainst\sinvalid\sPRAGMA\ssynchronous\ssettings. +D 2015-04-17T15:58:33.364 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in faaf75b89840659d74501bea269c7e33414761c1 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -176,7 +176,7 @@ F src/btmutex.c 45a968cc85afed9b5e6cf55bf1f42f8d18107f79 F src/btree.c 127aceb71ba93f59bc9c6ba810e992a04299e98a F src/btree.h 969adc948e89e449220ff0ff724c94bb2a52e9f1 F src/btreeInt.h 973a22a6fd61350b454ad614832b1f0a5e25a1e4 -F src/build.c 01b969b20a44a3d9620e597d9af8242348123540 +F src/build.c f82d394b9ad94be03a13d04edc2b6309ad5274e8 F src/callback.c 7b44ce59674338ad48b0e84e7b72f935ea4f68b0 F src/complete.c a5cf5b4b56390cfb7b8636e8f7ddef90258dd575 F src/ctime.c 98f89724adc891a1a4c655bee04e33e716e05887 @@ -223,7 +223,7 @@ F src/parse.y c4e0387bc88c8e21e5ba653e2578959a1f3cdbc7 F src/pcache.c 10539fb959849ad6efff80050541cab3d25089d4 F src/pcache.h b44658c9c932d203510279439d891a2a83e12ba8 F src/pcache1.c 69d137620a305f814398bd29a0c998038c0695e9 -F src/pragma.c 633cb355ab30b197d4e8e9976f94378199439b76 +F src/pragma.c 2a81f312cdb78bf0672a0484478ca3c1083028e9 F src/pragma.h 09c89bca58e9a44de2116cc8272b8d454657129f F src/prepare.c 1fffbdcd6f8a0173a8f70d71f22528f4c0e1e3d3 F src/printf.c 08fa675c200aac29e561c6153f91f909ed17612f @@ -794,7 +794,7 @@ F test/pcache.test b09104b03160aca0d968d99e8cd2c5b1921a993d F test/pcache2.test a83efe2dec0d392f814bfc998def1d1833942025 F test/percentile.test 4243af26b8f3f4555abe166f723715a1f74c77ff F test/permutations.test f9cc1dd987986c9d4949211c7a4ed55ec9aecba1 -F test/pragma.test 2e3d20785e463d7eeed636cba16e742b5df88073 +F test/pragma.test be7195f0aa72bdb8a512133e9640ac40f15b57a2 F test/pragma2.test f624a496a95ee878e81e59961eade66d5c00c028 F test/pragma3.test 6f849ccffeee7e496d2f2b5e74152306c0b8757c F test/printf.test b3ff34e73d59124140eaf89f7672e21bc2ca5fcc @@ -1251,7 +1251,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 db8d9af4d04ee862995ffa13ae6dcd9a1fc72855 -R a2d46793733766d02a97971b373ce378 +P 620d19c3b462f5c4763ebd26513321431f21dd72 +R 3232d5345bb2d152e6d22cf04db83714 U drh -Z 3bc04f03d72aa5c77d969deb6f174a4e +Z c636e6bb9960db85c57f7546f9b2327e diff --git a/manifest.uuid b/manifest.uuid index bc2b8b9300..aa1a8ea294 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -620d19c3b462f5c4763ebd26513321431f21dd72 \ No newline at end of file +7aeade9a07f29bf26e50394042ea18d0121fe7a3 \ No newline at end of file diff --git a/src/build.c b/src/build.c index 3021ad4e51..803c33461a 100644 --- a/src/build.c +++ b/src/build.c @@ -142,9 +142,11 @@ void sqlite3FinishCoding(Parse *pParse){ assert( pParse->pToplevel==0 ); db = pParse->db; - if( db->mallocFailed ) return; if( pParse->nested ) return; - if( pParse->nErr ) return; + if( db->mallocFailed || pParse->nErr ){ + if( pParse->rc==SQLITE_OK ) pParse->rc = SQLITE_ERROR; + return; + } /* Begin by generating some termination code at the end of the ** vdbe program diff --git a/src/pragma.c b/src/pragma.c index 3cecd8dda5..614daa54df 100644 --- a/src/pragma.c +++ b/src/pragma.c @@ -946,9 +946,9 @@ void sqlite3Pragma( sqlite3ErrorMsg(pParse, "Safety level may not be changed inside a transaction"); }else{ - testcase( (getSafetyLevel(zRight,0,1)+1) & ~PAGER_SYNCHRONOUS_MASK ); - pDb->safety_level = (getSafetyLevel(zRight,0,1)+1) - & PAGER_SYNCHRONOUS_MASK; + int iLevel = (getSafetyLevel(zRight,0,1)+1) & PAGER_SYNCHRONOUS_MASK; + if( iLevel==0 ) iLevel = 1; + pDb->safety_level = iLevel; setAllPagerFlags(db); } } diff --git a/test/pragma.test b/test/pragma.test index a45dc45a44..587a03c8a6 100644 --- a/test/pragma.test +++ b/test/pragma.test @@ -226,6 +226,12 @@ do_test pragma-1.14.1 { } } {0} do_test pragma-1.14.2 { + execsql { + PRAGMA synchronous=3; + PRAGMA synchronous; + } +} {0} +do_test pragma-1.14.3 { execsql { PRAGMA synchronous=10; PRAGMA synchronous; From c50c8f40433384c5b18401a0798fb0b74483c574 Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 17 Apr 2015 16:12:03 +0000 Subject: [PATCH 142/181] Remove an ALWAYS() that turns out to be false when there is a semantic error on a compound SELECT. FossilOrigin-Name: ad67a67c03078a2bc65d28f2b880b29bf02067c1 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/select.c | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 23cf01f4c5..643aef0dc4 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Ensure\sthat\ssemantic\sSQL\serrors\sare\salways\sreported\sback\sup\sto\sthe\ssyntax\nparser.\s\sAlso:\s\sImprove\sthe\sdefense\sagainst\sinvalid\sPRAGMA\ssynchronous\ssettings. -D 2015-04-17T15:58:33.364 +C Remove\san\sALWAYS()\sthat\sturns\sout\sto\sbe\sfalse\swhen\sthere\sis\sa\ssemantic\nerror\son\sa\scompound\sSELECT. +D 2015-04-17T16:12:03.870 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in faaf75b89840659d74501bea269c7e33414761c1 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -230,7 +230,7 @@ F src/printf.c 08fa675c200aac29e561c6153f91f909ed17612f F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c 66cfe49a9c3b449ef13b89a8c47036a4ed167eab F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e -F src/select.c e7d3f26dd2bb513049c6c585919aa195c862a287 +F src/select.c 361dfc32244656bbe3f0e53d8ed791b3ec0c4be8 F src/shell.c 28b3e1174a7fc00155d7d00880a33589a88508c9 F src/sqlite.h.in ca27603a36fcacdaac5a19d8ee35aaff8ce8516f F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad @@ -1251,7 +1251,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 620d19c3b462f5c4763ebd26513321431f21dd72 -R 3232d5345bb2d152e6d22cf04db83714 +P 7aeade9a07f29bf26e50394042ea18d0121fe7a3 +R 4ffb47078274895143770c4805431d69 U drh -Z c636e6bb9960db85c57f7546f9b2327e +Z 423cc03f9b773c1e0bc4b6f9fa63f5b6 diff --git a/manifest.uuid b/manifest.uuid index aa1a8ea294..1505561f94 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -7aeade9a07f29bf26e50394042ea18d0121fe7a3 \ No newline at end of file +ad67a67c03078a2bc65d28f2b880b29bf02067c1 \ No newline at end of file diff --git a/src/select.c b/src/select.c index fc5740e80f..c49f327893 100644 --- a/src/select.c +++ b/src/select.c @@ -1380,7 +1380,7 @@ static const char *columnTypeImpl( ** of the SELECT statement. Return the declaration type and origin ** data for the result-set column of the sub-select. */ - if( iCol>=0 && ALWAYS(iColpEList->nExpr) ){ + if( iCol>=0 && iColpEList->nExpr ){ /* If iCol is less than zero, then the expression requests the ** rowid of the sub-select or view. This expression is legal (see ** test case misc2.2.2) - it always evaluates to NULL. From 97ab32bcd3cb14cedca0dcea055ef3b6d3caea47 Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 17 Apr 2015 18:22:53 +0000 Subject: [PATCH 143/181] Remove unnecessary parser error count increments. Let the sqlite3ErrorMsg() take care of doing that. FossilOrigin-Name: 3f3b0f683af2fbee83811536f6bef770ff919385 --- manifest | 18 +++++++++--------- manifest.uuid | 2 +- src/attach.c | 1 - src/build.c | 2 -- src/trigger.c | 1 - test/table.test | 19 +++++++++++++++++++ 6 files changed, 29 insertions(+), 14 deletions(-) diff --git a/manifest b/manifest index 643aef0dc4..6ad8797b37 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Remove\san\sALWAYS()\sthat\sturns\sout\sto\sbe\sfalse\swhen\sthere\sis\sa\ssemantic\nerror\son\sa\scompound\sSELECT. -D 2015-04-17T16:12:03.870 +C Remove\sunnecessary\sparser\serror\scount\sincrements.\s\sLet\sthe\ssqlite3ErrorMsg()\ntake\scare\sof\sdoing\sthat. +D 2015-04-17T18:22:53.635 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in faaf75b89840659d74501bea269c7e33414761c1 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -168,7 +168,7 @@ F sqlite3.1 fc7ad8990fc8409983309bb80de8c811a7506786 F sqlite3.pc.in 48fed132e7cb71ab676105d2a4dc77127d8c1f3a F src/alter.c d23d6b6991f66b383934f137fd4384d93fb98c81 F src/analyze.c 91540f835163d5369ccbae78e2e6c74d0dd53c1d -F src/attach.c 3c1053a4cf1c3ca05c8c1d74a94cb688d763cef2 +F src/attach.c c38ac5a520a231d5d0308fd7f2ad95191c867bae F src/auth.c b56c78ebe40a2110fd361379f7e8162d23f92240 F src/backup.c ff743689c4d6c5cb55ad42ed9d174b2b3e71f1e3 F src/bitvec.c 19a4ba637bd85f8f63fc8c9bae5ade9fb05ec1cb @@ -176,7 +176,7 @@ F src/btmutex.c 45a968cc85afed9b5e6cf55bf1f42f8d18107f79 F src/btree.c 127aceb71ba93f59bc9c6ba810e992a04299e98a F src/btree.h 969adc948e89e449220ff0ff724c94bb2a52e9f1 F src/btreeInt.h 973a22a6fd61350b454ad614832b1f0a5e25a1e4 -F src/build.c f82d394b9ad94be03a13d04edc2b6309ad5274e8 +F src/build.c 8c4cbff225db37add6351496696151a69965c0b9 F src/callback.c 7b44ce59674338ad48b0e84e7b72f935ea4f68b0 F src/complete.c a5cf5b4b56390cfb7b8636e8f7ddef90258dd575 F src/ctime.c 98f89724adc891a1a4c655bee04e33e716e05887 @@ -288,7 +288,7 @@ F src/test_vfstrace.c bab9594adc976cbe696ff3970728830b4c5ed698 F src/test_wsd.c 41cadfd9d97fe8e3e4e44f61a4a8ccd6f7ca8fe9 F src/threads.c 6bbcc9fe50c917864d48287b4792d46d6e873481 F src/tokenize.c b7fb584c2be5ec39b6fdf04b185e7c6f33f8dc15 -F src/trigger.c a261da05e2ba65035d6f4b85d1fe6d4f363c1f1f +F src/trigger.c bc647c712454c9b209fac082bb82870b5fd6fa54 F src/update.c 3c4ecc282accf12d39edb8d524cf089645e55a13 F src/utf.c fc6b889ba0779b7722634cdeaa25f1930d93820c F src/util.c 98a7627ca48ad3265b6940915a1d08355eb3fc7e @@ -908,7 +908,7 @@ F test/superlock.test 1cde669f68d2dd37d6c9bd35eee1d95491ae3fc2 F test/sync.test a34cd43e98b7fb84eabbf38f7ed8f7349b3f3d85 F test/syscall.test d2fdaad713f103ac611fe7ef9b724c7b69f8149c F test/sysfault.test fa776e60bf46bdd3ae69f0b73e46ee3977a58ae6 -F test/table.test 06271d61eb13871490d38168433c1ef3dd82bb2a +F test/table.test bd841e8df69b99172ce9c7d53587463913d711ca F test/tableapi.test 2674633fa95d80da917571ebdd759a14d9819126 F test/tableopts.test dba698ba97251017b7c80d738c198d39ab747930 F test/tclsqlite.test 7fb866443c7deceed22b63948ccd6f76b52ad054 @@ -1251,7 +1251,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 7aeade9a07f29bf26e50394042ea18d0121fe7a3 -R 4ffb47078274895143770c4805431d69 +P ad67a67c03078a2bc65d28f2b880b29bf02067c1 +R b18dfa3e7e5ddb8a0e9d36234afbeb5d U drh -Z 423cc03f9b773c1e0bc4b6f9fa63f5b6 +Z 77598d348cd54fccd8be37637dc84656 diff --git a/manifest.uuid b/manifest.uuid index 1505561f94..3f288d1a15 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ad67a67c03078a2bc65d28f2b880b29bf02067c1 \ No newline at end of file +3f3b0f683af2fbee83811536f6bef770ff919385 \ No newline at end of file diff --git a/src/attach.c b/src/attach.c index 11296d02ad..efc9eb9a81 100644 --- a/src/attach.c +++ b/src/attach.c @@ -332,7 +332,6 @@ static void codeAttach( SQLITE_OK!=(rc = resolveAttachExpr(&sName, pDbname)) || SQLITE_OK!=(rc = resolveAttachExpr(&sName, pKey)) ){ - pParse->nErr++; goto attach_end; } diff --git a/src/build.c b/src/build.c index 803c33461a..e5e4515618 100644 --- a/src/build.c +++ b/src/build.c @@ -763,14 +763,12 @@ int sqlite3TwoPartName( if( ALWAYS(pName2!=0) && pName2->n>0 ){ if( db->init.busy ) { sqlite3ErrorMsg(pParse, "corrupt database"); - pParse->nErr++; return -1; } *pUnqual = pName2; iDb = sqlite3FindDb(db, pName1); if( iDb<0 ){ sqlite3ErrorMsg(pParse, "unknown database %T", pName1); - pParse->nErr++; return -1; } }else{ diff --git a/src/trigger.c b/src/trigger.c index d29f509a8d..1bc232727f 100644 --- a/src/trigger.c +++ b/src/trigger.c @@ -193,7 +193,6 @@ void sqlite3BeginTrigger( /* Do not create a trigger on a system table */ if( sqlite3StrNICmp(pTab->zName, "sqlite_", 7)==0 ){ sqlite3ErrorMsg(pParse, "cannot create trigger on system table"); - pParse->nErr++; goto trigger_cleanup; } diff --git a/test/table.test b/test/table.test index 69f105aa6c..faa9712bf7 100644 --- a/test/table.test +++ b/test/table.test @@ -272,6 +272,25 @@ do_test table-5.2.1 { } } {} +do_test table-5.2.2 { + db close + forcedelete test.db + sqlite3 db test.db + db eval { + CREATE TABLE t0(a,b); + CREATE INDEX t ON t0(a); + PRAGMA writable_schema=ON; + UPDATE sqlite_master SET sql='CREATE TABLE a.b(a UNIQUE'; + BEGIN; + CREATE TABLE t1(x); + ROLLBACK; + DROP TABLE IF EXISTS t99; + } +} {} +db close +forcedelete test.db +sqlite3 db test.db + # Make sure an EXPLAIN does not really create a new table # do_test table-5.3 { From 7b4da150da7615c380e1ce3bd142ff66e817d962 Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 17 Apr 2015 18:52:37 +0000 Subject: [PATCH 144/181] Always resolve symbols in all ORDER BY clauses of a compound-SELECT, even illegal ORDER BY clauses. FossilOrigin-Name: 6c39ef73d5899eabdb46db50c2b00c2d8381a41a --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/resolve.c | 9 ++++++++- test/select4.test | 8 +++++++- 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index 6ad8797b37..b91d23703e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Remove\sunnecessary\sparser\serror\scount\sincrements.\s\sLet\sthe\ssqlite3ErrorMsg()\ntake\scare\sof\sdoing\sthat. -D 2015-04-17T18:22:53.635 +C Always\sresolve\ssymbols\sin\sall\sORDER\sBY\sclauses\sof\sa\scompound-SELECT,\seven\nillegal\sORDER\sBY\sclauses. +D 2015-04-17T18:52:37.624 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in faaf75b89840659d74501bea269c7e33414761c1 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -228,7 +228,7 @@ F src/pragma.h 09c89bca58e9a44de2116cc8272b8d454657129f F src/prepare.c 1fffbdcd6f8a0173a8f70d71f22528f4c0e1e3d3 F src/printf.c 08fa675c200aac29e561c6153f91f909ed17612f F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 -F src/resolve.c 66cfe49a9c3b449ef13b89a8c47036a4ed167eab +F src/resolve.c 1ab0bd187f5590d10d51838b64976d6fb7da1ac1 F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e F src/select.c 361dfc32244656bbe3f0e53d8ed791b3ec0c4be8 F src/shell.c 28b3e1174a7fc00155d7d00880a33589a88508c9 @@ -839,7 +839,7 @@ F test/securedel2.test 2d54c28e46eb1fd6902089958b20b1b056c6f1c5 F test/select1.test be62204d2bd9a5a8a149e9974cfddce893d8f686 F test/select2.test 352480e0e9c66eda9c3044e412abdf5be0215b56 F test/select3.test 2ce595f8fb8e2ac10071d3b4e424cadd4634a054 -F test/select4.test 4b2df48129369a2a426f0f710fb94c50f75b31fb +F test/select4.test a3201fa921fdfc1397cc629e78c7a976e198a40d F test/select5.test e758b8ef94f69b111df4cb819008856655dcd535 F test/select6.test 39eac4a5c03650b2b473c532882273283ee8b7a0 F test/select7.test 7fd2ef598cfabb6b9ff6ac13973b91d0527df49d @@ -1251,7 +1251,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 ad67a67c03078a2bc65d28f2b880b29bf02067c1 -R b18dfa3e7e5ddb8a0e9d36234afbeb5d +P 3f3b0f683af2fbee83811536f6bef770ff919385 +R 2ffa33d8e1ee81a06afa86726c2d9478 U drh -Z 77598d348cd54fccd8be37637dc84656 +Z 2bc4a70be377f4bd80ade4dfaae10be0 diff --git a/manifest.uuid b/manifest.uuid index 3f288d1a15..dc86d8653f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -3f3b0f683af2fbee83811536f6bef770ff919385 \ No newline at end of file +6c39ef73d5899eabdb46db50c2b00c2d8381a41a \ No newline at end of file diff --git a/src/resolve.c b/src/resolve.c index 6294ba26e1..f7e68ff4f0 100644 --- a/src/resolve.c +++ b/src/resolve.c @@ -1300,8 +1300,15 @@ static int resolveSelectStep(Walker *pWalker, Select *p){ ** The ORDER BY clause for compounds SELECT statements is handled ** below, after all of the result-sets for all of the elements of ** the compound have been resolved. + ** + ** If there is an ORDER BY clause on a term of a compound-select other + ** than the right-most term, then that is a syntax error. But the error + ** is not detected until much later, and so we need to go ahead and + ** resolve those symbols on the incorrect ORDER BY for consistency. */ - if( !isCompound && resolveOrderGroupBy(&sNC, p, p->pOrderBy, "ORDER") ){ + if( isCompound<=nCompound /* Defer right-most ORDER BY of a compound */ + && resolveOrderGroupBy(&sNC, p, p->pOrderBy, "ORDER") + ){ return WRC_Abort; } if( db->mallocFailed ){ diff --git a/test/select4.test b/test/select4.test index 7718901c0c..ce7e7e7b0d 100644 --- a/test/select4.test +++ b/test/select4.test @@ -119,7 +119,7 @@ do_test select4-1.3 { lappend v $msg } {1 {ORDER BY clause should come after UNION ALL not before}} do_catchsql_test select4-1.4 { - SELECT (VALUES(0) INTERSECT SELECT(0) UNION SELECT(0) ORDER BY (0) UNION + SELECT (VALUES(0) INTERSECT SELECT(0) UNION SELECT(0) ORDER BY 1 UNION SELECT 0 UNION SELECT 0 ORDER BY 1); } {1 {ORDER BY clause should come after UNION not before}} @@ -152,6 +152,12 @@ do_test select4-2.3 { }} msg] lappend v $msg } {1 {ORDER BY clause should come after UNION not before}} +do_test select4-2.4 { + set v [catch {execsql { + SELECT 0 ORDER BY (SELECT 0) UNION SELECT 0; + }} msg] + lappend v $msg +} {1 {ORDER BY clause should come after UNION not before}} # Except operator # From 7693c42f1a01fe414fcc2b74721efe3c93aee88a Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 17 Apr 2015 19:41:37 +0000 Subject: [PATCH 145/181] In the expression-tree comparison routine, do not compiler Expr.iColumn and Expr.iTable for TK_STRING expressions. FossilOrigin-Name: b67bb16c72c3e015ea82665ada9b5d3289ef6fb2 --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/expr.c | 2 +- src/resolve.c | 1 - test/expr.test | 8 ++++++++ 5 files changed, 18 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index b91d23703e..ce4a75dce1 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Always\sresolve\ssymbols\sin\sall\sORDER\sBY\sclauses\sof\sa\scompound-SELECT,\seven\nillegal\sORDER\sBY\sclauses. -D 2015-04-17T18:52:37.624 +C In\sthe\sexpression-tree\scomparison\sroutine,\sdo\snot\scompiler\sExpr.iColumn\nand\sExpr.iTable\sfor\sTK_STRING\sexpressions. +D 2015-04-17T19:41:37.324 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in faaf75b89840659d74501bea269c7e33414761c1 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -182,7 +182,7 @@ F src/complete.c a5cf5b4b56390cfb7b8636e8f7ddef90258dd575 F src/ctime.c 98f89724adc891a1a4c655bee04e33e716e05887 F src/date.c e4d50b3283696836ec1036b695ead9a19e37a5ac F src/delete.c 37964e6c1d73ff49cbea9ff690c9605fb15f600e -F src/expr.c f37d5eb44a1fad4ca4faa6b0c4f1230f233e3835 +F src/expr.c 55e7ce8f7e6c98402365e253b277377fe567772a F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb F src/fkey.c 3343d551a8d810782257244fb33f2ce191493c39 F src/func.c 1414c24c873c48796ad45942257a179a423ba42f @@ -228,7 +228,7 @@ F src/pragma.h 09c89bca58e9a44de2116cc8272b8d454657129f F src/prepare.c 1fffbdcd6f8a0173a8f70d71f22528f4c0e1e3d3 F src/printf.c 08fa675c200aac29e561c6153f91f909ed17612f F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 -F src/resolve.c 1ab0bd187f5590d10d51838b64976d6fb7da1ac1 +F src/resolve.c 53486a98c17b7ae09b8c2b398013e973ce4c1aae F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e F src/select.c 361dfc32244656bbe3f0e53d8ed791b3ec0c4be8 F src/shell.c 28b3e1174a7fc00155d7d00880a33589a88508c9 @@ -499,7 +499,7 @@ F test/exclusive.test c7ebbc756eacf544c108b15eed64d7d4e5f86b75 F test/exclusive2.test 32798111aae78a5deec980eee383213f189df308 F test/exec.test e949714dc127eaa5ecc7d723efec1ec27118fdd7 F test/exists.test 8f7b27b61c2fbe5822f0a1f899c715d14e416e30 -F test/expr.test c4b9bf0cc60b26862475e19999fbd2609ca8259c +F test/expr.test 79c3e7502d9e571553b85f0ecc8ff2ac7d0e4931 F test/extension01.test 00d13cec817f331a687a243e0e5a2d87b0e358c9 F test/fallocate.test 3e979af17dfa7e5e9dda5eba1a696c04fa9d47f7 F test/filectrl.test 14fa712e42c4cb791e09dfd58a6a03efb47ef13a @@ -1251,7 +1251,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 3f3b0f683af2fbee83811536f6bef770ff919385 -R 2ffa33d8e1ee81a06afa86726c2d9478 +P 6c39ef73d5899eabdb46db50c2b00c2d8381a41a +R 040960ee1fc741cd8f8eec5fca5d25c5 U drh -Z 2bc4a70be377f4bd80ade4dfaae10be0 +Z 6cc887a5a4d09f0ddeeb5f3fd5032470 diff --git a/manifest.uuid b/manifest.uuid index dc86d8653f..82a61e13be 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -6c39ef73d5899eabdb46db50c2b00c2d8381a41a \ No newline at end of file +b67bb16c72c3e015ea82665ada9b5d3289ef6fb2 \ No newline at end of file diff --git a/src/expr.c b/src/expr.c index 418881ffd9..6a5ecfe4f2 100644 --- a/src/expr.c +++ b/src/expr.c @@ -4017,7 +4017,7 @@ int sqlite3ExprCompare(Expr *pA, Expr *pB, int iTab){ if( sqlite3ExprCompare(pA->pLeft, pB->pLeft, iTab) ) return 2; if( sqlite3ExprCompare(pA->pRight, pB->pRight, iTab) ) return 2; if( sqlite3ExprListCompare(pA->x.pList, pB->x.pList, iTab) ) return 2; - if( ALWAYS((combinedFlags & EP_Reduced)==0) ){ + if( ALWAYS((combinedFlags & EP_Reduced)==0) && pA->op!=TK_STRING ){ if( pA->iColumn!=pB->iColumn ) return 2; if( pA->iTable!=pB->iTable && (pA->iTable!=iTab || NEVER(pB->iTable>=0)) ) return 2; diff --git a/src/resolve.c b/src/resolve.c index f7e68ff4f0..32e0a98fd7 100644 --- a/src/resolve.c +++ b/src/resolve.c @@ -460,7 +460,6 @@ static int lookupName( if( cnt==0 && zTab==0 && ExprHasProperty(pExpr,EP_DblQuoted) ){ pExpr->op = TK_STRING; pExpr->pTab = 0; - pExpr->iTable = -1; return WRC_Prune; } diff --git a/test/expr.test b/test/expr.test index 8d913d2a1a..7d7b8ce5a7 100644 --- a/test/expr.test +++ b/test/expr.test @@ -943,5 +943,13 @@ do_realnum_test expr-13.7 { } } {9.22337203685478e+18} +do_execsql_test expr-13.8 { + SELECT "" <= ''; +} {1} +do_execsql_test expr-13.9 { + SELECT '' <= ""; +} {1} + + finish_test From 1586699cfc6ee55bdf726216df9995f2d86128b1 Mon Sep 17 00:00:00 2001 From: dan Date: Fri, 17 Apr 2015 20:51:55 +0000 Subject: [PATCH 146/181] Fix a problem affecting some fts3 UPDATE and DELETE statements on order=DESC tables. FossilOrigin-Name: 284c1623f81704ef80edb9324954525cb2b72172 --- ext/fts3/fts3.c | 22 +++++++++++++++++++++- manifest | 16 ++++++++-------- manifest.uuid | 2 +- test/fts3aa.test | 22 ++++++++++++++++++++++ 4 files changed, 52 insertions(+), 10 deletions(-) diff --git a/ext/fts3/fts3.c b/ext/fts3/fts3.c index 0555025f1a..3037719e9d 100644 --- a/ext/fts3/fts3.c +++ b/ext/fts3/fts3.c @@ -3459,11 +3459,31 @@ static void fts3ReversePoslist(char *pStart, char **ppPoslist){ char *p = &(*ppPoslist)[-2]; char c = 0; + /* Skip backwards passed any trailing 0x00 bytes added by NearTrim() */ while( p>pStart && (c=*p--)==0 ); + + /* Search backwards for a varint with value zero (the end of the previous + ** poslist). This is an 0x00 byte preceded by some byte that does not + ** have the 0x80 bit set. */ while( p>pStart && (*p & 0x80) | c ){ c = *p--; } - if( p>pStart ){ p = &p[2]; } + assert( p==pStart || c==0 ); + + /* At this point p points to that preceding byte without the 0x80 bit + ** set. So to find the start of the poslist, skip forward 2 bytes then + ** over a varint. + ** + ** Normally. The other case is that p==pStart and the poslist to return + ** is the first in the doclist. In this case do not skip forward 2 bytes. + ** The second part of the if condition (c==0 && *ppPoslist>&p[2]) + ** is required for cases where the first byte of a doclist and the + ** doclist is empty. For example, if the first docid is 10, a doclist + ** that begins with: + ** + ** 0x0A 0x00 + */ + if( p>pStart || (c==0 && *ppPoslist>&p[2]) ){ p = &p[2]; } while( *p++&0x80 ); *ppPoslist = p; } diff --git a/manifest b/manifest index ce4a75dce1..1fee776303 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C In\sthe\sexpression-tree\scomparison\sroutine,\sdo\snot\scompiler\sExpr.iColumn\nand\sExpr.iTable\sfor\sTK_STRING\sexpressions. -D 2015-04-17T19:41:37.324 +C Fix\sa\sproblem\saffecting\ssome\sfts3\sUPDATE\sand\sDELETE\sstatements\son\sorder=DESC\stables. +D 2015-04-17T20:51:55.807 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in faaf75b89840659d74501bea269c7e33414761c1 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -78,7 +78,7 @@ F ext/fts3/README.content fdc666a70d5257a64fee209f97cf89e0e6e32b51 F ext/fts3/README.syntax a19711dc5458c20734b8e485e75fb1981ec2427a F ext/fts3/README.tokenizers e0a8b81383ea60d0334d274fadf305ea14a8c314 F ext/fts3/README.txt 8c18f41574404623b76917b9da66fcb0ab38328d -F ext/fts3/fts3.c cb5019020e1ca8e999beb2a63100563c17def8ae +F ext/fts3/fts3.c 29300a76fabbbb8fc30bb261c27d421df9f40c76 F ext/fts3/fts3.h 3a10a0af180d502cecc50df77b1b22df142817fe F ext/fts3/fts3Int.h 3626655d6ba903a3919bb44e1c38e5f0f9d6be82 F ext/fts3/fts3_aux.c 5c211e17a64885faeb16b9ba7772f9d5445c2365 @@ -551,7 +551,7 @@ F test/fts2r.test b154c30b63061d8725e320fba1a39e2201cadd5e F test/fts2token.test d8070b241a15ff13592a9ae4a8b7c171af6f445a F test/fts3.test 672a040ea57036fb4b6fdc09027c18d7d24ab654 F test/fts3_common.tcl 99cf6659b87c0f74f55963c2aea03b3a7d66ceb0 -F test/fts3aa.test edd20ddbbc5b6015ab340abf2ca278ae11ec387d +F test/fts3aa.test 6c263a6f8845205ee02550981a94c2e8dc1e7058 F test/fts3ab.test 7f6cf260ae80dda064023df8e8e503e9a412b91f F test/fts3ac.test 636ed7486043055d4f126a0e385f2d5a82ebbf63 F test/fts3ad.test e40570cb6f74f059129ad48bcef3d7cbc20dda49 @@ -1251,7 +1251,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 6c39ef73d5899eabdb46db50c2b00c2d8381a41a -R 040960ee1fc741cd8f8eec5fca5d25c5 -U drh -Z 6cc887a5a4d09f0ddeeb5f3fd5032470 +P b67bb16c72c3e015ea82665ada9b5d3289ef6fb2 +R e2e6547f1f65a23306e35eed7a1b5202 +U dan +Z 1c324a552a5080240054761e4e92cb4f diff --git a/manifest.uuid b/manifest.uuid index 82a61e13be..afb90c6137 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -b67bb16c72c3e015ea82665ada9b5d3289ef6fb2 \ No newline at end of file +284c1623f81704ef80edb9324954525cb2b72172 \ No newline at end of file diff --git a/test/fts3aa.test b/test/fts3aa.test index 6ff384a0d3..08d825dd17 100644 --- a/test/fts3aa.test +++ b/test/fts3aa.test @@ -16,6 +16,7 @@ set testdir [file dirname $argv0] source $testdir/tester.tcl +set testprefix fts3aa # If SQLITE_ENABLE_FTS3 is defined, omit this file. ifcapable !fts3 { @@ -221,5 +222,26 @@ do_catchsql_test fts3aa-7.5 { CREATE VIRTUAL TABLE t4 USING fts4(tokenize=simple, tokenize=simple); } {1 {unrecognized parameter: tokenize=simple}} +do_execsql_test 8.0 { + CREATE VIRTUAL TABLE t0 USING fts4(order=desc); + BEGIN; + INSERT INTO t0(rowid, content) VALUES(1, 'abc'); + UPDATE t0 SET docid=5 WHERE docid=1; + INSERT INTO t0(rowid, content) VALUES(6, 'abc'); +} +do_execsql_test 8.1 { + SELECT docid FROM t0 WHERE t0 MATCH 'abc'; +} {6 5} +do_execsql_test 8.2 { + SELECT docid FROM t0 WHERE t0 MATCH '"abc abc"'; +} {} +do_execsql_test 8.3 { COMMIT } +do_execsql_test 8.4 { + SELECT docid FROM t0 WHERE t0 MATCH 'abc'; +} {6 5} +do_execsql_test 8.5 { + SELECT docid FROM t0 WHERE t0 MATCH '"abc abc"'; +} {} + finish_test From c982844097e7daa4a19e474fc95ee53d9d791d40 Mon Sep 17 00:00:00 2001 From: drh Date: Sat, 18 Apr 2015 00:22:17 +0000 Subject: [PATCH 147/181] Fix an incorrect assert() in the sqlite3_trace() logic. FossilOrigin-Name: eabde33997b5b2ffc0067930305d6fed5951a234 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/vdbetrace.c | 4 +++- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 1fee776303..f0df9f9723 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sproblem\saffecting\ssome\sfts3\sUPDATE\sand\sDELETE\sstatements\son\sorder=DESC\stables. -D 2015-04-17T20:51:55.807 +C Fix\san\sincorrect\sassert()\sin\sthe\ssqlite3_trace()\slogic. +D 2015-04-18T00:22:17.023 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in faaf75b89840659d74501bea269c7e33414761c1 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -301,7 +301,7 @@ F src/vdbeaux.c 03591cca98ec50e1493043f0ff7abbece0b9c83d F src/vdbeblob.c 4f2e8e075d238392df98c5e03a64342465b03f90 F src/vdbemem.c c0dc81285b7571b0a31c40f17846fe2397ec1cd9 F src/vdbesort.c 2e7f683464fd5db3be4beaa1ff2d39e24fcb64b8 -F src/vdbetrace.c 7e4222955e07dd707a2f360c0eb73452be1cb010 +F src/vdbetrace.c e41a50837d694ddd8434533964058e82f0ee7288 F src/vtab.c 9ca557215e8591ceb66e0b7c0a579c6df1e54b2d F src/vxworks.h c18586c8edc1bddbc15c004fa16aeb1e1342b4fb F src/wal.c 753995db83247f20361a8e8a874990b21a75abd9 @@ -1251,7 +1251,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 b67bb16c72c3e015ea82665ada9b5d3289ef6fb2 -R e2e6547f1f65a23306e35eed7a1b5202 -U dan -Z 1c324a552a5080240054761e4e92cb4f +P 284c1623f81704ef80edb9324954525cb2b72172 +R b9c1303fd29cc013899d58614b64ee34 +U drh +Z 1ad4f2ae3e13af8994ef4437fb3cca3c diff --git a/manifest.uuid b/manifest.uuid index afb90c6137..a0240a8cac 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -284c1623f81704ef80edb9324954525cb2b72172 \ No newline at end of file +eabde33997b5b2ffc0067930305d6fed5951a234 \ No newline at end of file diff --git a/src/vdbetrace.c b/src/vdbetrace.c index 507c2f12fc..aeda6aabb1 100644 --- a/src/vdbetrace.c +++ b/src/vdbetrace.c @@ -111,10 +111,12 @@ char *sqlite3VdbeExpandSql( idx = nextIndex; } }else{ - assert( zRawSql[0]==':' || zRawSql[0]=='$' || zRawSql[0]=='@' ); + assert( zRawSql[0]==':' || zRawSql[0]=='$' || + zRawSql[0]=='@' || zRawSql[0]=='#' ); testcase( zRawSql[0]==':' ); testcase( zRawSql[0]=='$' ); testcase( zRawSql[0]=='@' ); + testcase( zRawSql[0]=='#' ); idx = sqlite3VdbeParameterIndex(p, zRawSql, nToken); assert( idx>0 ); } From 935f2e70745b083784bd45d74b5afdbf25ddca80 Mon Sep 17 00:00:00 2001 From: drh Date: Sat, 18 Apr 2015 04:45:00 +0000 Subject: [PATCH 148/181] Disregard leading zeros when converting strings to 32-bit integers. FossilOrigin-Name: 691cc201e135a01c4cc4057be7e5d99285ab392d --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/util.c | 1 + 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/manifest b/manifest index f0df9f9723..67282b8375 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\san\sincorrect\sassert()\sin\sthe\ssqlite3_trace()\slogic. -D 2015-04-18T00:22:17.023 +C Disregard\sleading\szeros\swhen\sconverting\sstrings\sto\s32-bit\sintegers. +D 2015-04-18T04:45:00.010 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in faaf75b89840659d74501bea269c7e33414761c1 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -291,7 +291,7 @@ F src/tokenize.c b7fb584c2be5ec39b6fdf04b185e7c6f33f8dc15 F src/trigger.c bc647c712454c9b209fac082bb82870b5fd6fa54 F src/update.c 3c4ecc282accf12d39edb8d524cf089645e55a13 F src/utf.c fc6b889ba0779b7722634cdeaa25f1930d93820c -F src/util.c 98a7627ca48ad3265b6940915a1d08355eb3fc7e +F src/util.c a6431c92803b975b7322724a7b433e538d243539 F src/vacuum.c 2ddd5cad2a7b9cef7f9e431b8c7771634c6b1701 F src/vdbe.c 55650cb03d26ce5955cffcdc6568e046680b1fd4 F src/vdbe.h 7e538ecf47dccb307ea2d087c3ddc2dd8d70e79d @@ -1251,7 +1251,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 284c1623f81704ef80edb9324954525cb2b72172 -R b9c1303fd29cc013899d58614b64ee34 +P eabde33997b5b2ffc0067930305d6fed5951a234 +R 531a7d098945303938ecac96381b796d U drh -Z 1ad4f2ae3e13af8994ef4437fb3cca3c +Z 9c19b8dbab6a9d466a77ca5cd049d2a1 diff --git a/manifest.uuid b/manifest.uuid index a0240a8cac..05a45e30f7 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -eabde33997b5b2ffc0067930305d6fed5951a234 \ No newline at end of file +691cc201e135a01c4cc4057be7e5d99285ab392d \ No newline at end of file diff --git a/src/util.c b/src/util.c index 6e64242e87..0bc1eeacf4 100644 --- a/src/util.c +++ b/src/util.c @@ -655,6 +655,7 @@ int sqlite3GetInt32(const char *zNum, int *pValue){ } } #endif + while( zNum[0]=='0' ) zNum++; for(i=0; i<11 && (c = zNum[i] - '0')>=0 && c<=9; i++){ v = v*10 + c; } From ea8562edce7bc9c0f0273452dfe1378b5bb423b4 Mon Sep 17 00:00:00 2001 From: dan Date: Sat, 18 Apr 2015 16:25:54 +0000 Subject: [PATCH 149/181] Ensure that if a "ROLLBACK TO" statement is used to rollback (but not close) theoutermost transaction, the xRollbackTo() method of any virtual tables involved in the transaction is invoked. FossilOrigin-Name: e98d481d84ef31b6ed154f14deae9b261f722616 --- manifest | 18 +++++++++--------- manifest.uuid | 2 +- src/vdbe.c | 2 +- src/vtab.c | 2 +- test/vtab1.test | 37 +++++++++++++++++++++++++++++++++++++ 5 files changed, 49 insertions(+), 12 deletions(-) diff --git a/manifest b/manifest index 67282b8375..5e69d46cdc 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Disregard\sleading\szeros\swhen\sconverting\sstrings\sto\s32-bit\sintegers. -D 2015-04-18T04:45:00.010 +C Ensure\sthat\sif\sa\s"ROLLBACK\sTO"\sstatement\sis\sused\sto\srollback\s(but\snot\sclose)\stheoutermost\stransaction,\sthe\sxRollbackTo()\smethod\sof\sany\svirtual\stables\sinvolved\sin\sthe\stransaction\sis\sinvoked. +D 2015-04-18T16:25:54.955 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in faaf75b89840659d74501bea269c7e33414761c1 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -293,7 +293,7 @@ F src/update.c 3c4ecc282accf12d39edb8d524cf089645e55a13 F src/utf.c fc6b889ba0779b7722634cdeaa25f1930d93820c F src/util.c a6431c92803b975b7322724a7b433e538d243539 F src/vacuum.c 2ddd5cad2a7b9cef7f9e431b8c7771634c6b1701 -F src/vdbe.c 55650cb03d26ce5955cffcdc6568e046680b1fd4 +F src/vdbe.c f0cf3cf527d5a40b8d5d2324fdbb31da6c90cd8b F src/vdbe.h 7e538ecf47dccb307ea2d087c3ddc2dd8d70e79d F src/vdbeInt.h 9cbaa84f53ddd2d09a0cf61a94337a3a035d08a0 F src/vdbeapi.c 583d56b129dd27f12bed518270de9ebe521e6a75 @@ -302,7 +302,7 @@ F src/vdbeblob.c 4f2e8e075d238392df98c5e03a64342465b03f90 F src/vdbemem.c c0dc81285b7571b0a31c40f17846fe2397ec1cd9 F src/vdbesort.c 2e7f683464fd5db3be4beaa1ff2d39e24fcb64b8 F src/vdbetrace.c e41a50837d694ddd8434533964058e82f0ee7288 -F src/vtab.c 9ca557215e8591ceb66e0b7c0a579c6df1e54b2d +F src/vtab.c be741af2a377bd894104d62504796e7394a04916 F src/vxworks.h c18586c8edc1bddbc15c004fa16aeb1e1342b4fb F src/wal.c 753995db83247f20361a8e8a874990b21a75abd9 F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4 @@ -1113,7 +1113,7 @@ F test/vacuum4.test d3f8ecff345f166911568f397d2432c16d2867d9 F test/varint.test ab7b110089a08b9926ed7390e7e97bdefeb74102 F test/veryquick.test 57ab846bacf7b90cf4e9a672721ea5c5b669b661 F test/view.test f311691d696a5cc27e3c1b875cec1b0866b4ccd9 -F test/vtab1.test c9dc2a73e93331d70b37ce4b246ef6dc18412fef +F test/vtab1.test d1e5ec7a818f1d3f0402382b6a1d0c06071b770f F test/vtab2.test 3644649aa8d1daac57fd541f6a5f914cac59203e F test/vtab3.test b45f47d20f225ccc9c28dc915d92740c2dee311e F test/vtab4.test 942f8b8280b3ea8a41dae20e7822d065ca1cb275 @@ -1251,7 +1251,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 eabde33997b5b2ffc0067930305d6fed5951a234 -R 531a7d098945303938ecac96381b796d -U drh -Z 9c19b8dbab6a9d466a77ca5cd049d2a1 +P 691cc201e135a01c4cc4057be7e5d99285ab392d +R a45b779d489ba296bfd31a8dac248aa9 +U dan +Z 69dcdf9b3e64dbdf271ca541915d8dc9 diff --git a/manifest.uuid b/manifest.uuid index 05a45e30f7..72715a7cf0 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -691cc201e135a01c4cc4057be7e5d99285ab392d \ No newline at end of file +e98d481d84ef31b6ed154f14deae9b261f722616 \ No newline at end of file diff --git a/src/vdbe.c b/src/vdbe.c index 0890df11a5..52b4830577 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -2925,7 +2925,7 @@ case OP_Savepoint: { db->nDeferredImmCons = pSavepoint->nDeferredImmCons; } - if( !isTransaction ){ + if( !isTransaction || p1==SAVEPOINT_ROLLBACK ){ rc = sqlite3VtabSavepoint(db, p1, iSavepoint); if( rc!=SQLITE_OK ) goto abort_due_to_error; } diff --git a/src/vtab.c b/src/vtab.c index 9629a00dcb..530c3f305e 100644 --- a/src/vtab.c +++ b/src/vtab.c @@ -957,7 +957,7 @@ int sqlite3VtabSavepoint(sqlite3 *db, int op, int iSavepoint){ int rc = SQLITE_OK; assert( op==SAVEPOINT_RELEASE||op==SAVEPOINT_ROLLBACK||op==SAVEPOINT_BEGIN ); - assert( iSavepoint>=0 ); + assert( iSavepoint>=-1 ); if( db->aVTrans ){ int i; for(i=0; rc==SQLITE_OK && inVTrans; i++){ diff --git a/test/vtab1.test b/test/vtab1.test index dfc989a643..c0cf3e4e8d 100644 --- a/test/vtab1.test +++ b/test/vtab1.test @@ -1491,4 +1491,41 @@ do_test 23.3.1 { } {1 {database table is locked}} do_execsql_test 23.3.2 { SELECT * FROM t1e } {1 2 3 4} +#------------------------------------------------------------------------- +# At one point SQL like this: +# +# SAVEPOINT xyz; -- Opens SQL transaction +# INSERT INTO vtab -- Write to virtual table +# ROLLBACK TO xyz; +# RELEASE xyz; +# +# was not invoking the xRollbackTo() callback for the ROLLBACK TO +# operation. Which meant that virtual tables like FTS3 would incorrectly +# commit the results of the INSERT as part of the "RELEASE xyz" command. +# +# The following tests check that this has been fixed. +# +ifcapable fts3 { + do_execsql_test 24.0 { + CREATE VIRTUAL TABLE t4 USING fts3(); + SAVEPOINT a; + INSERT INTO t4 VALUES('a b c'); + ROLLBACK TO a; + RELEASE a; + SELECT * FROM t4; + } {} + + do_execsql_test 24.1 { SELECT * FROM t4 WHERE t4 MATCH 'b' } {} + do_execsql_test 24.2 { INSERT INTO t4(t4) VALUES('integrity-check') } {} + + do_execsql_test 24.3 { + SAVEPOINT a; + CREATE VIRTUAL TABLE t5 USING fts3(); + SAVEPOINT b; + ROLLBACK TO a; + SAVEPOINT c; + RELEASE a; + } +} + finish_test From 7088d50109868b1d7a352e8d41a5539ad1196699 Mon Sep 17 00:00:00 2001 From: drh Date: Sat, 18 Apr 2015 17:43:29 +0000 Subject: [PATCH 150/181] Fix an incorrect assert() statement in the CREATE INDEX code generator. FossilOrigin-Name: 2eed41fda068f2cbac55e63d7c1875ddaa331508 --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/build.c | 3 +-- test/index7.test | 4 ++++ 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index 5e69d46cdc..57c689678e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Ensure\sthat\sif\sa\s"ROLLBACK\sTO"\sstatement\sis\sused\sto\srollback\s(but\snot\sclose)\stheoutermost\stransaction,\sthe\sxRollbackTo()\smethod\sof\sany\svirtual\stables\sinvolved\sin\sthe\stransaction\sis\sinvoked. -D 2015-04-18T16:25:54.955 +C Fix\san\sincorrect\sassert()\sstatement\sin\sthe\sCREATE\sINDEX\scode\sgenerator. +D 2015-04-18T17:43:29.222 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in faaf75b89840659d74501bea269c7e33414761c1 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -176,7 +176,7 @@ F src/btmutex.c 45a968cc85afed9b5e6cf55bf1f42f8d18107f79 F src/btree.c 127aceb71ba93f59bc9c6ba810e992a04299e98a F src/btree.h 969adc948e89e449220ff0ff724c94bb2a52e9f1 F src/btreeInt.h 973a22a6fd61350b454ad614832b1f0a5e25a1e4 -F src/build.c 8c4cbff225db37add6351496696151a69965c0b9 +F src/build.c 2d43ee768a3678eaeed203ba5b55490b970f0a5e F src/callback.c 7b44ce59674338ad48b0e84e7b72f935ea4f68b0 F src/complete.c a5cf5b4b56390cfb7b8636e8f7ddef90258dd575 F src/ctime.c 98f89724adc891a1a4c655bee04e33e716e05887 @@ -659,7 +659,7 @@ F test/index3.test b6ec456cf3b81d9a32123fe7e449bde434db338b F test/index4.test ab92e736d5946840236cd61ac3191f91a7856bf6 F test/index5.test 25b0b451aceed4ac5f7d49f856f6de7257470b3e F test/index6.test 3ae54e53c53f2adcacda269237d8e52bdb05a481 -F test/index7.test 3d54dce09344c4530ea39a458aa304da044c887a +F test/index7.test 9c6765a74fc3fcde7aebc5b3bd40d98df14a527c F test/indexedby.test 5f527a78bae74c61b8046ae3037f9dfb0bf0c353 F test/indexfault.test 31d4ab9a7d2f6e9616933eb079722362a883eb1d F test/init.test 15c823093fdabbf7b531fe22cf037134d09587a7 @@ -1251,7 +1251,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 691cc201e135a01c4cc4057be7e5d99285ab392d -R a45b779d489ba296bfd31a8dac248aa9 -U dan -Z 69dcdf9b3e64dbdf271ca541915d8dc9 +P e98d481d84ef31b6ed154f14deae9b261f722616 +R 56d8c8ddd6b4abbbd3e6fe39eaafa28b +U drh +Z bd5e83def6fd1c67c4a5e49c1b029978 diff --git a/manifest.uuid b/manifest.uuid index 72715a7cf0..d89b9a35bd 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -e98d481d84ef31b6ed154f14deae9b261f722616 \ No newline at end of file +2eed41fda068f2cbac55e63d7c1875ddaa331508 \ No newline at end of file diff --git a/src/build.c b/src/build.c index e5e4515618..9e4adcb21b 100644 --- a/src/build.c +++ b/src/build.c @@ -2857,8 +2857,7 @@ Index *sqlite3CreateIndex( char *zExtra = 0; /* Extra space after the Index object */ Index *pPk = 0; /* PRIMARY KEY index for WITHOUT ROWID tables */ - assert( pParse->nErr==0 ); /* Never called with prior errors */ - if( db->mallocFailed || IN_DECLARE_VTAB ){ + if( db->mallocFailed || IN_DECLARE_VTAB || pParse->nErr>0 ){ goto exit_create_index; } if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){ diff --git a/test/index7.test b/test/index7.test index 9a2444a87e..557fe21324 100644 --- a/test/index7.test +++ b/test/index7.test @@ -311,5 +311,9 @@ do_eqp_test index7-6.4 { } { 0 0 0 {SEARCH TABLE t4 USING INDEX i4 (c=?)} } +do_catchsql_test index7-6.5 { + CREATE INDEX t5a ON t5(a) WHERE a=#1; +} {1 {near "#1": syntax error}} + finish_test From 816070cf5ca2e547e105400ea79104f206f00db7 Mon Sep 17 00:00:00 2001 From: drh Date: Sat, 18 Apr 2015 19:20:14 +0000 Subject: [PATCH 151/181] The sqlite3_trace() callback does not try to expand parameters in statements that have no parameter. FossilOrigin-Name: 917e3c36293a1bf052a16116c93e5037ed712f96 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/vdbetrace.c | 2 ++ 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/manifest b/manifest index 57c689678e..f1a2f3bac8 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\san\sincorrect\sassert()\sstatement\sin\sthe\sCREATE\sINDEX\scode\sgenerator. -D 2015-04-18T17:43:29.222 +C The\ssqlite3_trace()\scallback\sdoes\snot\stry\sto\sexpand\sparameters\sin\sstatements\nthat\shave\sno\sparameter. +D 2015-04-18T19:20:14.612 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in faaf75b89840659d74501bea269c7e33414761c1 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -301,7 +301,7 @@ F src/vdbeaux.c 03591cca98ec50e1493043f0ff7abbece0b9c83d F src/vdbeblob.c 4f2e8e075d238392df98c5e03a64342465b03f90 F src/vdbemem.c c0dc81285b7571b0a31c40f17846fe2397ec1cd9 F src/vdbesort.c 2e7f683464fd5db3be4beaa1ff2d39e24fcb64b8 -F src/vdbetrace.c e41a50837d694ddd8434533964058e82f0ee7288 +F src/vdbetrace.c f95c2dff9041fcf07f871789c22ebb0648ea0b7c F src/vtab.c be741af2a377bd894104d62504796e7394a04916 F src/vxworks.h c18586c8edc1bddbc15c004fa16aeb1e1342b4fb F src/wal.c 753995db83247f20361a8e8a874990b21a75abd9 @@ -1251,7 +1251,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 e98d481d84ef31b6ed154f14deae9b261f722616 -R 56d8c8ddd6b4abbbd3e6fe39eaafa28b +P 2eed41fda068f2cbac55e63d7c1875ddaa331508 +R fe8a360bbce7dedd87d096d07c896e4c U drh -Z bd5e83def6fd1c67c4a5e49c1b029978 +Z 768a04b82f6060145bfe8edb7197ea08 diff --git a/manifest.uuid b/manifest.uuid index d89b9a35bd..98458ab03b 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -2eed41fda068f2cbac55e63d7c1875ddaa331508 \ No newline at end of file +917e3c36293a1bf052a16116c93e5037ed712f96 \ No newline at end of file diff --git a/src/vdbetrace.c b/src/vdbetrace.c index aeda6aabb1..fe0dfd3f7a 100644 --- a/src/vdbetrace.c +++ b/src/vdbetrace.c @@ -95,6 +95,8 @@ char *sqlite3VdbeExpandSql( assert( (zRawSql - zStart) > 0 ); sqlite3StrAccumAppend(&out, zStart, (int)(zRawSql-zStart)); } + }else if( p->nVar==0 ){ + sqlite3StrAccumAppend(&out, zRawSql, sqlite3Strlen30(zRawSql)); }else{ while( zRawSql[0] ){ n = findNextHostParameter(zRawSql, &nToken); From 6bbe3dfaf2155e5a07cf6fd5fd4ae015f9901f17 Mon Sep 17 00:00:00 2001 From: mistachkin Date: Sun, 19 Apr 2015 06:18:10 +0000 Subject: [PATCH 152/181] Work in progress on making VSIX packages for the Visual Studio 2015 CTP. FossilOrigin-Name: 8469d651a0442a2bc572a869a0457a6ea8c06bc7 --- Makefile.msc | 5 ++++ manifest | 19 +++++++------ manifest.uuid | 2 +- tool/build-all-msvc.bat | 63 +++++++++++++++++++++++++++++++++++------ 4 files changed, 71 insertions(+), 18 deletions(-) diff --git a/Makefile.msc b/Makefile.msc index 914bb1e7ad..bf290d0040 100644 --- a/Makefile.msc +++ b/Makefile.msc @@ -288,6 +288,11 @@ BCC = $(BCC) -FAcs # !IF $(USE_NATIVE_LIBPATHS)!=0 NLTLIBPATHS = "/LIBPATH:$(NCRTLIBPATH)" "/LIBPATH:$(NSDKLIBPATH)" + +!IFDEF NUCRTLIBPATH +NUCRTLIBPATH = $(NUCRTLIBPATH:\\=\) +NLTLIBPATHS = $(NLTLIBPATHS) "/LIBPATH:$(NUCRTLIBPATH)" +!ENDIF !ENDIF # C compiler and options for use in building executables that diff --git a/manifest b/manifest index f1a2f3bac8..594e27b7eb 100644 --- a/manifest +++ b/manifest @@ -1,9 +1,9 @@ -C The\ssqlite3_trace()\scallback\sdoes\snot\stry\sto\sexpand\sparameters\sin\sstatements\nthat\shave\sno\sparameter. -D 2015-04-18T19:20:14.612 +C Work\sin\sprogress\son\smaking\sVSIX\spackages\sfor\sthe\sVisual\sStudio\s2015\sCTP. +D 2015-04-19T06:18:10.467 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in faaf75b89840659d74501bea269c7e33414761c1 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 -F Makefile.msc a19bceec468fa18bb54df52257b1a2211e69172d +F Makefile.msc 513abdaff333b04ef68775ec25ceb6053b4ecafd F Makefile.vxworks e1b65dea203f054e71653415bd8f96dcaed47858 F README.md d58e3bebc0a4145e0f2a87994015fdb575a8e866 F VERSION 2e244662b71e6e68a5c29b014ebc5b7564f4cc5a @@ -1196,7 +1196,7 @@ F test/without_rowid6.test db0dbf03c49030aa3c1ba5f618620334bd2baf5f F test/wordcount.c 9915e06cb33d8ca8109b8700791afe80d305afda F test/zeroblob.test fb3c0e4ab172d386954deda24c03f500e121d80d F test/zerodamage.test cf6748bad89553cc1632be51a6f54e487e4039ac -F tool/build-all-msvc.bat 72e05bc8deca39a547884485c086b915f50a91ed x +F tool/build-all-msvc.bat 62f4f74b55781757d5b20e12651650d5d94ef2cf x F tool/build-shell.sh 950f47c6174f1eea171319438b93ba67ff5bf367 F tool/checkSpacing.c 810e51703529a204fc4e1eb060e9ab663e3c06d2 F tool/diffdb.c 7524b1b5df217c20cd0431f6789851a4e0cb191b @@ -1251,7 +1251,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 2eed41fda068f2cbac55e63d7c1875ddaa331508 -R fe8a360bbce7dedd87d096d07c896e4c -U drh -Z 768a04b82f6060145bfe8edb7197ea08 +P 917e3c36293a1bf052a16116c93e5037ed712f96 +R db56dc9284c6212139225593eec3e32c +T *branch * vsix2015 +T *sym-vsix2015 * +T -sym-trunk * +U mistachkin +Z af05882e14ca6800d4b8b20f52645692 diff --git a/manifest.uuid b/manifest.uuid index 98458ab03b..b8085cc5cf 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -917e3c36293a1bf052a16116c93e5037ed712f96 \ No newline at end of file +8469d651a0442a2bc572a869a0457a6ea8c06bc7 \ No newline at end of file diff --git a/tool/build-all-msvc.bat b/tool/build-all-msvc.bat index 728183629b..5fe343c074 100755 --- a/tool/build-all-msvc.bat +++ b/tool/build-all-msvc.bat @@ -217,8 +217,20 @@ SET TOOLPATH=%gawk.exe_PATH%;%tclsh85.exe_PATH% %_VECHO% ToolPath = '%TOOLPATH%' REM -REM NOTE: Check for MSVC 2012/2013 because the Windows SDK directory handling -REM is slightly different for those versions. +REM NOTE: Setting the Windows SDK library path is only required for MSVC +REM 2012, 2013, and 2015. +REM +CALL :fn_UnsetVariable SET_NSDKLIBPATH + +REM +REM NOTE: Setting the Universal CRT library path is only required for MSVC +REM 2015. +REM +CALL :fn_UnsetVariable SET_NUCRTLIBPATH + +REM +REM NOTE: Check for MSVC 2012, 2013, and 2015 specially because the Windows +REM SDK directory handling is slightly different for those versions. REM IF "%VisualStudioVersion%" == "11.0" ( REM @@ -236,8 +248,22 @@ IF "%VisualStudioVersion%" == "11.0" ( IF NOT DEFINED NSDKLIBPATH ( SET SET_NSDKLIBPATH=1 ) -) ELSE ( - CALL :fn_UnsetVariable SET_NSDKLIBPATH +) ELSE IF "%VisualStudioVersion%" == "14.0" ( + REM + REM NOTE: If the Windows SDK library path has already been set, do not set + REM it to something else later on. + REM + IF NOT DEFINED NSDKLIBPATH ( + SET SET_NSDKLIBPATH=1 + ) + + REM + REM NOTE: If the Universal CRT library path has already been set, do not set + REM it to something else later on. + REM + IF NOT DEFINED NUCRTLIBPATH ( + SET SET_NUCRTLIBPATH=1 + ) ) REM @@ -294,6 +320,7 @@ FOR %%P IN (%PLATFORMS%) DO ( CALL :fn_UnsetVariable LIB CALL :fn_UnsetVariable LIBPATH CALL :fn_UnsetVariable Platform + CALL :fn_UnsetVariable UniversalCRTSdkDir REM CALL :fn_UnsetVariable VCINSTALLDIR CALL :fn_UnsetVariable VSINSTALLDIR CALL :fn_UnsetVariable WindowsPhoneKitDir @@ -385,8 +412,8 @@ FOR %%P IN (%PLATFORMS%) DO ( ) REM - REM NOTE: When using MSVC 2012 and/or 2013, the native SDK path cannot - REM simply use the "lib" sub-directory beneath the location + REM NOTE: When using MSVC 2012, 2013, or 2015, the native SDK path + REM cannot simply be the "lib" sub-directory beneath the location REM specified in the WindowsSdkDir environment variable because REM that location does not actually contain the necessary library REM files for x86. This must be done for each iteration because @@ -405,19 +432,37 @@ FOR %%P IN (%PLATFORMS%) DO ( CALL :fn_CopyVariable WindowsSdkDir NSDKLIBPATH REM - REM NOTE: The Windows 8.1 SDK has a slightly different directory - REM naming convention. + REM NOTE: The Windows 8.x and Windows 10 SDKs have a slightly + REM different directory naming conventions. REM - IF DEFINED USE_WINV63_NSDKLIBPATH ( + IF DEFINED USE_WINV100_NSDKLIBPATH ( + CALL :fn_AppendVariable NSDKLIBPATH \..\10\lib\10.0.10030.0\um\x86 + ) ELSE IF DEFINED USE_WINV63_NSDKLIBPATH ( CALL :fn_AppendVariable NSDKLIBPATH \lib\winv6.3\um\x86 ) ELSE IF "%VisualStudioVersion%" == "12.0" ( CALL :fn_AppendVariable NSDKLIBPATH \..\8.0\lib\win8\um\x86 + ) ELSE IF "%VisualStudioVersion%" == "14.0" ( + CALL :fn_AppendVariable NSDKLIBPATH \..\8.0\lib\win8\um\x86 ) ELSE ( CALL :fn_AppendVariable NSDKLIBPATH \lib\win8\um\x86 ) ) ) + REM + REM NOTE: When using MSVC 2015, setting the Universal CRT library path + REM for x86 may be required as well. This must also be done for + REM each iteration because it relies upon the UniversalCRTSdkDir + REM environment variable being set by the batch file used to + REM setup the MSVC environment. + REM + IF DEFINED SET_NUCRTLIBPATH ( + IF DEFINED UniversalCRTSdkDir ( + CALL :fn_CopyVariable UniversalCRTSdkDir NUCRTLIBPATH + CALL :fn_AppendVariable NUCRTLIBPATH \lib\winv10.0\ucrt\x86 + ) + ) + REM REM NOTE: Unless prevented from doing so, invoke NMAKE with the MSVC REM makefile to clean any stale build output from previous From a21f78b93fab3fa00b594fcab91c1b8e599547f0 Mon Sep 17 00:00:00 2001 From: drh Date: Sun, 19 Apr 2015 18:32:43 +0000 Subject: [PATCH 153/181] Bring comments on the INSERT code generator up-to-date. Fix the INSERT code generator so that it correctly handles inserts from a SELECT into a virtual table with non-terminal hidden columns. FossilOrigin-Name: 4ac81fac6c6302c042be3df493a41630b733fff0 --- manifest | 18 +++++++++--------- manifest.uuid | 2 +- src/insert.c | 33 +++++++++++++++++++-------------- src/sqliteInt.h | 7 +++++++ src/vtab.c | 9 ++++++++- test/vtabA.test | 23 +++++++++++++++++------ 6 files changed, 61 insertions(+), 31 deletions(-) diff --git a/manifest b/manifest index f1a2f3bac8..3f642604b2 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C The\ssqlite3_trace()\scallback\sdoes\snot\stry\sto\sexpand\sparameters\sin\sstatements\nthat\shave\sno\sparameter. -D 2015-04-18T19:20:14.612 +C Bring\scomments\son\sthe\sINSERT\scode\sgenerator\sup-to-date.\s\sFix\sthe\sINSERT\scode\ngenerator\sso\sthat\sit\scorrectly\shandles\sinserts\sfrom\sa\sSELECT\sinto\sa\svirtual\ntable\swith\snon-terminal\shidden\scolumns. +D 2015-04-19T18:32:43.531 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in faaf75b89840659d74501bea269c7e33414761c1 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -190,7 +190,7 @@ F src/global.c 4f77cadbc5427d00139ba43d0f3979804cbb700e F src/hash.c 4263fbc955f26c2e8cdc0cf214bc42435aa4e4f5 F src/hash.h c8f3c31722cf3277d03713909761e152a5b81094 F src/hwtime.h d32741c8f4df852c7d959236615444e2b1063b08 -F src/insert.c 305dd3f9539d0affa4bf1c14cc7dffb34867e040 +F src/insert.c 9f5f25a9d645089973d2f451711b7402bfde6ab5 F src/journal.c b4124532212b6952f42eb2c12fa3c25701d8ba8d F src/legacy.c ba1863ea58c4c840335a84ec276fc2b25e22bc4e F src/lempar.c 7274c97d24bb46631e504332ccd3bd1b37841770 @@ -235,7 +235,7 @@ F src/shell.c 28b3e1174a7fc00155d7d00880a33589a88508c9 F src/sqlite.h.in ca27603a36fcacdaac5a19d8ee35aaff8ce8516f F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h 17d487c3c91b0b8c584a32fbeb393f6f795eea7d -F src/sqliteInt.h af228df2a02bf1a608d678b312d46aa480470b3c +F src/sqliteInt.h 3a1fccc2bb62ab16750730b6f6f24305e686a0ce F src/sqliteLimit.h 216557999cb45f2e3578ed53ebefe228d779cb46 F src/status.c f266ad8a2892d659b74f0f50cb6a88b6e7c12179 F src/table.c e7a09215315a978057fb42c640f890160dbcc45e @@ -302,7 +302,7 @@ F src/vdbeblob.c 4f2e8e075d238392df98c5e03a64342465b03f90 F src/vdbemem.c c0dc81285b7571b0a31c40f17846fe2397ec1cd9 F src/vdbesort.c 2e7f683464fd5db3be4beaa1ff2d39e24fcb64b8 F src/vdbetrace.c f95c2dff9041fcf07f871789c22ebb0648ea0b7c -F src/vtab.c be741af2a377bd894104d62504796e7394a04916 +F src/vtab.c 4feb365e2688dd02474e671e37f27e35784d2cff F src/vxworks.h c18586c8edc1bddbc15c004fa16aeb1e1342b4fb F src/wal.c 753995db83247f20361a8e8a874990b21a75abd9 F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4 @@ -1122,7 +1122,7 @@ F test/vtab6.test 5f5380c425e52993560ab4763db4f826d2ba7b09 F test/vtab7.test ae560ebea870ed04e9aa4177cc302f910faaabb5 F test/vtab8.test e19fa4a538fcd1bb66c22825fa8f71618fb13583 F test/vtab9.test ea58d2b95d61955f87226381716b2d0b1d4e4f9b -F test/vtabA.test c86e1990b7e1e2bb34602a06fffa4c69f2b516dc +F test/vtabA.test 1317f06a03597eee29f40a49b6c21e1aaba4285f F test/vtabB.test 04df5dc531b9f44d9ca65b9c1b79f12b5922a796 F test/vtabC.test 4528f459a13136f982e75614d120aef165f17292 F test/vtabD.test 05b3f1d77117271671089e48719524b676842e96 @@ -1251,7 +1251,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 2eed41fda068f2cbac55e63d7c1875ddaa331508 -R fe8a360bbce7dedd87d096d07c896e4c +P 917e3c36293a1bf052a16116c93e5037ed712f96 +R b611a70a7a5e6fee6ae7534de091ac22 U drh -Z 768a04b82f6060145bfe8edb7197ea08 +Z cc4a9846aabfd76674510baafeb05d26 diff --git a/manifest.uuid b/manifest.uuid index 98458ab03b..c59b152783 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -917e3c36293a1bf052a16116c93e5037ed712f96 \ No newline at end of file +4ac81fac6c6302c042be3df493a41630b733fff0 \ No newline at end of file diff --git a/src/insert.c b/src/insert.c index fc8895bbd6..73c550b832 100644 --- a/src/insert.c +++ b/src/insert.c @@ -342,20 +342,23 @@ static int xferOptimization( /* ** This routine is called to handle SQL of the following forms: ** -** insert into TABLE (IDLIST) values(EXPRLIST) +** insert into TABLE (IDLIST) values(EXPRLIST),(EXPRLIST),... ** insert into TABLE (IDLIST) select +** insert into TABLE (IDLIST) default values ** ** The IDLIST following the table name is always optional. If omitted, -** then a list of all columns for the table is substituted. The IDLIST -** appears in the pColumn parameter. pColumn is NULL if IDLIST is omitted. +** then a list of all (non-hidden) columns for the table is substituted. +** The IDLIST appears in the pColumn parameter. pColumn is NULL if IDLIST +** is omitted. ** -** The pList parameter holds EXPRLIST in the first form of the INSERT -** statement above, and pSelect is NULL. For the second form, pList is -** NULL and pSelect is a pointer to the select statement used to generate -** data for the insert. +** For the pSelect parameter holds the values to be inserted for the +** first two forms shown above. A VALUES clause is really just short-hand +** for a SELECT statement that omits the FROM clause and everything else +** that follows. If the pSelect parameter is NULL, that means that the +** DEFAULT VALUES form of the INSERT statement is intended. ** ** The code generated follows one of four templates. For a simple -** insert with data coming from a VALUES clause, the code executes +** insert with data coming from a single-row VALUES clause, the code executes ** once straight down through. Pseudo-code follows (we call this ** the "1st template"): ** @@ -462,7 +465,7 @@ void sqlite3Insert( u8 useTempTable = 0; /* Store SELECT results in intermediate table */ u8 appendFlag = 0; /* True if the insert is likely to be an append */ u8 withoutRowid; /* 0 for normal table. 1 for WITHOUT ROWID table */ - u8 bIdListInOrder = 1; /* True if IDLIST is in table order */ + u8 bIdListInOrder; /* True if IDLIST is in table order */ ExprList *pList = 0; /* List of VALUES() to be inserted */ /* Register allocations */ @@ -487,8 +490,8 @@ void sqlite3Insert( } /* If the Select object is really just a simple VALUES() list with a - ** single row values (the common case) then keep that one row of values - ** and go ahead and discard the Select object + ** single row (the common case) then keep that one row of values + ** and discard the other (unused) parts of the pSelect object */ if( pSelect && (pSelect->selFlags & SF_Values)!=0 && pSelect->pPrior==0 ){ pList = pSelect->pEList; @@ -596,6 +599,7 @@ void sqlite3Insert( ** is appears in the original table. (The index of the INTEGER ** PRIMARY KEY in the original table is pTab->iPKey.) */ + bIdListInOrder = (pTab->tabFlags & TF_OOOHidden)==0; if( pColumn ){ for(i=0; inId; i++){ pColumn->a[i].idx = -1; @@ -631,7 +635,8 @@ void sqlite3Insert( ** co-routine is the common header to the 3rd and 4th templates. */ if( pSelect ){ - /* Data is coming from a SELECT. Generate a co-routine to run the SELECT */ + /* Data is coming from a SELECT or from a multi-row VALUES clause. + ** Generate a co-routine to run the SELECT. */ int regYield; /* Register holding co-routine entry-point */ int addrTop; /* Top of the co-routine */ int rc; /* Result code */ @@ -693,8 +698,8 @@ void sqlite3Insert( sqlite3ReleaseTempReg(pParse, regTempRowid); } }else{ - /* This is the case if the data for the INSERT is coming from a VALUES - ** clause + /* This is the case if the data for the INSERT is coming from a + ** single-row VALUES clause */ NameContext sNC; memset(&sNC, 0, sizeof(sNC)); diff --git a/src/sqliteInt.h b/src/sqliteInt.h index b1a2db3a28..deab70fc48 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -1622,6 +1622,12 @@ struct Table { /* ** Allowed values for Table.tabFlags. +** +** TF_OOOHidden applies to virtual tables that have hidden columns that are +** followed by non-hidden columns. Example: "CREATE VIRTUAL TABLE x USING +** vtab1(a HIDDEN, b);". Since "b" is a non-hidden column but "a" is hidden, +** the TF_OOOHidden attribute would apply in this case. Such tables require +** special handling during INSERT processing. */ #define TF_Readonly 0x01 /* Read-only system table */ #define TF_Ephemeral 0x02 /* An ephemeral table */ @@ -1629,6 +1635,7 @@ struct Table { #define TF_Autoincrement 0x08 /* Integer primary key is autoincrement */ #define TF_Virtual 0x10 /* Is a virtual table */ #define TF_WithoutRowid 0x20 /* No rowid used. PRIMARY KEY is the key */ +#define TF_OOOHidden 0x40 /* Out-of-Order hidden columns */ /* diff --git a/src/vtab.c b/src/vtab.c index 530c3f305e..ad65cdf7f4 100644 --- a/src/vtab.c +++ b/src/vtab.c @@ -559,6 +559,7 @@ static int vtabCallConstructor( rc = SQLITE_ERROR; }else{ int iCol; + u8 oooHidden = 0; /* If everything went according to plan, link the new VTable structure ** into the linked list headed by pTab->pVTable. Then loop through the ** columns of the table to see if any of them contain the token "hidden". @@ -571,7 +572,10 @@ static int vtabCallConstructor( char *zType = pTab->aCol[iCol].zType; int nType; int i = 0; - if( !zType ) continue; + if( !zType ){ + pTab->tabFlags |= oooHidden; + continue; + } nType = sqlite3Strlen30(zType); if( sqlite3StrNICmp("hidden", zType, 6)||(zType[6] && zType[6]!=' ') ){ for(i=0; iaCol[iCol].colFlags |= COLFLAG_HIDDEN; + oooHidden = TF_OOOHidden; + }else{ + pTab->tabFlags |= oooHidden; } } } diff --git a/test/vtabA.test b/test/vtabA.test index 928cc2b703..eddaa70d1f 100644 --- a/test/vtabA.test +++ b/test/vtabA.test @@ -74,28 +74,39 @@ do_test vtabA-1.6 { SELECT * FROM t1e; } } {{value a} {value c}} +do_execsql_test vtabA-1.7 { + DELETE FROM t1e; + INSERT INTO t1e SELECT 'abc','def'; +} {} +do_execsql_test vtabA-1.8 { + INSERT INTO t1e VALUES('ghi','jkl'),('mno','pqr'),('stu','vwx'); +} {} +do_execsql_test vtabA-1.9 { + SELECT a,b,c, '|' FROM t1e ORDER BY 1; +} {abc {} def | ghi {} jkl | mno {} pqr | stu {} vwx |} + # Test that the expansion of a '*' expression in the result set of # a SELECT does not include the hidden column. # -do_test vtabA-1.7 { +do_test vtabA-1.20 { execsql { INSERT INTO t1e SELECT * FROM t1e; } } {} -do_test vtabA-1.8 { +do_test vtabA-1.21 { execsql { - SELECT * FROM t1e; + SELECT * FROM t1e ORDER BY 1; } -} {{value a} {value c} {value a} {value c}} +} {abc def abc def ghi jkl ghi jkl mno pqr mno pqr stu vwx stu vwx} # Test that the declaration type of the hidden column does not include # the token "HIDDEN". # -do_test vtabA-1.9 { +do_test vtabA-1.22 { get_decltype t1e b } {VARCHAR} -do_test vtabA-1.10 { +do_test vtabA-1.23 { get_collist t1e } {a c} From 88eb7fa3286cf2d6ca9476be00f0d82e7e0e828c Mon Sep 17 00:00:00 2001 From: mistachkin Date: Sun, 19 Apr 2015 18:58:29 +0000 Subject: [PATCH 154/181] Improve documentation and comments in the MSVC batch build tool. FossilOrigin-Name: ca64ef079811006f3e0526919871ffd286c3e714 --- manifest | 15 +++++------ manifest.uuid | 2 +- tool/build-all-msvc.bat | 60 +++++++++++++++++++++++++++++++++-------- 3 files changed, 56 insertions(+), 21 deletions(-) diff --git a/manifest b/manifest index 594e27b7eb..3bd105c4f7 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Work\sin\sprogress\son\smaking\sVSIX\spackages\sfor\sthe\sVisual\sStudio\s2015\sCTP. -D 2015-04-19T06:18:10.467 +C Improve\sdocumentation\sand\scomments\sin\sthe\sMSVC\sbatch\sbuild\stool. +D 2015-04-19T18:58:29.991 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in faaf75b89840659d74501bea269c7e33414761c1 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -1196,7 +1196,7 @@ F test/without_rowid6.test db0dbf03c49030aa3c1ba5f618620334bd2baf5f F test/wordcount.c 9915e06cb33d8ca8109b8700791afe80d305afda F test/zeroblob.test fb3c0e4ab172d386954deda24c03f500e121d80d F test/zerodamage.test cf6748bad89553cc1632be51a6f54e487e4039ac -F tool/build-all-msvc.bat 62f4f74b55781757d5b20e12651650d5d94ef2cf x +F tool/build-all-msvc.bat 78d530f024c22828ce882a3f0b892490aaaf3201 x F tool/build-shell.sh 950f47c6174f1eea171319438b93ba67ff5bf367 F tool/checkSpacing.c 810e51703529a204fc4e1eb060e9ab663e3c06d2 F tool/diffdb.c 7524b1b5df217c20cd0431f6789851a4e0cb191b @@ -1251,10 +1251,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 917e3c36293a1bf052a16116c93e5037ed712f96 -R db56dc9284c6212139225593eec3e32c -T *branch * vsix2015 -T *sym-vsix2015 * -T -sym-trunk * +P 8469d651a0442a2bc572a869a0457a6ea8c06bc7 +R 05d8b709a19efc6c268ced1a9d746700 U mistachkin -Z af05882e14ca6800d4b8b20f52645692 +Z 13c315b8e34663ea44d46ce0d67e7224 diff --git a/manifest.uuid b/manifest.uuid index b8085cc5cf..f0b5233751 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -8469d651a0442a2bc572a869a0457a6ea8c06bc7 \ No newline at end of file +ca64ef079811006f3e0526919871ffd286c3e714 \ No newline at end of file diff --git a/tool/build-all-msvc.bat b/tool/build-all-msvc.bat index 5fe343c074..090c6266d1 100755 --- a/tool/build-all-msvc.bat +++ b/tool/build-all-msvc.bat @@ -28,6 +28,11 @@ REM In the example above, "C:\dev\sqlite\core" represents the root of the REM source tree for SQLite and "C:\Temp" represents the final destination REM directory for the generated output files. REM +REM Please note that the SQLite build process performed by the Makefile +REM associated with this batch script requires both Gawk ^(gawk.exe^) and Tcl +REM 8.5 ^(tclsh85.exe^) to be present in a directory contained in the PATH +REM environment variable unless a pre-existing amalgamation file is used. +REM REM There are several environment variables that may be set to modify the REM behavior of this batch script and its associated Makefile. The list of REM platforms to build may be overriden by using the PLATFORMS environment @@ -37,17 +42,50 @@ REM being used. The list of configurations to build may be overridden by REM setting the CONFIGURATIONS environment variable, which should contain a REM list of configurations to build ^(e.g. Debug Retail^). Neither of these REM variable values may contain any double quotes, surrounding or embedded. -REM Finally, the NCRTLIBPATH and NSDKLIBPATH environment variables may be set -REM to specify the location of the CRT and SDK, respectively, needed to compile -REM executables native to the architecture of the build machine during any -REM cross-compilation that may be necessary, depending on the platforms to be -REM built. These values in these two variables should be surrounded by double -REM quotes if they contain spaces. REM -REM Please note that the SQLite build process performed by the Makefile -REM associated with this batch script requires both Gawk ^(gawk.exe^) and Tcl -REM 8.5 ^(tclsh85.exe^) to be present in a directory contained in the PATH -REM environment variable unless a pre-existing amalgamation file is used. +REM Finally, the NCRTLIBPATH, NUCRTLIBPATH, and NSDKLIBPATH environment +REM variables may be set to specify the location of the CRT, Universal CRT, and +REM Windows SDK, respectively, that may be needed to compile executables native +REM to the architecture of the build machine during any cross-compilation that +REM may be necessary, depending on the platforms to be built. These values in +REM these three variables should be surrounded by double quotes if they contain +REM spaces. +REM +REM There are a few other environment variables that impact the build process +REM when set ^(to anything^), they are: +REM +REM NOCLEAN +REM +REM When set, the "clean" target will not be used during each build iteration. +REM However, the target binaries, if any, will still be deleted manually prior +REM to being rebuilt. Setting this environment variable is only rarely needed +REM and could cause issues in some circumstances; therefore, setting it is not +REM recommended. +REM +REM NOSYMBOLS +REM +REM When set, copying of symbol files ^(*.pdb^) created during the build will +REM be skipped and they will not appear in the final destination directory. +REM Setting this environment variable is never strictly needed and could cause +REM issues in some circumstances; therefore, setting it is not recommended. +REM +REM BUILD_ALL_SHELL +REM +REM When set, the command line shell will be built for each selected platform +REM and configuration as well. In addition, the command line shell binaries +REM will be copied, with their symbols, to the final destination directory. +REM +REM USE_WINV63_NSDKLIBPATH +REM +REM When set, modifies how the NSDKLIBPATH environment variable is built, based +REM on the WindowsSdkDir environment variable. It forces this batch script to +REM assume the Windows 8.1 SDK location should be used. +REM +REM USE_WINV100_NSDKLIBPATH +REM +REM When set, modifies how the NSDKLIBPATH environment variable is built, based +REM on the WindowsSdkDir environment variable. It causes this batch script to +REM assume the Windows 10.0 SDK location should be used. REM SETLOCAL @@ -432,7 +470,7 @@ FOR %%P IN (%PLATFORMS%) DO ( CALL :fn_CopyVariable WindowsSdkDir NSDKLIBPATH REM - REM NOTE: The Windows 8.x and Windows 10 SDKs have a slightly + REM NOTE: The Windows 8.x and Windows 10.0 SDKs have a slightly REM different directory naming conventions. REM IF DEFINED USE_WINV100_NSDKLIBPATH ( From d0c73053132e0d54952c04730f2749d6760ff9f6 Mon Sep 17 00:00:00 2001 From: drh Date: Sun, 19 Apr 2015 19:21:19 +0000 Subject: [PATCH 155/181] Fix a potential NULL pointer deference on a corrupt database schema. FossilOrigin-Name: dc61b292d8eaf422ca8a2b18f1caccef1a5389fd --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/expr.c | 3 ++- test/misc1.test | 14 ++++++++++++++ 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 3f642604b2..05699e70af 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Bring\scomments\son\sthe\sINSERT\scode\sgenerator\sup-to-date.\s\sFix\sthe\sINSERT\scode\ngenerator\sso\sthat\sit\scorrectly\shandles\sinserts\sfrom\sa\sSELECT\sinto\sa\svirtual\ntable\swith\snon-terminal\shidden\scolumns. -D 2015-04-19T18:32:43.531 +C Fix\sa\spotential\sNULL\spointer\sdeference\son\sa\scorrupt\sdatabase\sschema. +D 2015-04-19T19:21:19.025 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in faaf75b89840659d74501bea269c7e33414761c1 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -182,7 +182,7 @@ F src/complete.c a5cf5b4b56390cfb7b8636e8f7ddef90258dd575 F src/ctime.c 98f89724adc891a1a4c655bee04e33e716e05887 F src/date.c e4d50b3283696836ec1036b695ead9a19e37a5ac F src/delete.c 37964e6c1d73ff49cbea9ff690c9605fb15f600e -F src/expr.c 55e7ce8f7e6c98402365e253b277377fe567772a +F src/expr.c 25a732f30ba391dfb00bbdc9ec079056c2fbced5 F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb F src/fkey.c 3343d551a8d810782257244fb33f2ce191493c39 F src/func.c 1414c24c873c48796ad45942257a179a423ba42f @@ -743,7 +743,7 @@ F test/minmax.test 42fbad0e81afaa6e0de41c960329f2b2c3526efd F test/minmax2.test b44bae787fc7b227597b01b0ca5575c7cb54d3bc F test/minmax3.test cc1e8b010136db0d01a6f2a29ba5a9f321034354 F test/minmax4.test 936941484ebdceb8adec7c86b6cd9b6e5e897c1f -F test/misc1.test 9abcae9a0b8785d6fa92925dbb19c309ae9ea077 +F test/misc1.test 623405f6da1ea0b78b68c0549ee6c2cc027668f2 F test/misc2.test 00d7de54eda90e237fc9a38b9e5ccc769ebf6d4d F test/misc3.test cf3dda47d5dda3e53fc5804a100d3c82be736c9d F test/misc4.test 9c078510fbfff05a9869a0b6d8b86a623ad2c4f6 @@ -1251,7 +1251,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 917e3c36293a1bf052a16116c93e5037ed712f96 -R b611a70a7a5e6fee6ae7534de091ac22 +P 4ac81fac6c6302c042be3df493a41630b733fff0 +R 217c2ee5ae382a4066646fde6de10d74 U drh -Z cc4a9846aabfd76674510baafeb05d26 +Z 68ce861ea89d3d58ce69aec04612a1ea diff --git a/manifest.uuid b/manifest.uuid index c59b152783..18c9f61d96 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -4ac81fac6c6302c042be3df493a41630b733fff0 \ No newline at end of file +dc61b292d8eaf422ca8a2b18f1caccef1a5389fd \ No newline at end of file diff --git a/src/expr.c b/src/expr.c index 6a5ecfe4f2..660fbff7b6 100644 --- a/src/expr.c +++ b/src/expr.c @@ -1251,7 +1251,8 @@ u32 sqlite3ExprListFlags(const ExprList *pList){ u32 m = 0; if( pList ){ for(i=0; inExpr; i++){ - m |= pList->a[i].pExpr->flags; + Expr *pExpr = pList->a[i].pExpr; + if( pExpr ) m |= pList->a[i].pExpr->flags; } } return m; diff --git a/test/misc1.test b/test/misc1.test index 1b98eafc6a..9408f2a8a2 100644 --- a/test/misc1.test +++ b/test/misc1.test @@ -644,4 +644,18 @@ do_execsql_test misc1-22.1 { SELECT ""+3 FROM (SELECT ""+5); } {3} +# 2015-04-19: NULL pointer dereference on a corrupt schema +# +do_execsql_test misc1-23.1 { + DROP TABLE IF EXISTS t1; + DROP TABLE IF EXISTS t2; + CREATE TABLE t1(x); + PRAGMA writable_schema=ON; + UPDATE sqlite_master SET sql='CREATE table t(d CHECK(T(#0)'; + BEGIN; + CREATE TABLE t2(y); + ROLLBACK; + DROP TABLE IF EXISTS t3; +} {} + finish_test From 1c89a7710e5c0704cfd41d01a74e3c58ee6e3364 Mon Sep 17 00:00:00 2001 From: mistachkin Date: Sun, 19 Apr 2015 19:53:43 +0000 Subject: [PATCH 156/181] Document the NMAKE_ARGS environment variable as well. FossilOrigin-Name: 977fd39c1509edec2e28cc8bac64e0994699f398 --- manifest | 12 ++++++------ manifest.uuid | 2 +- tool/build-all-msvc.bat | 8 ++++++++ 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/manifest b/manifest index 3bd105c4f7..0180ba625a 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Improve\sdocumentation\sand\scomments\sin\sthe\sMSVC\sbatch\sbuild\stool. -D 2015-04-19T18:58:29.991 +C Document\sthe\sNMAKE_ARGS\senvironment\svariable\sas\swell. +D 2015-04-19T19:53:43.925 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in faaf75b89840659d74501bea269c7e33414761c1 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -1196,7 +1196,7 @@ F test/without_rowid6.test db0dbf03c49030aa3c1ba5f618620334bd2baf5f F test/wordcount.c 9915e06cb33d8ca8109b8700791afe80d305afda F test/zeroblob.test fb3c0e4ab172d386954deda24c03f500e121d80d F test/zerodamage.test cf6748bad89553cc1632be51a6f54e487e4039ac -F tool/build-all-msvc.bat 78d530f024c22828ce882a3f0b892490aaaf3201 x +F tool/build-all-msvc.bat 19be654f72b0b0ed4d2451a998c603a4eb65a60f x F tool/build-shell.sh 950f47c6174f1eea171319438b93ba67ff5bf367 F tool/checkSpacing.c 810e51703529a204fc4e1eb060e9ab663e3c06d2 F tool/diffdb.c 7524b1b5df217c20cd0431f6789851a4e0cb191b @@ -1251,7 +1251,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 8469d651a0442a2bc572a869a0457a6ea8c06bc7 -R 05d8b709a19efc6c268ced1a9d746700 +P ca64ef079811006f3e0526919871ffd286c3e714 +R 52d9f3383650b84247283bfd77621eab U mistachkin -Z 13c315b8e34663ea44d46ce0d67e7224 +Z 4ecdfe31e09fefcd24da72e520807bdb diff --git a/manifest.uuid b/manifest.uuid index f0b5233751..1edabded57 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ca64ef079811006f3e0526919871ffd286c3e714 \ No newline at end of file +977fd39c1509edec2e28cc8bac64e0994699f398 \ No newline at end of file diff --git a/tool/build-all-msvc.bat b/tool/build-all-msvc.bat index 090c6266d1..534ea75be6 100755 --- a/tool/build-all-msvc.bat +++ b/tool/build-all-msvc.bat @@ -87,6 +87,14 @@ REM When set, modifies how the NSDKLIBPATH environment variable is built, based REM on the WindowsSdkDir environment variable. It causes this batch script to REM assume the Windows 10.0 SDK location should be used. REM +REM NMAKE_ARGS +REM +REM When set, the value is expanded and passed to the NMAKE command line, after +REM its other arguments. This is used to specify additional NMAKE options, for +REM example: +REM +REM SET NMAKE_ARGS=FOR_WINRT=1 +REM SETLOCAL REM SET __ECHO=ECHO From 33c59ecafb82f60dc75df4c82c72d99e59a350fa Mon Sep 17 00:00:00 2001 From: drh Date: Sun, 19 Apr 2015 20:39:17 +0000 Subject: [PATCH 157/181] Fix a faulty assert in the schema parsing logic. FossilOrigin-Name: b1ed949584a2526c04952b98c3aa283427f45e10 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/build.c | 2 +- test/misc1.test | 19 +++++++++++++++++-- 4 files changed, 26 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index 05699e70af..45fb2ca55d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\spotential\sNULL\spointer\sdeference\son\sa\scorrupt\sdatabase\sschema. -D 2015-04-19T19:21:19.025 +C Fix\sa\sfaulty\sassert\sin\sthe\sschema\sparsing\slogic. +D 2015-04-19T20:39:17.335 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in faaf75b89840659d74501bea269c7e33414761c1 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -176,7 +176,7 @@ F src/btmutex.c 45a968cc85afed9b5e6cf55bf1f42f8d18107f79 F src/btree.c 127aceb71ba93f59bc9c6ba810e992a04299e98a F src/btree.h 969adc948e89e449220ff0ff724c94bb2a52e9f1 F src/btreeInt.h 973a22a6fd61350b454ad614832b1f0a5e25a1e4 -F src/build.c 2d43ee768a3678eaeed203ba5b55490b970f0a5e +F src/build.c bc3a513a57b0962aa98b38ab9c850f3987457885 F src/callback.c 7b44ce59674338ad48b0e84e7b72f935ea4f68b0 F src/complete.c a5cf5b4b56390cfb7b8636e8f7ddef90258dd575 F src/ctime.c 98f89724adc891a1a4c655bee04e33e716e05887 @@ -743,7 +743,7 @@ F test/minmax.test 42fbad0e81afaa6e0de41c960329f2b2c3526efd F test/minmax2.test b44bae787fc7b227597b01b0ca5575c7cb54d3bc F test/minmax3.test cc1e8b010136db0d01a6f2a29ba5a9f321034354 F test/minmax4.test 936941484ebdceb8adec7c86b6cd9b6e5e897c1f -F test/misc1.test 623405f6da1ea0b78b68c0549ee6c2cc027668f2 +F test/misc1.test e908edf5c6e02dcc7453c1519e59625c67cc099e F test/misc2.test 00d7de54eda90e237fc9a38b9e5ccc769ebf6d4d F test/misc3.test cf3dda47d5dda3e53fc5804a100d3c82be736c9d F test/misc4.test 9c078510fbfff05a9869a0b6d8b86a623ad2c4f6 @@ -1251,7 +1251,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 4ac81fac6c6302c042be3df493a41630b733fff0 -R 217c2ee5ae382a4066646fde6de10d74 +P dc61b292d8eaf422ca8a2b18f1caccef1a5389fd +R cfb6006d4eb96e8b001f7f44f28a3f5a U drh -Z 68ce861ea89d3d58ce69aec04612a1ea +Z 30562fcecce8e59f5b0c8b52be03b8fe diff --git a/manifest.uuid b/manifest.uuid index 18c9f61d96..496f912ba1 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -dc61b292d8eaf422ca8a2b18f1caccef1a5389fd \ No newline at end of file +b1ed949584a2526c04952b98c3aa283427f45e10 \ No newline at end of file diff --git a/src/build.c b/src/build.c index 9e4adcb21b..52f4e27e32 100644 --- a/src/build.c +++ b/src/build.c @@ -927,7 +927,7 @@ void sqlite3StartTable( if( !noErr ){ sqlite3ErrorMsg(pParse, "table %T already exists", pName); }else{ - assert( !db->init.busy ); + assert( !db->init.busy || CORRUPT_DB ); sqlite3CodeVerifySchema(pParse, iDb); } goto begin_table_error; diff --git a/test/misc1.test b/test/misc1.test index 9408f2a8a2..0dc4d81347 100644 --- a/test/misc1.test +++ b/test/misc1.test @@ -646,9 +646,9 @@ do_execsql_test misc1-22.1 { # 2015-04-19: NULL pointer dereference on a corrupt schema # +db close +sqlite3 db :memory: do_execsql_test misc1-23.1 { - DROP TABLE IF EXISTS t1; - DROP TABLE IF EXISTS t2; CREATE TABLE t1(x); PRAGMA writable_schema=ON; UPDATE sqlite_master SET sql='CREATE table t(d CHECK(T(#0)'; @@ -658,4 +658,19 @@ do_execsql_test misc1-23.1 { DROP TABLE IF EXISTS t3; } {} +# 2015-04-19: Faulty assert() statement +# +db close +database_may_be_corrupt +sqlite3 db :memory: +do_catchsql_test misc1-23.2 { + CREATE TABLE t1(x UNIQUE); + PRAGMA writable_schema=ON; + UPDATE sqlite_master SET sql='CREATE TABLE IF not EXISTS t(c)'; + BEGIN; + CREATE TABLE t2(x); + ROLLBACK; + DROP TABLE F; +} {1 {no such table: F}} + finish_test From 8e18922f12426bd781b5113be9398d59393d77d6 Mon Sep 17 00:00:00 2001 From: mistachkin Date: Sun, 19 Apr 2015 21:43:16 +0000 Subject: [PATCH 158/181] Fix harmless compiler warnings seen with MSVC 2015. FossilOrigin-Name: d05becd873a03a366843a34e7f4c732dd8f88c86 --- ext/fts3/fts3_tokenizer.c | 6 +-- ext/misc/fuzzer.c | 2 +- manifest | 36 +++++++------- manifest.uuid | 2 +- src/insert.c | 1 - src/pager.c | 4 -- src/pragma.c | 12 ++--- src/shell.c | 102 +++++++++++++++++++------------------- src/tclsqlite.c | 10 ++-- src/test_malloc.c | 10 ++-- src/test_multiplex.c | 14 +++--- src/test_onefile.c | 6 +-- src/test_osinst.c | 3 -- src/test_vfs.c | 3 +- tool/lemon.c | 72 +++++++++++++-------------- 15 files changed, 136 insertions(+), 147 deletions(-) diff --git a/ext/fts3/fts3_tokenizer.c b/ext/fts3/fts3_tokenizer.c index 2b985f5f33..2a8e18aa67 100644 --- a/ext/fts3/fts3_tokenizer.c +++ b/ext/fts3/fts3_tokenizer.c @@ -279,9 +279,9 @@ static void testFunc( p = (sqlite3_tokenizer_module *)sqlite3Fts3HashFind(pHash, zName, nName+1); if( !p ){ - char *zErr = sqlite3_mprintf("unknown tokenizer: %s", zName); - sqlite3_result_error(context, zErr, -1); - sqlite3_free(zErr); + char *zErr2 = sqlite3_mprintf("unknown tokenizer: %s", zName); + sqlite3_result_error(context, zErr2, -1); + sqlite3_free(zErr2); return; } diff --git a/ext/misc/fuzzer.c b/ext/misc/fuzzer.c index dc03161aaf..3ed4b0a977 100644 --- a/ext/misc/fuzzer.c +++ b/ext/misc/fuzzer.c @@ -876,7 +876,7 @@ static fuzzer_stem *fuzzerNewStem( if( pNew==0 ) return 0; memset(pNew, 0, sizeof(*pNew)); pNew->zBasis = (char*)&pNew[1]; - pNew->nBasis = (int)strlen(zWord); + pNew->nBasis = (fuzzer_len)strlen(zWord); memcpy(pNew->zBasis, zWord, pNew->nBasis+1); pRule = pCur->pVtab->pRule; while( fuzzerSkipRule(pRule, pNew, pCur->iRuleset) ){ diff --git a/manifest b/manifest index 0180ba625a..a250a05f62 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Document\sthe\sNMAKE_ARGS\senvironment\svariable\sas\swell. -D 2015-04-19T19:53:43.925 +C Fix\sharmless\scompiler\swarnings\sseen\swith\sMSVC\s2015. +D 2015-04-19T21:43:16.561 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in faaf75b89840659d74501bea269c7e33414761c1 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -91,7 +91,7 @@ F ext/fts3/fts3_snippet.c 52c2dcf410b1f9af5a44d81a2cf8c68ed1cb5283 F ext/fts3/fts3_term.c a521f75132f9a495bdca1bdd45949b3191c52763 F ext/fts3/fts3_test.c 8a3a78c4458b2d7c631fcf4b152a5cd656fa7038 F ext/fts3/fts3_tokenize_vtab.c becc661223db7898b213f9e8a23d75bac02408c9 -F ext/fts3/fts3_tokenizer.c b7e586baeb8d0a061cf01a0f7081d88f3935eecf +F ext/fts3/fts3_tokenizer.c 9afd223b07740b14dd589edd3116acacf951fd78 F ext/fts3/fts3_tokenizer.h 64c6ef6c5272c51ebe60fc607a896e84288fcbc3 F ext/fts3/fts3_tokenizer1.c 5c98225a53705e5ee34824087478cf477bdb7004 F ext/fts3/fts3_unicode.c a93f5edc0aff44ef8b06d7cb55b52026541ca145 @@ -111,7 +111,7 @@ F ext/misc/closure.c 636024302cde41b2bf0c542f81c40c624cfb7012 F ext/misc/compress.c 122faa92d25033d6c3f07c39231de074ab3d2e83 F ext/misc/eval.c f971962e92ebb8b0a4e6b62949463ee454d88fa2 F ext/misc/fileio.c d4171c815d6543a9edef8308aab2951413cd8d0f -F ext/misc/fuzzer.c e3e18f47252c151b5553d7e806f38e757d37c4cc +F ext/misc/fuzzer.c 4c84635c71c26cfa7c2e5848cf49fe2d2cfcd767 F ext/misc/ieee754.c b0362167289170627659e84173f5d2e8fee8566e F ext/misc/nextchar.c 35c8b8baacb96d92abbb34a83a997b797075b342 F ext/misc/percentile.c bcbee3c061b884eccb80e21651daaae8e1e43c63 @@ -190,7 +190,7 @@ F src/global.c 4f77cadbc5427d00139ba43d0f3979804cbb700e F src/hash.c 4263fbc955f26c2e8cdc0cf214bc42435aa4e4f5 F src/hash.h c8f3c31722cf3277d03713909761e152a5b81094 F src/hwtime.h d32741c8f4df852c7d959236615444e2b1063b08 -F src/insert.c 305dd3f9539d0affa4bf1c14cc7dffb34867e040 +F src/insert.c f43325e75175e3ca325f164464bb6475e3653d6d F src/journal.c b4124532212b6952f42eb2c12fa3c25701d8ba8d F src/legacy.c ba1863ea58c4c840335a84ec276fc2b25e22bc4e F src/lempar.c 7274c97d24bb46631e504332ccd3bd1b37841770 @@ -217,13 +217,13 @@ F src/os_setup.h c9d4553b5aaa6f73391448b265b89bed0b890faa F src/os_unix.c 5ed7e2e453c2980909a6b2c80dc55764b50819a8 F src/os_win.c 03d27be3a20048ef52a648d5f0a15f5edda9f2a3 F src/os_win.h eb7a47aa17b26b77eb97e4823f20a00b8bda12ca -F src/pager.c 4120a49ecd37697e28f5ed807f470b9c0b88410c +F src/pager.c 5283581c8ce8950ff483a0b3a3cab9cb4d25a21e F src/pager.h c3476e7c89cdf1c6914e50a11f3714e30b4e0a77 F src/parse.y c4e0387bc88c8e21e5ba653e2578959a1f3cdbc7 F src/pcache.c 10539fb959849ad6efff80050541cab3d25089d4 F src/pcache.h b44658c9c932d203510279439d891a2a83e12ba8 F src/pcache1.c 69d137620a305f814398bd29a0c998038c0695e9 -F src/pragma.c 2a81f312cdb78bf0672a0484478ca3c1083028e9 +F src/pragma.c c1f4d012ea9f6b1ce52d341b2cd0ad72d560afd7 F src/pragma.h 09c89bca58e9a44de2116cc8272b8d454657129f F src/prepare.c 1fffbdcd6f8a0173a8f70d71f22528f4c0e1e3d3 F src/printf.c 08fa675c200aac29e561c6153f91f909ed17612f @@ -231,7 +231,7 @@ F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c 53486a98c17b7ae09b8c2b398013e973ce4c1aae F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e F src/select.c 361dfc32244656bbe3f0e53d8ed791b3ec0c4be8 -F src/shell.c 28b3e1174a7fc00155d7d00880a33589a88508c9 +F src/shell.c 78eabce4c16c45e36fea2368f95118116399ba8a F src/sqlite.h.in ca27603a36fcacdaac5a19d8ee35aaff8ce8516f F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h 17d487c3c91b0b8c584a32fbeb393f6f795eea7d @@ -239,7 +239,7 @@ F src/sqliteInt.h af228df2a02bf1a608d678b312d46aa480470b3c F src/sqliteLimit.h 216557999cb45f2e3578ed53ebefe228d779cb46 F src/status.c f266ad8a2892d659b74f0f50cb6a88b6e7c12179 F src/table.c e7a09215315a978057fb42c640f890160dbcc45e -F src/tclsqlite.c fa72a7c5278662357c105ba7925c1d0972506ff9 +F src/tclsqlite.c 14f1992dd6100bfeb1a3dec7e7f449e1c814b8ee F src/test1.c 90fbedce75330d48d99eadb7d5f4223e86969585 F src/test2.c 577961fe48961b2f2e5c8b56ee50c3f459d3359d F src/test3.c 64d2afdd68feac1bb5e2ffb8226c8c639f798622 @@ -265,12 +265,12 @@ F src/test_intarray.c 6c610a21ab8edde85a3a2c7f2b069244ecf4d834 F src/test_intarray.h 9dc57417fb65bc7835cc18548852cc08cc062202 F src/test_journal.c 5360fbe1d1e4416ca36290562fd5a2e3f70f32aa F src/test_loadext.c a5251f956ab6af21e138dc1f9c0399394a510cb4 -F src/test_malloc.c b9495384e74923aefde8311de974bf9b0f5ba570 -F src/test_multiplex.c 97813565daa7ee480abcc5dd1e9984ed1f71eb8c +F src/test_malloc.c 208f09a4e21defa496bc1094fcfadea19385a112 +F src/test_multiplex.c 4dfb159e5c280c0ebdbf8b5ab9d95bf2765061f9 F src/test_multiplex.h c08e4e8f8651f0c5e0509b138ff4d5b43ed1f5d3 F src/test_mutex.c 293042d623ebba969160f471a82aa1551626454f -F src/test_onefile.c 0396f220561f3b4eedc450cef26d40c593c69a25 -F src/test_osinst.c 3d0340bc31a9f3d8a3547e0272373e80f78dde25 +F src/test_onefile.c 38f7cbe79d5bafe95bde683cc3a53b8ca16daf10 +F src/test_osinst.c 5423dc1d355f594371f27dd292ca54bd320b8196 F src/test_pcache.c a5cd24730cb43c5b18629043314548c9169abb00 F src/test_quota.c 180813f43683be5725458fc1ff13ac455d8e722d F src/test_quota.h 2a8ad1952d1d2ca9af0ce0465e56e6c023b5e15d @@ -283,7 +283,7 @@ F src/test_superlock.c 06797157176eb7085027d9dd278c0d7a105e3ec9 F src/test_syscall.c 2e21ca7f7dc54a028f1967b63f1e76155c356f9b F src/test_tclvar.c f4dc67d5f780707210d6bb0eb6016a431c04c7fa F src/test_thread.c af391ec03d23486dffbcc250b7e58e073f172af9 -F src/test_vfs.c b7e6831e6fcf04c5090accff30640ec5c9630739 +F src/test_vfs.c 3b65d42e18b262805716bd96178c81da8f2d9283 F src/test_vfstrace.c bab9594adc976cbe696ff3970728830b4c5ed698 F src/test_wsd.c 41cadfd9d97fe8e3e4e44f61a4a8ccd6f7ca8fe9 F src/threads.c 6bbcc9fe50c917864d48287b4792d46d6e873481 @@ -1207,7 +1207,7 @@ F tool/fuzzershell.c 9e7e273da203037154b433bb67f10b0d9772b370 F tool/genfkey.README cf68fddd4643bbe3ff8e31b8b6d8b0a1b85e20f4 F tool/genfkey.test 4196a8928b78f51d54ef58e99e99401ab2f0a7e5 F tool/getlock.c f4c39b651370156cae979501a7b156bdba50e7ce -F tool/lemon.c ae5f61e3b164d35955777b20d6febcbaf0950702 +F tool/lemon.c b9109f59b57e7b6f101c4fe644c8361ba6dee969 F tool/lempar.c 01ca97f87610d1dac6d8cd96ab109ab1130e76dc F tool/logest.c eef612f8adf4d0993dafed0416064cf50d5d33c6 F tool/mkautoconfamal.sh d1a2da0e15b2ed33d60af35c7e9d483f13a8eb9f @@ -1251,7 +1251,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 ca64ef079811006f3e0526919871ffd286c3e714 -R 52d9f3383650b84247283bfd77621eab +P 977fd39c1509edec2e28cc8bac64e0994699f398 +R 482b18ff9d203ff55695e8f455ac3925 U mistachkin -Z 4ecdfe31e09fefcd24da72e520807bdb +Z 1e735d37890a7ca485ccb54b168d7937 diff --git a/manifest.uuid b/manifest.uuid index 1edabded57..ab4a139b2c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -977fd39c1509edec2e28cc8bac64e0994699f398 \ No newline at end of file +d05becd873a03a366843a34e7f4c732dd8f88c86 \ No newline at end of file diff --git a/src/insert.c b/src/insert.c index fc8895bbd6..d9916a14a6 100644 --- a/src/insert.c +++ b/src/insert.c @@ -2021,7 +2021,6 @@ static int xferOptimization( ** might change the definition of a collation sequence and then run ** a VACUUM command. In that case keys may not be written in strictly ** sorted order. */ - int i; for(i=0; inColumn; i++){ char *zColl = pSrcIdx->azColl[i]; assert( zColl!=0 ); diff --git a/src/pager.c b/src/pager.c index 2230174e5c..9ee2ecab5a 100644 --- a/src/pager.c +++ b/src/pager.c @@ -3044,9 +3044,7 @@ static int pagerWalFrames( ){ int rc; /* Return code */ int nList; /* Number of pages in pList */ -#if defined(SQLITE_DEBUG) || defined(SQLITE_CHECK_PAGES) PgHdr *p; /* For looping over pages */ -#endif assert( pPager->pWal ); assert( pList ); @@ -3063,7 +3061,6 @@ static int pagerWalFrames( ** any pages with page numbers greater than nTruncate into the WAL file. ** They will never be read by any client. So remove them from the pDirty ** list here. */ - PgHdr *p; PgHdr **ppNext = &pList; nList = 0; for(p=pList; (*ppNext = p)!=0; p=p->pDirty){ @@ -3083,7 +3080,6 @@ static int pagerWalFrames( pPager->pageSize, pList, nTruncate, isCommit, pPager->walSyncFlags ); if( rc==SQLITE_OK && pPager->pBackup ){ - PgHdr *p; for(p=pList; p; p=p->pDirty){ sqlite3BackupUpdate(pPager->pBackup, p->pgno, (u8 *)p->pData); } diff --git a/src/pragma.c b/src/pragma.c index 614daa54df..1b4213844d 100644 --- a/src/pragma.c +++ b/src/pragma.c @@ -164,15 +164,15 @@ static int changeTempStorage(Parse *pParse, const char *zStorageType){ */ static void returnSingleInt(Parse *pParse, const char *zLabel, i64 value){ Vdbe *v = sqlite3GetVdbe(pParse); - int mem = ++pParse->nMem; + int nMem = ++pParse->nMem; i64 *pI64 = sqlite3DbMallocRaw(pParse->db, sizeof(value)); if( pI64 ){ memcpy(pI64, &value, sizeof(value)); } - sqlite3VdbeAddOp4(v, OP_Int64, 0, mem, 0, (char*)pI64, P4_INT64); + sqlite3VdbeAddOp4(v, OP_Int64, 0, nMem, 0, (char*)pI64, P4_INT64); sqlite3VdbeSetNumCols(v, 1); sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLabel, SQLITE_STATIC); - sqlite3VdbeAddOp2(v, OP_ResultRow, mem, 1); + sqlite3VdbeAddOp2(v, OP_ResultRow, nMem, 1); } @@ -337,11 +337,11 @@ void sqlite3Pragma( rc = sqlite3_file_control(db, zDb, SQLITE_FCNTL_PRAGMA, (void*)aFcntl); if( rc==SQLITE_OK ){ if( aFcntl[0] ){ - int mem = ++pParse->nMem; - sqlite3VdbeAddOp4(v, OP_String8, 0, mem, 0, aFcntl[0], 0); + int nMem = ++pParse->nMem; + sqlite3VdbeAddOp4(v, OP_String8, 0, nMem, 0, aFcntl[0], 0); sqlite3VdbeSetNumCols(v, 1); sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "result", SQLITE_STATIC); - sqlite3VdbeAddOp2(v, OP_ResultRow, mem, 1); + sqlite3VdbeAddOp2(v, OP_ResultRow, nMem, 1); sqlite3_free(aFcntl[0]); } goto pragma_out; diff --git a/src/shell.c b/src/shell.c index 0d83084741..830deb29a3 100644 --- a/src/shell.c +++ b/src/shell.c @@ -336,7 +336,7 @@ static int stdin_is_interactive = 1; ** to this database a static variable so that it can be accessed ** by the SIGINT handler to interrupt database processing. */ -static sqlite3 *db = 0; +static sqlite3 *globalDb = 0; /* ** True if an interrupt (Control-C) has been received. @@ -805,7 +805,7 @@ static void interrupt_handler(int NotUsed){ UNUSED_PARAMETER(NotUsed); seenInterrupt++; if( seenInterrupt>2 ) exit(1); - if( db ) sqlite3_interrupt(db); + if( globalDb ) sqlite3_interrupt(globalDb); } #endif @@ -1909,23 +1909,23 @@ static void open_db(ShellState *p, int keepAlive){ if( p->db==0 ){ sqlite3_initialize(); sqlite3_open(p->zDbFilename, &p->db); - db = p->db; - if( db && sqlite3_errcode(db)==SQLITE_OK ){ - sqlite3_create_function(db, "shellstatic", 0, SQLITE_UTF8, 0, + globalDb = p->db; + if( p->db && sqlite3_errcode(p->db)==SQLITE_OK ){ + sqlite3_create_function(p->db, "shellstatic", 0, SQLITE_UTF8, 0, shellstaticFunc, 0, 0); } - if( db==0 || SQLITE_OK!=sqlite3_errcode(db) ){ + if( p->db==0 || SQLITE_OK!=sqlite3_errcode(p->db) ){ fprintf(stderr,"Error: unable to open database \"%s\": %s\n", - p->zDbFilename, sqlite3_errmsg(db)); + p->zDbFilename, sqlite3_errmsg(p->db)); if( keepAlive ) return; exit(1); } #ifndef SQLITE_OMIT_LOAD_EXTENSION sqlite3_enable_load_extension(p->db, 1); #endif - sqlite3_create_function(db, "readfile", 1, SQLITE_UTF8, 0, + sqlite3_create_function(p->db, "readfile", 1, SQLITE_UTF8, 0, readfileFunc, 0, 0); - sqlite3_create_function(db, "writefile", 2, SQLITE_UTF8, 0, + sqlite3_create_function(p->db, "writefile", 2, SQLITE_UTF8, 0, writefileFunc, 0, 0); } } @@ -2586,7 +2586,7 @@ static int shell_dbinfo_command(ShellState *p, int nArg, char **azArg){ ** Return 1 on error, 2 to exit, and 0 otherwise. */ static int do_meta_command(char *zLine, ShellState *p){ - int i = 1; + int h = 1; int nArg = 0; int n, c; int rc = 0; @@ -2594,24 +2594,24 @@ static int do_meta_command(char *zLine, ShellState *p){ /* Parse the input line into tokens. */ - while( zLine[i] && nArgdb, zSql, -1, &pStmt, 0); import_append_char(&sCtx, 0); /* To ensure sCtx.z is allocated */ - if( rc && sqlite3_strglob("no such table: *", sqlite3_errmsg(db))==0 ){ + if( rc && sqlite3_strglob("no such table: *", sqlite3_errmsg(p->db))==0 ){ char *zCreate = sqlite3_mprintf("CREATE TABLE %s", zTable); char cSep = '('; while( xRead(&sCtx) ){ @@ -3007,7 +3007,7 @@ static int do_meta_command(char *zLine, ShellState *p){ sqlite3_free(zCreate); if( rc ){ fprintf(stderr, "CREATE TABLE %s(...) failed: %s\n", zTable, - sqlite3_errmsg(db)); + sqlite3_errmsg(p->db)); sqlite3_free(sCtx.z); xCloser(sCtx.in); return 1; @@ -3017,7 +3017,7 @@ static int do_meta_command(char *zLine, ShellState *p){ sqlite3_free(zSql); if( rc ){ if (pStmt) sqlite3_finalize(pStmt); - fprintf(stderr,"Error: %s\n", sqlite3_errmsg(db)); + fprintf(stderr,"Error: %s\n", sqlite3_errmsg(p->db)); xCloser(sCtx.in); return 1; } @@ -3042,13 +3042,13 @@ static int do_meta_command(char *zLine, ShellState *p){ rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0); sqlite3_free(zSql); if( rc ){ - fprintf(stderr, "Error: %s\n", sqlite3_errmsg(db)); + fprintf(stderr, "Error: %s\n", sqlite3_errmsg(p->db)); if (pStmt) sqlite3_finalize(pStmt); xCloser(sCtx.in); return 1; } - needCommit = sqlite3_get_autocommit(db); - if( needCommit ) sqlite3_exec(db, "BEGIN", 0, 0, 0); + needCommit = sqlite3_get_autocommit(p->db); + if( needCommit ) sqlite3_exec(p->db, "BEGIN", 0, 0, 0); do{ int startLine = sCtx.nLine; for(i=0; idb)); } } }while( sCtx.cTerm!=EOF ); @@ -3095,7 +3095,7 @@ static int do_meta_command(char *zLine, ShellState *p){ xCloser(sCtx.in); sqlite3_free(sCtx.z); sqlite3_finalize(pStmt); - if( needCommit ) sqlite3_exec(db, "COMMIT", 0, 0, 0); + if( needCommit ) sqlite3_exec(p->db, "COMMIT", 0, 0, 0); }else if( c=='i' && (strncmp(azArg[0], "indices", n)==0 @@ -3649,13 +3649,13 @@ static int do_meta_command(char *zLine, ShellState *p){ while( sqlite3_step(pStmt)==SQLITE_ROW ){ if( nRow>=nAlloc ){ char **azNew; - int n = nAlloc*2 + 10; - azNew = sqlite3_realloc(azResult, sizeof(azResult[0])*n); + int n2 = nAlloc*2 + 10; + azNew = sqlite3_realloc(azResult, sizeof(azResult[0])*n2); if( azNew==0 ){ fprintf(stderr, "Error: out of memory\n"); break; } - nAlloc = n; + nAlloc = n2; azResult = azNew; } azResult[nRow] = sqlite3_mprintf("%s", sqlite3_column_text(pStmt, 0)); @@ -3708,15 +3708,15 @@ static int do_meta_command(char *zLine, ShellState *p){ { "imposter", SQLITE_TESTCTRL_IMPOSTER }, }; int testctrl = -1; - int rc = 0; - int i, n; + int rc2 = 0; + int i, n2; open_db(p, 0); /* convert testctrl text option to value. allow any unique prefix ** of the option name, or a numerical value. */ - n = strlen30(azArg[1]); + n2 = strlen30(azArg[1]); for(i=0; i<(int)(sizeof(aCtrl)/sizeof(aCtrl[0])); i++){ - if( strncmp(azArg[1], aCtrl[i].zCtrlName, n)==0 ){ + if( strncmp(azArg[1], aCtrl[i].zCtrlName, n2)==0 ){ if( testctrl<0 ){ testctrl = aCtrl[i].ctrlCode; }else{ @@ -3737,8 +3737,8 @@ static int do_meta_command(char *zLine, ShellState *p){ case SQLITE_TESTCTRL_RESERVE: if( nArg==3 ){ int opt = (int)strtol(azArg[2], 0, 0); - rc = sqlite3_test_control(testctrl, p->db, opt); - fprintf(p->out, "%d (0x%08x)\n", rc, rc); + rc2 = sqlite3_test_control(testctrl, p->db, opt); + fprintf(p->out, "%d (0x%08x)\n", rc2, rc2); } else { fprintf(stderr,"Error: testctrl %s takes a single int option\n", azArg[1]); @@ -3751,8 +3751,8 @@ static int do_meta_command(char *zLine, ShellState *p){ case SQLITE_TESTCTRL_PRNG_RESET: case SQLITE_TESTCTRL_BYTEORDER: if( nArg==2 ){ - rc = sqlite3_test_control(testctrl); - fprintf(p->out, "%d (0x%08x)\n", rc, rc); + rc2 = sqlite3_test_control(testctrl); + fprintf(p->out, "%d (0x%08x)\n", rc2, rc2); } else { fprintf(stderr,"Error: testctrl %s takes no options\n", azArg[1]); } @@ -3762,8 +3762,8 @@ static int do_meta_command(char *zLine, ShellState *p){ case SQLITE_TESTCTRL_PENDING_BYTE: if( nArg==3 ){ unsigned int opt = (unsigned int)integerValue(azArg[2]); - rc = sqlite3_test_control(testctrl, opt); - fprintf(p->out, "%d (0x%08x)\n", rc, rc); + rc2 = sqlite3_test_control(testctrl, opt); + fprintf(p->out, "%d (0x%08x)\n", rc2, rc2); } else { fprintf(stderr,"Error: testctrl %s takes a single unsigned" " int option\n", azArg[1]); @@ -3776,8 +3776,8 @@ static int do_meta_command(char *zLine, ShellState *p){ case SQLITE_TESTCTRL_NEVER_CORRUPT: if( nArg==3 ){ int opt = booleanValue(azArg[2]); - rc = sqlite3_test_control(testctrl, opt); - fprintf(p->out, "%d (0x%08x)\n", rc, rc); + rc2 = sqlite3_test_control(testctrl, opt); + fprintf(p->out, "%d (0x%08x)\n", rc2, rc2); } else { fprintf(stderr,"Error: testctrl %s takes a single int option\n", azArg[1]); @@ -3789,8 +3789,8 @@ static int do_meta_command(char *zLine, ShellState *p){ case SQLITE_TESTCTRL_ISKEYWORD: if( nArg==3 ){ const char *opt = azArg[2]; - rc = sqlite3_test_control(testctrl, opt); - fprintf(p->out, "%d (0x%08x)\n", rc, rc); + rc2 = sqlite3_test_control(testctrl, opt); + fprintf(p->out, "%d (0x%08x)\n", rc2, rc2); } else { fprintf(stderr,"Error: testctrl %s takes a single char * option\n", azArg[1]); @@ -3800,11 +3800,11 @@ static int do_meta_command(char *zLine, ShellState *p){ case SQLITE_TESTCTRL_IMPOSTER: if( nArg==5 ){ - rc = sqlite3_test_control(testctrl, p->db, + rc2 = sqlite3_test_control(testctrl, p->db, azArg[2], integerValue(azArg[3]), integerValue(azArg[4])); - fprintf(p->out, "%d (0x%08x)\n", rc, rc); + fprintf(p->out, "%d (0x%08x)\n", rc2, rc2); }else{ fprintf(stderr,"Usage: .testctrl imposter dbName onoff tnum\n"); } diff --git a/src/tclsqlite.c b/src/tclsqlite.c index 710084b89e..e38c1dd083 100644 --- a/src/tclsqlite.c +++ b/src/tclsqlite.c @@ -1191,7 +1191,7 @@ static int dbPrepareAndBind( int n; u8 *data; const char *zType = (pVar->typePtr ? pVar->typePtr->name : ""); - char c = zType[0]; + c = zType[0]; if( zVar[0]=='@' || (c=='b' && strcmp(zType,"bytearray")==0 && pVar->bytes==0) ){ /* Load a BLOB type if the Tcl variable is a bytearray and @@ -2298,7 +2298,7 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){ } Tcl_DecrRefCount(pRet); }else{ - ClientData cd[2]; + ClientData cd2[2]; DbEvalContext *p; Tcl_Obj *pArray = 0; Tcl_Obj *pScript; @@ -2312,9 +2312,9 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){ p = (DbEvalContext *)Tcl_Alloc(sizeof(DbEvalContext)); dbEvalInit(p, pDb, objv[2], pArray); - cd[0] = (void *)p; - cd[1] = (void *)pScript; - rc = DbEvalNextCmd(cd, interp, TCL_OK); + cd2[0] = (void *)p; + cd2[1] = (void *)pScript; + rc = DbEvalNextCmd(cd2, interp, TCL_OK); } break; } diff --git a/src/test_malloc.c b/src/test_malloc.c index 1ea4de5063..94a2282923 100644 --- a/src/test_malloc.c +++ b/src/test_malloc.c @@ -211,15 +211,15 @@ static int faultsimInstall(int install){ faultsimBeginBenign, faultsimEndBenign ); }else{ - sqlite3_mem_methods m; + sqlite3_mem_methods m2; assert(memfault.m.xMalloc); /* One should be able to reset the default memory allocator by storing ** a zeroed allocator then calling GETMALLOC. */ - memset(&m, 0, sizeof(m)); - sqlite3_config(SQLITE_CONFIG_MALLOC, &m); - sqlite3_config(SQLITE_CONFIG_GETMALLOC, &m); - assert( memcmp(&m, &memfault.m, sizeof(m))==0 ); + memset(&m2, 0, sizeof(m2)); + sqlite3_config(SQLITE_CONFIG_MALLOC, &m2); + sqlite3_config(SQLITE_CONFIG_GETMALLOC, &m2); + assert( memcmp(&m2, &memfault.m, sizeof(m2))==0 ); rc = sqlite3_config(SQLITE_CONFIG_MALLOC, &memfault.m); sqlite3_test_control(SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS, 0, 0); diff --git a/src/test_multiplex.c b/src/test_multiplex.c index cd379f18f6..c1077fbee3 100644 --- a/src/test_multiplex.c +++ b/src/test_multiplex.c @@ -568,15 +568,15 @@ static int multiplexOpen( if( pSubOpen==0 && rc==SQLITE_OK ) rc = SQLITE_CANTOPEN; } if( rc==SQLITE_OK ){ - sqlite3_int64 sz; + sqlite3_int64 sz64; - rc = pSubOpen->pMethods->xFileSize(pSubOpen, &sz); + rc = pSubOpen->pMethods->xFileSize(pSubOpen, &sz64); if( rc==SQLITE_OK && zName ){ int bExists; if( flags & SQLITE_OPEN_MASTER_JOURNAL ){ pGroup->bEnabled = 0; }else - if( sz==0 ){ + if( sz64==0 ){ if( flags & SQLITE_OPEN_MAIN_JOURNAL ){ /* If opening a main journal file and the first chunk is zero ** bytes in size, delete any subsequent chunks from the @@ -607,10 +607,10 @@ static int multiplexOpen( rc = pOrigVfs->xAccess(pOrigVfs, pGroup->aReal[1].z, SQLITE_ACCESS_EXISTS, &bExists); bExists = multiplexSubSize(pGroup, 1, &rc)>0; - if( rc==SQLITE_OK && bExists && sz==(sz&0xffff0000) && sz>0 - && sz!=pGroup->szChunk ){ - pGroup->szChunk = (int)sz; - }else if( rc==SQLITE_OK && !bExists && sz>pGroup->szChunk ){ + if( rc==SQLITE_OK && bExists && sz64==(sz64&0xffff0000) && sz64>0 + && sz64!=pGroup->szChunk ){ + pGroup->szChunk = (int)sz64; + }else if( rc==SQLITE_OK && !bExists && sz64>pGroup->szChunk ){ pGroup->bEnabled = 0; } } diff --git a/src/test_onefile.c b/src/test_onefile.c index 69867441b8..122be700e6 100644 --- a/src/test_onefile.c +++ b/src/test_onefile.c @@ -595,9 +595,9 @@ static int fsOpen( int rc = SQLITE_OK; if( 0==(flags&(SQLITE_OPEN_MAIN_DB|SQLITE_OPEN_MAIN_JOURNAL)) ){ - tmp_file *p = (tmp_file *)pFile; - memset(p, 0, sizeof(*p)); - p->base.pMethods = &tmp_io_methods; + tmp_file *p2 = (tmp_file *)pFile; + memset(p2, 0, sizeof(*p2)); + p2->base.pMethods = &tmp_io_methods; return SQLITE_OK; } diff --git a/src/test_osinst.c b/src/test_osinst.c index 1701def159..4ae23a87c6 100644 --- a/src/test_osinst.c +++ b/src/test_osinst.c @@ -1131,7 +1131,6 @@ static int test_vfslog( switch( (enum VL_enum)iSub ){ case VL_ANNOTATE: { - int rc; char *zVfs; char *zMsg; if( objc!=4 ){ @@ -1148,7 +1147,6 @@ static int test_vfslog( break; } case VL_FINALIZE: { - int rc; char *zVfs; if( objc!=3 ){ Tcl_WrongNumArgs(interp, 2, objv, "VFS"); @@ -1164,7 +1162,6 @@ static int test_vfslog( }; case VL_NEW: { - int rc; char *zVfs; char *zParent; char *zLog; diff --git a/src/test_vfs.c b/src/test_vfs.c index 2277cf7eb5..a8c6ae7bf5 100644 --- a/src/test_vfs.c +++ b/src/test_vfs.c @@ -1080,7 +1080,7 @@ static int testvfs_obj_cmd( switch( aSubcmd[i].eCmd ){ case CMD_SHM: { Tcl_Obj *pObj; - int i, rc; + int rc; TestvfsBuffer *pBuffer; char *zName; if( objc!=3 && objc!=4 ){ @@ -1160,7 +1160,6 @@ static int testvfs_obj_cmd( }; Tcl_Obj **apElem = 0; int nElem = 0; - int i; int mask = 0; if( objc!=3 ){ Tcl_WrongNumArgs(interp, 2, objv, "LIST"); diff --git a/tool/lemon.c b/tool/lemon.c index cc3066bec0..89d992c37e 100644 --- a/tool/lemon.c +++ b/tool/lemon.c @@ -1114,7 +1114,6 @@ void FindActions(struct lemon *lemp) /* Resolve conflicts */ for(i=0; instate; i++){ struct action *ap, *nap; - struct state *stp; stp = lemp->sorted[i]; /* assert( stp->ap ); */ stp->ap = Action_sort(stp->ap); @@ -3748,9 +3747,9 @@ void ReportTable( /* Generate the include code, if any */ tplt_print(out,lemp,lemp->include,&lineno); if( mhflag ){ - char *name = file_makename(lemp, ".h"); - fprintf(out,"#include \"%s\"\n", name); lineno++; - free(name); + char *incName = file_makename(lemp, ".h"); + fprintf(out,"#include \"%s\"\n", incName); lineno++; + free(incName); } tplt_xfer(lemp->name,in,out,&lineno); @@ -3791,7 +3790,6 @@ void ReportTable( } name = lemp->name ? lemp->name : "Parse"; if( lemp->arg && lemp->arg[0] ){ - int i; i = lemonStrlen(lemp->arg); while( i>=1 && isspace(lemp->arg[i-1]) ) i--; while( i>=1 && (isalnum(lemp->arg[i-1]) || lemp->arg[i-1]=='_') ) i--; @@ -4479,18 +4477,18 @@ int Strsafe_insert(const char *data) } if( x1a->count>=x1a->size ){ /* Need to make the hash table bigger */ - int i,size; + int i,arrSize; struct s_x1 array; - array.size = size = x1a->size*2; + array.size = arrSize = x1a->size*2; array.count = x1a->count; - array.tbl = (x1node*)calloc(size, sizeof(x1node) + sizeof(x1node*)); + array.tbl = (x1node*)calloc(arrSize, sizeof(x1node) + sizeof(x1node*)); if( array.tbl==0 ) return 0; /* Fail due to malloc failure */ - array.ht = (x1node**)&(array.tbl[size]); - for(i=0; icount; i++){ x1node *oldnp, *newnp; oldnp = &(x1a->tbl[i]); - h = strhash(oldnp->data) & (size-1); + h = strhash(oldnp->data) & (arrSize-1); newnp = &(array.tbl[i]); if( array.ht[h] ) array.ht[h]->from = &(newnp->next); newnp->next = array.ht[h]; @@ -4646,18 +4644,18 @@ int Symbol_insert(struct symbol *data, const char *key) } if( x2a->count>=x2a->size ){ /* Need to make the hash table bigger */ - int i,size; + int i,arrSize; struct s_x2 array; - array.size = size = x2a->size*2; + array.size = arrSize = x2a->size*2; array.count = x2a->count; - array.tbl = (x2node*)calloc(size, sizeof(x2node) + sizeof(x2node*)); + array.tbl = (x2node*)calloc(arrSize, sizeof(x2node) + sizeof(x2node*)); if( array.tbl==0 ) return 0; /* Fail due to malloc failure */ - array.ht = (x2node**)&(array.tbl[size]); - for(i=0; icount; i++){ x2node *oldnp, *newnp; oldnp = &(x2a->tbl[i]); - h = strhash(oldnp->key) & (size-1); + h = strhash(oldnp->key) & (arrSize-1); newnp = &(array.tbl[i]); if( array.ht[h] ) array.ht[h]->from = &(newnp->next); newnp->next = array.ht[h]; @@ -4722,12 +4720,12 @@ int Symbol_count() struct symbol **Symbol_arrayof() { struct symbol **array; - int i,size; + int i,arrSize; if( x2a==0 ) return 0; - size = x2a->count; - array = (struct symbol **)calloc(size, sizeof(struct symbol *)); + arrSize = x2a->count; + array = (struct symbol **)calloc(arrSize, sizeof(struct symbol *)); if( array ){ - for(i=0; itbl[i].data; + for(i=0; itbl[i].data; } return array; } @@ -4843,18 +4841,18 @@ int State_insert(struct state *data, struct config *key) } if( x3a->count>=x3a->size ){ /* Need to make the hash table bigger */ - int i,size; + int i,arrSize; struct s_x3 array; - array.size = size = x3a->size*2; + array.size = arrSize = x3a->size*2; array.count = x3a->count; - array.tbl = (x3node*)calloc(size, sizeof(x3node) + sizeof(x3node*)); + array.tbl = (x3node*)calloc(arrSize, sizeof(x3node) + sizeof(x3node*)); if( array.tbl==0 ) return 0; /* Fail due to malloc failure */ - array.ht = (x3node**)&(array.tbl[size]); - for(i=0; icount; i++){ x3node *oldnp, *newnp; oldnp = &(x3a->tbl[i]); - h = statehash(oldnp->key) & (size-1); + h = statehash(oldnp->key) & (arrSize-1); newnp = &(array.tbl[i]); if( array.ht[h] ) array.ht[h]->from = &(newnp->next); newnp->next = array.ht[h]; @@ -4901,12 +4899,12 @@ struct state *State_find(struct config *key) struct state **State_arrayof() { struct state **array; - int i,size; + int i,arrSize; if( x3a==0 ) return 0; - size = x3a->count; - array = (struct state **)calloc(size, sizeof(struct state *)); + arrSize = x3a->count; + array = (struct state **)calloc(arrSize, sizeof(struct state *)); if( array ){ - for(i=0; itbl[i].data; + for(i=0; itbl[i].data; } return array; } @@ -4983,18 +4981,18 @@ int Configtable_insert(struct config *data) } if( x4a->count>=x4a->size ){ /* Need to make the hash table bigger */ - int i,size; + int i,arrSize; struct s_x4 array; - array.size = size = x4a->size*2; + array.size = arrSize = x4a->size*2; array.count = x4a->count; - array.tbl = (x4node*)calloc(size, sizeof(x4node) + sizeof(x4node*)); + array.tbl = (x4node*)calloc(arrSize, sizeof(x4node) + sizeof(x4node*)); if( array.tbl==0 ) return 0; /* Fail due to malloc failure */ - array.ht = (x4node**)&(array.tbl[size]); - for(i=0; icount; i++){ x4node *oldnp, *newnp; oldnp = &(x4a->tbl[i]); - h = confighash(oldnp->data) & (size-1); + h = confighash(oldnp->data) & (arrSize-1); newnp = &(array.tbl[i]); if( array.ht[h] ) array.ht[h]->from = &(newnp->next); newnp->next = array.ht[h]; From 5f1d2fa4d2f75470dcac0b85ba60e3495cce0e88 Mon Sep 17 00:00:00 2001 From: drh Date: Sun, 19 Apr 2015 21:59:19 +0000 Subject: [PATCH 159/181] Fix another assert() that is not true if the database schema is corrupt. FossilOrigin-Name: bc97cec6338b16a4e9b1a9457d01bb7fe462934d --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/build.c | 3 ++- test/misc1.test | 11 +++++++++++ 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 45fb2ca55d..afcf92746e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sfaulty\sassert\sin\sthe\sschema\sparsing\slogic. -D 2015-04-19T20:39:17.335 +C Fix\sanother\sassert()\sthat\sis\snot\strue\sif\sthe\sdatabase\sschema\sis\scorrupt. +D 2015-04-19T21:59:19.589 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in faaf75b89840659d74501bea269c7e33414761c1 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -176,7 +176,7 @@ F src/btmutex.c 45a968cc85afed9b5e6cf55bf1f42f8d18107f79 F src/btree.c 127aceb71ba93f59bc9c6ba810e992a04299e98a F src/btree.h 969adc948e89e449220ff0ff724c94bb2a52e9f1 F src/btreeInt.h 973a22a6fd61350b454ad614832b1f0a5e25a1e4 -F src/build.c bc3a513a57b0962aa98b38ab9c850f3987457885 +F src/build.c 2e46e275a9104bbebdaf04bccae3fe47c95d57b2 F src/callback.c 7b44ce59674338ad48b0e84e7b72f935ea4f68b0 F src/complete.c a5cf5b4b56390cfb7b8636e8f7ddef90258dd575 F src/ctime.c 98f89724adc891a1a4c655bee04e33e716e05887 @@ -743,7 +743,7 @@ F test/minmax.test 42fbad0e81afaa6e0de41c960329f2b2c3526efd F test/minmax2.test b44bae787fc7b227597b01b0ca5575c7cb54d3bc F test/minmax3.test cc1e8b010136db0d01a6f2a29ba5a9f321034354 F test/minmax4.test 936941484ebdceb8adec7c86b6cd9b6e5e897c1f -F test/misc1.test e908edf5c6e02dcc7453c1519e59625c67cc099e +F test/misc1.test 783ba75743b2cf71e0f646bf540a6cef57264811 F test/misc2.test 00d7de54eda90e237fc9a38b9e5ccc769ebf6d4d F test/misc3.test cf3dda47d5dda3e53fc5804a100d3c82be736c9d F test/misc4.test 9c078510fbfff05a9869a0b6d8b86a623ad2c4f6 @@ -1251,7 +1251,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 dc61b292d8eaf422ca8a2b18f1caccef1a5389fd -R cfb6006d4eb96e8b001f7f44f28a3f5a +P b1ed949584a2526c04952b98c3aa283427f45e10 +R 7eb252d844c06f104bb11959e0f1c997 U drh -Z 30562fcecce8e59f5b0c8b52be03b8fe +Z 149b8d57c1b56c76702cf167c619275e diff --git a/manifest.uuid b/manifest.uuid index 496f912ba1..a0dbc177c1 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -b1ed949584a2526c04952b98c3aa283427f45e10 \ No newline at end of file +bc97cec6338b16a4e9b1a9457d01bb7fe462934d \ No newline at end of file diff --git a/src/build.c b/src/build.c index 52f4e27e32..19783ecee3 100644 --- a/src/build.c +++ b/src/build.c @@ -1216,7 +1216,8 @@ void sqlite3AddColumnType(Parse *pParse, Token *pType){ p = pParse->pNewTable; if( p==0 || NEVER(p->nCol<1) ) return; pCol = &p->aCol[p->nCol-1]; - assert( pCol->zType==0 ); + assert( pCol->zType==0 || CORRUPT_DB ); + sqlite3DbFree(pParse->db, pCol->zType); pCol->zType = sqlite3NameFromToken(pParse->db, pType); pCol->affinity = sqlite3AffinityType(pCol->zType, &pCol->szEst); } diff --git a/test/misc1.test b/test/misc1.test index 0dc4d81347..7ae50e4fe0 100644 --- a/test/misc1.test +++ b/test/misc1.test @@ -672,5 +672,16 @@ do_catchsql_test misc1-23.2 { ROLLBACK; DROP TABLE F; } {1 {no such table: F}} +db close +sqlite3 db :memory: +do_catchsql_test misc1-23.3 { + CREATE TABLE t1(x UNIQUE); + PRAGMA writable_schema=ON; + UPDATE sqlite_master SET sql='CREATE table y(a TEXT, a TEXT)'; + BEGIN; + CREATE TABLE t2(y); + ROLLBACK; + DROP TABLE IF EXISTS t; +} {0 {}} finish_test From 752099696505db3abc1a841028c2ca6d3713d3e3 Mon Sep 17 00:00:00 2001 From: drh Date: Sun, 19 Apr 2015 22:31:45 +0000 Subject: [PATCH 160/181] Silently ignore parser stack overflow when parsing a malformed schema in PRAGMA writable_schema mode. FossilOrigin-Name: 2cb37b959c66b5ae3535ab81ba14a4ebf9732df7 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/build.c | 1 + test/misc5.test | 18 ++++++++++++++++++ 4 files changed, 27 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index afcf92746e..6f897f3bcf 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sanother\sassert()\sthat\sis\snot\strue\sif\sthe\sdatabase\sschema\sis\scorrupt. -D 2015-04-19T21:59:19.589 +C Silently\signore\sparser\sstack\soverflow\swhen\sparsing\sa\smalformed\sschema\sin\nPRAGMA\swritable_schema\smode. +D 2015-04-19T22:31:45.600 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in faaf75b89840659d74501bea269c7e33414761c1 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -176,7 +176,7 @@ F src/btmutex.c 45a968cc85afed9b5e6cf55bf1f42f8d18107f79 F src/btree.c 127aceb71ba93f59bc9c6ba810e992a04299e98a F src/btree.h 969adc948e89e449220ff0ff724c94bb2a52e9f1 F src/btreeInt.h 973a22a6fd61350b454ad614832b1f0a5e25a1e4 -F src/build.c 2e46e275a9104bbebdaf04bccae3fe47c95d57b2 +F src/build.c e246c2cea69c8f6fc825a156ea2de9dd4a17f18b F src/callback.c 7b44ce59674338ad48b0e84e7b72f935ea4f68b0 F src/complete.c a5cf5b4b56390cfb7b8636e8f7ddef90258dd575 F src/ctime.c 98f89724adc891a1a4c655bee04e33e716e05887 @@ -747,7 +747,7 @@ F test/misc1.test 783ba75743b2cf71e0f646bf540a6cef57264811 F test/misc2.test 00d7de54eda90e237fc9a38b9e5ccc769ebf6d4d F test/misc3.test cf3dda47d5dda3e53fc5804a100d3c82be736c9d F test/misc4.test 9c078510fbfff05a9869a0b6d8b86a623ad2c4f6 -F test/misc5.test 528468b26d03303b1f047146e5eefc941b9069f5 +F test/misc5.test f96428ea95b3820aafc6f1c50cf48a09e4597ee1 F test/misc6.test 953cc693924d88e6117aeba16f46f0bf5abede91 F test/misc7.test edd0b63e2ee29a256900b0514f6fff27e19e9bb2 F test/misc8.test fc2754d38892f7dac30c22db3616c2764f117d66 @@ -1251,7 +1251,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 b1ed949584a2526c04952b98c3aa283427f45e10 -R 7eb252d844c06f104bb11959e0f1c997 +P bc97cec6338b16a4e9b1a9457d01bb7fe462934d +R 01f9eeee512ab8c1eb8c49d658fe5ba3 U drh -Z 149b8d57c1b56c76702cf167c619275e +Z 025d0c7f7a9e2517785c78c21f380610 diff --git a/manifest.uuid b/manifest.uuid index a0dbc177c1..09db9c0876 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -bc97cec6338b16a4e9b1a9457d01bb7fe462934d \ No newline at end of file +2cb37b959c66b5ae3535ab81ba14a4ebf9732df7 \ No newline at end of file diff --git a/src/build.c b/src/build.c index 19783ecee3..11f0b39245 100644 --- a/src/build.c +++ b/src/build.c @@ -2451,6 +2451,7 @@ void sqlite3DropTable(Parse *pParse, SrcList *pName, int isView, int noErr){ } assert( pParse->nErr==0 ); assert( pName->nSrc==1 ); + if( sqlite3ReadSchema(pParse) ) goto exit_drop_table; if( noErr ) db->suppressErr++; pTab = sqlite3LocateTableItem(pParse, isView, &pName->a[0]); if( noErr ) db->suppressErr--; diff --git a/test/misc5.test b/test/misc5.test index 14ba44ead0..30176b8082 100644 --- a/test/misc5.test +++ b/test/misc5.test @@ -583,6 +583,24 @@ do_test misc5-7.1 { catchsql $sql } {1 {parser stack overflow}} +# Parser stack overflow is silently ignored when it occurs while parsing the +# schema and PRAGMA writable_schema is turned on. +# +do_test misc5-7.2 { + sqlite3 db2 :memory: + catchsql { + CREATE TABLE t1(x UNIQUE); + PRAGMA writable_schema=ON; + UPDATE sqlite_master SET sql='CREATE table t(o CHECK(((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((;VALUES(o)'; + BEGIN; + CREATE TABLE t2(y); + ROLLBACK; + DROP TABLE IF EXISTS D; + } db2 +} {0 {}} +db2 close + + # Ticket #1911 # ifcapable compound { From 992590be1c72af9d6d5c09b4a5793b16d0cd90af Mon Sep 17 00:00:00 2001 From: drh Date: Sun, 19 Apr 2015 22:41:22 +0000 Subject: [PATCH 161/181] Fix a broken assert() and comparison for INSERT INTO ... SELECT when the SELECT uses an unknown collating sequence. FossilOrigin-Name: e73ac0cbac257d2d2b28e51423e30d7449b6c7b5 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/insert.c | 3 +-- test/insert4.test | 5 +++++ 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index 6f897f3bcf..806b4e4f19 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Silently\signore\sparser\sstack\soverflow\swhen\sparsing\sa\smalformed\sschema\sin\nPRAGMA\swritable_schema\smode. -D 2015-04-19T22:31:45.600 +C Fix\sa\sbroken\sassert()\sand\scomparison\sfor\sINSERT\sINTO\s...\sSELECT\swhen\sthe\nSELECT\suses\san\sunknown\scollating\ssequence. +D 2015-04-19T22:41:22.682 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in faaf75b89840659d74501bea269c7e33414761c1 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -190,7 +190,7 @@ F src/global.c 4f77cadbc5427d00139ba43d0f3979804cbb700e F src/hash.c 4263fbc955f26c2e8cdc0cf214bc42435aa4e4f5 F src/hash.h c8f3c31722cf3277d03713909761e152a5b81094 F src/hwtime.h d32741c8f4df852c7d959236615444e2b1063b08 -F src/insert.c 9f5f25a9d645089973d2f451711b7402bfde6ab5 +F src/insert.c b152e71457c40a3967ceafa9e7cbbb52e9ead2c1 F src/journal.c b4124532212b6952f42eb2c12fa3c25701d8ba8d F src/legacy.c ba1863ea58c4c840335a84ec276fc2b25e22bc4e F src/lempar.c 7274c97d24bb46631e504332ccd3bd1b37841770 @@ -666,7 +666,7 @@ F test/init.test 15c823093fdabbf7b531fe22cf037134d09587a7 F test/insert.test 38742b5e9601c8f8d76e9b7555f7270288c2d371 F test/insert2.test 4f3a04d168c728ed5ec2c88842e772606c7ce435 F test/insert3.test 1b7db95a03ad9c5013fdf7d6722b6cd66ee55e30 -F test/insert4.test 4791662c50518bdd37d394cae9a7a8014e845bb3 +F test/insert4.test a20432f1c0fbbcff8f11d0e6ab4acb8c9db58023 F test/insert5.test 394f96728d1258f406fe5f5aeb0aaf29487c39a6 F test/instr.test 737bbf80685232033f3abedc6ae92f75860b5dd2 F test/intarray.test 066b7d7ac38d25bf96f87f1b017bfc687551cdd4 @@ -1251,7 +1251,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 bc97cec6338b16a4e9b1a9457d01bb7fe462934d -R 01f9eeee512ab8c1eb8c49d658fe5ba3 +P 2cb37b959c66b5ae3535ab81ba14a4ebf9732df7 +R e2cf191d4292c134d8577e2e34e33df7 U drh -Z 025d0c7f7a9e2517785c78c21f380610 +Z 7931b9be35191227870d2d70e1da695e diff --git a/manifest.uuid b/manifest.uuid index 09db9c0876..aa056fdc0a 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -2cb37b959c66b5ae3535ab81ba14a4ebf9732df7 \ No newline at end of file +e73ac0cbac257d2d2b28e51423e30d7449b6c7b5 \ No newline at end of file diff --git a/src/insert.c b/src/insert.c index 73c550b832..f8f37666a1 100644 --- a/src/insert.c +++ b/src/insert.c @@ -649,8 +649,7 @@ void sqlite3Insert( dest.nSdst = pTab->nCol; rc = sqlite3Select(pParse, pSelect, &dest); regFromSelect = dest.iSdst; - assert( pParse->nErr==0 || rc ); - if( rc || db->mallocFailed ) goto insert_cleanup; + if( rc || db->mallocFailed || pParse->nErr ) goto insert_cleanup; sqlite3VdbeAddOp1(v, OP_EndCoroutine, regYield); sqlite3VdbeJumpHere(v, addrTop - 1); /* label B: */ assert( pSelect->pEList ); diff --git a/test/insert4.test b/test/insert4.test index 889d5e7807..3eece87e5f 100644 --- a/test/insert4.test +++ b/test/insert4.test @@ -560,5 +560,10 @@ do_test insert4-8.25 { } } {1 3} +do_catchsql_test insert4-9.1 { + DROP TABLE IF EXISTS t1; + CREATE TABLE t1(x); + INSERT INTO t1(x) VALUES(5 COLLATE xyzzy) UNION SELECT 0; +} {1 {no such collation sequence: xyzzy}} finish_test From 542a176d5e6fb2446265bdda5c0db79448a4be63 Mon Sep 17 00:00:00 2001 From: drh Date: Sun, 19 Apr 2015 23:11:10 +0000 Subject: [PATCH 162/181] Fix an off-by-one assert() in the virtual table argument tokenizer. FossilOrigin-Name: c83052e48bbae0f45db2a44155b4e5482ee4a901 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/vtab.c | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 806b4e4f19..340322d8fa 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sbroken\sassert()\sand\scomparison\sfor\sINSERT\sINTO\s...\sSELECT\swhen\sthe\nSELECT\suses\san\sunknown\scollating\ssequence. -D 2015-04-19T22:41:22.682 +C Fix\san\soff-by-one\sassert()\sin\sthe\svirtual\stable\sargument\stokenizer. +D 2015-04-19T23:11:10.399 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in faaf75b89840659d74501bea269c7e33414761c1 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -302,7 +302,7 @@ F src/vdbeblob.c 4f2e8e075d238392df98c5e03a64342465b03f90 F src/vdbemem.c c0dc81285b7571b0a31c40f17846fe2397ec1cd9 F src/vdbesort.c 2e7f683464fd5db3be4beaa1ff2d39e24fcb64b8 F src/vdbetrace.c f95c2dff9041fcf07f871789c22ebb0648ea0b7c -F src/vtab.c 4feb365e2688dd02474e671e37f27e35784d2cff +F src/vtab.c 5f81f8a59c1f5ddb94c918f25ed5d83578fcc633 F src/vxworks.h c18586c8edc1bddbc15c004fa16aeb1e1342b4fb F src/wal.c 753995db83247f20361a8e8a874990b21a75abd9 F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4 @@ -1251,7 +1251,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 2cb37b959c66b5ae3535ab81ba14a4ebf9732df7 -R e2cf191d4292c134d8577e2e34e33df7 +P e73ac0cbac257d2d2b28e51423e30d7449b6c7b5 +R 70d28450bd13a75aeed954614a2f2b46 U drh -Z 7931b9be35191227870d2d70e1da695e +Z 2b960b7774bbbdaf4d5bf53bdfe32951 diff --git a/manifest.uuid b/manifest.uuid index aa056fdc0a..a3ebe5f013 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -e73ac0cbac257d2d2b28e51423e30d7449b6c7b5 \ No newline at end of file +c83052e48bbae0f45db2a44155b4e5482ee4a901 \ No newline at end of file diff --git a/src/vtab.c b/src/vtab.c index ad65cdf7f4..2c6d106794 100644 --- a/src/vtab.c +++ b/src/vtab.c @@ -472,7 +472,7 @@ void sqlite3VtabArgExtend(Parse *pParse, Token *p){ pArg->z = p->z; pArg->n = p->n; }else{ - assert(pArg->z < p->z); + assert(pArg->z <= p->z); pArg->n = (int)(&p->z[p->n] - pArg->z); } } From f659cf48e848cbb7946815a2ec65e3eb622355ae Mon Sep 17 00:00:00 2001 From: mistachkin Date: Sun, 19 Apr 2015 23:39:05 +0000 Subject: [PATCH 163/181] Modify the 'mkvsix' tool itself to support the Visual Studio 2015 CTP. FossilOrigin-Name: e0b7a191f3c22d9eacf645c58be59e0fdcb8860d --- manifest | 12 ++++++------ manifest.uuid | 2 +- tool/mkvsix.tcl | 52 ++++++++++++++++++++++++++++++++++++++++++++----- 3 files changed, 54 insertions(+), 12 deletions(-) diff --git a/manifest b/manifest index a250a05f62..dbfe67b412 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sharmless\scompiler\swarnings\sseen\swith\sMSVC\s2015. -D 2015-04-19T21:43:16.561 +C Modify\sthe\s'mkvsix'\stool\sitself\sto\ssupport\sthe\sVisual\sStudio\s2015\sCTP. +D 2015-04-19T23:39:05.488 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in faaf75b89840659d74501bea269c7e33414761c1 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -1219,7 +1219,7 @@ F tool/mksqlite3c-noext.tcl 69bae8ce4aa52d2ff82d4a8a856bf283ec035b2e F tool/mksqlite3c.tcl 52a3352f7aa15f1db851e45ac3a5e2173d6fe93c F tool/mksqlite3h.tcl 44730d586c9031638cdd2eb443b801c0d2dbd9f8 F tool/mksqlite3internalh.tcl eb994013e833359137eb53a55acdad0b5ae1049b -F tool/mkvsix.tcl 52a4c613707ac34ae9c226e5ccc69cb948556105 +F tool/mkvsix.tcl 3b58b9398f91c7dbf18d49eb87cefeee9efdbce1 F tool/offsets.c fe4262fdfa378e8f5499a42136d17bf3b98f6091 F tool/omittest.tcl 34d7ac01fe4fd18e3637f64abe12c40eca0f6b97 F tool/opcodeDoc.awk b3a2a3d5d3075b8bd90b7afe24283efdd586659c @@ -1251,7 +1251,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 977fd39c1509edec2e28cc8bac64e0994699f398 -R 482b18ff9d203ff55695e8f455ac3925 +P d05becd873a03a366843a34e7f4c732dd8f88c86 +R bb1f1e19d70e43199cc9b8784e79ff68 U mistachkin -Z 1e735d37890a7ca485ccb54b168d7937 +Z 8dda7ece1b23ed740b28f121d2c5d713 diff --git a/manifest.uuid b/manifest.uuid index ab4a139b2c..19e522ec1e 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -d05becd873a03a366843a34e7f4c732dd8f88c86 \ No newline at end of file +e0b7a191f3c22d9eacf645c58be59e0fdcb8860d \ No newline at end of file diff --git a/tool/mkvsix.tcl b/tool/mkvsix.tcl index 208ce2b142..15ae2b0d3a 100644 --- a/tool/mkvsix.tcl +++ b/tool/mkvsix.tcl @@ -174,6 +174,9 @@ proc writeFile { fileName data } { return "" } +# +# TODO: Modify this procedure when a new version of Visual Studio is released. +# proc getMinVsVersionXmlChunk { vsVersion } { switch -exact $vsVersion { 2012 { @@ -184,17 +187,26 @@ proc getMinVsVersionXmlChunk { vsVersion } { return [appendArgs \ "\r\n " {MinVSVersion="12.0"}] } + 2015 { + return [appendArgs \ + "\r\n " {MinVSVersion="14.0"}] + } default { return "" } } } +# +# TODO: Modify this procedure when a new version of Visual Studio is released. +# proc getMaxPlatformVersionXmlChunk { packageFlavor vsVersion } { # - # NOTE: Only Visual Studio 2013 supports this SDK manifest attribute. + # NOTE: Only Visual Studio 2013 and later support this attribute within the + # SDK manifest. # - if {![string equal $vsVersion 2013]} then { + if {![string equal $vsVersion 2013] && \ + ![string equal $vsVersion 2015]} then { return "" } @@ -221,6 +233,9 @@ proc getMaxPlatformVersionXmlChunk { packageFlavor vsVersion } { } } +# +# TODO: Modify this procedure when a new version of Visual Studio is released. +# proc getExtraFileListXmlChunk { packageFlavor vsVersion } { # # NOTE: Windows Phone 8.0 does not require any extra attributes in its VSIX @@ -245,6 +260,14 @@ proc getExtraFileListXmlChunk { packageFlavor vsVersion } { "\r\n " AppliesTo=\" $appliesTo \" \ "\r\n " {DependsOn="Microsoft.VCLibs, version=12.0"}] } + 2015 { + # + # TODO: Is the ".AppLocal" suffix always needed here? + # + return [appendArgs \ + "\r\n " AppliesTo=\" $appliesTo \" \ + "\r\n " {DependsOn="Microsoft.VCLibs.AppLocal, version=14.0"}] + } default { return "" } @@ -354,10 +377,11 @@ if {[string length $vsVersion] == 0} then { fail "invalid Visual Studio version" } -if {![string equal $vsVersion 2012] && ![string equal $vsVersion 2013]} then { +if {![string equal $vsVersion 2012] && ![string equal $vsVersion 2013] && \ + ![string equal $vsVersion 2015]} then { fail [appendArgs \ "unsupported Visual Studio version, must be one of: " \ - [list 2012 2013]] + [list 2012 2013 2015]] } set shortNames(WinRT,2012) SQLite.WinRT @@ -368,6 +392,7 @@ set shortNames(WP80,2013) SQLite.WP80.2013 set shortNames(WP81,2013) SQLite.WP81 set shortNames(Win32,2012) SQLite.Win32 set shortNames(Win32,2013) SQLite.Win32.2013 +set shortNames(UAP,2015) SQLite.UAP.2015 set displayNames(WinRT,2012) "SQLite for Windows Runtime" set displayNames(WinRT,2013) "SQLite for Windows Runtime" @@ -377,6 +402,7 @@ set displayNames(WP80,2013) "SQLite for Windows Phone" set displayNames(WP81,2013) "SQLite for Windows Phone 8.1" set displayNames(Win32,2012) "SQLite for Windows" set displayNames(Win32,2013) "SQLite for Windows" +set displayNames(UAP,2015) "SQLite for Universal App Platform" if {[string equal $packageFlavor WinRT]} then { set shortName $shortNames($packageFlavor,$vsVersion) @@ -432,6 +458,22 @@ if {[string equal $packageFlavor WinRT]} then { set extraSdkPath "\\..\\$targetPlatformIdentifier" set extraFileListAttributes \ [getExtraFileListXmlChunk $packageFlavor $vsVersion] +} elseif {[string equal $packageFlavor UAP]} then { + if {$vsVersion ne "2015"} then { + fail [appendArgs \ + "unsupported combination, package flavor " $packageFlavor \ + " is only supported with Visual Studio 2015"] + } + set shortName $shortNames($packageFlavor,$vsVersion) + set displayName $displayNames($packageFlavor,$vsVersion) + set targetPlatformIdentifier UAP + set targetPlatformVersion v0.8.0.0 + set minVsVersion [getMinVsVersionXmlChunk $vsVersion] + set maxPlatformVersion \ + [getMaxPlatformVersionXmlChunk $packageFlavor $vsVersion] + set extraSdkPath "\\..\\$targetPlatformIdentifier" + set extraFileListAttributes \ + [getExtraFileListXmlChunk $packageFlavor $vsVersion] } elseif {[string equal $packageFlavor Win32]} then { set shortName $shortNames($packageFlavor,$vsVersion) set displayName $displayNames($packageFlavor,$vsVersion) @@ -446,7 +488,7 @@ if {[string equal $packageFlavor WinRT]} then { } else { fail [appendArgs \ "unsupported package flavor, must be one of: " \ - [list WinRT WinRT81 WP80 WP81 Win32]] + [list WinRT WinRT81 WP80 WP81 UAP Win32]] } ############################################################################### From 19b887e4ecce4bbcc0b175337712121b6deb15da Mon Sep 17 00:00:00 2001 From: mistachkin Date: Sun, 19 Apr 2015 23:48:10 +0000 Subject: [PATCH 164/181] Fix another harmless compiler warning. FossilOrigin-Name: 5ae853aaebaee76c9265061984185f74c10c4c8b --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/where.c | 1 - 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index d47bc01416..911f609b4e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Merge\supdates\sfrom\strunk. -D 2015-04-19T23:40:55.108 +C Fix\sanother\sharmless\scompiler\swarning. +D 2015-04-19T23:48:10.023 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in faaf75b89840659d74501bea269c7e33414761c1 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -307,7 +307,7 @@ F src/vxworks.h c18586c8edc1bddbc15c004fa16aeb1e1342b4fb F src/wal.c 753995db83247f20361a8e8a874990b21a75abd9 F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4 F src/walker.c c253b95b4ee44b21c406e2a1052636c31ea27804 -F src/where.c 8ba8ff31dc9bf1b69fe771d35d8764d5a1efd310 +F src/where.c 723b4f614cd60b7198f5f1cc053362f8a28b0bed F src/whereInt.h cbe4aa57326998d89e7698ca65bb7c28541d483c F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2 @@ -1251,7 +1251,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 e0b7a191f3c22d9eacf645c58be59e0fdcb8860d c83052e48bbae0f45db2a44155b4e5482ee4a901 -R 82b5a61054e21833b8d835777835ac1a +P 59d1a3bb6050a812c4eb0d25ac53327081b9efed +R c62ac4459285512471f07359006f6839 U mistachkin -Z eb6e9bb0494d4ea430c53bed9c33a7ce +Z 8e5b7cac312056ae4f94ac4a6cc605a8 diff --git a/manifest.uuid b/manifest.uuid index 74e4f4e1c0..f36e0dbd24 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -59d1a3bb6050a812c4eb0d25ac53327081b9efed \ No newline at end of file +5ae853aaebaee76c9265061984185f74c10c4c8b \ No newline at end of file diff --git a/src/where.c b/src/where.c index 3467a68626..1b97ebf98f 100644 --- a/src/where.c +++ b/src/where.c @@ -6646,7 +6646,6 @@ WhereInfo *sqlite3WhereBegin( } #ifdef WHERETRACE_ENABLED /* !=0 */ if( sqlite3WhereTrace ){ - int ii; sqlite3DebugPrintf("---- Solution nRow=%d", pWInfo->nRowOut); if( pWInfo->nOBSat>0 ){ sqlite3DebugPrintf(" ORDERBY=%d,0x%llx", pWInfo->nOBSat, pWInfo->revMask); From b496a8f547853a12c02d16cd4cfb100a3ee5ba70 Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 20 Apr 2015 01:13:33 +0000 Subject: [PATCH 165/181] Add an ALWAYS() around a new branch that was made unreachable by an even newer change. FossilOrigin-Name: 592c010478fba7410424f011a62e019c826f1ac3 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/expr.c | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 340322d8fa..98ea026575 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\san\soff-by-one\sassert()\sin\sthe\svirtual\stable\sargument\stokenizer. -D 2015-04-19T23:11:10.399 +C Add\san\sALWAYS()\saround\sa\snew\sbranch\sthat\swas\smade\sunreachable\sby\san\seven\nnewer\schange. +D 2015-04-20T01:13:33.830 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in faaf75b89840659d74501bea269c7e33414761c1 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -182,7 +182,7 @@ F src/complete.c a5cf5b4b56390cfb7b8636e8f7ddef90258dd575 F src/ctime.c 98f89724adc891a1a4c655bee04e33e716e05887 F src/date.c e4d50b3283696836ec1036b695ead9a19e37a5ac F src/delete.c 37964e6c1d73ff49cbea9ff690c9605fb15f600e -F src/expr.c 25a732f30ba391dfb00bbdc9ec079056c2fbced5 +F src/expr.c 5555f768c05d7d4a7840c6c2e72ad7aecbe0fe54 F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb F src/fkey.c 3343d551a8d810782257244fb33f2ce191493c39 F src/func.c 1414c24c873c48796ad45942257a179a423ba42f @@ -1251,7 +1251,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 e73ac0cbac257d2d2b28e51423e30d7449b6c7b5 -R 70d28450bd13a75aeed954614a2f2b46 +P c83052e48bbae0f45db2a44155b4e5482ee4a901 +R 952a9e0aae8c56d03933920a47e90909 U drh -Z 2b960b7774bbbdaf4d5bf53bdfe32951 +Z b000b63de0ad5ddbe40a2bc087fe2878 diff --git a/manifest.uuid b/manifest.uuid index a3ebe5f013..0e878dee1e 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c83052e48bbae0f45db2a44155b4e5482ee4a901 \ No newline at end of file +592c010478fba7410424f011a62e019c826f1ac3 \ No newline at end of file diff --git a/src/expr.c b/src/expr.c index 660fbff7b6..3f8bd942ef 100644 --- a/src/expr.c +++ b/src/expr.c @@ -1252,7 +1252,7 @@ u32 sqlite3ExprListFlags(const ExprList *pList){ if( pList ){ for(i=0; inExpr; i++){ Expr *pExpr = pList->a[i].pExpr; - if( pExpr ) m |= pList->a[i].pExpr->flags; + if( ALWAYS(pExpr) ) m |= pList->a[i].pExpr->flags; } } return m; From f34e9aabd8af209fa849eea0141ba9e0302e4a93 Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 20 Apr 2015 12:50:13 +0000 Subject: [PATCH 166/181] Enhance fuzzershell to support multiple blocks of SQL, each run in its own private in-memory database. FossilOrigin-Name: ab0a96ca73cfe92d5a837c71c148e8361f42acc3 --- manifest | 12 ++--- manifest.uuid | 2 +- tool/fuzzershell.c | 122 ++++++++++++++++++++++++++++++++------------- 3 files changed, 95 insertions(+), 41 deletions(-) diff --git a/manifest b/manifest index 98ea026575..6d6a24c20d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\san\sALWAYS()\saround\sa\snew\sbranch\sthat\swas\smade\sunreachable\sby\san\seven\nnewer\schange. -D 2015-04-20T01:13:33.830 +C Enhance\sfuzzershell\sto\ssupport\smultiple\sblocks\sof\sSQL,\seach\srun\sin\sits\sown\nprivate\sin-memory\sdatabase. +D 2015-04-20T12:50:13.942 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in faaf75b89840659d74501bea269c7e33414761c1 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -1203,7 +1203,7 @@ F tool/diffdb.c 7524b1b5df217c20cd0431f6789851a4e0cb191b F tool/extract.c 054069d81b095fbdc189a6f5d4466e40380505e2 F tool/fast_vacuum.c 5ba0d6f5963a0a63bdc42840f678bad75b2ebce1 F tool/fragck.tcl 5265a95126abcf6ab357f7efa544787e5963f439 -F tool/fuzzershell.c 9e7e273da203037154b433bb67f10b0d9772b370 +F tool/fuzzershell.c d6f9206395645668499aa5b097cbcda5ef67d457 F tool/genfkey.README cf68fddd4643bbe3ff8e31b8b6d8b0a1b85e20f4 F tool/genfkey.test 4196a8928b78f51d54ef58e99e99401ab2f0a7e5 F tool/getlock.c f4c39b651370156cae979501a7b156bdba50e7ce @@ -1251,7 +1251,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 c83052e48bbae0f45db2a44155b4e5482ee4a901 -R 952a9e0aae8c56d03933920a47e90909 +P 592c010478fba7410424f011a62e019c826f1ac3 +R 55f62d08aa055d79c5fb00626b830397 U drh -Z b000b63de0ad5ddbe40a2bc087fe2878 +Z 4938f7ca9f322011187311f0d5e05712 diff --git a/manifest.uuid b/manifest.uuid index 0e878dee1e..2ad27925f2 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -592c010478fba7410424f011a62e019c826f1ac3 \ No newline at end of file +ab0a96ca73cfe92d5a837c71c148e8361f42acc3 \ No newline at end of file diff --git a/tool/fuzzershell.c b/tool/fuzzershell.c index a44a722505..6f841e220c 100644 --- a/tool/fuzzershell.c +++ b/tool/fuzzershell.c @@ -31,6 +31,29 @@ ** ** (4) The eval() SQL function is added, allowing the fuzzer to do ** interesting recursive operations. +** +** 2015-04-20: The input text can be divided into separate SQL chunks using +** lines of the form: +** +** |****<...>****| +** +** where the "..." is arbitrary text, except the "|" should really be "/". +** ("|" is used here to avoid compiler warnings about nested comments.) +** Each such SQL comment is printed as it is encountered. A separate +** in-memory SQLite database is created to run each chunk of SQL. This +** feature allows the "queue" of AFL to be captured into a single big +** file using a command like this: +** +** (for i in id:*; do echo '|****<'$i'>****|'; cat $i; done) >~/all-queue.txt +** +** (Once again, change the "|" to "/") Then all elements of the AFL queue +** can be run in a single go (for regression testing, for example, by typing: +** +** fuzzershell -f ~/all-queue.txt >out.txt +** +** After running each chunk of SQL, the database connection is closed. The +** program aborts if the close fails or if there is any unfreed memory after +** the close. */ #include #include @@ -218,8 +241,9 @@ int main(int argc, char **argv){ FILE *in = stdin; /* Where to read SQL text from */ int rc = SQLITE_OK; /* Result codes from API functions */ int i; /* Loop counter */ + int iNext; /* Next block of SQL */ sqlite3 *db; /* Open database */ - sqlite3 *dbInit; /* On-disk database used to initialize the in-memory db */ + sqlite3 *dbInit = 0; /* On-disk database used to initialize the in-memory db */ const char *zInitDb = 0;/* Name of the initialization database file */ char *zErrMsg = 0; /* Error message returned from sqlite3_exec() */ @@ -250,45 +274,75 @@ int main(int argc, char **argv){ } } sqlite3_config(SQLITE_CONFIG_LOG, shellLog, 0); - rc = sqlite3_open_v2( - "main.db", &db, - SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_MEMORY, - 0); - if( rc!=SQLITE_OK ){ - abendError("Unable to open the in-memory database"); - } - if( zInitDb ){ - sqlite3_backup *pBackup; - rc = sqlite3_open_v2(zInitDb, &dbInit, SQLITE_OPEN_READONLY, 0); - if( rc!=SQLITE_OK ){ - abendError("unable to open initialization database \"%s\"", zInitDb); - } - pBackup = sqlite3_backup_init(db, "main", dbInit, "main"); - rc = sqlite3_backup_step(pBackup, -1); - if( rc!=SQLITE_DONE ){ - abendError("attempt to initialize the in-memory database failed (rc=%d)",rc); - } - sqlite3_backup_finish(pBackup); - sqlite3_close(dbInit); - } - sqlite3_trace(db, traceCallback, 0); - sqlite3_create_function(db, "eval", 1, SQLITE_UTF8, 0, sqlEvalFunc, 0, 0); - sqlite3_create_function(db, "eval", 2, SQLITE_UTF8, 0, sqlEvalFunc, 0, 0); while( !feof(in) ){ - nAlloc += 1000; - zIn = sqlite3_realloc(zIn, nAlloc); + nAlloc += nAlloc+1000; + zIn = realloc(zIn, nAlloc); if( zIn==0 ) fatalError("out of memory"); got = fread(zIn+nIn, 1, nAlloc-nIn-1, in); nIn += (int)got; zIn[nIn] = 0; if( got==0 ) break; } - printf("INPUT (%d bytes): [%s]\n", nIn, zIn); - rc = sqlite3_exec(db, zIn, execCallback, 0, &zErrMsg); - printf("RESULT-CODE: %d\n", rc); - if( zErrMsg ){ - printf("ERROR-MSG: [%s]\n", zErrMsg); - sqlite3_free(zErrMsg); + if( zInitDb ){ + rc = sqlite3_open_v2(zInitDb, &dbInit, SQLITE_OPEN_READONLY, 0); + if( rc!=SQLITE_OK ){ + abendError("unable to open initialization database \"%s\"", zInitDb); + } } - return rc!=SQLITE_OK; + for(i=0; i****/"); + if( z ){ + z += 6; + printf("%.*s\n", (int)(z-&zIn[i]), &zIn[i]); + i += (int)(z-&zIn[i]); + } + } + for(iNext=i; iNext0 ){ + abendError("memory in use after close: %lld bytes", sqlite3_memory_used()); + } + } + free(zIn); + return 0; } From cef258433592d83aff6441338fbcf3d52a121fc2 Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 20 Apr 2015 13:59:18 +0000 Subject: [PATCH 167/181] Fix an obscure memory leak in sqlite3Stat4ProbeFree() FossilOrigin-Name: c72abbe2c1735f3d563c6672616b2918b6209922 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/vdbemem.c | 2 +- test/analyze3.test | 13 +++++++++++++ 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 6d6a24c20d..e5d22be389 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Enhance\sfuzzershell\sto\ssupport\smultiple\sblocks\sof\sSQL,\seach\srun\sin\sits\sown\nprivate\sin-memory\sdatabase. -D 2015-04-20T12:50:13.942 +C Fix\san\sobscure\smemory\sleak\sin\ssqlite3Stat4ProbeFree() +D 2015-04-20T13:59:18.103 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in faaf75b89840659d74501bea269c7e33414761c1 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -299,7 +299,7 @@ F src/vdbeInt.h 9cbaa84f53ddd2d09a0cf61a94337a3a035d08a0 F src/vdbeapi.c 583d56b129dd27f12bed518270de9ebe521e6a75 F src/vdbeaux.c 03591cca98ec50e1493043f0ff7abbece0b9c83d F src/vdbeblob.c 4f2e8e075d238392df98c5e03a64342465b03f90 -F src/vdbemem.c c0dc81285b7571b0a31c40f17846fe2397ec1cd9 +F src/vdbemem.c b5256445b318b0f2b3bc429028469cfbb08f19a5 F src/vdbesort.c 2e7f683464fd5db3be4beaa1ff2d39e24fcb64b8 F src/vdbetrace.c f95c2dff9041fcf07f871789c22ebb0648ea0b7c F src/vtab.c 5f81f8a59c1f5ddb94c918f25ed5d83578fcc633 @@ -321,7 +321,7 @@ F test/alter4.test c461150723ac957f3b2214aa0b11552cd72023ec F test/altermalloc.test e81ac9657ed25c6c5bb09bebfa5a047cd8e4acfc F test/amatch1.test b5ae7065f042b7f4c1c922933f4700add50cdb9f F test/analyze.test 3eb35a4af972f98422e5dc0586501b17d103d321 -F test/analyze3.test 75b9e42ea1e4edc919250450dc5762186965d4e6 +F test/analyze3.test c2c07285e1012315e561132fcfa8fd43be66ec8c F test/analyze4.test eff2df19b8dd84529966420f29ea52edc6b56213 F test/analyze5.test 765c4e284aa69ca172772aa940946f55629bc8c4 F test/analyze6.test f1c552ce39cca4ec922a7e4e0e5d0203d6b3281f @@ -1251,7 +1251,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 592c010478fba7410424f011a62e019c826f1ac3 -R 55f62d08aa055d79c5fb00626b830397 +P ab0a96ca73cfe92d5a837c71c148e8361f42acc3 +R 3caac82026514fa2d10894c0463eb30d U drh -Z 4938f7ca9f322011187311f0d5e05712 +Z 942c4169ecb37cfefc1570a95881cae9 diff --git a/manifest.uuid b/manifest.uuid index 2ad27925f2..07bc7a50d8 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ab0a96ca73cfe92d5a837c71c148e8361f42acc3 \ No newline at end of file +c72abbe2c1735f3d563c6672616b2918b6209922 \ No newline at end of file diff --git a/src/vdbemem.c b/src/vdbemem.c index 76147442ab..7c9a2d919b 100644 --- a/src/vdbemem.c +++ b/src/vdbemem.c @@ -1647,7 +1647,7 @@ void sqlite3Stat4ProbeFree(UnpackedRecord *pRec){ Mem *aMem = pRec->aMem; sqlite3 *db = aMem[0].db; for(i=0; ipKeyInfo); sqlite3DbFree(db, pRec); diff --git a/test/analyze3.test b/test/analyze3.test index d22387dcc3..75a2cc4f7e 100644 --- a/test/analyze3.test +++ b/test/analyze3.test @@ -662,4 +662,17 @@ do_eqp_test analyze3-6-2 { SELECT * FROM t1 WHERE a = 5 AND b > 'w' AND c = 13; } {0 0 0 {SEARCH TABLE t1 USING INDEX i2 (c=?)}} +#----------------------------------------------------------------------------- +# 2015-04-20. +# Memory leak in sqlite3Stat4ProbeFree(). (Discovered while fuzzing.) +# +do_execsql_test analyze-7.1 { + DROP TABLE IF EXISTS t1; + CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c); + INSERT INTO t1 VALUES(1,1,'0000'); + CREATE INDEX t0b ON t1(b); + ANALYZE; + SELECT c FROM t1 WHERE b=3 AND a BETWEEN 30 AND hex(1); +} {} + finish_test From 4eed05347c7ab6444c95e805c117e5aafac8aa76 Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 20 Apr 2015 15:13:08 +0000 Subject: [PATCH 168/181] Fix a memory leak caused by duplicate entries in the sqlite_stat1 table. FossilOrigin-Name: 2f58c8c9722fffc486610f9e6b08178d53a56b64 --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/analyze.c | 15 +++++++++------ test/analyze3.test | 17 +++++++++++++++++ 4 files changed, 35 insertions(+), 15 deletions(-) diff --git a/manifest b/manifest index e5d22be389..985903506a 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\san\sobscure\smemory\sleak\sin\ssqlite3Stat4ProbeFree() -D 2015-04-20T13:59:18.103 +C Fix\sa\smemory\sleak\scaused\sby\sduplicate\sentries\sin\sthe\ssqlite_stat1\stable. +D 2015-04-20T15:13:08.018 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in faaf75b89840659d74501bea269c7e33414761c1 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -167,7 +167,7 @@ F sqlite.pc.in 42b7bf0d02e08b9e77734a47798d1a55a9e0716b F sqlite3.1 fc7ad8990fc8409983309bb80de8c811a7506786 F sqlite3.pc.in 48fed132e7cb71ab676105d2a4dc77127d8c1f3a F src/alter.c d23d6b6991f66b383934f137fd4384d93fb98c81 -F src/analyze.c 91540f835163d5369ccbae78e2e6c74d0dd53c1d +F src/analyze.c d23790787f80ebed58df7774744b4cf96401498b F src/attach.c c38ac5a520a231d5d0308fd7f2ad95191c867bae F src/auth.c b56c78ebe40a2110fd361379f7e8162d23f92240 F src/backup.c ff743689c4d6c5cb55ad42ed9d174b2b3e71f1e3 @@ -321,7 +321,7 @@ F test/alter4.test c461150723ac957f3b2214aa0b11552cd72023ec F test/altermalloc.test e81ac9657ed25c6c5bb09bebfa5a047cd8e4acfc F test/amatch1.test b5ae7065f042b7f4c1c922933f4700add50cdb9f F test/analyze.test 3eb35a4af972f98422e5dc0586501b17d103d321 -F test/analyze3.test c2c07285e1012315e561132fcfa8fd43be66ec8c +F test/analyze3.test 0f0ee6135b293a0e5af471a8423b80b688469d71 F test/analyze4.test eff2df19b8dd84529966420f29ea52edc6b56213 F test/analyze5.test 765c4e284aa69ca172772aa940946f55629bc8c4 F test/analyze6.test f1c552ce39cca4ec922a7e4e0e5d0203d6b3281f @@ -1251,7 +1251,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 ab0a96ca73cfe92d5a837c71c148e8361f42acc3 -R 3caac82026514fa2d10894c0463eb30d -U drh -Z 942c4169ecb37cfefc1570a95881cae9 +P c72abbe2c1735f3d563c6672616b2918b6209922 +R 1099b0a7b8aeb7ed253f854d69b78f1d +U dan +Z 6ab446cc76a19cef515e242940078110 diff --git a/manifest.uuid b/manifest.uuid index 07bc7a50d8..0affbc1e57 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c72abbe2c1735f3d563c6672616b2918b6209922 \ No newline at end of file +2f58c8c9722fffc486610f9e6b08178d53a56b64 \ No newline at end of file diff --git a/src/analyze.c b/src/analyze.c index fec2bdb39d..2a0d6d2fb7 100644 --- a/src/analyze.c +++ b/src/analyze.c @@ -1519,14 +1519,17 @@ static int analysisLoader(void *pData, int argc, char **argv, char **NotUsed){ z = argv[2]; if( pIndex ){ + tRowcnt *aiRowEst = 0; int nCol = pIndex->nKeyCol+1; #ifdef SQLITE_ENABLE_STAT3_OR_STAT4 - tRowcnt * const aiRowEst = pIndex->aiRowEst = (tRowcnt*)sqlite3MallocZero( - sizeof(tRowcnt) * nCol - ); - if( aiRowEst==0 ) pInfo->db->mallocFailed = 1; -#else - tRowcnt * const aiRowEst = 0; + /* Index.aiRowEst may already be set here if there are duplicate + ** sqlite_stat1 entries for this index. In that case just clobber + ** the old data with the new instead of allocating a new array. */ + if( pIndex->aiRowEst==0 ){ + pIndex->aiRowEst = (tRowcnt*)sqlite3MallocZero(sizeof(tRowcnt) * nCol); + if( pIndex->aiRowEst==0 ) pInfo->db->mallocFailed = 1; + } + aiRowEst = pIndex->aiRowEst; #endif pIndex->bUnordered = 0; decodeIntArray((char*)z, nCol, aiRowEst, pIndex->aiRowLogEst, pIndex); diff --git a/test/analyze3.test b/test/analyze3.test index 75a2cc4f7e..d61d21a947 100644 --- a/test/analyze3.test +++ b/test/analyze3.test @@ -16,6 +16,7 @@ set testdir [file dirname $argv0] source $testdir/tester.tcl +set testprefix analyze3 ifcapable !stat4&&!stat3 { finish_test @@ -46,6 +47,9 @@ ifcapable !stat4&&!stat3 { # # analyze3-6.*: Test that the problem fixed by commit [127a5b776d] is fixed. # +# analyze3-7.*: Test that some memory leaks discovered by fuzz testing +# have been fixed. +# proc getvar {varname} { uplevel #0 set $varname } db function var getvar @@ -675,4 +679,17 @@ do_execsql_test analyze-7.1 { SELECT c FROM t1 WHERE b=3 AND a BETWEEN 30 AND hex(1); } {} +# At one point duplicate stat1 entries were causing a memory leak. +# +reset_db +do_execsql_test 7.2 { + CREATE TABLE t1(a,b,c); + CREATE INDEX t1a ON t1(a); + ANALYZE; + SELECT * FROM sqlite_stat1; + INSERT INTO sqlite_stat1(tbl,idx,stat) VALUES('t1','t1a','12000'); + INSERT INTO sqlite_stat1(tbl,idx,stat) VALUES('t1','t1a','12000'); + ANALYZE sqlite_master; +} + finish_test From 4a74d076e3d184383a5550a16d0ceebfc37abdcb Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 20 Apr 2015 18:58:38 +0000 Subject: [PATCH 169/181] Many new configuration options for fuzzershell. FossilOrigin-Name: 41c954391690833bf2ece4ea14457ee4bdd74e90 --- manifest | 14 ++-- manifest.uuid | 2 +- tool/fuzzershell.c | 179 +++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 182 insertions(+), 13 deletions(-) diff --git a/manifest b/manifest index 985903506a..53525fbdbb 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\smemory\sleak\scaused\sby\sduplicate\sentries\sin\sthe\ssqlite_stat1\stable. -D 2015-04-20T15:13:08.018 +C Many\snew\sconfiguration\soptions\sfor\sfuzzershell. +D 2015-04-20T18:58:38.348 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in faaf75b89840659d74501bea269c7e33414761c1 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -1203,7 +1203,7 @@ F tool/diffdb.c 7524b1b5df217c20cd0431f6789851a4e0cb191b F tool/extract.c 054069d81b095fbdc189a6f5d4466e40380505e2 F tool/fast_vacuum.c 5ba0d6f5963a0a63bdc42840f678bad75b2ebce1 F tool/fragck.tcl 5265a95126abcf6ab357f7efa544787e5963f439 -F tool/fuzzershell.c d6f9206395645668499aa5b097cbcda5ef67d457 +F tool/fuzzershell.c a25ae00de7ec929723981bc5d0c8c484ea1e6a9c F tool/genfkey.README cf68fddd4643bbe3ff8e31b8b6d8b0a1b85e20f4 F tool/genfkey.test 4196a8928b78f51d54ef58e99e99401ab2f0a7e5 F tool/getlock.c f4c39b651370156cae979501a7b156bdba50e7ce @@ -1251,7 +1251,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 c72abbe2c1735f3d563c6672616b2918b6209922 -R 1099b0a7b8aeb7ed253f854d69b78f1d -U dan -Z 6ab446cc76a19cef515e242940078110 +P 2f58c8c9722fffc486610f9e6b08178d53a56b64 +R 3fade4dfead5d7d8a2c7049fe386ecdf +U drh +Z 1d6c6c4ef178b17fd0f9732ebc91d908 diff --git a/manifest.uuid b/manifest.uuid index 0affbc1e57..564fc7fe47 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -2f58c8c9722fffc486610f9e6b08178d53a56b64 \ No newline at end of file +41c954391690833bf2ece4ea14457ee4bdd74e90 \ No newline at end of file diff --git a/tool/fuzzershell.c b/tool/fuzzershell.c index 6f841e220c..e412e59b38 100644 --- a/tool/fuzzershell.c +++ b/tool/fuzzershell.c @@ -47,7 +47,7 @@ ** (for i in id:*; do echo '|****<'$i'>****|'; cat $i; done) >~/all-queue.txt ** ** (Once again, change the "|" to "/") Then all elements of the AFL queue -** can be run in a single go (for regression testing, for example, by typing: +** can be run in a single go (for regression testing, for example) by typing: ** ** fuzzershell -f ~/all-queue.txt >out.txt ** @@ -59,6 +59,7 @@ #include #include #include +#include #include "sqlite3.h" /* @@ -97,6 +98,22 @@ static void fatalError(const char *zFormat, ...){ exit(1); } +/* +** Evaluate some SQL. Abort if unable. +*/ +static void sqlexec(sqlite3 *db, const char *zFormat, ...){ + va_list ap; + char *zSql; + char *zErrMsg = 0; + int rc; + va_start(ap, zFormat); + zSql = sqlite3_vmprintf(zFormat, ap); + va_end(ap); + rc = sqlite3_exec(db, zSql, 0, 0, &zErrMsg); + if( rc ) abendError("failed sql [%s]: %s", zSql, zErrMsg); + sqlite3_free(zSql); +} + /* ** This callback is invoked by sqlite3_log(). */ @@ -226,12 +243,78 @@ static void showHelp(void){ printf( "Read SQL text from standard input and evaluate it.\n" "Options:\n" +" --autovacuum Enable AUTOVACUUM mode\n" " -f FILE Read SQL text from FILE instead of standard input\n" +" --heap SZ MIN Memory allocator uses SZ bytes & min allocation MIN\n" " --help Show this help text\n" " --initdb DBFILE Initialize the in-memory database using template DBFILE\n" +" --lookaside N SZ Configure lookaside for N slots of SZ bytes each\n" +" --pagesize N Set the page size to N\n" +" --pcache N SZ Configure N pages of pagecache each of size SZ bytes\n" +" --scratch N SZ Configure scratch memory for N slots of SZ bytes each\n" +" --utf16be Set text encoding to UTF-16BE\n" +" --utf16le Set text encoding to UTF-16LE\n" ); } +/* +** Return the value of a hexadecimal digit. Return -1 if the input +** is not a hex digit. +*/ +static int hexDigitValue(char c){ + if( c>='0' && c<='9' ) return c - '0'; + if( c>='a' && c<='f' ) return c - 'a' + 10; + if( c>='A' && c<='F' ) return c - 'A' + 10; + return -1; +} + +/* +** Interpret zArg as an integer value, possibly with suffixes. +*/ +static int integerValue(const char *zArg){ + sqlite3_int64 v = 0; + static const struct { char *zSuffix; int iMult; } aMult[] = { + { "KiB", 1024 }, + { "MiB", 1024*1024 }, + { "GiB", 1024*1024*1024 }, + { "KB", 1000 }, + { "MB", 1000000 }, + { "GB", 1000000000 }, + { "K", 1000 }, + { "M", 1000000 }, + { "G", 1000000000 }, + }; + int i; + int isNeg = 0; + if( zArg[0]=='-' ){ + isNeg = 1; + zArg++; + }else if( zArg[0]=='+' ){ + zArg++; + } + if( zArg[0]=='0' && zArg[1]=='x' ){ + int x; + zArg += 2; + while( (x = hexDigitValue(zArg[0]))>=0 ){ + v = (v<<4) + x; + zArg++; + } + }else{ + while( isdigit(zArg[0]) ){ + v = v*10 + zArg[0] - '0'; + zArg++; + } + } + for(i=0; i0x7fffffff ) abendError("parameter too large - max 2147483648"); + return (int)(isNeg? -v : v); +} + int main(int argc, char **argv){ char *zIn = 0; /* Input text */ @@ -246,6 +329,18 @@ int main(int argc, char **argv){ sqlite3 *dbInit = 0; /* On-disk database used to initialize the in-memory db */ const char *zInitDb = 0;/* Name of the initialization database file */ char *zErrMsg = 0; /* Error message returned from sqlite3_exec() */ + const char *zEncoding = 0; /* --utf16be or --utf16le */ + int nHeap = 0, mnHeap = 0; /* Heap size from --heap */ + int nLook = 0, szLook = 0; /* --lookaside configuration */ + int nPCache = 0, szPCache = 0;/* --pcache configuration */ + int nScratch = 0, szScratch=0;/* --scratch configuration */ + int pageSize = 0; /* Desired page size. 0 means default */ + void *pHeap = 0; /* Allocated heap space */ + void *pLook = 0; /* Allocated lookaside space */ + void *pPCache = 0; /* Allocated storage for pcache */ + void *pScratch = 0; /* Allocated storage for scratch */ + int doAutovac = 0; /* True for --autovacuum */ + g.zArgv0 = argv[0]; for(i=1; i=argc-2 ) abendError("missing arguments on %s\n", argv[i]); + nHeap = integerValue(argv[i+1]); + mnHeap = integerValue(argv[i+2]); + i += 2; + }else + if( strcmp(z,"help")==0 ){ + showHelp(); + return 0; + }else if( strcmp(z, "initdb")==0 && i+1=argc-2 ) abendError("missing arguments on %s", argv[i]); + nLook = integerValue(argv[i+1]); + szLook = integerValue(argv[i+2]); + i += 2; + }else + if( strcmp(z,"pagesize")==0 ){ + if( i>=argc-1 ) abendError("missing argument on %s", argv[i]); + pageSize = integerValue(argv[++i]); + }else + if( strcmp(z,"pcache")==0 ){ + if( i>=argc-2 ) abendError("missing arguments on %s", argv[i]); + nPCache = integerValue(argv[i+1]); + szPCache = integerValue(argv[i+2]); + i += 2; + }else + if( strcmp(z,"scratch")==0 ){ + if( i>=argc-2 ) abendError("missing arguments on %s", argv[i]); + nScratch = integerValue(argv[i+1]); + szScratch = integerValue(argv[i+2]); + i += 2; + }else + if( strcmp(z,"utf16le")==0 ){ + zEncoding = "utf16le"; + }else + if( strcmp(z,"utf16be")==0 ){ + zEncoding = "utf16be"; + }else { abendError("unknown option: %s", argv[i]); } @@ -274,6 +406,33 @@ int main(int argc, char **argv){ } } sqlite3_config(SQLITE_CONFIG_LOG, shellLog, 0); + if( nHeap>0 ){ + pHeap = malloc( nHeap ); + if( pHeap==0 ) fatalError("cannot allocate %d-byte heap\n", nHeap); + rc = sqlite3_config(SQLITE_CONFIG_HEAP, pHeap, nHeap, mnHeap); + if( rc ) abendError("heap configuration failed: %d\n", rc); + } + if( nLook>0 ){ + sqlite3_config(SQLITE_CONFIG_LOOKASIDE, 0, 0); + if( szLook>0 ){ + pLook = malloc( nLook*szLook ); + if( pLook==0 ) fatalError("out of memory"); + } + } + if( nScratch>0 && szScratch>0 ){ + pScratch = malloc( nScratch*(sqlite3_int64)szScratch ); + if( pScratch==0 ) fatalError("cannot allocate %lld-byte scratch", + nScratch*(sqlite3_int64)szScratch); + rc = sqlite3_config(SQLITE_CONFIG_SCRATCH, pScratch, szScratch, nScratch); + if( rc ) abendError("scratch configuration failed: %d\n", rc); + } + if( nPCache>0 && szPCache>0 ){ + pPCache = malloc( nPCache*(sqlite3_int64)szPCache ); + if( pPCache==0 ) fatalError("cannot allocate %lld-byte pcache", + nPCache*(sqlite3_int64)szPCache); + rc = sqlite3_config(SQLITE_CONFIG_PAGECACHE, pPCache, szPCache, nPCache); + if( rc ) abendError("pcache configuration failed: %d", rc); + } while( !feof(in) ){ nAlloc += nAlloc+1000; zIn = realloc(zIn, nAlloc); @@ -308,6 +467,10 @@ int main(int argc, char **argv){ if( rc!=SQLITE_OK ){ abendError("Unable to open the in-memory database"); } + if( pLook ){ + rc = sqlite3_db_config(db, SQLITE_DBCONFIG_LOOKASIDE, pLook, szLook, nLook); + if( rc!=SQLITE_OK ) abendError("lookaside configuration filed: %d", rc); + } if( zInitDb ){ sqlite3_backup *pBackup; pBackup = sqlite3_backup_init(db, "main", dbInit, "main"); @@ -322,7 +485,9 @@ int main(int argc, char **argv){ sqlite3_create_function(db, "eval", 1, SQLITE_UTF8, 0, sqlEvalFunc, 0, 0); sqlite3_create_function(db, "eval", 2, SQLITE_UTF8, 0, sqlEvalFunc, 0, 0); sqlite3_limit(db, SQLITE_LIMIT_LENGTH, 1000000); - + if( zEncoding ) sqlexec(db, "PRAGMA encoding=%s", zEncoding); + if( pageSize ) sqlexec(db, "PRAGMA pagesize=%d", pageSize); + if( doAutovac ) sqlexec(db, "PRAGMA auto_vacuum=FULL"); cSaved = zIn[iNext]; zIn[iNext] = 0; printf("INPUT (offset: %d, size: %d): [%s]\n", @@ -344,5 +509,9 @@ int main(int argc, char **argv){ } } free(zIn); + free(pHeap); + free(pLook); + free(pScratch); + free(pPCache); return 0; } From 9985dabbacc878e7c11c4e3b79aecb43d6ec836c Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 20 Apr 2015 22:36:49 +0000 Subject: [PATCH 170/181] Add the --mode option to fuzzershell. FossilOrigin-Name: b940b0fa6cf68fef58344d269ad5d39468ffe72f --- manifest | 12 ++++++------ manifest.uuid | 2 +- tool/fuzzershell.c | 44 +++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 50 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 53525fbdbb..68707be4d4 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Many\snew\sconfiguration\soptions\sfor\sfuzzershell. -D 2015-04-20T18:58:38.348 +C Add\sthe\s--mode\soption\sto\sfuzzershell. +D 2015-04-20T22:36:49.631 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in faaf75b89840659d74501bea269c7e33414761c1 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -1203,7 +1203,7 @@ F tool/diffdb.c 7524b1b5df217c20cd0431f6789851a4e0cb191b F tool/extract.c 054069d81b095fbdc189a6f5d4466e40380505e2 F tool/fast_vacuum.c 5ba0d6f5963a0a63bdc42840f678bad75b2ebce1 F tool/fragck.tcl 5265a95126abcf6ab357f7efa544787e5963f439 -F tool/fuzzershell.c a25ae00de7ec929723981bc5d0c8c484ea1e6a9c +F tool/fuzzershell.c 00c12b1e95095f43980ae3cafb51938eda577fe2 F tool/genfkey.README cf68fddd4643bbe3ff8e31b8b6d8b0a1b85e20f4 F tool/genfkey.test 4196a8928b78f51d54ef58e99e99401ab2f0a7e5 F tool/getlock.c f4c39b651370156cae979501a7b156bdba50e7ce @@ -1251,7 +1251,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 2f58c8c9722fffc486610f9e6b08178d53a56b64 -R 3fade4dfead5d7d8a2c7049fe386ecdf +P 41c954391690833bf2ece4ea14457ee4bdd74e90 +R 18124f1b8c247e9f547c30e618d3a441 U drh -Z 1d6c6c4ef178b17fd0f9732ebc91d908 +Z d312afa4cd0d932d0a233db0b53736ad diff --git a/manifest.uuid b/manifest.uuid index 564fc7fe47..dfe61ad96a 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -41c954391690833bf2ece4ea14457ee4bdd74e90 \ No newline at end of file +b940b0fa6cf68fef58344d269ad5d39468ffe72f \ No newline at end of file diff --git a/tool/fuzzershell.c b/tool/fuzzershell.c index e412e59b38..abdfd3ff00 100644 --- a/tool/fuzzershell.c +++ b/tool/fuzzershell.c @@ -315,6 +315,14 @@ static int integerValue(const char *zArg){ return (int)(isNeg? -v : v); } +/* +** Various operating modes +*/ +#define FZMODE_Generic 1 +#define FZMODE_Strftime 2 +#define FZMODE_Printf 3 +#define FZMODE_Glob 4 + int main(int argc, char **argv){ char *zIn = 0; /* Input text */ @@ -340,6 +348,9 @@ int main(int argc, char **argv){ void *pPCache = 0; /* Allocated storage for pcache */ void *pScratch = 0; /* Allocated storage for scratch */ int doAutovac = 0; /* True for --autovacuum */ + char *zSql; /* SQL to run */ + char *zToFree = 0; /* Call sqlite3_free() on this afte running zSql */ + int iMode = FZMODE_Generic; /* Operating mode */ g.zArgv0 = argv[0]; @@ -376,6 +387,21 @@ int main(int argc, char **argv){ szLook = integerValue(argv[i+2]); i += 2; }else + if( strcmp(z,"mode")==0 ){ + if( i>=argc-1 ) abendError("missing argument on %s", argv[i]); + z = argv[++i]; + if( strcmp(z,"generic")==0 ){ + iMode = FZMODE_Printf; + }else if( strcmp(z, "glob")==0 ){ + iMode = FZMODE_Glob; + }else if( strcmp(z, "printf")==0 ){ + iMode = FZMODE_Printf; + }else if( strcmp(z, "strftime")==0 ){ + iMode = FZMODE_Strftime; + }else{ + abendError("unknown --mode: %s", z); + } + }else if( strcmp(z,"pagesize")==0 ){ if( i>=argc-1 ) abendError("missing argument on %s", argv[i]); pageSize = integerValue(argv[++i]); @@ -492,7 +518,23 @@ int main(int argc, char **argv){ zIn[iNext] = 0; printf("INPUT (offset: %d, size: %d): [%s]\n", i, (int)strlen(&zIn[i]), &zIn[i]); - rc = sqlite3_exec(db, &zIn[i], execCallback, 0, &zErrMsg); + zSql = &zIn[i]; + switch( iMode ){ + case FZMODE_Glob: + zSql = zToFree = sqlite3_mprintf("SELECT glob(%s);", zSql); + break; + case FZMODE_Printf: + zSql = zToFree = sqlite3_mprintf("SELECT printf(%s);", zSql); + break; + case FZMODE_Strftime: + zSql = zToFree = sqlite3_mprintf("SELECT strftime(%s);", zSql); + break; + } + rc = sqlite3_exec(db, zSql, execCallback, 0, &zErrMsg); + if( zToFree ){ + sqlite3_free(zToFree); + zToFree = 0; + } zIn[iNext] = cSaved; printf("RESULT-CODE: %d\n", rc); From 0f517ea8d4400858233e1c8c2368eaa22661771e Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 21 Apr 2015 02:12:13 +0000 Subject: [PATCH 171/181] Make sure the whereSplit() routine in the query planner is not confused by the likely() operator. FossilOrigin-Name: 588db14ffb4b0e8e76d511b7b1541db3ec78836a --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/where.c | 9 +++++---- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/manifest b/manifest index c16ea75772..722a49165b 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Enable\scompilation\sand\sVSIX\spackage\screation\swith\sthe\sVisual\sStudio\s2015\sCTP. -D 2015-04-21T00:23:38.259 +C Make\ssure\sthe\swhereSplit()\sroutine\sin\sthe\squery\splanner\sis\snot\sconfused\nby\sthe\slikely()\soperator. +D 2015-04-21T02:12:13.667 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in faaf75b89840659d74501bea269c7e33414761c1 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -307,7 +307,7 @@ F src/vxworks.h c18586c8edc1bddbc15c004fa16aeb1e1342b4fb F src/wal.c 753995db83247f20361a8e8a874990b21a75abd9 F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4 F src/walker.c c253b95b4ee44b21c406e2a1052636c31ea27804 -F src/where.c 723b4f614cd60b7198f5f1cc053362f8a28b0bed +F src/where.c 32fe265e3dc74ef3b27deb9e6eb5fc3c71409612 F src/whereInt.h cbe4aa57326998d89e7698ca65bb7c28541d483c F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2 @@ -1251,7 +1251,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 b940b0fa6cf68fef58344d269ad5d39468ffe72f 5ae853aaebaee76c9265061984185f74c10c4c8b -R 9804529a8e22c5281a0b002dbd15342c -U mistachkin -Z 2ec7897fcafe697e2540c7ecf3cbf657 +P 03b725a768290e3c7b31f1ba3310532fd7dc05cd +R 1a86c7004bf5b29df45cd677c642d5c4 +U drh +Z 973efc28f5c5e0de1e0d5148069074b3 diff --git a/manifest.uuid b/manifest.uuid index 39b81f4f27..e1164a819a 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -03b725a768290e3c7b31f1ba3310532fd7dc05cd \ No newline at end of file +588db14ffb4b0e8e76d511b7b1541db3ec78836a \ No newline at end of file diff --git a/src/where.c b/src/where.c index 1b97ebf98f..25d20c8808 100644 --- a/src/where.c +++ b/src/where.c @@ -255,13 +255,14 @@ static int whereClauseInsert(WhereClause *pWC, Expr *p, u16 wtFlags){ ** all terms of the WHERE clause. */ static void whereSplit(WhereClause *pWC, Expr *pExpr, u8 op){ + Expr *pE2 = sqlite3ExprSkipCollate(pExpr); pWC->op = op; - if( pExpr==0 ) return; - if( pExpr->op!=op ){ + if( pE2==0 ) return; + if( pE2->op!=op ){ whereClauseInsert(pWC, pExpr, 0); }else{ - whereSplit(pWC, pExpr->pLeft, op); - whereSplit(pWC, pExpr->pRight, op); + whereSplit(pWC, pE2->pLeft, op); + whereSplit(pWC, pE2->pRight, op); } } From 60f4e0918d0aeb74fc92ae1fe7e329abda1fb0b2 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 21 Apr 2015 02:17:30 +0000 Subject: [PATCH 172/181] Test case for the previous check-in. FossilOrigin-Name: a526f58bc96c0fdead51b6bd9aafea7b48bf398e --- manifest | 12 ++++++------ manifest.uuid | 2 +- test/select4.test | 3 +++ 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/manifest b/manifest index 722a49165b..52f60dcf18 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Make\ssure\sthe\swhereSplit()\sroutine\sin\sthe\squery\splanner\sis\snot\sconfused\nby\sthe\slikely()\soperator. -D 2015-04-21T02:12:13.667 +C Test\scase\sfor\sthe\sprevious\scheck-in. +D 2015-04-21T02:17:30.839 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in faaf75b89840659d74501bea269c7e33414761c1 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -839,7 +839,7 @@ F test/securedel2.test 2d54c28e46eb1fd6902089958b20b1b056c6f1c5 F test/select1.test be62204d2bd9a5a8a149e9974cfddce893d8f686 F test/select2.test 352480e0e9c66eda9c3044e412abdf5be0215b56 F test/select3.test 2ce595f8fb8e2ac10071d3b4e424cadd4634a054 -F test/select4.test a3201fa921fdfc1397cc629e78c7a976e198a40d +F test/select4.test 48e14766d98b744b2202cca6d4679bf7ef3784c8 F test/select5.test e758b8ef94f69b111df4cb819008856655dcd535 F test/select6.test 39eac4a5c03650b2b473c532882273283ee8b7a0 F test/select7.test 7fd2ef598cfabb6b9ff6ac13973b91d0527df49d @@ -1251,7 +1251,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 03b725a768290e3c7b31f1ba3310532fd7dc05cd -R 1a86c7004bf5b29df45cd677c642d5c4 +P 588db14ffb4b0e8e76d511b7b1541db3ec78836a +R 0379e03a168715422bfe2697c2af7c68 U drh -Z 973efc28f5c5e0de1e0d5148069074b3 +Z ee4991a8fe0a3ae557d83e10280b0c68 diff --git a/manifest.uuid b/manifest.uuid index e1164a819a..82b2d7e2ea 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -588db14ffb4b0e8e76d511b7b1541db3ec78836a \ No newline at end of file +a526f58bc96c0fdead51b6bd9aafea7b48bf398e \ No newline at end of file diff --git a/test/select4.test b/test/select4.test index ce7e7e7b0d..42c61d92ad 100644 --- a/test/select4.test +++ b/test/select4.test @@ -893,5 +893,8 @@ do_execsql_test select4-14.13 { do_execsql_test select4-14.14 { VALUES(1),(2),(3) EXCEPT VALUES(1),(3); } {2} +do_execsql_test select4-14.15 { + SELECT * FROM (SELECT 123), (SELECT 456) ON likely(0 OR 1) OR 0; +} {123 456} finish_test From b6b676ea7c5361112130fbb0e7d471e9c610f7d4 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 21 Apr 2015 03:13:47 +0000 Subject: [PATCH 173/181] Fix some identifier name de-quoting issues in the foreign key and trigger logic. FossilOrigin-Name: 59e92bd9521f1e8315a9a7e7fd3d63b0c75eaf0e --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/fkey.c | 18 +++++++++--------- src/trigger.c | 4 +++- test/fkey1.test | 30 ++++++++++++++++++++++++++++++ 5 files changed, 51 insertions(+), 19 deletions(-) diff --git a/manifest b/manifest index 52f60dcf18..59e1c9e13d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Test\scase\sfor\sthe\sprevious\scheck-in. -D 2015-04-21T02:17:30.839 +C Fix\ssome\sidentifier\sname\sde-quoting\sissues\sin\sthe\sforeign\skey\sand\strigger\slogic. +D 2015-04-21T03:13:47.283 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in faaf75b89840659d74501bea269c7e33414761c1 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -184,7 +184,7 @@ F src/date.c e4d50b3283696836ec1036b695ead9a19e37a5ac F src/delete.c 37964e6c1d73ff49cbea9ff690c9605fb15f600e F src/expr.c 5555f768c05d7d4a7840c6c2e72ad7aecbe0fe54 F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb -F src/fkey.c 3343d551a8d810782257244fb33f2ce191493c39 +F src/fkey.c 6040cf888922273171f30b8d6e0726aeae4ec82d F src/func.c 1414c24c873c48796ad45942257a179a423ba42f F src/global.c 4f77cadbc5427d00139ba43d0f3979804cbb700e F src/hash.c 4263fbc955f26c2e8cdc0cf214bc42435aa4e4f5 @@ -288,7 +288,7 @@ F src/test_vfstrace.c bab9594adc976cbe696ff3970728830b4c5ed698 F src/test_wsd.c 41cadfd9d97fe8e3e4e44f61a4a8ccd6f7ca8fe9 F src/threads.c 6bbcc9fe50c917864d48287b4792d46d6e873481 F src/tokenize.c b7fb584c2be5ec39b6fdf04b185e7c6f33f8dc15 -F src/trigger.c bc647c712454c9b209fac082bb82870b5fd6fa54 +F src/trigger.c 45db6f59c6a945e1fe1acbdc77263c5c414d4c65 F src/update.c 3c4ecc282accf12d39edb8d524cf089645e55a13 F src/utf.c fc6b889ba0779b7722634cdeaa25f1930d93820c F src/util.c a6431c92803b975b7322724a7b433e538d243539 @@ -504,7 +504,7 @@ F test/extension01.test 00d13cec817f331a687a243e0e5a2d87b0e358c9 F test/fallocate.test 3e979af17dfa7e5e9dda5eba1a696c04fa9d47f7 F test/filectrl.test 14fa712e42c4cb791e09dfd58a6a03efb47ef13a F test/filefmt.test cb34663f126cbc2d358af552dcaf5c72769b0146 -F test/fkey1.test e1d1fa84cde579185ea01358436839703e415a5b +F test/fkey1.test de5b287f6a480b36bd51e8debcf48168e26e4ed2 F test/fkey2.test f3d27ecba480a348c328965d154214719bb158a9 F test/fkey3.test 76d475c80b84ee7a5d062e56ccb6ea68882e2b49 F test/fkey4.test 86446017011273aad8f9a99c1a65019e7bd9ca9d @@ -1251,7 +1251,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 588db14ffb4b0e8e76d511b7b1541db3ec78836a -R 0379e03a168715422bfe2697c2af7c68 +P a526f58bc96c0fdead51b6bd9aafea7b48bf398e +R 6263ca10bc3a41fc51b68112322cb0ff U drh -Z ee4991a8fe0a3ae557d83e10280b0c68 +Z 0f5648b8f58dd956d25b7cd57819a2e5 diff --git a/manifest.uuid b/manifest.uuid index 82b2d7e2ea..0549accf50 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -a526f58bc96c0fdead51b6bd9aafea7b48bf398e \ No newline at end of file +59e92bd9521f1e8315a9a7e7fd3d63b0c75eaf0e \ No newline at end of file diff --git a/src/fkey.c b/src/fkey.c index 3e4b752e86..e85ec6156c 100644 --- a/src/fkey.c +++ b/src/fkey.c @@ -1197,10 +1197,10 @@ static Trigger *fkActionTrigger( ** parent table are used for the comparison. */ pEq = sqlite3PExpr(pParse, TK_EQ, sqlite3PExpr(pParse, TK_DOT, - sqlite3PExpr(pParse, TK_ID, 0, 0, &tOld), - sqlite3PExpr(pParse, TK_ID, 0, 0, &tToCol) + sqlite3ExprAlloc(db, TK_ID, &tOld, 0), + sqlite3ExprAlloc(db, TK_ID, &tToCol, 0) , 0), - sqlite3PExpr(pParse, TK_ID, 0, 0, &tFromCol) + sqlite3ExprAlloc(db, TK_ID, &tFromCol, 0) , 0); pWhere = sqlite3ExprAnd(db, pWhere, pEq); @@ -1212,12 +1212,12 @@ static Trigger *fkActionTrigger( if( pChanges ){ pEq = sqlite3PExpr(pParse, TK_IS, sqlite3PExpr(pParse, TK_DOT, - sqlite3PExpr(pParse, TK_ID, 0, 0, &tOld), - sqlite3PExpr(pParse, TK_ID, 0, 0, &tToCol), + sqlite3ExprAlloc(db, TK_ID, &tOld, 0), + sqlite3ExprAlloc(db, TK_ID, &tToCol, 0), 0), sqlite3PExpr(pParse, TK_DOT, - sqlite3PExpr(pParse, TK_ID, 0, 0, &tNew), - sqlite3PExpr(pParse, TK_ID, 0, 0, &tToCol), + sqlite3ExprAlloc(db, TK_ID, &tNew, 0), + sqlite3ExprAlloc(db, TK_ID, &tToCol, 0), 0), 0); pWhen = sqlite3ExprAnd(db, pWhen, pEq); @@ -1227,8 +1227,8 @@ static Trigger *fkActionTrigger( Expr *pNew; if( action==OE_Cascade ){ pNew = sqlite3PExpr(pParse, TK_DOT, - sqlite3PExpr(pParse, TK_ID, 0, 0, &tNew), - sqlite3PExpr(pParse, TK_ID, 0, 0, &tToCol) + sqlite3ExprAlloc(db, TK_ID, &tNew, 0), + sqlite3ExprAlloc(db, TK_ID, &tToCol, 0) , 0); }else if( action==OE_SetDflt ){ Expr *pDflt = pFKey->pFrom->aCol[iFromCol].pDflt; diff --git a/src/trigger.c b/src/trigger.c index 1bc232727f..3a8e006f27 100644 --- a/src/trigger.c +++ b/src/trigger.c @@ -676,9 +676,11 @@ static SrcList *targetSrcList( int iDb; /* Index of the database to use */ SrcList *pSrc; /* SrcList to be returned */ - pSrc = sqlite3SrcListAppend(pParse->db, 0, &pStep->target, 0); + pSrc = sqlite3SrcListAppend(pParse->db, 0, 0, 0); if( pSrc ){ assert( pSrc->nSrc>0 ); + pSrc->a[pSrc->nSrc-1].zName = + sqlite3DbStrNDup(pParse->db, pStep->target.z, pStep->target.n); iDb = sqlite3SchemaToIndex(pParse->db, pStep->pTrig->pSchema); if( iDb==0 || iDb>=2 ){ sqlite3 *db = pParse->db; diff --git a/test/fkey1.test b/test/fkey1.test index 90a4c44409..0bd4939eb5 100644 --- a/test/fkey1.test +++ b/test/fkey1.test @@ -121,4 +121,34 @@ do_test fkey1-3.5 { sqlite3_db_status db DBSTATUS_DEFERRED_FKS 0 } {0 0 0} +# Stress the dequoting logic. The first test is not so bad. +do_execsql_test fkey1-4.0 { + PRAGMA foreign_keys=ON; + CREATE TABLE "xx1"("xx2" TEXT PRIMARY KEY, "xx3" TEXT); + INSERT INTO "xx1"("xx2","xx3") VALUES('abc','def'); + CREATE TABLE "xx4"("xx5" TEXT REFERENCES "xx1" ON DELETE CASCADE); + INSERT INTO "xx4"("xx5") VALUES('abc'); + INSERT INTO "xx1"("xx2","xx3") VALUES('uvw','xyz'); + SELECT 1, "xx5" FROM "xx4"; + DELETE FROM "xx1"; + SELECT 2, "xx5" FROM "xx4"; +} {1 abc} + +# This case is identical to the previous except the "xx" in each name +# is changed to a single escaped double-quote character. +do_execsql_test fkey1-4.1 { + PRAGMA foreign_keys=ON; + CREATE TABLE """1"("""2" TEXT PRIMARY KEY, """3" TEXT); + INSERT INTO """1"("""2","""3") VALUES('abc','def'); + CREATE TABLE """4"("""5" TEXT REFERENCES """1" ON DELETE CASCADE); + INSERT INTO """4"("""5") VALUES('abc'); + INSERT INTO """1"("""2","""3") VALUES('uvw','xyz'); + SELECT 1, """5" FROM """4"; + DELETE FROM """1"; + SELECT 2, """5" FROM """4"; +} {1 abc} +do_execsql_test fkey1-4.2 { + PRAGMA table_info="""1"; +} {0 {"2} TEXT 0 {} 1 1 {"3} TEXT 0 {} 0} + finish_test From 3c9a0737232d1800155bc42c9b7158487069a42a Mon Sep 17 00:00:00 2001 From: dan Date: Tue, 21 Apr 2015 12:06:53 +0000 Subject: [PATCH 174/181] Fix an fts4 problem to do with the handling of phrases that contain zero tokens. FossilOrigin-Name: caba5be0b2bdaf4eb4af9af267c0c22dfbd3dba5 --- ext/fts3/fts3.c | 10 ++++++---- manifest | 15 +++++++------- manifest.uuid | 2 +- test/fts3expr5.test | 48 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 63 insertions(+), 12 deletions(-) create mode 100644 test/fts3expr5.test diff --git a/ext/fts3/fts3.c b/ext/fts3/fts3.c index 3037719e9d..41c93daaeb 100644 --- a/ext/fts3/fts3.c +++ b/ext/fts3/fts3.c @@ -4617,12 +4617,14 @@ static void fts3EvalStartReaders( ){ if( pExpr && SQLITE_OK==*pRc ){ if( pExpr->eType==FTSQUERY_PHRASE ){ - int i; int nToken = pExpr->pPhrase->nToken; - for(i=0; ipPhrase->aToken[i].pDeferred==0 ) break; + if( nToken ){ + int i; + for(i=0; ipPhrase->aToken[i].pDeferred==0 ) break; + } + pExpr->bDeferred = (i==nToken); } - pExpr->bDeferred = (i==nToken); *pRc = fts3EvalPhraseStart(pCsr, 1, pExpr->pPhrase); }else{ fts3EvalStartReaders(pCsr, pExpr->pLeft, pRc); diff --git a/manifest b/manifest index 59e1c9e13d..f4075fa3d3 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\ssome\sidentifier\sname\sde-quoting\sissues\sin\sthe\sforeign\skey\sand\strigger\slogic. -D 2015-04-21T03:13:47.283 +C Fix\san\sfts4\sproblem\sto\sdo\swith\sthe\shandling\sof\sphrases\sthat\scontain\szero\stokens. +D 2015-04-21T12:06:53.262 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in faaf75b89840659d74501bea269c7e33414761c1 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -78,7 +78,7 @@ F ext/fts3/README.content fdc666a70d5257a64fee209f97cf89e0e6e32b51 F ext/fts3/README.syntax a19711dc5458c20734b8e485e75fb1981ec2427a F ext/fts3/README.tokenizers e0a8b81383ea60d0334d274fadf305ea14a8c314 F ext/fts3/README.txt 8c18f41574404623b76917b9da66fcb0ab38328d -F ext/fts3/fts3.c 29300a76fabbbb8fc30bb261c27d421df9f40c76 +F ext/fts3/fts3.c 1b198ddb76cd706722dacbbaeb17a2fde6fca2cc F ext/fts3/fts3.h 3a10a0af180d502cecc50df77b1b22df142817fe F ext/fts3/fts3Int.h 3626655d6ba903a3919bb44e1c38e5f0f9d6be82 F ext/fts3/fts3_aux.c 5c211e17a64885faeb16b9ba7772f9d5445c2365 @@ -587,6 +587,7 @@ F test/fts3expr.test 3401d47b229c4504424caf362cc4ff704cad4162 F test/fts3expr2.test 18da930352e5693eaa163a3eacf96233b7290d1a F test/fts3expr3.test 9e91b8edbcb197bf2e92161aa7696446d96dce5f F test/fts3expr4.test e1be1248566f43c252d4404d52914f1fc4bfa065 +F test/fts3expr5.test f9abfffbf5e53d48a33e12a1e8f8ba2c551c9b49 F test/fts3fault.test cb72dccb0a3b9f730f16c5240f3fcb9303eb1660 F test/fts3fault2.test f953bb3cf903988172270a9a0aafd5a890b0f98f F test/fts3first.test dbdedd20914c8d539aa3206c9b34a23775644641 @@ -1251,7 +1252,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 a526f58bc96c0fdead51b6bd9aafea7b48bf398e -R 6263ca10bc3a41fc51b68112322cb0ff -U drh -Z 0f5648b8f58dd956d25b7cd57819a2e5 +P 59e92bd9521f1e8315a9a7e7fd3d63b0c75eaf0e +R e9b5552434d39d6b3276df99138ae1dc +U dan +Z 403ed60a8d3b410bd6a0e0c95de6325c diff --git a/manifest.uuid b/manifest.uuid index 0549accf50..8b3d6459df 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -59e92bd9521f1e8315a9a7e7fd3d63b0c75eaf0e \ No newline at end of file +caba5be0b2bdaf4eb4af9af267c0c22dfbd3dba5 \ No newline at end of file diff --git a/test/fts3expr5.test b/test/fts3expr5.test new file mode 100644 index 0000000000..1e0985108e --- /dev/null +++ b/test/fts3expr5.test @@ -0,0 +1,48 @@ +# 2006 September 9 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# This file implements regression tests for SQLite library. The +# focus of this script is testing the FTS3 module. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix fts3expr5 + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +#------------------------------------------------------------------------- +# Various forms of empty phrase expressions. +# +do_execsql_test 1.0 { + CREATE VIRTUAL TABLE t0 USING fts3(x); + SELECT rowid FROM t0 WHERE x MATCH ''; +} {} +do_execsql_test 1.1 { + SELECT rowid FROM t0 WHERE x MATCH '""'; +} {} +do_execsql_test 1.2 { + SELECT rowid FROM t0 WHERE x MATCH '"" ""'; +} {} +do_execsql_test 1.3 { + SELECT rowid FROM t0 WHERE x MATCH '"" OR ""'; +} {} +do_execsql_test 1.4 { + SELECT rowid FROM t0 WHERE x MATCH '"" NOT ""'; +} {} +do_execsql_test 1.5 { + SELECT rowid FROM t0 WHERE x MATCH '""""'; +} {} + +finish_test From 7c052da54dd6b7f6182f36650333b09e691346d1 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 21 Apr 2015 15:16:48 +0000 Subject: [PATCH 175/181] Change an assert() in the aggregate query code generator into a testcase(). FossilOrigin-Name: d1e6bc918b0c8e0701f5e15afb91b84a9004231b --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/select.c | 3 ++- test/count.test | 5 +++++ 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index f4075fa3d3..269786e967 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\san\sfts4\sproblem\sto\sdo\swith\sthe\shandling\sof\sphrases\sthat\scontain\szero\stokens. -D 2015-04-21T12:06:53.262 +C Change\san\sassert()\sin\sthe\saggregate\squery\scode\sgenerator\sinto\sa\stestcase(). +D 2015-04-21T15:16:48.720 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in faaf75b89840659d74501bea269c7e33414761c1 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -230,7 +230,7 @@ F src/printf.c 08fa675c200aac29e561c6153f91f909ed17612f F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c 53486a98c17b7ae09b8c2b398013e973ce4c1aae F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e -F src/select.c 361dfc32244656bbe3f0e53d8ed791b3ec0c4be8 +F src/select.c d87c64b394293f00e85c95d729c8663b74d560ea F src/shell.c 78eabce4c16c45e36fea2368f95118116399ba8a F src/sqlite.h.in ca27603a36fcacdaac5a19d8ee35aaff8ce8516f F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad @@ -435,7 +435,7 @@ F test/corruptH.test 5dd4fa98c6c1ed33b178f9e8a48c4fdd3cfc9067 F test/corruptI.test 221ad8b7f0a9ac6b80fc577e73b5ad8cdea31243 F test/corruptJ.test 9e29e7a81ee3b6ac50f77ea7a9e2f3fa03f32d91 F test/cost.test 19d314526616ce4473eb4e4e450fcb94499ce318 -F test/count.test 42a251178e32f617eda33f76236a7f79825a50b5 +F test/count.test cb2e0f934c6eb33670044520748d2ecccd46259c F test/coveridxscan.test cdb47d01acc4a634a34fd25abe85189e0d0f1e62 F test/crash.test fb9dc4a02dcba30d4aa5c2c226f98b220b2b959f F test/crash2.test 5b14d4eb58b880e231361d3b609b216acda86651 @@ -1252,7 +1252,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 59e92bd9521f1e8315a9a7e7fd3d63b0c75eaf0e -R e9b5552434d39d6b3276df99138ae1dc -U dan -Z 403ed60a8d3b410bd6a0e0c95de6325c +P caba5be0b2bdaf4eb4af9af267c0c22dfbd3dba5 +R a42d4b42e1e0eeb130dc235a2eaf2ef6 +U drh +Z f1234d42aa2af13247e7d70d40d070fb diff --git a/manifest.uuid b/manifest.uuid index 8b3d6459df..f0aa771194 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -caba5be0b2bdaf4eb4af9af267c0c22dfbd3dba5 \ No newline at end of file +d1e6bc918b0c8e0701f5e15afb91b84a9004231b \ No newline at end of file diff --git a/src/select.c b/src/select.c index c49f327893..a72db2c0f9 100644 --- a/src/select.c +++ b/src/select.c @@ -4608,7 +4608,8 @@ static void updateAccumulator(Parse *pParse, AggInfo *pAggInfo){ } if( pF->iDistinct>=0 ){ addrNext = sqlite3VdbeMakeLabel(v); - assert( nArg==1 ); + testcase( nArg==0 ); /* Error condition */ + testcase( nArg>1 ); /* Also an error */ codeDistinct(pParse, pF->iDistinct, addrNext, 1, regAgg); } if( pF->pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){ diff --git a/test/count.test b/test/count.test index 3461e49c1d..862b62ab17 100644 --- a/test/count.test +++ b/test/count.test @@ -191,4 +191,9 @@ do_execsql_test count-5.1 { SELECT count(*) FROM t5; } {1} +do_catchsql_test count-6.1 { + CREATE TABLE t6(x); + SELECT count(DISTINCT) FROM t6 GROUP BY x; +} {1 {DISTINCT aggregates must have exactly one argument}} + finish_test From 4b79bde7a222380946c54e8158f746767a9d30b0 Mon Sep 17 00:00:00 2001 From: dan Date: Tue, 21 Apr 2015 15:49:04 +0000 Subject: [PATCH 176/181] Fix an obscure problem with "INSERT INTO tbl(cols) SELECT" statements where the SELECT is a compound with an ORDER BY and "cols" is a strict subset of tbl's columns. FossilOrigin-Name: 718d5d0eab045a874107e078a857226a80ab912d --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/select.c | 2 +- test/insert2.test | 20 ++++++++++++++++++++ 4 files changed, 30 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index 269786e967..6f4fc284aa 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Change\san\sassert()\sin\sthe\saggregate\squery\scode\sgenerator\sinto\sa\stestcase(). -D 2015-04-21T15:16:48.720 +C Fix\san\sobscure\sproblem\swith\s"INSERT\sINTO\stbl(cols)\sSELECT"\sstatements\swhere\sthe\sSELECT\sis\sa\scompound\swith\san\sORDER\sBY\sand\s"cols"\sis\sa\sstrict\ssubset\sof\stbl's\scolumns. +D 2015-04-21T15:49:04.252 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in faaf75b89840659d74501bea269c7e33414761c1 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -230,7 +230,7 @@ F src/printf.c 08fa675c200aac29e561c6153f91f909ed17612f F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c 53486a98c17b7ae09b8c2b398013e973ce4c1aae F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e -F src/select.c d87c64b394293f00e85c95d729c8663b74d560ea +F src/select.c b14a9e1ee035166df10f8f5c9379ac697ef43f62 F src/shell.c 78eabce4c16c45e36fea2368f95118116399ba8a F src/sqlite.h.in ca27603a36fcacdaac5a19d8ee35aaff8ce8516f F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad @@ -665,7 +665,7 @@ F test/indexedby.test 5f527a78bae74c61b8046ae3037f9dfb0bf0c353 F test/indexfault.test 31d4ab9a7d2f6e9616933eb079722362a883eb1d F test/init.test 15c823093fdabbf7b531fe22cf037134d09587a7 F test/insert.test 38742b5e9601c8f8d76e9b7555f7270288c2d371 -F test/insert2.test 4f3a04d168c728ed5ec2c88842e772606c7ce435 +F test/insert2.test 4d14b8f1b810a41995f6286b64a6943215d52208 F test/insert3.test 1b7db95a03ad9c5013fdf7d6722b6cd66ee55e30 F test/insert4.test a20432f1c0fbbcff8f11d0e6ab4acb8c9db58023 F test/insert5.test 394f96728d1258f406fe5f5aeb0aaf29487c39a6 @@ -1252,7 +1252,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 caba5be0b2bdaf4eb4af9af267c0c22dfbd3dba5 -R a42d4b42e1e0eeb130dc235a2eaf2ef6 -U drh -Z f1234d42aa2af13247e7d70d40d070fb +P d1e6bc918b0c8e0701f5e15afb91b84a9004231b +R 7ccd1057167111672b7d4496a5645687 +U dan +Z 692b69290119d874ac81343f57f21abd diff --git a/manifest.uuid b/manifest.uuid index f0aa771194..90ab0db88f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -d1e6bc918b0c8e0701f5e15afb91b84a9004231b \ No newline at end of file +718d5d0eab045a874107e078a857226a80ab912d \ No newline at end of file diff --git a/src/select.c b/src/select.c index a72db2c0f9..09186668a4 100644 --- a/src/select.c +++ b/src/select.c @@ -2642,7 +2642,7 @@ static int generateOutputSubroutine( pDest->iSdst = sqlite3GetTempRange(pParse, pIn->nSdst); pDest->nSdst = pIn->nSdst; } - sqlite3ExprCodeMove(pParse, pIn->iSdst, pDest->iSdst, pDest->nSdst); + sqlite3ExprCodeMove(pParse, pIn->iSdst, pDest->iSdst, pIn->nSdst); sqlite3VdbeAddOp1(v, OP_Yield, pDest->iSDParm); break; } diff --git a/test/insert2.test b/test/insert2.test index 6876d538ae..977fbc584a 100644 --- a/test/insert2.test +++ b/test/insert2.test @@ -16,6 +16,7 @@ set testdir [file dirname $argv0] source $testdir/tester.tcl +set testprefix insert2 # Create some tables with data that we can select against # @@ -275,4 +276,23 @@ ifcapable subquery { } {1 2 1 3 1 4} } +do_execsql_test 6.0 { + CREATE TABLE t5(a, b, c DEFAULT 'c', d); +} +do_execsql_test 6.1 { + INSERT INTO t5(a) SELECT 456 UNION ALL SELECT 123 ORDER BY 1; + SELECT * FROM t5 ORDER BY rowid; +} {123 {} c {} 456 {} c {}} + +ifcapable fts3 { + do_execsql_test 6.2 { + CREATE VIRTUAL TABLE t0 USING fts4(a); + } + do_execsql_test 6.3 { + INSERT INTO t0 SELECT 0 UNION SELECT 0 AS 'x' ORDER BY x; + SELECT * FROM t0; + } {0} +} + + finish_test From be360e1ed1d1519a8702abef8a5f761ad06f9cd5 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 21 Apr 2015 16:09:07 +0000 Subject: [PATCH 177/181] Fix a memory leak in the SELECT code generator tracing logic (code that is omitted in non-debugging builds). FossilOrigin-Name: b623ebd859dcb1d99398aa9953f6b113bad26304 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/select.c | 1 + 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 6f4fc284aa..11361b4b2a 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\san\sobscure\sproblem\swith\s"INSERT\sINTO\stbl(cols)\sSELECT"\sstatements\swhere\sthe\sSELECT\sis\sa\scompound\swith\san\sORDER\sBY\sand\s"cols"\sis\sa\sstrict\ssubset\sof\stbl's\scolumns. -D 2015-04-21T15:49:04.252 +C Fix\sa\smemory\sleak\sin\sthe\sSELECT\scode\sgenerator\stracing\slogic\s(code\sthat\sis\nomitted\sin\snon-debugging\sbuilds). +D 2015-04-21T16:09:07.623 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in faaf75b89840659d74501bea269c7e33414761c1 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -230,7 +230,7 @@ F src/printf.c 08fa675c200aac29e561c6153f91f909ed17612f F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c 53486a98c17b7ae09b8c2b398013e973ce4c1aae F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e -F src/select.c b14a9e1ee035166df10f8f5c9379ac697ef43f62 +F src/select.c 3b64da1c1130a9c82a9b5d3afe1d44ab8a31f25a F src/shell.c 78eabce4c16c45e36fea2368f95118116399ba8a F src/sqlite.h.in ca27603a36fcacdaac5a19d8ee35aaff8ce8516f F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad @@ -1252,7 +1252,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 d1e6bc918b0c8e0701f5e15afb91b84a9004231b -R 7ccd1057167111672b7d4496a5645687 -U dan -Z 692b69290119d874ac81343f57f21abd +P 718d5d0eab045a874107e078a857226a80ab912d +R 7e6bc612737dab76da35e37065b9b922 +U drh +Z ba983635f4ecc26ab029799e1b9c58b7 diff --git a/manifest.uuid b/manifest.uuid index 90ab0db88f..e6e16b709b 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -718d5d0eab045a874107e078a857226a80ab912d \ No newline at end of file +b623ebd859dcb1d99398aa9953f6b113bad26304 \ No newline at end of file diff --git a/src/select.c b/src/select.c index 09186668a4..6a18ff4599 100644 --- a/src/select.c +++ b/src/select.c @@ -5538,6 +5538,7 @@ void sqlite3TreeViewSelect(TreeView *pView, const Select *p, u8 moreToFollow){ StrAccum x; char zLine[100]; sqlite3StrAccumInit(&x, zLine, sizeof(zLine), 0); + x.useMalloc = 0; sqlite3XPrintf(&x, 0, "{%d,*}", pItem->iCursor); if( pItem->zDatabase ){ sqlite3XPrintf(&x, 0, " %s.%s", pItem->zDatabase, pItem->zName); From 464083544eae55666b8b75d3b801235b3fe4b983 Mon Sep 17 00:00:00 2001 From: dan Date: Tue, 21 Apr 2015 16:38:49 +0000 Subject: [PATCH 178/181] Ensure that tables names are dequoted exactly once by the trigger logic. FossilOrigin-Name: 9d887b92f8086961e045f8acb9ee7a443796d411 --- manifest | 20 +++++++++---------- manifest.uuid | 2 +- src/fkey.c | 7 +++---- src/sqliteInt.h | 10 +++++----- src/trigger.c | 19 +++++++++--------- test/triggerC.test | 49 ++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 77 insertions(+), 30 deletions(-) diff --git a/manifest b/manifest index 11361b4b2a..72aeca55c3 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\smemory\sleak\sin\sthe\sSELECT\scode\sgenerator\stracing\slogic\s(code\sthat\sis\nomitted\sin\snon-debugging\sbuilds). -D 2015-04-21T16:09:07.623 +C Ensure\sthat\stables\snames\sare\sdequoted\sexactly\sonce\sby\sthe\strigger\slogic. +D 2015-04-21T16:38:49.045 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in faaf75b89840659d74501bea269c7e33414761c1 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -184,7 +184,7 @@ F src/date.c e4d50b3283696836ec1036b695ead9a19e37a5ac F src/delete.c 37964e6c1d73ff49cbea9ff690c9605fb15f600e F src/expr.c 5555f768c05d7d4a7840c6c2e72ad7aecbe0fe54 F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb -F src/fkey.c 6040cf888922273171f30b8d6e0726aeae4ec82d +F src/fkey.c c9b63a217d86582c22121699a47f22f524608869 F src/func.c 1414c24c873c48796ad45942257a179a423ba42f F src/global.c 4f77cadbc5427d00139ba43d0f3979804cbb700e F src/hash.c 4263fbc955f26c2e8cdc0cf214bc42435aa4e4f5 @@ -235,7 +235,7 @@ F src/shell.c 78eabce4c16c45e36fea2368f95118116399ba8a F src/sqlite.h.in ca27603a36fcacdaac5a19d8ee35aaff8ce8516f F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h 17d487c3c91b0b8c584a32fbeb393f6f795eea7d -F src/sqliteInt.h 3a1fccc2bb62ab16750730b6f6f24305e686a0ce +F src/sqliteInt.h 8abcea1295138f10ef8f7ed38db5f1b573b93ece F src/sqliteLimit.h 216557999cb45f2e3578ed53ebefe228d779cb46 F src/status.c f266ad8a2892d659b74f0f50cb6a88b6e7c12179 F src/table.c e7a09215315a978057fb42c640f890160dbcc45e @@ -288,7 +288,7 @@ F src/test_vfstrace.c bab9594adc976cbe696ff3970728830b4c5ed698 F src/test_wsd.c 41cadfd9d97fe8e3e4e44f61a4a8ccd6f7ca8fe9 F src/threads.c 6bbcc9fe50c917864d48287b4792d46d6e873481 F src/tokenize.c b7fb584c2be5ec39b6fdf04b185e7c6f33f8dc15 -F src/trigger.c 45db6f59c6a945e1fe1acbdc77263c5c414d4c65 +F src/trigger.c 322f23aad694e8f31d384dcfa386d52a48d3c52f F src/update.c 3c4ecc282accf12d39edb8d524cf089645e55a13 F src/utf.c fc6b889ba0779b7722634cdeaa25f1930d93820c F src/util.c a6431c92803b975b7322724a7b433e538d243539 @@ -1088,7 +1088,7 @@ F test/trigger8.test 30cb0530bd7c4728055420e3f739aa00412eafa4 F test/trigger9.test 2226ec795a33b0460ab5cf8891e9054cc7edef41 F test/triggerA.test fe5597f47ee21bacb4936dc827994ed94161e332 F test/triggerB.test 56780c031b454abac2340dbb3b71ac5c56c3d7fe -F test/triggerC.test a68980c5955d62ee24be6f97129d824f199f9a4c +F test/triggerC.test 302d8995f5ffe63bbc15053abb3ef7a39cf5a092 F test/triggerD.test 8e7f3921a92a5797d472732108109e44575fa650 F test/triggerE.test 355e9c5cbaed5cd039a60baad1fb2197caeb8e52 F test/tt3_checkpoint.c 9e75cf7c1c364f52e1c47fd0f14c4340a9db0fe1 @@ -1252,7 +1252,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 718d5d0eab045a874107e078a857226a80ab912d -R 7e6bc612737dab76da35e37065b9b922 -U drh -Z ba983635f4ecc26ab029799e1b9c58b7 +P b623ebd859dcb1d99398aa9953f6b113bad26304 +R 1545a9c9d59837055bc5d4ecbd66cac7 +U dan +Z a1ff940bb9d58b1311bd4296ffd3ef6a diff --git a/manifest.uuid b/manifest.uuid index e6e16b709b..73ad47817c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -b623ebd859dcb1d99398aa9953f6b113bad26304 \ No newline at end of file +9d887b92f8086961e045f8acb9ee7a443796d411 \ No newline at end of file diff --git a/src/fkey.c b/src/fkey.c index e85ec6156c..09513e4620 100644 --- a/src/fkey.c +++ b/src/fkey.c @@ -1275,13 +1275,12 @@ static Trigger *fkActionTrigger( pTrigger = (Trigger *)sqlite3DbMallocZero(db, sizeof(Trigger) + /* struct Trigger */ sizeof(TriggerStep) + /* Single step in trigger program */ - nFrom + 1 /* Space for pStep->target.z */ + nFrom + 1 /* Space for pStep->zTarget */ ); if( pTrigger ){ pStep = pTrigger->step_list = (TriggerStep *)&pTrigger[1]; - pStep->target.z = (char *)&pStep[1]; - pStep->target.n = nFrom; - memcpy((char *)pStep->target.z, zFrom, nFrom); + pStep->zTarget = (char *)&pStep[1]; + memcpy((char *)pStep->zTarget, zFrom, nFrom); pStep->pWhere = sqlite3ExprDup(db, pWhere, EXPRDUP_REDUCE); pStep->pExprList = sqlite3ExprListDup(db, pList, EXPRDUP_REDUCE); diff --git a/src/sqliteInt.h b/src/sqliteInt.h index deab70fc48..f34645fa8d 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -2776,7 +2776,7 @@ struct Trigger { * orconf -> stores the ON CONFLICT algorithm * pSelect -> If this is an INSERT INTO ... SELECT ... statement, then * this stores a pointer to the SELECT statement. Otherwise NULL. - * target -> A token holding the quoted name of the table to insert into. + * zTarget -> Dequoted name of the table to insert into. * pExprList -> If this is an INSERT INTO ... VALUES ... statement, then * this stores values to be inserted. Otherwise NULL. * pIdList -> If this is an INSERT INTO ... () VALUES ... @@ -2784,12 +2784,12 @@ struct Trigger { * inserted into. * * (op == TK_DELETE) - * target -> A token holding the quoted name of the table to delete from. + * zTarget -> Dequoted name of the table to delete from. * pWhere -> The WHERE clause of the DELETE statement if one is specified. * Otherwise NULL. * * (op == TK_UPDATE) - * target -> A token holding the quoted name of the table to update rows of. + * zTarget -> Dequoted name of the table to update. * pWhere -> The WHERE clause of the UPDATE statement if one is specified. * Otherwise NULL. * pExprList -> A list of the columns to update and the expressions to update @@ -2801,8 +2801,8 @@ struct TriggerStep { u8 op; /* One of TK_DELETE, TK_UPDATE, TK_INSERT, TK_SELECT */ u8 orconf; /* OE_Rollback etc. */ Trigger *pTrig; /* The trigger that this step is a part of */ - Select *pSelect; /* SELECT statment or RHS of INSERT INTO .. SELECT ... */ - Token target; /* Target table for DELETE, UPDATE, INSERT */ + Select *pSelect; /* SELECT statement or RHS of INSERT INTO SELECT ... */ + char *zTarget; /* Target table for DELETE, UPDATE, INSERT */ Expr *pWhere; /* The WHERE clause for DELETE or UPDATE steps */ ExprList *pExprList; /* SET clause for UPDATE. */ IdList *pIdList; /* Column names for INSERT */ diff --git a/src/trigger.c b/src/trigger.c index 3a8e006f27..2eba0cf92c 100644 --- a/src/trigger.c +++ b/src/trigger.c @@ -372,12 +372,12 @@ static TriggerStep *triggerStepAllocate( ){ TriggerStep *pTriggerStep; - pTriggerStep = sqlite3DbMallocZero(db, sizeof(TriggerStep) + pName->n); + pTriggerStep = sqlite3DbMallocZero(db, sizeof(TriggerStep) + pName->n + 1); if( pTriggerStep ){ char *z = (char*)&pTriggerStep[1]; memcpy(z, pName->z, pName->n); - pTriggerStep->target.z = z; - pTriggerStep->target.n = pName->n; + sqlite3Dequote(z); + pTriggerStep->zTarget = z; pTriggerStep->op = op; } return pTriggerStep; @@ -660,7 +660,7 @@ Trigger *sqlite3TriggersExist( } /* -** Convert the pStep->target token into a SrcList and return a pointer +** Convert the pStep->zTarget string into a SrcList and return a pointer ** to that SrcList. ** ** This routine adds a specific database name, if needed, to the target when @@ -673,18 +673,17 @@ static SrcList *targetSrcList( Parse *pParse, /* The parsing context */ TriggerStep *pStep /* The trigger containing the target token */ ){ + sqlite3 *db = pParse->db; int iDb; /* Index of the database to use */ SrcList *pSrc; /* SrcList to be returned */ - pSrc = sqlite3SrcListAppend(pParse->db, 0, 0, 0); + pSrc = sqlite3SrcListAppend(db, 0, 0, 0); if( pSrc ){ assert( pSrc->nSrc>0 ); - pSrc->a[pSrc->nSrc-1].zName = - sqlite3DbStrNDup(pParse->db, pStep->target.z, pStep->target.n); - iDb = sqlite3SchemaToIndex(pParse->db, pStep->pTrig->pSchema); + pSrc->a[pSrc->nSrc-1].zName = sqlite3DbStrDup(db, pStep->zTarget); + iDb = sqlite3SchemaToIndex(db, pStep->pTrig->pSchema); if( iDb==0 || iDb>=2 ){ - sqlite3 *db = pParse->db; - assert( iDbdb->nDb ); + assert( iDbnDb ); pSrc->a[pSrc->nSrc-1].zDatabase = sqlite3DbStrDup(db, db->aDb[iDb].zName); } } diff --git a/test/triggerC.test b/test/triggerC.test index 14cc0f01dd..3e47521fd1 100644 --- a/test/triggerC.test +++ b/test/triggerC.test @@ -12,6 +12,7 @@ set testdir [file dirname $argv0] source $testdir/tester.tcl +set testprefix triggerC ifcapable {!trigger} { finish_test return @@ -993,4 +994,52 @@ reset_db optimization_control db factor-constants 0 do_execsql_test triggerC-14.2 $SQL {1 2 3} +#------------------------------------------------------------------------- +# Check that table names used by trigger programs are dequoted exactly +# once. +# +do_execsql_test 15.1.1 { + PRAGMA recursive_triggers = 1; + CREATE TABLE node( + id int not null primary key, + pid int not null default 0 references node, + key varchar not null, + path varchar default '', + unique(pid, key) + ); + CREATE TRIGGER node_delete_referencing AFTER DELETE ON "node" + BEGIN + DELETE FROM "node" WHERE pid = old."id"; + END; +} +do_execsql_test 15.1.2 { + INSERT INTO node(id, pid, key) VALUES(9, 0, 'test'); + INSERT INTO node(id, pid, key) VALUES(90, 9, 'test1'); + INSERT INTO node(id, pid, key) VALUES(900, 90, 'test2'); + DELETE FROM node WHERE id=9; + SELECT * FROM node; +} + +do_execsql_test 15.2.1 { + CREATE TABLE x1 (x); + + CREATE TABLE x2 (a, b); + CREATE TABLE '"x2"'(a, b); + + INSERT INTO x2 VALUES(1, 2); + INSERT INTO x2 VALUES(3, 4); + INSERT INTO '"x2"' SELECT * FROM x2; + + CREATE TRIGGER x1ai AFTER INSERT ON x1 BEGIN + INSERT INTO """x2""" VALUES('x', 'y'); + DELETE FROM """x2""" WHERE a=1; + UPDATE """x2""" SET b = 11 WHERE a = 3; + END; + + INSERT INTO x1 VALUES('go!'); +} + +do_execsql_test 15.2.2 { SELECT * FROM x2; } {1 2 3 4} +do_execsql_test 15.2.3 { SELECT * FROM """x2"""; } {3 11 x y} + finish_test From dfb5e1cbc629287038ed72d7498aacf812c7a437 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 21 Apr 2015 17:07:01 +0000 Subject: [PATCH 179/181] Make sure the datatype and collating sequence of transients tables are not initialized more than once. Otherwise a memory leak results. FossilOrigin-Name: 9e6beda2c8d879e438ee933e658f860d6eb42a20 --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/select.c | 2 ++ test/subquery.test | 10 ++++++++++ 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 72aeca55c3..7762cd732f 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Ensure\sthat\stables\snames\sare\sdequoted\sexactly\sonce\sby\sthe\strigger\slogic. -D 2015-04-21T16:38:49.045 +C Make\ssure\sthe\sdatatype\sand\scollating\ssequence\sof\stransients\stables\sare\nnot\sinitialized\smore\sthan\sonce.\s\sOtherwise\sa\smemory\sleak\sresults. +D 2015-04-21T17:07:01.179 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in faaf75b89840659d74501bea269c7e33414761c1 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -230,7 +230,7 @@ F src/printf.c 08fa675c200aac29e561c6153f91f909ed17612f F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c 53486a98c17b7ae09b8c2b398013e973ce4c1aae F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e -F src/select.c 3b64da1c1130a9c82a9b5d3afe1d44ab8a31f25a +F src/select.c 01c386a3fda06bf3a1fee5391f103390480937bb F src/shell.c 78eabce4c16c45e36fea2368f95118116399ba8a F src/sqlite.h.in ca27603a36fcacdaac5a19d8ee35aaff8ce8516f F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad @@ -901,7 +901,7 @@ F test/spellfix.test 24f676831acddd2f4056a598fd731a72c6311f49 F test/sqllimits1.test e05786eaed7950ff6a2d00031d001d8a26131e68 F test/stat.test 76fd746b85459e812a0193410fb599f0531f22de F test/stmt.test 25d64e3dbf9a3ce89558667d7f39d966fe2a71b9 -F test/subquery.test 666fdecceac258f5fd84bed09a64e49d9f37edd9 +F test/subquery.test d7268d193dd33d5505df965399d3a594e76ae13f F test/subquery2.test 438f8a7da1457277b22e4176510f7659b286995f F test/subselect.test d24fd8757daf97dafd2e889c73ea4c4272dcf4e4 F test/substr.test 18f57c4ca8a598805c4d64e304c418734d843c1a @@ -1252,7 +1252,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 b623ebd859dcb1d99398aa9953f6b113bad26304 -R 1545a9c9d59837055bc5d4ecbd66cac7 -U dan -Z a1ff940bb9d58b1311bd4296ffd3ef6a +P 9d887b92f8086961e045f8acb9ee7a443796d411 +R 3636eb5c943e6a1ccf08bc5de8e48684 +U drh +Z d704b3d64babe71da7ea3a63e7e599d3 diff --git a/manifest.uuid b/manifest.uuid index 73ad47817c..ac07ad5039 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -9d887b92f8086961e045f8acb9ee7a443796d411 \ No newline at end of file +9e6beda2c8d879e438ee933e658f860d6eb42a20 \ No newline at end of file diff --git a/src/select.c b/src/select.c index 6a18ff4599..20d39440cb 100644 --- a/src/select.c +++ b/src/select.c @@ -1700,6 +1700,8 @@ static void selectAddColumnTypeAndCollation( a = pSelect->pEList->a; for(i=0, pCol=pTab->aCol; inCol; i++, pCol++){ p = a[i].pExpr; + if( pCol->zType ) break; + if( pCol->zColl ) break; pCol->zType = sqlite3DbStrDup(db, columnType(&sNC, p,0,0,0, &pCol->szEst)); szAll += pCol->szEst; pCol->affinity = sqlite3ExprAffinity(p); diff --git a/test/subquery.test b/test/subquery.test index 93c3f28ddb..06facbbae0 100644 --- a/test/subquery.test +++ b/test/subquery.test @@ -584,4 +584,14 @@ do_test subquery-7.11 { } {30303} } ;############# Disabled +# 2015-04-21. +# Verify that a memory leak in the table column type and collation analysis +# is plugged. +# +do_execsql_test subquery-8.1 { + CREATE TABLE t8(a TEXT, b INT); + SELECT (SELECT 0 FROM (SELECT * FROM t1)) AS x WHERE x; + SELECT (SELECT 0 FROM (SELECT * FROM (SELECT 0))) AS x WHERE x; +} {} + finish_test From 1cb50c880e02a469bbb3cb02112e89ba3a5c6857 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 21 Apr 2015 17:17:47 +0000 Subject: [PATCH 180/181] Alternative fix for the double-initialization of type and collating sequence problem that leaves the estimated table size intact. FossilOrigin-Name: 623ddbdbf48d26dac58c593bcb9e7b184334ddfc --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/select.c | 8 ++++---- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index 7762cd732f..e1382b4f62 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Make\ssure\sthe\sdatatype\sand\scollating\ssequence\sof\stransients\stables\sare\nnot\sinitialized\smore\sthan\sonce.\s\sOtherwise\sa\smemory\sleak\sresults. -D 2015-04-21T17:07:01.179 +C Alternative\sfix\sfor\sthe\sdouble-initialization\sof\stype\sand\scollating\ssequence\nproblem\sthat\sleaves\sthe\sestimated\stable\ssize\sintact. +D 2015-04-21T17:17:47.197 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in faaf75b89840659d74501bea269c7e33414761c1 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -230,7 +230,7 @@ F src/printf.c 08fa675c200aac29e561c6153f91f909ed17612f F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c 53486a98c17b7ae09b8c2b398013e973ce4c1aae F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e -F src/select.c 01c386a3fda06bf3a1fee5391f103390480937bb +F src/select.c 35433ea8894ac42594ddc31eb0165a6d6401cfe5 F src/shell.c 78eabce4c16c45e36fea2368f95118116399ba8a F src/sqlite.h.in ca27603a36fcacdaac5a19d8ee35aaff8ce8516f F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad @@ -1252,7 +1252,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 9d887b92f8086961e045f8acb9ee7a443796d411 -R 3636eb5c943e6a1ccf08bc5de8e48684 +P 9e6beda2c8d879e438ee933e658f860d6eb42a20 +R e945ee9cd5bcd63adee2f8cd77bbfeb7 U drh -Z d704b3d64babe71da7ea3a63e7e599d3 +Z a3d2a31d5a72cc2f0da62ee0f93b8c64 diff --git a/manifest.uuid b/manifest.uuid index ac07ad5039..bfbccd2f06 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -9e6beda2c8d879e438ee933e658f860d6eb42a20 \ No newline at end of file +623ddbdbf48d26dac58c593bcb9e7b184334ddfc \ No newline at end of file diff --git a/src/select.c b/src/select.c index 20d39440cb..7797804c18 100644 --- a/src/select.c +++ b/src/select.c @@ -1700,14 +1700,14 @@ static void selectAddColumnTypeAndCollation( a = pSelect->pEList->a; for(i=0, pCol=pTab->aCol; inCol; i++, pCol++){ p = a[i].pExpr; - if( pCol->zType ) break; - if( pCol->zColl ) break; - pCol->zType = sqlite3DbStrDup(db, columnType(&sNC, p,0,0,0, &pCol->szEst)); + if( pCol->zType==0 ){ + pCol->zType = sqlite3DbStrDup(db, columnType(&sNC, p,0,0,0, &pCol->szEst)); + } szAll += pCol->szEst; pCol->affinity = sqlite3ExprAffinity(p); if( pCol->affinity==0 ) pCol->affinity = SQLITE_AFF_NONE; pColl = sqlite3ExprCollSeq(pParse, p); - if( pColl ){ + if( pColl && pCol->zColl==0 ){ pCol->zColl = sqlite3DbStrDup(db, pColl->zName); } } From 318d38cf7e16d0f47dc982c33e80792e06a6fff6 Mon Sep 17 00:00:00 2001 From: mistachkin Date: Wed, 22 Apr 2015 01:33:53 +0000 Subject: [PATCH 181/181] When compiling for UAP, link against the new minimal MSVC runtime. FossilOrigin-Name: 2cb945116e7a5b78741b19839899826b539d5868 --- Makefile.msc | 20 +++++++++++++++++++- manifest | 16 ++++++++-------- manifest.uuid | 2 +- tool/build-all-msvc.bat | 15 +++++++++++++++ 4 files changed, 43 insertions(+), 10 deletions(-) diff --git a/Makefile.msc b/Makefile.msc index bf290d0040..382f2b7dc0 100644 --- a/Makefile.msc +++ b/Makefile.msc @@ -115,6 +115,14 @@ USE_RC = 1 FOR_WINRT = 0 !ENDIF +# Set this non-0 to compile binaries suitable for the UAP environment. +# This setting does not apply to any binaries that require Tcl to operate +# properly (i.e. the text fixture, etc). +# +!IFNDEF FOR_UAP +FOR_UAP = 0 +!ENDIF + # Set this non-0 to skip attempting to look for and/or link with the Tcl # runtime library. # @@ -713,7 +721,7 @@ LTLIBOPTS = /NOLOGO # !IF $(FOR_WINRT)!=0 LTLINKOPTS = $(LTLINKOPTS) /APPCONTAINER -!IF "$(VISUALSTUDIOVERSION)"=="12.0" +!IF "$(VISUALSTUDIOVERSION)"=="12.0" || "$(VISUALSTUDIOVERSION)"=="14.0" !IFNDEF STORELIBPATH !IF "$(PLATFORM)"=="x86" STORELIBPATH = $(CRTLIBPATH)\store @@ -757,6 +765,16 @@ LTLINKOPTS = $(LTLINKOPTS) WindowsPhoneCore.lib RuntimeObject.lib PhoneAppModelH LTLINKOPTS = $(LTLINKOPTS) /NODEFAULTLIB:kernel32.lib /NODEFAULTLIB:ole32.lib !ENDIF +# When compiling for UAP, some extra linker options are also required. +# +!IF $(FOR_UAP)!=0 +LTLINKOPTS = $(LTLINKOPTS) /DYNAMICBASE /NODEFAULTLIB:kernel32.lib +LTLINKOPTS = $(LTLINKOPTS) mincore.lib +!IFDEF PSDKLIBPATH +LTLINKOPTS = $(LTLINKOPTS) "/LIBPATH:$(PSDKLIBPATH)" +!ENDIF +!ENDIF + # If either debugging or symbols are enabled, enable PDBs. # !IF $(DEBUG)>1 || $(SYMBOLS)!=0 diff --git a/manifest b/manifest index e1382b4f62..f62c283903 100644 --- a/manifest +++ b/manifest @@ -1,9 +1,9 @@ -C Alternative\sfix\sfor\sthe\sdouble-initialization\sof\stype\sand\scollating\ssequence\nproblem\sthat\sleaves\sthe\sestimated\stable\ssize\sintact. -D 2015-04-21T17:17:47.197 +C When\scompiling\sfor\sUAP,\slink\sagainst\sthe\snew\sminimal\sMSVC\sruntime. +D 2015-04-22T01:33:53.959 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in faaf75b89840659d74501bea269c7e33414761c1 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 -F Makefile.msc 513abdaff333b04ef68775ec25ceb6053b4ecafd +F Makefile.msc 32d8fe89ac5c130f9f14293fb4a59b120895c943 F Makefile.vxworks e1b65dea203f054e71653415bd8f96dcaed47858 F README.md d58e3bebc0a4145e0f2a87994015fdb575a8e866 F VERSION 2e244662b71e6e68a5c29b014ebc5b7564f4cc5a @@ -1197,7 +1197,7 @@ F test/without_rowid6.test db0dbf03c49030aa3c1ba5f618620334bd2baf5f F test/wordcount.c 9915e06cb33d8ca8109b8700791afe80d305afda F test/zeroblob.test fb3c0e4ab172d386954deda24c03f500e121d80d F test/zerodamage.test cf6748bad89553cc1632be51a6f54e487e4039ac -F tool/build-all-msvc.bat 19be654f72b0b0ed4d2451a998c603a4eb65a60f x +F tool/build-all-msvc.bat 9058bd90a3c078a3d8c17d40e853aaa0f47885f4 x F tool/build-shell.sh 950f47c6174f1eea171319438b93ba67ff5bf367 F tool/checkSpacing.c 810e51703529a204fc4e1eb060e9ab663e3c06d2 F tool/diffdb.c 7524b1b5df217c20cd0431f6789851a4e0cb191b @@ -1252,7 +1252,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 9e6beda2c8d879e438ee933e658f860d6eb42a20 -R e945ee9cd5bcd63adee2f8cd77bbfeb7 -U drh -Z a3d2a31d5a72cc2f0da62ee0f93b8c64 +P 623ddbdbf48d26dac58c593bcb9e7b184334ddfc +R 647b9c5f348c3c64b56250400a815823 +U mistachkin +Z 2676785d203eabdaf7fb118930189562 diff --git a/manifest.uuid b/manifest.uuid index bfbccd2f06..9362726267 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -623ddbdbf48d26dac58c593bcb9e7b184334ddfc \ No newline at end of file +2cb945116e7a5b78741b19839899826b539d5868 \ No newline at end of file diff --git a/tool/build-all-msvc.bat b/tool/build-all-msvc.bat index 534ea75be6..9f5176db9d 100755 --- a/tool/build-all-msvc.bat +++ b/tool/build-all-msvc.bat @@ -483,6 +483,8 @@ FOR %%P IN (%PLATFORMS%) DO ( REM IF DEFINED USE_WINV100_NSDKLIBPATH ( CALL :fn_AppendVariable NSDKLIBPATH \..\10\lib\10.0.10030.0\um\x86 + CALL :fn_CopyVariable UniversalCRTSdkDir PSDKLIBPATH + CALL :fn_AppendVariable PSDKLIBPATH Lib\10.0.10030.0\um\%%D ) ELSE IF DEFINED USE_WINV63_NSDKLIBPATH ( CALL :fn_AppendVariable NSDKLIBPATH \lib\winv6.3\um\x86 ) ELSE IF "%VisualStudioVersion%" == "12.0" ( @@ -666,6 +668,19 @@ REM NOTE: If we get to this point, we have succeeded. REM GOTO no_errors +:fn_ShowVariable + SETLOCAL + SET __ECHO_CMD=ECHO %%%2%% + FOR /F "delims=" %%V IN ('%__ECHO_CMD%') DO ( + IF NOT "%%V" == "" ( + IF NOT "%%V" == "%%%2%%" ( + %_VECHO% %1 = '%%V' + ) + ) + ) + ENDLOCAL + GOTO :EOF + :fn_ResetErrorLevel VERIFY > NUL GOTO :EOF