From 9b5d76bf57ee240bd745bad993027dcd26e957f2 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 10 Mar 2015 13:50:18 +0000 Subject: [PATCH 01/63] Revise test cases in malloc5.test to accommodate varying allocation sizes returned by some system malloc() implementations. FossilOrigin-Name: fbae6bafd74d8da9c72be5f562a62f80b01cc846 --- manifest | 13 ++++++------- manifest.uuid | 2 +- test/malloc5.test | 29 +++++++++++++++++++++++------ 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/manifest b/manifest index a8566de963..3769cadfe2 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sthe\sLIKE\soptimization\sso\sthat\sit\sworks\seven\sif\sthere\sare\sadditional\nrange\scontraints\son\sthe\scolumn\sthat\sis\ssubject\sto\sthe\sLIKE\sor\sGLOB. -D 2015-03-09T13:01:02.136 +C Revise\stest\scases\sin\smalloc5.test\sto\saccommodate\svarying\sallocation\nsizes\sreturned\sby\ssome\ssystem\smalloc()\simplementations. +D 2015-03-10T13:50:18.414 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 2f643d6968dfc0b82d2e546a0525a39079f9e928 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -709,7 +709,7 @@ F test/make-where7.tcl 05c16b5d4f5d6512881dfec560cb793915932ef9 F test/malloc.test 96939d2d1a6f39667bbebe5bc27c6525f2ab614e F test/malloc3.test e3b32c724b5a124b57cb0ed177f675249ad0c66a F test/malloc4.test 957337613002b7058a85116493a262f679f3a261 -F test/malloc5.test fafce0aa9157060445cd1a56ad50fc79d82f28c3 +F test/malloc5.test 79182b8bffd6d62f77b1a5a8ba8e6bf0e5053b8e F test/malloc6.test 2f039d9821927eacae43e1831f815e157659a151 F test/malloc7.test 7c68a32942858bc715284856c5507446bba88c3a F test/malloc8.test 9b7a3f8cb9cf0b12fff566e80a980b1767bd961d @@ -1241,8 +1241,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P e5da5e7d5dc5a3438ced23f1ee83e695abc29c45 0e02dc94fd1bb891d0edd1e34b57e923b17712a7 -R c1700660b0fab033a6359aa8c00c1b69 -T +closed 0e02dc94fd1bb891d0edd1e34b57e923b17712a7 +P 984c3fd5261619fb542a5a95dab37707b5d79dbf +R 755476faee751a04385de321ff0c4db7 U drh -Z 0d4bf9b628bd332a63a01f9a77a070c3 +Z d102bfa9bbfc74e74ac15b539033106b diff --git a/manifest.uuid b/manifest.uuid index 5e807e391c..960352f2cd 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -984c3fd5261619fb542a5a95dab37707b5d79dbf \ No newline at end of file +fbae6bafd74d8da9c72be5f562a62f80b01cc846 \ No newline at end of file diff --git a/test/malloc5.test b/test/malloc5.test index 6abedf79e1..c046499261 100644 --- a/test/malloc5.test +++ b/test/malloc5.test @@ -71,6 +71,23 @@ do_test malloc5-1.3 { expr $::pgalloc > 0 } {1} +# The sizes of memory allocations from system malloc() might vary, +# depending on the memory allocator algorithms used. The following +# routine is designed to support answers that fall within a range +# of values while also supplying easy-to-understand "expected" values +# when errors occur. +# +proc value_in_range {target x args} { + set v [lindex $args 0] + if {$v!=""} { + if {$v<$target*$x} {return $v} + if {$v>$target/$x} {return $v} + } + return "number between [expr {int($target*$x)}] and [expr {int($target/$x)}]" +} +set mrange 0.98 ;# plus or minus 2% + + do_test malloc5-1.4 { # Commit the transaction and open a new one. Read 1 page into the cache. # Because the page is not dirty, it is eligible for collection even @@ -81,16 +98,16 @@ do_test malloc5-1.4 { BEGIN; SELECT * FROM abc; } - sqlite3_release_memory -} $::pgalloc + value_in_range $::pgalloc $::mrange [sqlite3_release_memory] +} [value_in_range $::pgalloc $::mrange] do_test malloc5-1.5 { # Conclude the transaction opened in the previous [do_test] block. This # causes another page (page 1) to become eligible for recycling. # execsql { COMMIT } - sqlite3_release_memory -} $::pgalloc + value_in_range $::pgalloc $::mrange [sqlite3_release_memory] +} [value_in_range $::pgalloc $::mrange] do_test malloc5-1.6 { # Manipulate the cache so that it contains two unused pages. One requires @@ -101,8 +118,8 @@ do_test malloc5-1.6 { SELECT * FROM abc; CREATE TABLE def(d, e, f); } - sqlite3_release_memory 500 -} $::pgalloc + value_in_range $::pgalloc $::mrange [sqlite3_release_memory 500] +} [value_in_range $::pgalloc $::mrange] do_test malloc5-1.7 { # Database should not be locked this time. From 94929646f109b72bb5f22cb44ce9afd65fc1c9ce Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 10 Mar 2015 15:34:47 +0000 Subject: [PATCH 02/63] Fix an incrblob2 test case so that it works on 32-bit systems. FossilOrigin-Name: 8d0b11c96e15556dd65ced05708a832aef134e69 --- manifest | 12 ++++++------ manifest.uuid | 2 +- test/incrblob2.test | 14 ++++++++++++-- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 3769cadfe2..1387322488 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Revise\stest\scases\sin\smalloc5.test\sto\saccommodate\svarying\sallocation\nsizes\sreturned\sby\ssome\ssystem\smalloc()\simplementations. -D 2015-03-10T13:50:18.414 +C Fix\san\sincrblob2\stest\scase\sso\sthat\sit\sworks\son\s32-bit\ssystems. +D 2015-03-10T15:34:47.080 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 2f643d6968dfc0b82d2e546a0525a39079f9e928 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -639,7 +639,7 @@ F test/in3.test 3cbf58c87f4052cee3a58b37b6389777505aa0c0 F test/in4.test d2b38cba404bc4320f4fe1b595b3d163f212c068 F test/in5.test 1de657472fa9ac2924be25c2c959ac5ca1aae554 F test/incrblob.test e81846d214f3637622620fbde7cd526781cfe328 -F test/incrblob2.test 0d8821730a84f90af78a9dd547fe7a2480a06240 +F test/incrblob2.test a5ce5ed1d0b01e2ed347245a21170372528af0a5 F test/incrblob3.test d8d036fde015d4a159cd3cbae9d29003b37227a4 F test/incrblob4.test f26502a5697893e5acea268c910f16478c2f0fab F test/incrblob_err.test af1f12ba60d220c9752073ff2bda2ad59e88960d @@ -1241,7 +1241,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 984c3fd5261619fb542a5a95dab37707b5d79dbf -R 755476faee751a04385de321ff0c4db7 +P fbae6bafd74d8da9c72be5f562a62f80b01cc846 +R f19e7f30be378d3111028d8dd74f6a7d U drh -Z d102bfa9bbfc74e74ac15b539033106b +Z 0ddafeebdf23c7d95a3d79f2f7b9a23f diff --git a/manifest.uuid b/manifest.uuid index 960352f2cd..3acf7708d9 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -fbae6bafd74d8da9c72be5f562a62f80b01cc846 \ No newline at end of file +8d0b11c96e15556dd65ced05708a832aef134e69 \ No newline at end of file diff --git a/test/incrblob2.test b/test/incrblob2.test index 1a235f7d22..b6c75cd6c7 100644 --- a/test/incrblob2.test +++ b/test/incrblob2.test @@ -324,11 +324,21 @@ do_test incrblob2-6.2 { sqlite3_blob_read $rdHandle 0 2 } {AB} -do_test incrblob2-6.2b { +if {$::tcl_platform(pointerSize)>=8} { + do_test incrblob2-6.2b { + set rc [catch { + # Prior to 2015-02-07, the following caused a segfault due to + # integer overflow. + sqlite3_blob_read $rdHandle 2147483647 2147483647 + } errmsg] + lappend rc $errmsg + } {1 SQLITE_ERROR} +} +do_test incrblob2-6.2c { set rc [catch { # Prior to 2015-02-07, the following caused a segfault due to # integer overflow. - sqlite3_blob_read $rdHandle 2147483647 2147483647 + sqlite3_blob_read $rdHandle 2147483647 100 } errmsg] lappend rc $errmsg } {1 SQLITE_ERROR} From bbf76eec342f7a4732b7e38329b6ea1ac8c682da Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 10 Mar 2015 20:22:35 +0000 Subject: [PATCH 03/63] Arrange for some of the transient locks in WAL mode to block, as a single to the OS to fix priority inversions. FossilOrigin-Name: c6e6d5f4e06c3ac0bfb620c0c728fbc7230c4a02 --- manifest | 19 +++++++++++-------- manifest.uuid | 2 +- src/os_unix.c | 28 +++++++++++++++++++--------- src/sqlite.h.in | 8 ++++++++ src/wal.c | 17 +++++++++-------- 5 files changed, 48 insertions(+), 26 deletions(-) diff --git a/manifest b/manifest index 1387322488..881ae7d644 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\san\sincrblob2\stest\scase\sso\sthat\sit\sworks\son\s32-bit\ssystems. -D 2015-03-10T15:34:47.080 +C Arrange\sfor\ssome\sof\sthe\stransient\slocks\sin\sWAL\smode\sto\sblock,\sas\sa\ssingle\nto\sthe\sOS\sto\sfix\spriority\sinversions. +D 2015-03-10T20:22:35.302 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 2f643d6968dfc0b82d2e546a0525a39079f9e928 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 49d06acee4053920e4a6429844f440b5f975cea4 +F src/os_unix.c cc903ecc6ebda90ef703d043ddaa7f33de0cab0f F src/os_win.c 8223e7db5b7c4a81d8b161098ac3959400434cdb F src/os_win.h eb7a47aa17b26b77eb97e4823f20a00b8bda12ca F src/pager.c 4120a49ecd37697e28f5ed807f470b9c0b88410c @@ -232,7 +232,7 @@ F src/resolve.c f4d79e31ffa5820c2e3d1740baa5e9b190425f2b F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e F src/select.c 94e016b6733b1d39a2f4c8d431155b4c2897d907 F src/shell.c cce82ca26392578a4a1ee927dfe55ea3411c7c92 -F src/sqlite.h.in 356e69db9500b3fd11705c21ca247e19b95884a3 +F src/sqlite.h.in 4eb59d93caec4b60eada51d3211087746187edef F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h 17d487c3c91b0b8c584a32fbeb393f6f795eea7d F src/sqliteInt.h fae682c2b4dfbe489b134d74521c41c088f16ab1 @@ -304,7 +304,7 @@ F src/vdbesort.c 6d64c5448b64851b99931ede980addc3af70d5e2 F src/vdbetrace.c 7e4222955e07dd707a2f360c0eb73452be1cb010 F src/vtab.c 699f2b8d509cfe379c33dde33827875d5b030e01 F src/vxworks.h c18586c8edc1bddbc15c004fa16aeb1e1342b4fb -F src/wal.c 39303f2c9db02a4e422cd8eb2c8760420c6a51fe +F src/wal.c 878c8e1a51cb2ec45c395d26b7d5cd9e1a098e4a F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4 F src/walker.c c253b95b4ee44b21c406e2a1052636c31ea27804 F src/where.c eb141b075776e9864d38f279333e2472a8653202 @@ -1241,7 +1241,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 fbae6bafd74d8da9c72be5f562a62f80b01cc846 -R f19e7f30be378d3111028d8dd74f6a7d +P 8d0b11c96e15556dd65ced05708a832aef134e69 +R e3a6235cb886b3e146e5aa9fea4e9436 +T *branch * wal-blocking-lock +T *sym-wal-blocking-lock * +T -sym-trunk * U drh -Z 0ddafeebdf23c7d95a3d79f2f7b9a23f +Z 53b7d268fee9eb6c03e124e757f212c1 diff --git a/manifest.uuid b/manifest.uuid index 3acf7708d9..e908b35f97 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -8d0b11c96e15556dd65ced05708a832aef134e69 \ No newline at end of file +c6e6d5f4e06c3ac0bfb620c0c728fbc7230c4a02 \ No newline at end of file diff --git a/src/os_unix.c b/src/os_unix.c index 927b9e1c54..16cb935dec 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -248,6 +248,7 @@ static pid_t randomnessPid = 0; #define UNIXFILE_URI 0x40 /* Filename might have query parameters */ #define UNIXFILE_NOLOCK 0x80 /* Do no file locking */ #define UNIXFILE_WARNED 0x0100 /* verifyDbFile() warnings issued */ +#define UNIXFILE_BLOCK 0x0200 /* Next SHM lock might block */ /* ** Include code that is common to all os_*.c files @@ -4090,15 +4091,17 @@ struct unixShm { ** otherwise. */ static int unixShmSystemLock( - unixShmNode *pShmNode, /* Apply locks to this open shared-memory segment */ + unixFile *pFile, /* Open connection to the WAL file */ int lockType, /* F_UNLCK, F_RDLCK, or F_WRLCK */ int ofst, /* First byte of the locking range */ int n /* Number of bytes to lock */ ){ - struct flock f; /* The posix advisory locking structure */ - int rc = SQLITE_OK; /* Result code form fcntl() */ + unixShmNode *pShmNode; /* Apply locks to this open shared-memory segment */ + struct flock f; /* The posix advisory locking structure */ + int rc = SQLITE_OK; /* Result code form fcntl() */ /* Access to the unixShmNode object is serialized by the caller */ + pShmNode = pFile->pInode->pShmNode; assert( sqlite3_mutex_held(pShmNode->mutex) || pShmNode->nRef==0 ); /* Shared locks never span more than one byte */ @@ -4108,6 +4111,7 @@ static int unixShmSystemLock( assert( n>=1 && nh>=0 ){ + int lkType; /* Initialize the locking parameters */ memset(&f, 0, sizeof(f)); f.l_type = lockType; @@ -4115,8 +4119,10 @@ static int unixShmSystemLock( f.l_start = ofst; f.l_len = n; - rc = osFcntl(pShmNode->h, F_SETLK, &f); + lkType = (pFile->ctrlFlags & UNIXFILE_BLOCK)!=0 ? F_SETLKW : F_SETLK; + rc = osFcntl(pShmNode->h, lkType, &f); rc = (rc!=(-1)) ? SQLITE_OK : SQLITE_BUSY; + pFile->ctrlFlags &= ~UNIXFILE_BLOCK; } /* Update the global lock state and do debug tracing */ @@ -4326,13 +4332,13 @@ static int unixOpenSharedMemory(unixFile *pDbFd){ ** If not, truncate the file to zero length. */ rc = SQLITE_OK; - if( unixShmSystemLock(pShmNode, F_WRLCK, UNIX_SHM_DMS, 1)==SQLITE_OK ){ + if( unixShmSystemLock(pDbFd, F_WRLCK, UNIX_SHM_DMS, 1)==SQLITE_OK ){ if( robust_ftruncate(pShmNode->h, 0) ){ rc = unixLogError(SQLITE_IOERR_SHMOPEN, "ftruncate", zShmFilename); } } if( rc==SQLITE_OK ){ - rc = unixShmSystemLock(pShmNode, F_RDLCK, UNIX_SHM_DMS, 1); + rc = unixShmSystemLock(pDbFd, F_RDLCK, UNIX_SHM_DMS, 1); } if( rc ) goto shm_open_err; } @@ -4564,7 +4570,7 @@ static int unixShmLock( /* Unlock the system-level locks */ if( (mask & allMask)==0 ){ - rc = unixShmSystemLock(pShmNode, F_UNLCK, ofst+UNIX_SHM_BASE, n); + rc = unixShmSystemLock(pDbFd, F_UNLCK, ofst+UNIX_SHM_BASE, n); }else{ rc = SQLITE_OK; } @@ -4592,7 +4598,7 @@ static int unixShmLock( /* Get shared locks at the system level, if necessary */ if( rc==SQLITE_OK ){ if( (allShared & mask)==0 ){ - rc = unixShmSystemLock(pShmNode, F_RDLCK, ofst+UNIX_SHM_BASE, n); + rc = unixShmSystemLock(pDbFd, F_RDLCK, ofst+UNIX_SHM_BASE, n); }else{ rc = SQLITE_OK; } @@ -4617,7 +4623,7 @@ static int unixShmLock( ** also mark the local connection as being locked. */ if( rc==SQLITE_OK ){ - rc = unixShmSystemLock(pShmNode, F_WRLCK, ofst+UNIX_SHM_BASE, n); + rc = unixShmSystemLock(pDbFd, F_WRLCK, ofst+UNIX_SHM_BASE, n); if( rc==SQLITE_OK ){ assert( (p->sharedMask & mask)==0 ); p->exclMask |= mask; @@ -7222,6 +7228,10 @@ 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 ){ diff --git a/src/sqlite.h.in b/src/sqlite.h.in index 06e0f7eb9f..f0f6f5ddcf 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -945,6 +945,13 @@ struct sqlite3_io_methods { ** pointed to by the pArg argument. This capability is used during testing ** and only needs to be supported when SQLITE_TEST is defined. ** +**
  • [[SQLITE_FCNTL_WAL_BLOCK]] +** The [SQLITE_FCNTL_WAL_BLOCK] is a single to the VFS layer that it might +** be advantageous to block on the next WAL lock if the lock is not immediately +** available. The WAL subsystem issues this ioctl() during some rare +** circumstances in order to fix a problem with priority inversion. +** Applications should not use this file-control. +** ** */ #define SQLITE_FCNTL_LOCKSTATE 1 @@ -969,6 +976,7 @@ struct sqlite3_io_methods { #define SQLITE_FCNTL_SYNC 21 #define SQLITE_FCNTL_COMMIT_PHASETWO 22 #define SQLITE_FCNTL_WIN32_SET_HANDLE 23 +#define SQLITE_FCNTL_WAL_BLOCK 24 /* deprecated names */ #define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE diff --git a/src/wal.c b/src/wal.c index 71f4a3d452..558adbcad2 100644 --- a/src/wal.c +++ b/src/wal.c @@ -788,9 +788,10 @@ static void walUnlockShared(Wal *pWal, int lockIdx){ SQLITE_SHM_UNLOCK | SQLITE_SHM_SHARED); WALTRACE(("WAL%p: release SHARED-%s\n", pWal, walLockName(lockIdx))); } -static int walLockExclusive(Wal *pWal, int lockIdx, int n){ +static int walLockExclusive(Wal *pWal, int lockIdx, int n, int fBlock){ int rc; if( pWal->exclusiveMode ) return SQLITE_OK; + if( fBlock ) sqlite3OsFileControl(pWal->pDbFd, SQLITE_FCNTL_WAL_BLOCK, 0); rc = sqlite3OsShmLock(pWal->pDbFd, lockIdx, n, SQLITE_SHM_LOCK | SQLITE_SHM_EXCLUSIVE); WALTRACE(("WAL%p: acquire EXCLUSIVE-%s cnt=%d %s\n", pWal, @@ -1076,7 +1077,7 @@ static int walIndexRecover(Wal *pWal){ assert( pWal->writeLock ); iLock = WAL_ALL_BUT_WRITE + pWal->ckptLock; nLock = SQLITE_SHM_NLOCK - iLock; - rc = walLockExclusive(pWal, iLock, nLock); + rc = walLockExclusive(pWal, iLock, nLock, 0); if( rc ){ return rc; } @@ -1610,7 +1611,7 @@ static int walBusyLock( ){ int rc; do { - rc = walLockExclusive(pWal, lockIdx, n); + rc = walLockExclusive(pWal, lockIdx, n, 0); }while( xBusy && rc==SQLITE_BUSY && xBusy(pBusyArg) ); return rc; } @@ -2043,7 +2044,7 @@ static int walIndexReadHdr(Wal *pWal, int *pChanged){ walUnlockShared(pWal, WAL_WRITE_LOCK); rc = SQLITE_READONLY_RECOVERY; } - }else if( SQLITE_OK==(rc = walLockExclusive(pWal, WAL_WRITE_LOCK, 1)) ){ + }else if( SQLITE_OK==(rc = walLockExclusive(pWal, WAL_WRITE_LOCK, 1, 1)) ){ pWal->writeLock = 1; if( SQLITE_OK==(rc = walIndexPage(pWal, 0, &page0)) ){ badHdr = walIndexTryHdr(pWal, pChanged); @@ -2249,7 +2250,7 @@ static int walTryBeginRead(Wal *pWal, int *pChanged, int useWal, int cnt){ && (mxReadMarkhdr.mxFrame || mxI==0) ){ for(i=1; iaReadMark[i] = pWal->hdr.mxFrame; mxI = i; @@ -2505,7 +2506,7 @@ int sqlite3WalBeginWriteTransaction(Wal *pWal){ /* Only one writer allowed at a time. Get the write lock. Return ** SQLITE_BUSY if unable. */ - rc = walLockExclusive(pWal, WAL_WRITE_LOCK, 1); + rc = walLockExclusive(pWal, WAL_WRITE_LOCK, 1, 0); if( rc ){ return rc; } @@ -2650,7 +2651,7 @@ static int walRestartLog(Wal *pWal){ if( pInfo->nBackfill>0 ){ u32 salt1; sqlite3_randomness(4, &salt1); - rc = walLockExclusive(pWal, WAL_READ_LOCK(1), WAL_NREADER-1); + rc = walLockExclusive(pWal, WAL_READ_LOCK(1), WAL_NREADER-1, 0); if( rc==SQLITE_OK ){ /* If all readers are using WAL_READ_LOCK(0) (in other words if no ** readers are currently using the WAL), then the transactions @@ -2975,7 +2976,7 @@ int sqlite3WalCheckpoint( /* IMPLEMENTATION-OF: R-62028-47212 All calls obtain an exclusive ** "checkpoint" lock on the database file. */ - rc = walLockExclusive(pWal, WAL_CKPT_LOCK, 1); + rc = walLockExclusive(pWal, WAL_CKPT_LOCK, 1, 0); if( rc ){ /* EVIDENCE-OF: R-10421-19736 If any other process is running a ** checkpoint operation at the same time, the lock cannot be obtained and From cc285c5ab021e8973142b7cedce90e2451ba5cf3 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 11 Mar 2015 14:34:38 +0000 Subject: [PATCH 04/63] Expand the multi-process test cases to repeat each case 20 times and to repeat tests using different journal modes. FossilOrigin-Name: a2715b049a86555990abccc7aa363c524ddb9982 --- Makefile.in | 16 ++++++++++++---- manifest | 18 +++++++++--------- manifest.uuid | 2 +- mptest/crash01.test | 4 ++++ mptest/mptest.c | 21 +++++++++++++++++---- mptest/multiwrite01.test | 10 ++++++++++ 6 files changed, 53 insertions(+), 18 deletions(-) diff --git a/Makefile.in b/Makefile.in index 058a13a655..4ac06938fd 100644 --- a/Makefile.in +++ b/Makefile.in @@ -540,11 +540,19 @@ mptester$(EXE): sqlite3.c $(TOP)/mptest/mptest.c $(LTLINK) -o $@ -I. $(TOP)/mptest/mptest.c sqlite3.c \ $(TLIBS) -rpath "$(libdir)" +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 mptest1.db - ./mptester$(EXE) mptest1.db $(TOP)/mptest/crash01.test - rm -f mptest2.db - ./mptester$(EXE) mptest2.db $(TOP)/mptest/multiwrite01.test + 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 + # This target creates a directory named "tsrc" and fills it with # copies of all of the C source code and header files needed to diff --git a/manifest b/manifest index 1387322488..abbbe02140 100644 --- a/manifest +++ b/manifest @@ -1,7 +1,7 @@ -C Fix\san\sincrblob2\stest\scase\sso\sthat\sit\sworks\son\s32-bit\ssystems. -D 2015-03-10T15:34:47.080 +C Expand\sthe\smulti-process\stest\scases\sto\srepeat\seach\scase\s20\stimes\sand\nto\srepeat\stests\susing\sdifferent\sjournal\smodes. +D 2015-03-11T14:34:38.239 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f -F Makefile.in 2f643d6968dfc0b82d2e546a0525a39079f9e928 +F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 F Makefile.msc 529e61cd9d29a3934758b4b3a0bb649b6c653481 F Makefile.vxworks e1b65dea203f054e71653415bd8f96dcaed47858 @@ -158,10 +158,10 @@ F mkopcodeh.awk c6b3fa301db6ef7ac916b14c60868aeaec1337b5 F mkso.sh fd21c06b063bb16a5d25deea1752c2da6ac3ed83 F mptest/config01.test 3c6adcbc50b991866855f1977ff172eb6d901271 F mptest/config02.test 4415dfe36c48785f751e16e32c20b077c28ae504 -F mptest/crash01.test cce8e306d8596d5a2e497e27112dae1f6e5e3538 +F mptest/crash01.test 61e61469e257df0850df4293d7d4d6c2af301421 F mptest/crash02.subtest f4ef05adcd15d60e5d2bd654204f2c008b519df8 -F mptest/mptest.c 24c5f72415df2eab7088ef8c9f99f163aed590c8 -F mptest/multiwrite01.test 499ad0310da8dff8e8f98d2e272fc2a8aa741b2e +F mptest/mptest.c 0c0c82c1d9aea0b1a60ef9456a04c35ab1106622 +F mptest/multiwrite01.test dab5c5f8f9534971efce679152c5146da265222d F spec.template 86a4a43b99ebb3e75e6b9a735d5fd293a24e90ca F sqlite.pc.in 42b7bf0d02e08b9e77734a47798d1a55a9e0716b F sqlite3.1 fc7ad8990fc8409983309bb80de8c811a7506786 @@ -1241,7 +1241,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P fbae6bafd74d8da9c72be5f562a62f80b01cc846 -R f19e7f30be378d3111028d8dd74f6a7d +P 8d0b11c96e15556dd65ced05708a832aef134e69 +R 2327229d01e481a57e92de598065db5c U drh -Z 0ddafeebdf23c7d95a3d79f2f7b9a23f +Z cd1fd5866edba6a7b1ae8e17fb546b84 diff --git a/manifest.uuid b/manifest.uuid index 3acf7708d9..57b677aa08 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -8d0b11c96e15556dd65ced05708a832aef134e69 \ No newline at end of file +a2715b049a86555990abccc7aa363c524ddb9982 \ No newline at end of file diff --git a/mptest/crash01.test b/mptest/crash01.test index 46f170cecc..f1483dfa1d 100644 --- a/mptest/crash01.test +++ b/mptest/crash01.test @@ -32,6 +32,7 @@ --end --wait 1 --task 2 + DROP TABLE IF EXISTS t2; CREATE TABLE t2(a INTEGER PRIMARY KEY, b); INSERT INTO t2 SELECT a, b FROM t1; UPDATE t1 SET b='x'||a||'y'; @@ -46,6 +47,7 @@ --match 29 28 27 26 25 --end --task 3 + DROP TABLE IF EXISTS t3; CREATE TABLE t3(a INTEGER PRIMARY KEY, b); INSERT INTO t3 SELECT a, b FROM t1; UPDATE t1 SET b='x'||a||'y'; @@ -60,6 +62,7 @@ --match 29 28 27 26 25 --end --task 4 + DROP TABLE IF EXISTS t4; CREATE TABLE t4(a INTEGER PRIMARY KEY, b); INSERT INTO t4 SELECT a, b FROM t1; UPDATE t1 SET b='x'||a||'y'; @@ -74,6 +77,7 @@ --match 29 28 27 26 25 --end --task 5 + DROP TABLE IF EXISTS t5; CREATE TABLE t5(a INTEGER PRIMARY KEY, b); INSERT INTO t5 SELECT a, b FROM t1; UPDATE t1 SET b='x'||a||'y'; diff --git a/mptest/mptest.c b/mptest/mptest.c index 7b56b61902..fdfe5f4a9d 100644 --- a/mptest/mptest.c +++ b/mptest/mptest.c @@ -1262,6 +1262,9 @@ int main(int argc, char **argv){ int taskId; const char *zTrace; const char *zCOption; + const char *zJMode; + const char *zNRep; + int nRep = 1, iRep; g.argv0 = argv[0]; g.iTrace = 1; @@ -1277,6 +1280,10 @@ int main(int argc, char **argv){ } n = argc-2; sqlite3_snprintf(sizeof(g.zName), g.zName, "%05d.mptest", GETPID()); + zJMode = findOption(argv+2, &n, "journalmode", 1); + zNRep = findOption(argv+2, &n, "repeat", 1); + if( zNRep ) nRep = atoi(zNRep); + if( nRep<1 ) nRep = 1; g.zVfs = findOption(argv+2, &n, "vfs", 1); zClient = findOption(argv+2, &n, "client", 1); g.zErrLog = findOption(argv+2, &n, "errlog", 1); @@ -1348,7 +1355,11 @@ int 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" + "DROP TABLE IF EXISTS client;\n" "CREATE TABLE task(\n" " id INTEGER PRIMARY KEY,\n" " name TEXT,\n" @@ -1364,10 +1375,12 @@ int main(int argc, char **argv){ "CREATE TABLE client(id INTEGER PRIMARY KEY, wantHalt);\n" ); zScript = readFile(argv[2]); - if( g.iTrace ) logMessage("begin script [%s]\n", argv[2]); - runScript(0, 0, zScript, argv[2]); + for(iRep=1; iRep<=nRep; iRep++){ + if( g.iTrace ) logMessage("begin script [%s] cycle %d\n", argv[2], iRep); + runScript(0, 0, zScript, argv[2]); + if( g.iTrace ) logMessage("end script [%s] cycle %d\n", argv[2], iRep); + } sqlite3_free(zScript); - if( g.iTrace ) logMessage("end script [%s]\n", argv[2]); waitForClient(0, 2000, "during shutdown...\n"); trySql("UPDATE client SET wantHalt=1"); sqlite3_sleep(10); @@ -1391,7 +1404,7 @@ int main(int argc, char **argv){ } sqlite3_finalize(pStmt); } - sqlite3_close(g.db); + sqlite3_close(g.db); maybeClose(g.pLog); maybeClose(g.pErrLog); if( iClient==0 ){ diff --git a/mptest/multiwrite01.test b/mptest/multiwrite01.test index 4f88a68949..7062ae0d51 100644 --- a/mptest/multiwrite01.test +++ b/mptest/multiwrite01.test @@ -361,6 +361,8 @@ PRAGMA integrity_check(10); WHERE t4.b GLOB 'x4?y' AND t3.b=('x'||(t4.a+5)||'y') ORDER BY t3.a LIMIT 7 --match 45 46 47 48 49 50 51 + PRAGMA integrity_check; + --match ok --end --task 5 SELECT t1.a FROM t1, t2 @@ -371,6 +373,8 @@ PRAGMA integrity_check(10); WHERE t4.b GLOB 'x4?y' AND t3.b=('x'||(t4.a+5)||'y') ORDER BY t3.a LIMIT 7 --match 45 46 47 48 49 50 51 + PRAGMA integrity_check; + --match ok --end --task 3 SELECT t1.a FROM t1, t2 @@ -381,6 +385,8 @@ PRAGMA integrity_check(10); WHERE t4.b GLOB 'x4?y' AND t3.b=('x'||(t4.a+5)||'y') ORDER BY t3.a LIMIT 7 --match 45 46 47 48 49 50 51 + PRAGMA integrity_check; + --match ok --end --task 2 SELECT t1.a FROM t1, t2 @@ -391,6 +397,8 @@ PRAGMA integrity_check(10); WHERE t4.b GLOB 'x4?y' AND t3.b=('x'||(t4.a+5)||'y') ORDER BY t3.a LIMIT 7 --match 45 46 47 48 49 50 51 + PRAGMA integrity_check; + --match ok --end --task 4 SELECT t1.a FROM t1, t2 @@ -401,5 +409,7 @@ PRAGMA integrity_check(10); WHERE t4.b GLOB 'x4?y' AND t3.b=('x'||(t4.a+5)||'y') ORDER BY t3.a LIMIT 7 --match 45 46 47 48 49 50 51 + PRAGMA integrity_check; + --match ok --end --wait all From 18bf80768934fe2f610de8eb8334806a73c181ff Mon Sep 17 00:00:00 2001 From: dan Date: Wed, 11 Mar 2015 20:06:40 +0000 Subject: [PATCH 05/63] Allow the query planner to evaluate deterministic scalar SQL functions used in WHERE constraints if all arguments are SQL literals in order to compare the results with sqlite_stat4 sample data. FossilOrigin-Name: b7f1fc26d24012e1e7c7f6b3cc0b84ad2b02b8ad --- manifest | 20 ++++--- manifest.uuid | 2 +- src/vdbeapi.c | 13 +++-- src/vdbemem.c | 126 +++++++++++++++++++++++++++++++++++++++++++++ test/analyzeF.test | 78 ++++++++++++++++++++++++++++ 5 files changed, 225 insertions(+), 14 deletions(-) create mode 100644 test/analyzeF.test diff --git a/manifest b/manifest index abbbe02140..60c76c5cba 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Expand\sthe\smulti-process\stest\scases\sto\srepeat\seach\scase\s20\stimes\sand\nto\srepeat\stests\susing\sdifferent\sjournal\smodes. -D 2015-03-11T14:34:38.239 +C Allow\sthe\squery\splanner\sto\sevaluate\sdeterministic\sscalar\sSQL\sfunctions\sused\sin\sWHERE\sconstraints\sif\sall\sarguments\sare\sSQL\sliterals\sin\sorder\sto\scompare\sthe\sresults\swith\ssqlite_stat4\ssample\sdata. +D 2015-03-11T20:06:40.904 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -296,10 +296,10 @@ F src/vacuum.c 9460b9de7b2d4e34b0d374894aa6c8a0632be8ec F src/vdbe.c 94cbc2115075b1a562a2a702c29ba48e74f85d34 F src/vdbe.h 6fc69d9c5e146302c56e163cb4b31d1ee64a18c3 F src/vdbeInt.h bb56fd199d8af1a2c1b9639ee2f70724b4338e3a -F src/vdbeapi.c dac0d0d8009a8aa549cd77d9c29da44c0344f0c4 +F src/vdbeapi.c 5c207659c8a57c12c3f77a8fb97544e032fc2f14 F src/vdbeaux.c 97911edb61074b871ec4aa2d6bb779071643dee5 F src/vdbeblob.c 4f2e8e075d238392df98c5e03a64342465b03f90 -F src/vdbemem.c 31d8eabb0cd78bfeab4e5124c7363c3e9e54db9f +F src/vdbemem.c 8572106eb3b64ad6e02698c0fb312ccb47bb5c9e F src/vdbesort.c 6d64c5448b64851b99931ede980addc3af70d5e2 F src/vdbetrace.c 7e4222955e07dd707a2f360c0eb73452be1cb010 F src/vtab.c 699f2b8d509cfe379c33dde33827875d5b030e01 @@ -333,6 +333,7 @@ F test/analyzeB.test 8bf35ee0a548aea831bf56762cb8e7fdb1db083d F test/analyzeC.test 555a6cc388b9818b6eda6df816f01ce0a75d3a93 F test/analyzeD.test 08f9d0bee4e118a66fff3a32d02dbe0ee0a2b594 F test/analyzeE.test 8684e8ac5722fb97c251887ad97e5d496a98af1d +F test/analyzeF.test 299a47183c648d8ad92671f313def8fd7cb09875 F test/async.test 1d0e056ba1bb9729283a0f22718d3a25e82c277b F test/async2.test c0a9bd20816d7d6a2ceca7b8c03d3d69c28ffb8b F test/async3.test d73a062002376d7edc1fe3edff493edbec1fc2f7 @@ -1241,7 +1242,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 8d0b11c96e15556dd65ced05708a832aef134e69 -R 2327229d01e481a57e92de598065db5c -U drh -Z cd1fd5866edba6a7b1ae8e17fb546b84 +P a2715b049a86555990abccc7aa363c524ddb9982 +R 8289f5b5a84378b5cf3294cc8646b1fb +T *branch * stat4-function +T *sym-stat4-function * +T -sym-trunk * +U dan +Z a4cf4e61f3250d5413e8887a5d5cd094 diff --git a/manifest.uuid b/manifest.uuid index 57b677aa08..28f0ab069b 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -a2715b049a86555990abccc7aa363c524ddb9982 \ No newline at end of file +b7f1fc26d24012e1e7c7f6b3cc0b84ad2b02b8ad \ No newline at end of file diff --git a/src/vdbeapi.c b/src/vdbeapi.c index 8c0038e4e8..fc3d60f20b 100644 --- a/src/vdbeapi.c +++ b/src/vdbeapi.c @@ -637,12 +637,13 @@ sqlite3 *sqlite3_context_db_handle(sqlite3_context *p){ */ sqlite3_int64 sqlite3StmtCurrentTime(sqlite3_context *p){ Vdbe *v = p->pVdbe; + sqlite3_int64 iTime = 0; int rc; - if( v->iCurrentTime==0 ){ - rc = sqlite3OsCurrentTimeInt64(p->pOut->db->pVfs, &v->iCurrentTime); - if( rc ) v->iCurrentTime = 0; - } - return v->iCurrentTime; + if( v && v->iCurrentTime ) return v->iCurrentTime; + rc = sqlite3OsCurrentTimeInt64(p->pOut->db->pVfs, &iTime); + if( rc ) return 0; + if( v ) v->iCurrentTime = iTime; + return iTime; } /* @@ -712,6 +713,7 @@ void *sqlite3_get_auxdata(sqlite3_context *pCtx, int iArg){ AuxData *pAuxData; assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) ); + if( pCtx->pVdbe==0 ) return 0; for(pAuxData=pCtx->pVdbe->pAuxData; pAuxData; pAuxData=pAuxData->pNext){ if( pAuxData->iOp==pCtx->iOp && pAuxData->iArg==iArg ) break; } @@ -735,6 +737,7 @@ void sqlite3_set_auxdata( assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) ); if( iArg<0 ) goto failed; + if( pVdbe==0 ) goto failed; for(pAuxData=pVdbe->pAuxData; pAuxData; pAuxData=pAuxData->pNext){ if( pAuxData->iOp==pCtx->iOp && pAuxData->iArg==iArg ) break; diff --git a/src/vdbemem.c b/src/vdbemem.c index 870fb5bd89..ce7b73deac 100644 --- a/src/vdbemem.c +++ b/src/vdbemem.c @@ -1134,6 +1134,128 @@ static sqlite3_value *valueNew(sqlite3 *db, struct ValueNewStat4Ctx *p){ return sqlite3ValueNew(db); } +/* +** The expression object indicated by the second argument is guaranteed +** to be a scalar SQL function. If +** +** * all function arguments are SQL literals, +** * the SQLITE_FUNC_CONSTANT function flag is set, +** * the SQLITE_FUNC_NEEDCOLL function flag is not set, and +** * this routine is being invoked as part of examining stat4 data, +** not as part of handling a default value on a column created using +** ALTER TABLE ADD COLUMN, +** +** then this routine attempts to invoke the SQL function. Assuming no +** error occurs, output parameter (*ppVal) is set to point to a value +** object containing the result before returning SQLITE_OK. +** +** Affinity aff is applied to the result of the function before returning. +** If the result is a text value, the sqlite3_value object uses encoding +** enc. +** +** If the conditions above are not met, this function returns SQLITE_OK +** and sets (*ppVal) to NULL. Or, if an error occurs, (*ppVal) is set to +** NULL and an SQLite error code returned. +*/ +#ifdef SQLITE_ENABLE_STAT3_OR_STAT4 +static int valueFromFunction( + sqlite3 *db, /* The database connection */ + Expr *p, /* The expression to evaluate */ + u8 enc, /* Encoding to use */ + u8 aff, /* Affinity to use */ + sqlite3_value **ppVal, /* Write the new value here */ + struct ValueNewStat4Ctx *pCtx /* Second argument for valueNew() */ +){ + sqlite3_context ctx; /* Context object for function invocation */ + sqlite3_value **apVal = 0; /* Function arguments */ + int nVal = 0; /* Size of apVal[] array */ + FuncDef *pFunc = 0; /* Function definition */ + sqlite3_value *pVal = 0; /* New value */ + int rc = SQLITE_OK; /* Return code */ + int nName; /* Size of function name in bytes */ + ExprList *pList; /* Function arguments */ + int i; /* Iterator variable */ + + /* If pCtx==0, then this is probably being called to to obtain an + ** sqlite3_value object for the default value of a column. In that case + ** function expressions are not supported. Function expressions are + ** only supported when extracting values to compare with sqlite_stat4 + ** records. + ** + ** It may also be that this function expression is an argument passed + ** to another function expression. As in "f2(...)" within the query: + ** + ** SELECT * FROM tbl WHERE tbl.c = f1(0, f2(...), 1); + ** + ** For now, extracting the value of "f1(...)" is not supported either. + */ + if( pCtx==0 ) return SQLITE_OK; + + assert( (p->flags & (EP_TokenOnly|EP_Reduced))==0 ); + pList = p->x.pList; + if( pList ) nVal = pList->nExpr; + nName = sqlite3Strlen30(p->u.zToken); + pFunc = sqlite3FindFunction(db, p->u.zToken, nName, nVal, enc, 0); + assert( pFunc ); + if( (pFunc->funcFlags & SQLITE_FUNC_CONSTANT)==0 + || (pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL) + ){ + return SQLITE_OK; + } + + if( pList ){ + apVal = (sqlite3_value**)sqlite3DbMallocZero(db, sizeof(apVal[0]) * nVal); + if( apVal==0 ){ + rc = SQLITE_NOMEM; + goto value_from_function_out; + } + for(i=0; ia[i].pExpr, enc, aff, &apVal[i]); + if( apVal[i]==0 ) goto value_from_function_out; + assert( rc==SQLITE_OK ); + } + } + + pVal = valueNew(db, pCtx); + if( pVal==0 ){ + rc = SQLITE_NOMEM; + goto value_from_function_out; + } + + memset(&ctx, 0, sizeof(ctx)); + ctx.pOut = pVal; + ctx.pFunc = pFunc; + pFunc->xFunc(&ctx, nVal, apVal); + if( ctx.isError ){ + rc = ctx.isError; + sqlite3ErrorMsg(pCtx->pParse, "%s", sqlite3_value_text(pVal)); + }else{ + sqlite3ValueApplyAffinity(pVal, aff, SQLITE_UTF8); + if( rc==SQLITE_OK ){ + rc = sqlite3VdbeChangeEncoding(pVal, enc); + } + if( rc==SQLITE_OK && sqlite3VdbeMemTooBig(pVal) ){ + rc = SQLITE_TOOBIG; + } + } + + value_from_function_out: + if( rc!=SQLITE_OK ){ + if( pCtx==0 ) sqlite3ValueFree(pVal); + pVal = 0; + } + for(i=0; i Date: Wed, 11 Mar 2015 20:59:42 +0000 Subject: [PATCH 06/63] Allow the default value for columns added using ALTER TABLE ADD COLUMN to be a function in existing schemas loaded from disk. But prevent this version of SQLite from being used to create such a column. FossilOrigin-Name: ff868e22ca0393eaac417872a4c10738f0d7d970 --- manifest | 17 +++++++---------- manifest.uuid | 2 +- src/alter.c | 4 +++- src/vdbemem.c | 33 ++++++++------------------------- 4 files changed, 19 insertions(+), 37 deletions(-) diff --git a/manifest b/manifest index 60c76c5cba..421022d674 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Allow\sthe\squery\splanner\sto\sevaluate\sdeterministic\sscalar\sSQL\sfunctions\sused\sin\sWHERE\sconstraints\sif\sall\sarguments\sare\sSQL\sliterals\sin\sorder\sto\scompare\sthe\sresults\swith\ssqlite_stat4\ssample\sdata. -D 2015-03-11T20:06:40.904 +C Allow\sthe\sdefault\svalue\sfor\scolumns\sadded\susing\sALTER\sTABLE\sADD\sCOLUMN\sto\sbe\sa\sfunction\sin\sexisting\sschemas\sloaded\sfrom\sdisk.\sBut\sprevent\sthis\sversion\sof\sSQLite\sfrom\sbeing\sused\sto\screate\ssuch\sa\scolumn. +D 2015-03-11T20:59:42.115 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -166,7 +166,7 @@ F spec.template 86a4a43b99ebb3e75e6b9a735d5fd293a24e90ca F sqlite.pc.in 42b7bf0d02e08b9e77734a47798d1a55a9e0716b F sqlite3.1 fc7ad8990fc8409983309bb80de8c811a7506786 F sqlite3.pc.in 48fed132e7cb71ab676105d2a4dc77127d8c1f3a -F src/alter.c ba266a779bc7ce10e52e59e7d3dc79fa342e8fdb +F src/alter.c 809313ddb2dea2a8cdd2d0da944d6a859e3657dc F src/analyze.c 91540f835163d5369ccbae78e2e6c74d0dd53c1d F src/attach.c 880f9b8641a829c563e52dd13c452ce457ae4dd8 F src/auth.c b56c78ebe40a2110fd361379f7e8162d23f92240 @@ -299,7 +299,7 @@ F src/vdbeInt.h bb56fd199d8af1a2c1b9639ee2f70724b4338e3a F src/vdbeapi.c 5c207659c8a57c12c3f77a8fb97544e032fc2f14 F src/vdbeaux.c 97911edb61074b871ec4aa2d6bb779071643dee5 F src/vdbeblob.c 4f2e8e075d238392df98c5e03a64342465b03f90 -F src/vdbemem.c 8572106eb3b64ad6e02698c0fb312ccb47bb5c9e +F src/vdbemem.c 85dd9cb7a98717ad821d388c10053da2fe66f0f7 F src/vdbesort.c 6d64c5448b64851b99931ede980addc3af70d5e2 F src/vdbetrace.c 7e4222955e07dd707a2f360c0eb73452be1cb010 F src/vtab.c 699f2b8d509cfe379c33dde33827875d5b030e01 @@ -1242,10 +1242,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P a2715b049a86555990abccc7aa363c524ddb9982 -R 8289f5b5a84378b5cf3294cc8646b1fb -T *branch * stat4-function -T *sym-stat4-function * -T -sym-trunk * +P b7f1fc26d24012e1e7c7f6b3cc0b84ad2b02b8ad +R 3e606265a1ac491b0b1ab16052f58807 U dan -Z a4cf4e61f3250d5413e8887a5d5cd094 +Z 8153e0e591b223bdb869dacd2f48bbd5 diff --git a/manifest.uuid b/manifest.uuid index 28f0ab069b..906c7ad764 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -b7f1fc26d24012e1e7c7f6b3cc0b84ad2b02b8ad \ No newline at end of file +ff868e22ca0393eaac417872a4c10738f0d7d970 \ No newline at end of file diff --git a/src/alter.c b/src/alter.c index dd060248b8..908b251f06 100644 --- a/src/alter.c +++ b/src/alter.c @@ -690,7 +690,9 @@ void sqlite3AlterFinishAddColumn(Parse *pParse, Token *pColDef){ */ if( pDflt ){ sqlite3_value *pVal = 0; - if( sqlite3ValueFromExpr(db, pDflt, SQLITE_UTF8, SQLITE_AFF_NONE, &pVal) ){ + if( pDflt->op!=TK_FUNCTION + && sqlite3ValueFromExpr(db, pDflt, SQLITE_UTF8, SQLITE_AFF_NONE, &pVal) + ){ db->mallocFailed = 1; return; } diff --git a/src/vdbemem.c b/src/vdbemem.c index ce7b73deac..269afe148c 100644 --- a/src/vdbemem.c +++ b/src/vdbemem.c @@ -1139,11 +1139,8 @@ static sqlite3_value *valueNew(sqlite3 *db, struct ValueNewStat4Ctx *p){ ** to be a scalar SQL function. If ** ** * all function arguments are SQL literals, -** * the SQLITE_FUNC_CONSTANT function flag is set, -** * the SQLITE_FUNC_NEEDCOLL function flag is not set, and -** * this routine is being invoked as part of examining stat4 data, -** not as part of handling a default value on a column created using -** ALTER TABLE ADD COLUMN, +** * the SQLITE_FUNC_CONSTANT function flag is set, and +** * the SQLITE_FUNC_NEEDCOLL function flag is not set, ** ** then this routine attempts to invoke the SQL function. Assuming no ** error occurs, output parameter (*ppVal) is set to point to a value @@ -1173,27 +1170,13 @@ static int valueFromFunction( sqlite3_value *pVal = 0; /* New value */ int rc = SQLITE_OK; /* Return code */ int nName; /* Size of function name in bytes */ - ExprList *pList; /* Function arguments */ + ExprList *pList = 0; /* Function arguments */ int i; /* Iterator variable */ - /* If pCtx==0, then this is probably being called to to obtain an - ** sqlite3_value object for the default value of a column. In that case - ** function expressions are not supported. Function expressions are - ** only supported when extracting values to compare with sqlite_stat4 - ** records. - ** - ** It may also be that this function expression is an argument passed - ** to another function expression. As in "f2(...)" within the query: - ** - ** SELECT * FROM tbl WHERE tbl.c = f1(0, f2(...), 1); - ** - ** For now, extracting the value of "f1(...)" is not supported either. - */ - if( pCtx==0 ) return SQLITE_OK; - - assert( (p->flags & (EP_TokenOnly|EP_Reduced))==0 ); - pList = p->x.pList; - if( pList ) nVal = pList->nExpr; + if( (p->flags & EP_TokenOnly)==0 ){ + pList = p->x.pList; + if( pList ) nVal = pList->nExpr; + } nName = sqlite3Strlen30(p->u.zToken); pFunc = sqlite3FindFunction(db, p->u.zToken, nName, nVal, enc, 0); assert( pFunc ); @@ -1228,7 +1211,7 @@ static int valueFromFunction( pFunc->xFunc(&ctx, nVal, apVal); if( ctx.isError ){ rc = ctx.isError; - sqlite3ErrorMsg(pCtx->pParse, "%s", sqlite3_value_text(pVal)); + if( pCtx ) sqlite3ErrorMsg(pCtx->pParse, "%s", sqlite3_value_text(pVal)); }else{ sqlite3ValueApplyAffinity(pVal, aff, SQLITE_UTF8); if( rc==SQLITE_OK ){ From 0a0d0560aba40e958d1a4d801041f34120f97fc9 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 12 Mar 2015 05:08:34 +0000 Subject: [PATCH 07/63] Improve the text on one of the opcode documentation comments in vdbe.c. FossilOrigin-Name: 08958f57970d2346f3e98e62225e2b5d351d12d8 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/vdbe.c | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index abbbe02140..eb1ce5769c 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Expand\sthe\smulti-process\stest\scases\sto\srepeat\seach\scase\s20\stimes\sand\nto\srepeat\stests\susing\sdifferent\sjournal\smodes. -D 2015-03-11T14:34:38.239 +C Improve\sthe\stext\son\sone\sof\sthe\sopcode\sdocumentation\scomments\sin\svdbe.c. +D 2015-03-12T05:08:34.697 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 94cbc2115075b1a562a2a702c29ba48e74f85d34 +F src/vdbe.c a2725107658fd9572637e8e09d46dcfe851edb96 F src/vdbe.h 6fc69d9c5e146302c56e163cb4b31d1ee64a18c3 F src/vdbeInt.h bb56fd199d8af1a2c1b9639ee2f70724b4338e3a F src/vdbeapi.c dac0d0d8009a8aa549cd77d9c29da44c0344f0c4 @@ -1241,7 +1241,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 8d0b11c96e15556dd65ced05708a832aef134e69 -R 2327229d01e481a57e92de598065db5c +P a2715b049a86555990abccc7aa363c524ddb9982 +R 1bec88e395839df1ba1894bf7660872a U drh -Z cd1fd5866edba6a7b1ae8e17fb546b84 +Z 0eea53c05ab1bdce3a6e00e90246f492 diff --git a/manifest.uuid b/manifest.uuid index 57b677aa08..8c4aa9928d 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -a2715b049a86555990abccc7aa363c524ddb9982 \ No newline at end of file +08958f57970d2346f3e98e62225e2b5d351d12d8 \ No newline at end of file diff --git a/src/vdbe.c b/src/vdbe.c index f81bfa8a79..b67a3e766c 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -1517,7 +1517,7 @@ arithmetic_result_is_null: ** ** The interface used by the implementation of the aforementioned functions ** to retrieve the collation sequence set by this opcode is not available -** publicly, only to user functions defined in func.c. +** publicly. Only built-in functions have access to this feature. */ case OP_CollSeq: { assert( pOp->p4type==P4_COLLSEQ ); From a9e03b1b82312b2b99c0b6b443c4a09c8dd70e05 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 12 Mar 2015 06:46:52 +0000 Subject: [PATCH 08/63] The valueFromFunction() routine is better able to handle OOM errors. Omit unreachable branches. FossilOrigin-Name: 8fb6bd9be59d6b04e922d7b246aaefd4851539b6 --- manifest | 18 +++++++++--------- manifest.uuid | 2 +- src/func.c | 4 +++- src/vdbeapi.c | 34 ++++++++++++++++++++++++++-------- src/vdbemem.c | 11 ++++++----- 5 files changed, 45 insertions(+), 24 deletions(-) diff --git a/manifest b/manifest index 421022d674..1dc1a5dfbc 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Allow\sthe\sdefault\svalue\sfor\scolumns\sadded\susing\sALTER\sTABLE\sADD\sCOLUMN\sto\sbe\sa\sfunction\sin\sexisting\sschemas\sloaded\sfrom\sdisk.\sBut\sprevent\sthis\sversion\sof\sSQLite\sfrom\sbeing\sused\sto\screate\ssuch\sa\scolumn. -D 2015-03-11T20:59:42.115 +C The\svalueFromFunction()\sroutine\sis\sbetter\sable\sto\shandle\sOOM\serrors.\nOmit\sunreachable\sbranches. +D 2015-03-12T06:46:52.204 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -185,7 +185,7 @@ F src/delete.c 37964e6c1d73ff49cbea9ff690c9605fb15f600e F src/expr.c 3ef111b88ae2941b84b6b6ea4be8d501ba1af0cb F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb F src/fkey.c e0444b61bed271a76840cbe6182df93a9baa3f12 -F src/func.c 44512c557d6d4a40e51f3980c5854ae3e92862d6 +F src/func.c 1414c24c873c48796ad45942257a179a423ba42f F src/global.c 4f77cadbc5427d00139ba43d0f3979804cbb700e F src/hash.c 4263fbc955f26c2e8cdc0cf214bc42435aa4e4f5 F src/hash.h c8f3c31722cf3277d03713909761e152a5b81094 @@ -296,10 +296,10 @@ F src/vacuum.c 9460b9de7b2d4e34b0d374894aa6c8a0632be8ec F src/vdbe.c 94cbc2115075b1a562a2a702c29ba48e74f85d34 F src/vdbe.h 6fc69d9c5e146302c56e163cb4b31d1ee64a18c3 F src/vdbeInt.h bb56fd199d8af1a2c1b9639ee2f70724b4338e3a -F src/vdbeapi.c 5c207659c8a57c12c3f77a8fb97544e032fc2f14 +F src/vdbeapi.c da6551c9a9b9272f9cf7c776a09302ce9ca691d3 F src/vdbeaux.c 97911edb61074b871ec4aa2d6bb779071643dee5 F src/vdbeblob.c 4f2e8e075d238392df98c5e03a64342465b03f90 -F src/vdbemem.c 85dd9cb7a98717ad821d388c10053da2fe66f0f7 +F src/vdbemem.c ba461e1aa9a3b2ef0507748057dd1ab9b850ea45 F src/vdbesort.c 6d64c5448b64851b99931ede980addc3af70d5e2 F src/vdbetrace.c 7e4222955e07dd707a2f360c0eb73452be1cb010 F src/vtab.c 699f2b8d509cfe379c33dde33827875d5b030e01 @@ -1242,7 +1242,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P b7f1fc26d24012e1e7c7f6b3cc0b84ad2b02b8ad -R 3e606265a1ac491b0b1ab16052f58807 -U dan -Z 8153e0e591b223bdb869dacd2f48bbd5 +P ff868e22ca0393eaac417872a4c10738f0d7d970 +R 116c507ff65f2736c7022117ecad1fa2 +U drh +Z e8a2ef91ffc822055ee072f19f53dce6 diff --git a/manifest.uuid b/manifest.uuid index 906c7ad764..83d9b81077 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ff868e22ca0393eaac417872a4c10738f0d7d970 \ No newline at end of file +8fb6bd9be59d6b04e922d7b246aaefd4851539b6 \ No newline at end of file diff --git a/src/func.c b/src/func.c index d917bdbec3..782a240884 100644 --- a/src/func.c +++ b/src/func.c @@ -22,7 +22,9 @@ ** Return the collating function associated with a function. */ static CollSeq *sqlite3GetFuncCollSeq(sqlite3_context *context){ - VdbeOp *pOp = &context->pVdbe->aOp[context->iOp-1]; + VdbeOp *pOp; + assert( context->pVdbe!=0 ); + pOp = &context->pVdbe->aOp[context->iOp-1]; assert( pOp->opcode==OP_CollSeq ); assert( pOp->p4type==P4_COLLSEQ ); return pOp->p4.pColl; diff --git a/src/vdbeapi.c b/src/vdbeapi.c index fc3d60f20b..42cc715d7c 100644 --- a/src/vdbeapi.c +++ b/src/vdbeapi.c @@ -633,17 +633,27 @@ sqlite3 *sqlite3_context_db_handle(sqlite3_context *p){ } /* -** Return the current time for a statement +** Return the current time for a statement. If the current time +** is requested more than once within the same run of a single prepared +** statement, the exact same time is returned for each invocation regardless +** of the amount of time that elapses between invocations. In other words, +** the time returned is always the time of the first call. */ sqlite3_int64 sqlite3StmtCurrentTime(sqlite3_context *p){ - Vdbe *v = p->pVdbe; - sqlite3_int64 iTime = 0; int rc; - if( v && v->iCurrentTime ) return v->iCurrentTime; - rc = sqlite3OsCurrentTimeInt64(p->pOut->db->pVfs, &iTime); - if( rc ) return 0; - if( v ) v->iCurrentTime = iTime; - return iTime; + sqlite3_int64 iTime = 0; +#ifndef SQLITE_ENABLE_STAT3_OR_STAT4 + sqlite3_int64 *piTime = &iTime; + assert( p->pVdbe!=0 ); +#else + sqlite3_int64 *piTime = p->pVdbe!=0 ? &p->pVdbe->iCurrentTime : &iTime; + if( *piTime==0 ) +#endif + { + rc = sqlite3OsCurrentTimeInt64(p->pOut->db->pVfs, piTime); + if( rc ) *piTime = 0; + } + return *piTime; } /* @@ -713,7 +723,11 @@ void *sqlite3_get_auxdata(sqlite3_context *pCtx, int iArg){ AuxData *pAuxData; assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) ); +#if SQLITE_ENABLE_STAT3_OR_STAT4 if( pCtx->pVdbe==0 ) return 0; +#else + assert( pCtx->pVdbe!=0 ); +#endif for(pAuxData=pCtx->pVdbe->pAuxData; pAuxData; pAuxData=pAuxData->pNext){ if( pAuxData->iOp==pCtx->iOp && pAuxData->iArg==iArg ) break; } @@ -737,7 +751,11 @@ void sqlite3_set_auxdata( assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) ); if( iArg<0 ) goto failed; +#ifdef SQLITE_ENABLE_STAT3_OR_STAT4 if( pVdbe==0 ) goto failed; +#else + assert( pVdbe!=0 ); +#endif for(pAuxData=pVdbe->pAuxData; pAuxData; pAuxData=pAuxData->pNext){ if( pAuxData->iOp==pCtx->iOp && pAuxData->iArg==iArg ) break; diff --git a/src/vdbemem.c b/src/vdbemem.c index 269afe148c..8b23d678ea 100644 --- a/src/vdbemem.c +++ b/src/vdbemem.c @@ -1194,8 +1194,7 @@ static int valueFromFunction( } for(i=0; ia[i].pExpr, enc, aff, &apVal[i]); - if( apVal[i]==0 ) goto value_from_function_out; - assert( rc==SQLITE_OK ); + if( apVal[i]==0 || rc!=SQLITE_OK ) goto value_from_function_out; } } @@ -1227,10 +1226,12 @@ static int valueFromFunction( if( pCtx==0 ) sqlite3ValueFree(pVal); pVal = 0; } - for(i=0; i Date: Thu, 12 Mar 2015 18:38:51 +0000 Subject: [PATCH 09/63] If an error occurs in the compile-time evaluation of an application-defined function, then propagate back out the exact error code, not just the generic SQLITE_ERROR. FossilOrigin-Name: 93f42586cc9db63c5a4599ce06630e60204a5bc9 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/vdbemem.c | 5 ++++- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 1dc1a5dfbc..9c102ed96c 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C The\svalueFromFunction()\sroutine\sis\sbetter\sable\sto\shandle\sOOM\serrors.\nOmit\sunreachable\sbranches. -D 2015-03-12T06:46:52.204 +C If\san\serror\soccurs\sin\sthe\scompile-time\sevaluation\sof\san\sapplication-defined\nfunction,\sthen\spropagate\sback\sout\sthe\sexact\serror\scode,\snot\sjust\sthe\ngeneric\sSQLITE_ERROR. +D 2015-03-12T18:38:51.338 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -299,7 +299,7 @@ F src/vdbeInt.h bb56fd199d8af1a2c1b9639ee2f70724b4338e3a F src/vdbeapi.c da6551c9a9b9272f9cf7c776a09302ce9ca691d3 F src/vdbeaux.c 97911edb61074b871ec4aa2d6bb779071643dee5 F src/vdbeblob.c 4f2e8e075d238392df98c5e03a64342465b03f90 -F src/vdbemem.c ba461e1aa9a3b2ef0507748057dd1ab9b850ea45 +F src/vdbemem.c 981fa5ac239d6a646b5720779844d991277dcd07 F src/vdbesort.c 6d64c5448b64851b99931ede980addc3af70d5e2 F src/vdbetrace.c 7e4222955e07dd707a2f360c0eb73452be1cb010 F src/vtab.c 699f2b8d509cfe379c33dde33827875d5b030e01 @@ -1242,7 +1242,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P ff868e22ca0393eaac417872a4c10738f0d7d970 -R 116c507ff65f2736c7022117ecad1fa2 +P 8fb6bd9be59d6b04e922d7b246aaefd4851539b6 +R 46972b8481418c9af660c8cf08bd0f3b U drh -Z e8a2ef91ffc822055ee072f19f53dce6 +Z f07316ba19973dffcb9b3c2ed85bb043 diff --git a/manifest.uuid b/manifest.uuid index 83d9b81077..b430dfd546 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -8fb6bd9be59d6b04e922d7b246aaefd4851539b6 \ No newline at end of file +93f42586cc9db63c5a4599ce06630e60204a5bc9 \ No newline at end of file diff --git a/src/vdbemem.c b/src/vdbemem.c index 8b23d678ea..353bfa7255 100644 --- a/src/vdbemem.c +++ b/src/vdbemem.c @@ -1210,7 +1210,10 @@ static int valueFromFunction( pFunc->xFunc(&ctx, nVal, apVal); if( ctx.isError ){ rc = ctx.isError; - if( pCtx ) sqlite3ErrorMsg(pCtx->pParse, "%s", sqlite3_value_text(pVal)); + if( pCtx ){ + sqlite3ErrorMsg(pCtx->pParse, "%s", sqlite3_value_text(pVal)); + pCtx->pParse->rc = rc; + } }else{ sqlite3ValueApplyAffinity(pVal, aff, SQLITE_UTF8); if( rc==SQLITE_OK ){ From 63c088e7835a81d9711b09424df43af87dc62d72 Mon Sep 17 00:00:00 2001 From: dan Date: Thu, 12 Mar 2015 19:12:30 +0000 Subject: [PATCH 10/63] Disable multiplexing of master-journal files in the test_multiplex.c module. FossilOrigin-Name: b8684df395b5585a9428417c2bfd076515560f19 --- manifest | 15 +++++---- manifest.uuid | 2 +- src/test_multiplex.c | 3 ++ test/crashM.test | 80 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 92 insertions(+), 8 deletions(-) create mode 100644 test/crashM.test diff --git a/manifest b/manifest index eb1ce5769c..7b21245301 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Improve\sthe\stext\son\sone\sof\sthe\sopcode\sdocumentation\scomments\sin\svdbe.c. -D 2015-03-12T05:08:34.697 +C Disable\smultiplexing\sof\smaster-journal\sfiles\sin\sthe\stest_multiplex.c\smodule. +D 2015-03-12T19:12:30.098 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -266,7 +266,7 @@ 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 61edf02530f7511a0529352cd8139ead3af4c401 +F src/test_multiplex.c 97813565daa7ee480abcc5dd1e9984ed1f71eb8c F src/test_multiplex.h c08e4e8f8651f0c5e0509b138ff4d5b43ed1f5d3 F src/test_mutex.c 293042d623ebba969160f471a82aa1551626454f F src/test_onefile.c 0396f220561f3b4eedc450cef26d40c593c69a25 @@ -442,6 +442,7 @@ F test/crash5.test 05dd3aa9dbb751a22d5cdaf22a9c49b6667aa219 F test/crash6.test 4c56f1e40d0291e1110790a99807aa875b1647ba F test/crash7.test 1a194c4900a255258cf94b7fcbfd29536db572df F test/crash8.test 61442a9964ab6b124fc5254e4258b45747842e6f +F test/crashM.test d95f59046fa749b0d0822edf18a717788c8f318d F test/crashtest1.c 09c1c7d728ccf4feb9e481671e29dda5669bbcc2 F test/createtab.test b5de160630b209c4b8925bdcbbaf48cc90b67fe8 F test/cse.test 277350a26264495e86b1785f34d2d0c8600e021c @@ -1241,7 +1242,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P a2715b049a86555990abccc7aa363c524ddb9982 -R 1bec88e395839df1ba1894bf7660872a -U drh -Z 0eea53c05ab1bdce3a6e00e90246f492 +P 08958f57970d2346f3e98e62225e2b5d351d12d8 +R 0a12f0c8ae987d613ddb45d39ab86f14 +U dan +Z 376d550a3accda483a2b851b4ef12904 diff --git a/manifest.uuid b/manifest.uuid index 8c4aa9928d..c810d416da 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -08958f57970d2346f3e98e62225e2b5d351d12d8 \ No newline at end of file +b8684df395b5585a9428417c2bfd076515560f19 \ No newline at end of file diff --git a/src/test_multiplex.c b/src/test_multiplex.c index dbd395d620..cd379f18f6 100644 --- a/src/test_multiplex.c +++ b/src/test_multiplex.c @@ -573,6 +573,9 @@ static int multiplexOpen( rc = pSubOpen->pMethods->xFileSize(pSubOpen, &sz); if( rc==SQLITE_OK && zName ){ int bExists; + if( flags & SQLITE_OPEN_MASTER_JOURNAL ){ + pGroup->bEnabled = 0; + }else if( sz==0 ){ if( flags & SQLITE_OPEN_MAIN_JOURNAL ){ /* If opening a main journal file and the first chunk is zero diff --git a/test/crashM.test b/test/crashM.test new file mode 100644 index 0000000000..de10c4589a --- /dev/null +++ b/test/crashM.test @@ -0,0 +1,80 @@ +# 2015 Mar 13 +# +# 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. +# +#*********************************************************************** +# +# Crash tests for the multiplex module with 8.3 filenames enabled. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix crashM + +ifcapable !crashtest||!8_3_names { + finish_test + return +} + +db close +sqlite3_shutdown +sqlite3_config_uri 1 + +foreach f [glob -nocomplain test1.* test2.*] { forcedelete $f } +sqlite3_multiplex_initialize "" 1 +sqlite3 db file:test1.db?8_3_names=1 +sqlite3_multiplex_control db main chunk_size [expr 64*1024] + +do_execsql_test 1.0 { + ATTACH 'file:test2.db?8_3_names=1' AS aux; + + CREATE TABLE t1(x, y); + CREATE INDEX t1x ON t1(x); + CREATE INDEX t1y ON t1(y); + + CREATE TABLE aux.t2(x, y); + CREATE INDEX aux.t2x ON t2(x); + CREATE INDEX aux.t2y ON t2(y); + + WITH s(a) AS ( + SELECT 1 UNION ALL SELECT a+1 FROM s WHERE a<1000 + ) + INSERT INTO t1 SELECT a, randomblob(500) FROM s; + + WITH s(a) AS ( + SELECT 1 UNION ALL SELECT a+1 FROM s WHERE a<1000 + ) + INSERT INTO t2 SELECT a, randomblob(500) FROM s; +} {} + +for {set i 0} {$i < 20} {incr i} { + do_test 2.$i.1 { + crashsql -delay 1 -file test1.db -opendb { + sqlite3_shutdown + sqlite3_config_uri 1 + sqlite3_multiplex_initialize crash 1 + sqlite3 db file:test1.db?8_3_names=1 + sqlite3_multiplex_control db main chunk_size [expr 64*1024] + } { + ATTACH 'file:test2.db?8_3_names=1' AS aux; + BEGIN; + UPDATE t1 SET y = randomblob(500) WHERE (x%10)==0; + UPDATE t2 SET y = randomblob(500) WHERE (x%10)==0; + COMMIT; + } + } {1 {child process exited abnormally}} + + do_execsql_test 2.$i.2 { + PRAGMA main.integrity_check; + PRAGMA aux.integrity_check; + } {ok ok} +} + +catch { db close } +sqlite3_multiplex_shutdown +finish_test From 96f4ad20fd9e7f3c5ecd59145cbe3dc8b7ef8465 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 12 Mar 2015 21:02:36 +0000 Subject: [PATCH 11/63] Always disallow functions as the DEFAULT of a column. Add assert()s and FossilOrigin-Name: a991bb1a9eb54bdbd45bd623e8b304bdfeb481a3 --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/alter.c | 7 ++++--- src/vdbeapi.c | 2 +- src/vdbemem.c | 30 ++++++++++++++++-------------- 5 files changed, 30 insertions(+), 27 deletions(-) diff --git a/manifest b/manifest index 9c102ed96c..06dd27ad1c 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C If\san\serror\soccurs\sin\sthe\scompile-time\sevaluation\sof\san\sapplication-defined\nfunction,\sthen\spropagate\sback\sout\sthe\sexact\serror\scode,\snot\sjust\sthe\ngeneric\sSQLITE_ERROR. -D 2015-03-12T18:38:51.338 +C Always\sdisallow\sfunctions\sas\sthe\sDEFAULT\sof\sa\scolumn.\s\sAdd\sassert()s\sand +D 2015-03-12T21:02:36.947 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -166,7 +166,7 @@ F spec.template 86a4a43b99ebb3e75e6b9a735d5fd293a24e90ca F sqlite.pc.in 42b7bf0d02e08b9e77734a47798d1a55a9e0716b F sqlite3.1 fc7ad8990fc8409983309bb80de8c811a7506786 F sqlite3.pc.in 48fed132e7cb71ab676105d2a4dc77127d8c1f3a -F src/alter.c 809313ddb2dea2a8cdd2d0da944d6a859e3657dc +F src/alter.c d23d6b6991f66b383934f137fd4384d93fb98c81 F src/analyze.c 91540f835163d5369ccbae78e2e6c74d0dd53c1d F src/attach.c 880f9b8641a829c563e52dd13c452ce457ae4dd8 F src/auth.c b56c78ebe40a2110fd361379f7e8162d23f92240 @@ -296,10 +296,10 @@ F src/vacuum.c 9460b9de7b2d4e34b0d374894aa6c8a0632be8ec F src/vdbe.c 94cbc2115075b1a562a2a702c29ba48e74f85d34 F src/vdbe.h 6fc69d9c5e146302c56e163cb4b31d1ee64a18c3 F src/vdbeInt.h bb56fd199d8af1a2c1b9639ee2f70724b4338e3a -F src/vdbeapi.c da6551c9a9b9272f9cf7c776a09302ce9ca691d3 +F src/vdbeapi.c 1295402cabda4473ddee24955c8f7039514497e4 F src/vdbeaux.c 97911edb61074b871ec4aa2d6bb779071643dee5 F src/vdbeblob.c 4f2e8e075d238392df98c5e03a64342465b03f90 -F src/vdbemem.c 981fa5ac239d6a646b5720779844d991277dcd07 +F src/vdbemem.c d52fa9f3bcf75d27d7b7846d81ee7898829c763d F src/vdbesort.c 6d64c5448b64851b99931ede980addc3af70d5e2 F src/vdbetrace.c 7e4222955e07dd707a2f360c0eb73452be1cb010 F src/vtab.c 699f2b8d509cfe379c33dde33827875d5b030e01 @@ -1242,7 +1242,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 8fb6bd9be59d6b04e922d7b246aaefd4851539b6 -R 46972b8481418c9af660c8cf08bd0f3b +P 93f42586cc9db63c5a4599ce06630e60204a5bc9 +R b3d39823270cf35170812e8663c1c07d U drh -Z f07316ba19973dffcb9b3c2ed85bb043 +Z b97bd037eac2f46713c8bf83215d5d81 diff --git a/manifest.uuid b/manifest.uuid index b430dfd546..22a8fe8715 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -93f42586cc9db63c5a4599ce06630e60204a5bc9 \ No newline at end of file +a991bb1a9eb54bdbd45bd623e8b304bdfeb481a3 \ No newline at end of file diff --git a/src/alter.c b/src/alter.c index 908b251f06..03605b25aa 100644 --- a/src/alter.c +++ b/src/alter.c @@ -690,9 +690,10 @@ void sqlite3AlterFinishAddColumn(Parse *pParse, Token *pColDef){ */ if( pDflt ){ sqlite3_value *pVal = 0; - if( pDflt->op!=TK_FUNCTION - && sqlite3ValueFromExpr(db, pDflt, SQLITE_UTF8, SQLITE_AFF_NONE, &pVal) - ){ + int rc; + rc = sqlite3ValueFromExpr(db, pDflt, SQLITE_UTF8, SQLITE_AFF_NONE, &pVal); + assert( rc==SQLITE_OK || rc==SQLITE_NOMEM ); + if( rc!=SQLITE_OK ){ db->mallocFailed = 1; return; } diff --git a/src/vdbeapi.c b/src/vdbeapi.c index 42cc715d7c..ae53d93006 100644 --- a/src/vdbeapi.c +++ b/src/vdbeapi.c @@ -370,7 +370,7 @@ void sqlite3_result_error_code(sqlite3_context *pCtx, int errCode){ pCtx->isError = errCode; pCtx->fErrorOrAux = 1; #ifdef SQLITE_DEBUG - pCtx->pVdbe->rcApp = errCode; + if( pCtx->pVdbe ) pCtx->pVdbe->rcApp = errCode; #endif if( pCtx->pOut->flags & MEM_Null ){ sqlite3VdbeMemSetStr(pCtx->pOut, sqlite3ErrStr(errCode), -1, diff --git a/src/vdbemem.c b/src/vdbemem.c index 353bfa7255..0e9bb873ae 100644 --- a/src/vdbemem.c +++ b/src/vdbemem.c @@ -1090,7 +1090,7 @@ struct ValueNewStat4Ctx { ** Otherwise, if the second argument is non-zero, then this function is ** being called indirectly by sqlite3Stat4ProbeSetValue(). If it has not ** already been allocated, allocate the UnpackedRecord structure that -** that function will return to its caller here. Then return a pointer +** that function will return to its caller here. Then return a pointer to ** an sqlite3_value within the UnpackedRecord.a[] array. */ static sqlite3_value *valueNew(sqlite3 *db, struct ValueNewStat4Ctx *p){ @@ -1173,10 +1173,10 @@ static int valueFromFunction( ExprList *pList = 0; /* Function arguments */ int i; /* Iterator variable */ - if( (p->flags & EP_TokenOnly)==0 ){ - pList = p->x.pList; - if( pList ) nVal = pList->nExpr; - } + assert( pCtx!=0 ); + assert( (p->flags & EP_TokenOnly)==0 ); + pList = p->x.pList; + if( pList ) nVal = pList->nExpr; nName = sqlite3Strlen30(p->u.zToken); pFunc = sqlite3FindFunction(db, p->u.zToken, nName, nVal, enc, 0); assert( pFunc ); @@ -1210,15 +1210,12 @@ static int valueFromFunction( pFunc->xFunc(&ctx, nVal, apVal); if( ctx.isError ){ rc = ctx.isError; - if( pCtx ){ - sqlite3ErrorMsg(pCtx->pParse, "%s", sqlite3_value_text(pVal)); - pCtx->pParse->rc = rc; - } + sqlite3ErrorMsg(pCtx->pParse, "%s", sqlite3_value_text(pVal)); + pCtx->pParse->rc = rc; }else{ sqlite3ValueApplyAffinity(pVal, aff, SQLITE_UTF8); - if( rc==SQLITE_OK ){ - rc = sqlite3VdbeChangeEncoding(pVal, enc); - } + assert( rc==SQLITE_OK ); + rc = sqlite3VdbeChangeEncoding(pVal, enc); if( rc==SQLITE_OK && sqlite3VdbeMemTooBig(pVal) ){ rc = SQLITE_TOOBIG; } @@ -1226,7 +1223,6 @@ static int valueFromFunction( value_from_function_out: if( rc!=SQLITE_OK ){ - if( pCtx==0 ) sqlite3ValueFree(pVal); pVal = 0; } if( apVal ){ @@ -1275,6 +1271,12 @@ static int valueFromExpr( while( (op = pExpr->op)==TK_UPLUS ) pExpr = pExpr->pLeft; if( NEVER(op==TK_REGISTER) ) op = pExpr->op2; + /* Compressed expressions only appear when parsing the DEFAULT clause + ** on a table column definition, and hence only when pCtx==0. This + ** check ensures that an EP_TokenOnly expression is never passed down + ** into valueFromFunction(). */ + assert( (pExpr->flags & EP_TokenOnly)==0 || pCtx==0 ); + if( op==TK_CAST ){ u8 aff = sqlite3AffinityType(pExpr->u.zToken,0); rc = valueFromExpr(db, pExpr->pLeft, enc, aff, ppVal, pCtx); @@ -1351,7 +1353,7 @@ static int valueFromExpr( } #endif - else if( op==TK_FUNCTION ){ + else if( op==TK_FUNCTION && pCtx!=0 ){ rc = valueFromFunction(db, pExpr, enc, affinity, &pVal, pCtx); } From 3df79a9a1fa48c78b0a5d621791de6ad51c46701 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 12 Mar 2015 23:48:27 +0000 Subject: [PATCH 12/63] Fix the "now" option for date-time functions for cases when STAT4 is disabled. FossilOrigin-Name: 3ac1f6a3cf1a8fd3ab1ca96b2564c13c4b8d2234 --- manifest | 15 +++++++-------- manifest.uuid | 2 +- src/vdbeapi.c | 7 +++---- test/date.test | 2 +- 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/manifest b/manifest index 3fe0a0e7b9..b5061eb40e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C When\sSTAT4\sis\senabled,\sallow\sprobes\sof\sthe\sSTAT4\stable\susing\sthe\svalue\nof\sconstant\sfunctions\scomputed\sat\scompile-time. -D 2015-03-12T21:22:08.630 +C Fix\sthe\s"now"\soption\sfor\sdate-time\sfunctions\sfor\scases\swhen\sSTAT4\sis\sdisabled. +D 2015-03-12T23:48:27.096 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -296,7 +296,7 @@ F src/vacuum.c 9460b9de7b2d4e34b0d374894aa6c8a0632be8ec F src/vdbe.c a2725107658fd9572637e8e09d46dcfe851edb96 F src/vdbe.h 6fc69d9c5e146302c56e163cb4b31d1ee64a18c3 F src/vdbeInt.h bb56fd199d8af1a2c1b9639ee2f70724b4338e3a -F src/vdbeapi.c 1295402cabda4473ddee24955c8f7039514497e4 +F src/vdbeapi.c 583d56b129dd27f12bed518270de9ebe521e6a75 F src/vdbeaux.c 97911edb61074b871ec4aa2d6bb779071643dee5 F src/vdbeblob.c 4f2e8e075d238392df98c5e03a64342465b03f90 F src/vdbemem.c d52fa9f3bcf75d27d7b7846d81ee7898829c763d @@ -448,7 +448,7 @@ F test/crashtest1.c 09c1c7d728ccf4feb9e481671e29dda5669bbcc2 F test/createtab.test b5de160630b209c4b8925bdcbbaf48cc90b67fe8 F test/cse.test 277350a26264495e86b1785f34d2d0c8600e021c F test/ctime.test 7bd009071e242aac4f18521581536b652b789a47 -F test/date.test 42973251b9429f2c41b77eb98a7b0b0ba2d3b2c0 +F test/date.test 6b7c1261805155be2c6a3ee073529ff75bc773f0 F test/dbstatus.test 8de104bb5606f19537d23cd553b41349b5ab1204 F test/dbstatus2.test 10418e62b3db5dca070f0c3eef3ea13946f339c2 F test/default.test 0cb49b1c315a0d81c81d775e407f66906a2a604d @@ -1243,8 +1243,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P b8684df395b5585a9428417c2bfd076515560f19 a991bb1a9eb54bdbd45bd623e8b304bdfeb481a3 -R 8dac3425ac00e8cb91887f6600a4a803 -T +closed a991bb1a9eb54bdbd45bd623e8b304bdfeb481a3 +P 0f250957cd82be63e44eb99be6cc10760f4fdfc4 +R d3144e9ce0f6932ade646e074c4a6fee U drh -Z f8e2642fd9bb84da1db25f0a4d97336b +Z 40daa56c14064d43d4b007995d358cfd diff --git a/manifest.uuid b/manifest.uuid index 062ef8e236..d23e56ec10 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -0f250957cd82be63e44eb99be6cc10760f4fdfc4 \ No newline at end of file +3ac1f6a3cf1a8fd3ab1ca96b2564c13c4b8d2234 \ No newline at end of file diff --git a/src/vdbeapi.c b/src/vdbeapi.c index ae53d93006..e03640dfbd 100644 --- a/src/vdbeapi.c +++ b/src/vdbeapi.c @@ -641,15 +641,14 @@ sqlite3 *sqlite3_context_db_handle(sqlite3_context *p){ */ sqlite3_int64 sqlite3StmtCurrentTime(sqlite3_context *p){ int rc; - sqlite3_int64 iTime = 0; #ifndef SQLITE_ENABLE_STAT3_OR_STAT4 - sqlite3_int64 *piTime = &iTime; + sqlite3_int64 *piTime = &p->pVdbe->iCurrentTime; assert( p->pVdbe!=0 ); #else + sqlite3_int64 iTime = 0; sqlite3_int64 *piTime = p->pVdbe!=0 ? &p->pVdbe->iCurrentTime : &iTime; - if( *piTime==0 ) #endif - { + if( *piTime==0 ){ rc = sqlite3OsCurrentTimeInt64(p->pOut->db->pVfs, piTime); if( rc ) *piTime = 0; } diff --git a/test/date.test b/test/date.test index b1d1c677c1..51c8ff378b 100644 --- a/test/date.test +++ b/test/date.test @@ -540,7 +540,7 @@ proc sleeper {} {after 100} do_test date-15.1 { db func sleeper sleeper db eval { - SELECT c - a FROM (SELECT julianday('now') AS a, + SELECT c, a, c - a FROM (SELECT julianday('now') AS a, sleeper(), julianday('now') AS c); } } {0.0} From e9b9f7599a1ba4cafc68ebd120824181b1c96752 Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 13 Mar 2015 00:11:09 +0000 Subject: [PATCH 13/63] Remove debugging logic accidently included in the previous check-in. FossilOrigin-Name: 2887fb38ffc28712c34028cd38db2b7993d864eb --- manifest | 12 ++++++------ manifest.uuid | 2 +- test/date.test | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index b5061eb40e..1a145c5348 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sthe\s"now"\soption\sfor\sdate-time\sfunctions\sfor\scases\swhen\sSTAT4\sis\sdisabled. -D 2015-03-12T23:48:27.096 +C Remove\sdebugging\slogic\saccidently\sincluded\sin\sthe\sprevious\scheck-in. +D 2015-03-13T00:11:09.762 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -448,7 +448,7 @@ F test/crashtest1.c 09c1c7d728ccf4feb9e481671e29dda5669bbcc2 F test/createtab.test b5de160630b209c4b8925bdcbbaf48cc90b67fe8 F test/cse.test 277350a26264495e86b1785f34d2d0c8600e021c F test/ctime.test 7bd009071e242aac4f18521581536b652b789a47 -F test/date.test 6b7c1261805155be2c6a3ee073529ff75bc773f0 +F test/date.test 42973251b9429f2c41b77eb98a7b0b0ba2d3b2c0 F test/dbstatus.test 8de104bb5606f19537d23cd553b41349b5ab1204 F test/dbstatus2.test 10418e62b3db5dca070f0c3eef3ea13946f339c2 F test/default.test 0cb49b1c315a0d81c81d775e407f66906a2a604d @@ -1243,7 +1243,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 0f250957cd82be63e44eb99be6cc10760f4fdfc4 -R d3144e9ce0f6932ade646e074c4a6fee +P 3ac1f6a3cf1a8fd3ab1ca96b2564c13c4b8d2234 +R f96af88025cc91d1b5a757f614ed39bf U drh -Z 40daa56c14064d43d4b007995d358cfd +Z e7218e6f8a6b14017f98ae01eb2e9668 diff --git a/manifest.uuid b/manifest.uuid index d23e56ec10..e5cf9c334d 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -3ac1f6a3cf1a8fd3ab1ca96b2564c13c4b8d2234 \ No newline at end of file +2887fb38ffc28712c34028cd38db2b7993d864eb \ No newline at end of file diff --git a/test/date.test b/test/date.test index 51c8ff378b..b1d1c677c1 100644 --- a/test/date.test +++ b/test/date.test @@ -540,7 +540,7 @@ proc sleeper {} {after 100} do_test date-15.1 { db func sleeper sleeper db eval { - SELECT c, a, c - a FROM (SELECT julianday('now') AS a, + SELECT c - a FROM (SELECT julianday('now') AS a, sleeper(), julianday('now') AS c); } } {0.0} From 3df305925288e177ff386e63dbf32ff2110030a0 Mon Sep 17 00:00:00 2001 From: dan Date: Fri, 13 Mar 2015 08:31:54 +0000 Subject: [PATCH 14/63] Extra tests for commit [0f250957]. FossilOrigin-Name: 5aa522dcb9bfa18d49683f7cc889516984e2bcd2 --- manifest | 24 +++++++++++----------- manifest.uuid | 2 +- src/tclsqlite.c | 37 ++++++++++++++++++++++++---------- src/test_func.c | 17 +++++++++++++++- src/vdbemem.c | 4 +++- test/analyzeF.test | 49 +++++++++++++++++++++++++++++++++++++++++++++ test/mallocK.test | 27 +++++++++++++++++++++++++ test/tclsqlite.test | 2 +- 8 files changed, 135 insertions(+), 27 deletions(-) diff --git a/manifest b/manifest index 1a145c5348..fd821ade74 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Remove\sdebugging\slogic\saccidently\sincluded\sin\sthe\sprevious\scheck-in. -D 2015-03-13T00:11:09.762 +C Extra\stests\sfor\scommit\s[0f250957]. +D 2015-03-13T08:31:54.154 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -239,7 +239,7 @@ F src/sqliteInt.h fae682c2b4dfbe489b134d74521c41c088f16ab1 F src/sqliteLimit.h 216557999cb45f2e3578ed53ebefe228d779cb46 F src/status.c 81712116e826b0089bb221b018929536b2b5406f F src/table.c e7a09215315a978057fb42c640f890160dbcc45e -F src/tclsqlite.c b290774586f022e16e04ba8ed2f0b8edd86b5b77 +F src/tclsqlite.c fa72a7c5278662357c105ba7925c1d0972506ff9 F src/test1.c 90fbedce75330d48d99eadb7d5f4223e86969585 F src/test2.c 577961fe48961b2f2e5c8b56ee50c3f459d3359d F src/test3.c 64d2afdd68feac1bb5e2ffb8226c8c639f798622 @@ -258,7 +258,7 @@ F src/test_config.c c2d3ff6c129d50183900c7eff14158ff7e9b3f03 F src/test_demovfs.c 0de72c2c89551629f58486fde5734b7d90758852 F src/test_devsym.c e7498904e72ba7491d142d5c83b476c4e76993bc F src/test_fs.c ced436e3d4b8e4681328409b8081051ce614e28f -F src/test_func.c 14e543ae4d905ee31dc322b2f8d31bfac1769d45 +F src/test_func.c f1ac201465472e76a73e2f3695c3553c63e7322a F src/test_hexio.c abfdecb6fa58c354623978efceb088ca18e379cd F src/test_init.c 66b33120ffe9cd853b5a905ec850d51151337b32 F src/test_intarray.c 6c610a21ab8edde85a3a2c7f2b069244ecf4d834 @@ -299,7 +299,7 @@ F src/vdbeInt.h bb56fd199d8af1a2c1b9639ee2f70724b4338e3a F src/vdbeapi.c 583d56b129dd27f12bed518270de9ebe521e6a75 F src/vdbeaux.c 97911edb61074b871ec4aa2d6bb779071643dee5 F src/vdbeblob.c 4f2e8e075d238392df98c5e03a64342465b03f90 -F src/vdbemem.c d52fa9f3bcf75d27d7b7846d81ee7898829c763d +F src/vdbemem.c 78aef62d0298e15485cb5a429c912c9c3ed054b8 F src/vdbesort.c 6d64c5448b64851b99931ede980addc3af70d5e2 F src/vdbetrace.c 7e4222955e07dd707a2f360c0eb73452be1cb010 F src/vtab.c 699f2b8d509cfe379c33dde33827875d5b030e01 @@ -333,7 +333,7 @@ F test/analyzeB.test 8bf35ee0a548aea831bf56762cb8e7fdb1db083d F test/analyzeC.test 555a6cc388b9818b6eda6df816f01ce0a75d3a93 F test/analyzeD.test 08f9d0bee4e118a66fff3a32d02dbe0ee0a2b594 F test/analyzeE.test 8684e8ac5722fb97c251887ad97e5d496a98af1d -F test/analyzeF.test 299a47183c648d8ad92671f313def8fd7cb09875 +F test/analyzeF.test 7ccd7a04f7d3061bde1a8a4dacc4792edccf6bf2 F test/async.test 1d0e056ba1bb9729283a0f22718d3a25e82c277b F test/async2.test c0a9bd20816d7d6a2ceca7b8c03d3d69c28ffb8b F test/async3.test d73a062002376d7edc1fe3edff493edbec1fc2f7 @@ -727,7 +727,7 @@ F test/mallocG.test 0ff91b65c50bdaba680fb75d87fe4ad35bb7934f F test/mallocH.test 79b65aed612c9b3ed2dcdaa727c85895fd1bfbdb F test/mallocI.test a88c2b9627c8506bf4703d8397420043a786cdb6 F test/mallocJ.test b5d1839da331d96223e5f458856f8ffe1366f62e -F test/mallocK.test 223cc80c870c80d4a9c2014e94133efdf0123f82 +F test/mallocK.test da01dcdd316767b8356741f8d33a23a06a23def5 F test/mallocL.test 252ddc7eb4fbf75364eab17b938816085ff1fc17 F test/malloc_common.tcl 3663f9001ce3e29bbaa9677ffe15cd468e3ec7e3 F test/manydb.test 28385ae2087967aa05c38624cec7d96ec74feb3e @@ -908,7 +908,7 @@ F test/sysfault.test fa776e60bf46bdd3ae69f0b73e46ee3977a58ae6 F test/table.test 06271d61eb13871490d38168433c1ef3dd82bb2a F test/tableapi.test 2674633fa95d80da917571ebdd759a14d9819126 F test/tableopts.test dba698ba97251017b7c80d738c198d39ab747930 -F test/tclsqlite.test 37a61c2da7e3bfe3b8c1a2867199f6b860df5d43 +F test/tclsqlite.test 7fb866443c7deceed22b63948ccd6f76b52ad054 F test/tempdb.test 19d0f66e2e3eeffd68661a11c83ba5e6ace9128c F test/temptable.test d2c9b87a54147161bcd1822e30c1d1cd891e5b30 F test/temptrigger.test 8ec228b0db5d7ebc4ee9b458fc28cb9e7873f5e1 @@ -1243,7 +1243,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 3ac1f6a3cf1a8fd3ab1ca96b2564c13c4b8d2234 -R f96af88025cc91d1b5a757f614ed39bf -U drh -Z e7218e6f8a6b14017f98ae01eb2e9668 +P 2887fb38ffc28712c34028cd38db2b7993d864eb +R b89c9ce97b230db0ae63022a487b40cc +U dan +Z ccca41f9c448bc442b12b8c9fe5620ec diff --git a/manifest.uuid b/manifest.uuid index e5cf9c334d..f5b9305905 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -2887fb38ffc28712c34028cd38db2b7993d864eb \ No newline at end of file +5aa522dcb9bfa18d49683f7cc889516984e2bcd2 \ No newline at end of file diff --git a/src/tclsqlite.c b/src/tclsqlite.c index 549a410b28..710084b89e 100644 --- a/src/tclsqlite.c +++ b/src/tclsqlite.c @@ -2320,34 +2320,49 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){ } /* - ** $db function NAME [-argcount N] SCRIPT + ** $db function NAME [-argcount N] [-deterministic] SCRIPT ** ** Create a new SQL function called NAME. Whenever that function is ** called, invoke SCRIPT to evaluate the function. */ case DB_FUNCTION: { + int flags = SQLITE_UTF8; SqlFunc *pFunc; Tcl_Obj *pScript; char *zName; int nArg = -1; - if( objc==6 ){ - const char *z = Tcl_GetString(objv[3]); + int i; + if( objc<4 ){ + Tcl_WrongNumArgs(interp, 2, objv, "NAME ?SWITCHES? SCRIPT"); + return TCL_ERROR; + } + for(i=3; i<(objc-1); i++){ + const char *z = Tcl_GetString(objv[i]); int n = strlen30(z); if( n>2 && strncmp(z, "-argcount",n)==0 ){ - if( Tcl_GetIntFromObj(interp, objv[4], &nArg) ) return TCL_ERROR; + if( i==(objc-2) ){ + Tcl_AppendResult(interp, "option requires an argument: ", z, 0); + return TCL_ERROR; + } + if( Tcl_GetIntFromObj(interp, objv[i+1], &nArg) ) return TCL_ERROR; if( nArg<0 ){ Tcl_AppendResult(interp, "number of arguments must be non-negative", (char*)0); return TCL_ERROR; } + i++; + }else + if( n>2 && strncmp(z, "-deterministic",n)==0 ){ + flags |= SQLITE_DETERMINISTIC; + }else{ + Tcl_AppendResult(interp, "bad option \"", z, + "\": must be -argcount or -deterministic", 0 + ); + return TCL_ERROR; } - pScript = objv[5]; - }else if( objc!=4 ){ - Tcl_WrongNumArgs(interp, 2, objv, "NAME [-argcount N] SCRIPT"); - return TCL_ERROR; - }else{ - pScript = objv[3]; } + + pScript = objv[objc-1]; zName = Tcl_GetStringFromObj(objv[2], 0); pFunc = findSqlFunc(pDb, zName); if( pFunc==0 ) return TCL_ERROR; @@ -2357,7 +2372,7 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){ pFunc->pScript = pScript; Tcl_IncrRefCount(pScript); pFunc->useEvalObjv = safeToUseEvalObjv(interp, pScript); - rc = sqlite3_create_function(pDb->db, zName, nArg, SQLITE_UTF8, + rc = sqlite3_create_function(pDb->db, zName, nArg, flags, pFunc, tclSqlFunc, 0, 0); if( rc!=SQLITE_OK ){ rc = TCL_ERROR; diff --git a/src/test_func.c b/src/test_func.c index c7850631d7..2e34fa074e 100644 --- a/src/test_func.c +++ b/src/test_func.c @@ -600,12 +600,26 @@ static void test_decode( Tcl_DecrRefCount(pRet); } +/* +** The implementation of scalar SQL function "test_zeroblob()". This is +** similar to the built-in zeroblob() function, except that it does not +** check that the integer parameter is within range before passing it +** to sqlite3_result_zeroblob(). +*/ +static void test_zeroblob( + sqlite3_context *context, + int argc, + sqlite3_value **argv +){ + int nZero = sqlite3_value_int(argv[0]); + sqlite3_result_zeroblob(context, nZero); +} static int registerTestFunctions(sqlite3 *db){ static const struct { char *zName; signed char nArg; - unsigned char eTextRep; /* 1: UTF-16. 0: UTF-8 */ + unsigned int eTextRep; /* 1: UTF-16. 0: UTF-8 */ void (*xFunc)(sqlite3_context*,int,sqlite3_value **); } aFuncs[] = { { "randstr", 2, SQLITE_UTF8, randStr }, @@ -626,6 +640,7 @@ static int registerTestFunctions(sqlite3 *db){ { "real2hex", 1, SQLITE_UTF8, real2hex}, { "test_decode", 1, SQLITE_UTF8, test_decode}, { "test_extract", 2, SQLITE_UTF8, test_extract}, + { "test_zeroblob", 1, SQLITE_UTF8|SQLITE_DETERMINISTIC, test_zeroblob}, }; int i; diff --git a/src/vdbemem.c b/src/vdbemem.c index 0e9bb873ae..b92ec84337 100644 --- a/src/vdbemem.c +++ b/src/vdbemem.c @@ -1204,6 +1204,7 @@ static int valueFromFunction( goto value_from_function_out; } + assert( pCtx->pParse->rc==SQLITE_OK ); memset(&ctx, 0, sizeof(ctx)); ctx.pOut = pVal; ctx.pFunc = pFunc; @@ -1211,15 +1212,16 @@ static int valueFromFunction( if( ctx.isError ){ rc = ctx.isError; sqlite3ErrorMsg(pCtx->pParse, "%s", sqlite3_value_text(pVal)); - pCtx->pParse->rc = rc; }else{ sqlite3ValueApplyAffinity(pVal, aff, SQLITE_UTF8); assert( rc==SQLITE_OK ); rc = sqlite3VdbeChangeEncoding(pVal, enc); if( rc==SQLITE_OK && sqlite3VdbeMemTooBig(pVal) ){ rc = SQLITE_TOOBIG; + pCtx->pParse->nErr++; } } + pCtx->pParse->rc = rc; value_from_function_out: if( rc!=SQLITE_OK ){ diff --git a/test/analyzeF.test b/test/analyzeF.test index e96cd87075..670d178a81 100644 --- a/test/analyzeF.test +++ b/test/analyzeF.test @@ -66,6 +66,8 @@ foreach {tn where idx} { do_eqp_test 1.$tn "SELECT * FROM t1 WHERE $where" $res } +# Test that functions that do not exist - "func()" - do not cause an error. +# do_catchsql_test 2.1 { SELECT * FROM t1 WHERE x = substr('145', 2, 1) AND y = func(1, 2, 3) } {1 {no such function: func}} @@ -74,5 +76,52 @@ do_catchsql_test 2.2 { } {1 {no such function: func}} +# Check that functions that accept zero arguments do not cause problems. +# +proc ret {x} { return $x } + +db func det4 -deterministic [list ret 4] +db func nondet4 [list ret 4] +db func det19 -deterministic [list ret 19] +db func nondet19 [list ret 19] + +foreach {tn where idx} { + 1 "x = det4() AND y = det19()" {t1x (x=?)} + 2 "x = det19() AND y = det4()" {t1y (y=?)} + + 3 "x = nondet4() AND y = nondet19()" {t1y (y=?)} + 4 "x = nondet19() AND y = nondet4()" {t1y (y=?)} +} { + set res "0 0 0 {SEARCH TABLE t1 USING INDEX $idx}" + do_eqp_test 3.$tn "SELECT * FROM t1 WHERE $where" $res +} + + +execsql { DELETE FROM t1 } + +proc throw_error {err} { error $err } +db func error -deterministic throw_error +do_catchsql_test 4.1 { + SELECT * FROM t1 WHERE x = error('error one') AND y = 4; +} {1 {error one}} + +do_catchsql_test 4.2 { + SELECT * FROM t1 WHERE x = zeroblob(2000000000) AND y = 4; +} {1 {string or blob too big}} + +sqlite3_limit db SQLITE_LIMIT_LENGTH 1000000 +proc dstr {} { return [string repeat x 1100000] } +db func dstr -deterministic dstr +do_catchsql_test 4.3 { + SELECT * FROM t1 WHERE x = dstr() AND y = 11; +} {1 {string or blob too big}} + +do_catchsql_test 4.4 { + SELECT * FROM t1 WHERE x = test_zeroblob(1100000) AND y = 4; +} {1 {string or blob too big}} + + finish_test + + diff --git a/test/mallocK.test b/test/mallocK.test index 0a21b9fa0a..65791e79ea 100644 --- a/test/mallocK.test +++ b/test/mallocK.test @@ -143,6 +143,33 @@ do_faultsim_test 7.2 -faults oom* -body { faultsim_test_result [list 0 {}] } +reset_db + +proc isqrt {i} { expr { int(sqrt($i)) } } +db func isqrt isqrt + +do_execsql_test 8.0 { + PRAGMA encoding = 'utf-16'; + CREATE TABLE x2(x TEXT, y TEXT); + WITH data(i) AS ( + SELECT 1 UNION ALL SELECT i+1 FROM data + ) + INSERT INTO x2 SELECT isqrt(i), isqrt(i) FROM data LIMIT 400; + CREATE INDEX x2x ON x2(x); + CREATE INDEX x2y ON x2(y); + ANALYZE; + DELETE FROM x2; +} + +proc str {a} { return $a } +db func str -deterministic str + +do_faultsim_test 8 -faults oom* -body { + execsql { SELECT * FROM x2 WHERE x = str('19') AND y = str('4') } +} -test { + faultsim_test_result [list 0 {}] +} + finish_test diff --git a/test/tclsqlite.test b/test/tclsqlite.test index 3d9cd46ac6..8d7fea0d2a 100644 --- a/test/tclsqlite.test +++ b/test/tclsqlite.test @@ -118,7 +118,7 @@ do_test tcl-1.14 { do_test tcl-1.15 { set v [catch {db function} msg] lappend v $msg -} {1 {wrong # args: should be "db function NAME [-argcount N] SCRIPT"}} +} {1 {wrong # args: should be "db function NAME ?SWITCHES? SCRIPT"}} do_test tcl-1.16 { set v [catch {db last_insert_rowid xyz} msg] lappend v $msg From dfac7016a7b95ed1b65bd62ea1e6dfbb48ab7d54 Mon Sep 17 00:00:00 2001 From: dan Date: Fri, 13 Mar 2015 15:44:36 +0000 Subject: [PATCH 15/63] Add tests to ensure "PRAGMA incremental_vacuum" and "PRAGMA auto_vacuum = incremental" handle corrupt databases correctly. FossilOrigin-Name: 1c2166cb2a387a0856f41b399c3648bf8c5fce73 --- manifest | 11 ++-- manifest.uuid | 2 +- test/incrcorrupt.test | 127 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 134 insertions(+), 6 deletions(-) create mode 100644 test/incrcorrupt.test diff --git a/manifest b/manifest index fd821ade74..e1d464f1a0 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Extra\stests\sfor\scommit\s[0f250957]. -D 2015-03-13T08:31:54.154 +C Add\stests\sto\sensure\s"PRAGMA\sincremental_vacuum"\sand\s"PRAGMA\sauto_vacuum\s=\sincremental"\shandle\scorrupt\sdatabases\scorrectly. +D 2015-03-13T15:44:36.085 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -646,6 +646,7 @@ F test/incrblob3.test d8d036fde015d4a159cd3cbae9d29003b37227a4 F test/incrblob4.test f26502a5697893e5acea268c910f16478c2f0fab F test/incrblob_err.test af1f12ba60d220c9752073ff2bda2ad59e88960d F test/incrblobfault.test 280474078f6da9e732cd2a215d3d854969014b6e +F test/incrcorrupt.test 9786cba68c5832f01887fde1c06b43c3904d86f6 F test/incrvacuum.test d2a6ddf5e429720b5fe502766af747915ccf6c32 F test/incrvacuum2.test 676c41428765d58f1da7dbe659ef27726d3d30ac F test/incrvacuum3.test 75256fb1377e7c39ef2de62bfc42bbff67be295a @@ -1243,7 +1244,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 2887fb38ffc28712c34028cd38db2b7993d864eb -R b89c9ce97b230db0ae63022a487b40cc +P 5aa522dcb9bfa18d49683f7cc889516984e2bcd2 +R a79445283a8ae7c7f85ae571d23bc239 U dan -Z ccca41f9c448bc442b12b8c9fe5620ec +Z d6c136b9ed1be16533c60706d0427e82 diff --git a/manifest.uuid b/manifest.uuid index f5b9305905..e474b58d5e 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -5aa522dcb9bfa18d49683f7cc889516984e2bcd2 \ No newline at end of file +1c2166cb2a387a0856f41b399c3648bf8c5fce73 \ No newline at end of file diff --git a/test/incrcorrupt.test b/test/incrcorrupt.test new file mode 100644 index 0000000000..eda65e4035 --- /dev/null +++ b/test/incrcorrupt.test @@ -0,0 +1,127 @@ +# 2001 October 12 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# Test that "PRAGMA incremental_vacuum" detects and reports database +# corruption properly. And that "PRAGMA auto_vacuum = INCREMENTAL" +# does as well. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix incrcorrupt + +# If this build of the library does not support auto-vacuum, omit this +# whole file. +ifcapable {!autovacuum} { + finish_test + return +} + +do_execsql_test 1.0 { + PRAGMA auto_vacuum = 2; + CREATE TABLE t1(a PRIMARY KEY, b); + + WITH data(i) AS ( + SELECT 1 UNION ALL SELECT i+1 FROM data + ) + INSERT INTO t1 SELECT i, randomblob(600) FROM data LIMIT 20; + PRAGMA page_count; +} {24} + +do_execsql_test 1.1 { + PRAGMA incremental_vacuum; +} {} + +do_test 1.2 { + db_save + hexio_write test.db 36 00000019 + catchsql { PRAGMA incremental_vacuum; } +} {1 {database disk image is malformed}} + +do_test 1.3 { + set stmt [sqlite3_prepare_v2 db "PRAGMA incremental_vacuum" -1 dummy] + sqlite3_step $stmt +} {SQLITE_CORRUPT} +do_test 1.4 { sqlite3_errcode db } {SQLITE_CORRUPT} +do_test 1.5 { sqlite3_errmsg db } {database disk image is malformed} +do_test 1.6 { sqlite3_finalize $stmt } {SQLITE_CORRUPT} +do_test 1.7 { sqlite3_errcode db } {SQLITE_CORRUPT} +do_test 1.8 { sqlite3_errmsg db } {database disk image is malformed} + +do_test 1.9 { + set stmt [sqlite3_prepare_v2 db "PRAGMA incremental_vacuum" -1 dummy] + sqlite3_step $stmt +} {SQLITE_CORRUPT} +do_test 1.10 { sqlite3_errcode db } {SQLITE_CORRUPT} +do_test 1.11 { sqlite3_errmsg db } {database disk image is malformed} + +do_test 1.12 { + set stmt2 [sqlite3_prepare_v2 db "SELECT 1" -1 dummy] + sqlite3_finalize $stmt2 +} {SQLITE_OK} +do_test 1.13 { sqlite3_errcode db } {SQLITE_OK} +do_test 1.14 { sqlite3_errmsg db } {not an error} + +do_test 1.15 { sqlite3_finalize $stmt } {SQLITE_CORRUPT} +do_test 1.16 { sqlite3_errcode db } {SQLITE_CORRUPT} +do_test 1.17 { sqlite3_errmsg db } {database disk image is malformed} + +#------------------------------------------------------------------------- +# +reset_db + +do_execsql_test 2.1 { + PRAGMA auto_vacuum = 1; + CREATE TABLE t1(a PRIMARY KEY, b); + WITH data(i) AS ( + SELECT 1 UNION ALL SELECT i+1 FROM data + ) + INSERT INTO t1 SELECT i, randomblob(600) FROM data LIMIT 20; + PRAGMA page_count; +} {24} + +do_test 2.2 { + db_save + set fd [open test.db r+] + chan truncate $fd [expr 22*1024] + close $fd + catchsql { PRAGMA incremental_vacuum; } +} {1 {database disk image is malformed}} + +do_test 2.3 { + set stmt [sqlite3_prepare_v2 db "PRAGMA auto_vacuum = INCREMENTAL" -1 dummy] + sqlite3_step $stmt +} {SQLITE_CORRUPT} +do_test 2.4 { sqlite3_errcode db } {SQLITE_CORRUPT} +do_test 2.5 { sqlite3_errmsg db } {database disk image is malformed} +do_test 2.6 { sqlite3_finalize $stmt } {SQLITE_CORRUPT} +do_test 2.7 { sqlite3_errcode db } {SQLITE_CORRUPT} +do_test 2.8 { sqlite3_errmsg db } {database disk image is malformed} + +do_test 2.9 { + set stmt [sqlite3_prepare_v2 db "PRAGMA auto_vacuum = INCREMENTAL" -1 dummy] + sqlite3_step $stmt +} {SQLITE_CORRUPT} +do_test 2.10 { sqlite3_errcode db } {SQLITE_CORRUPT} +do_test 2.11 { sqlite3_errmsg db } {database disk image is malformed} + +do_test 2.12 { + set stmt2 [sqlite3_prepare_v2 db "SELECT 1" -1 dummy] + sqlite3_finalize $stmt2 +} {SQLITE_OK} +do_test 2.13 { sqlite3_errcode db } {SQLITE_OK} +do_test 2.14 { sqlite3_errmsg db } {not an error} + +do_test 2.15 { sqlite3_finalize $stmt } {SQLITE_CORRUPT} +do_test 2.16 { sqlite3_errcode db } {SQLITE_CORRUPT} +do_test 2.17 { sqlite3_errmsg db } {database disk image is malformed} + +finish_test + From a3d0c1365470318410d4993375f34b13a7edc96a Mon Sep 17 00:00:00 2001 From: dan Date: Sat, 14 Mar 2015 18:59:58 +0000 Subject: [PATCH 16/63] When estimating the number of rows visited by a range scan for which the keys consist of more than one field, consider prefixes of stat4 samples as well as the full samples. FossilOrigin-Name: e1caf93c9ad0ee15d42030af95619f212d3fcf9d --- manifest | 17 +++-- manifest.uuid | 2 +- src/where.c | 174 +++++++++++++++++++++++++++++++++++---------- test/analyze9.test | 63 ++++++++++++++++ 4 files changed, 210 insertions(+), 46 deletions(-) diff --git a/manifest b/manifest index e1d464f1a0..4946d588ee 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\stests\sto\sensure\s"PRAGMA\sincremental_vacuum"\sand\s"PRAGMA\sauto_vacuum\s=\sincremental"\shandle\scorrupt\sdatabases\scorrectly. -D 2015-03-13T15:44:36.085 +C When\sestimating\sthe\snumber\sof\srows\svisited\sby\sa\srange\sscan\sfor\swhich\sthe\skeys\sconsist\sof\smore\sthan\sone\sfield,\sconsider\sprefixes\sof\sstat4\ssamples\sas\swell\sas\sthe\sfull\ssamples. +D 2015-03-14T18:59:58.801 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -307,7 +307,7 @@ F src/vxworks.h c18586c8edc1bddbc15c004fa16aeb1e1342b4fb F src/wal.c 39303f2c9db02a4e422cd8eb2c8760420c6a51fe F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4 F src/walker.c c253b95b4ee44b21c406e2a1052636c31ea27804 -F src/where.c eb141b075776e9864d38f279333e2472a8653202 +F src/where.c 5a4e4ab378dbddeca59ad283c61aa67c6e56a913 F src/whereInt.h cbe4aa57326998d89e7698ca65bb7c28541d483c F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2 @@ -327,7 +327,7 @@ F test/analyze5.test 765c4e284aa69ca172772aa940946f55629bc8c4 F test/analyze6.test f1c552ce39cca4ec922a7e4e0e5d0203d6b3281f F test/analyze7.test bb1409afc9e8629e414387ef048b8e0e3e0bdc4f F test/analyze8.test c05a461d0a6b05991106467d0c47480f2e709c82 -F test/analyze9.test 72795c8113604b5dcd47a1498a61d6d7fb5d041a +F test/analyze9.test 2f6cfeae1fcc61cc531bd19f68e1e28fb6edafbf F test/analyzeA.test 3335697f6700c7052295cfd0067fc5b2aacddf9a F test/analyzeB.test 8bf35ee0a548aea831bf56762cb8e7fdb1db083d F test/analyzeC.test 555a6cc388b9818b6eda6df816f01ce0a75d3a93 @@ -1244,7 +1244,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 5aa522dcb9bfa18d49683f7cc889516984e2bcd2 -R a79445283a8ae7c7f85ae571d23bc239 +P 1c2166cb2a387a0856f41b399c3648bf8c5fce73 +R f0473fc546184f7826d3d60610130f49 +T *branch * stat4-change +T *sym-stat4-change * +T -sym-trunk * U dan -Z d6c136b9ed1be16533c60706d0427e82 +Z e2a2579617ea31b6dadba1e9a71ba744 diff --git a/manifest.uuid b/manifest.uuid index e474b58d5e..02ad1198b1 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -1c2166cb2a387a0856f41b399c3648bf8c5fce73 \ No newline at end of file +e1caf93c9ad0ee15d42030af95619f212d3fcf9d \ No newline at end of file diff --git a/src/where.c b/src/where.c index 8b9060b0a7..6ecc9c33c2 100644 --- a/src/where.c +++ b/src/where.c @@ -1931,11 +1931,14 @@ static int vtabBestIndex(Parse *pParse, Table *pTab, sqlite3_index_info *p){ ** Estimate the location of a particular key among all keys in an ** index. Store the results in aStat as follows: ** -** aStat[0] Est. number of rows less than pVal -** aStat[1] Est. number of rows equal to pVal +** aStat[0] Est. number of rows less than pRec +** aStat[1] Est. number of rows equal to pRec ** ** Return the index of the sample that is the smallest sample that -** is greater than or equal to pRec. +** is greater than or equal to pRec. Note that this index is not an index +** into the aSample[] array - it is an index into a virtual set of samples +** based on the contents of aSample[] and the number of fields in record +** pRec. */ static int whereKeyStats( Parse *pParse, /* Database connection */ @@ -1946,67 +1949,158 @@ static int whereKeyStats( ){ IndexSample *aSample = pIdx->aSample; int iCol; /* Index of required stats in anEq[] etc. */ + int i; /* Index of first sample >= pRec */ + int iSample; /* Smallest sample larger than or equal to pRec */ int iMin = 0; /* Smallest sample not yet tested */ - int i = pIdx->nSample; /* Smallest sample larger than or equal to pRec */ int iTest; /* Next sample to test */ int res; /* Result of comparison operation */ + int nField; /* Number of fields in pRec */ + tRowcnt iLower = 0; /* anLt[] + anEq[] of largest sample pRec is > */ #ifndef SQLITE_DEBUG UNUSED_PARAMETER( pParse ); #endif assert( pRec!=0 ); - iCol = pRec->nField - 1; assert( pIdx->nSample>0 ); - assert( pRec->nField>0 && iColnSampleCol ); + assert( pRec->nField>0 && pRec->nField<=pIdx->nSampleCol ); + + /* Do a binary search to find the first sample greater than or equal + ** to pRec. If pRec contains a single field, the set of samples to search + ** is simply the aSample[] array. If the samples in aSample[] contain more + ** than one fields, all fields following the first are ignored. + ** + ** If pRec contains N fields, where N is more than one, then as well as the + ** samples in aSample[] (truncated to N fields), the search also has to + ** consider prefixes of those samples. For example, if the set of samples + ** in aSample is: + ** + ** aSample[0] = (a, 5) + ** aSample[1] = (a, 10) + ** aSample[2] = (b, 5) + ** aSample[3] = (c, 100) + ** aSample[4] = (c, 105) + ** + ** Then the search space should ideally be the samples above and the + ** unique prefixes [a], [b] and [c]. But since that is hard to organize, + ** the code actually searches this set: + ** + ** 0: (a) + ** 1: (a, 5) + ** 2: (a, 10) + ** 3: (a, 10) + ** 4: (b) + ** 5: (b, 5) + ** 6: (c) + ** 7: (c, 100) + ** 8: (c, 105) + ** 9: (c, 105) + ** + ** For each sample in the aSample[] array, N samples are present in the + ** effective sample array. In the above, samples 0 and 1 are based on + ** sample aSample[0]. Samples 2 and 3 on aSample[1] etc. + ** + ** Often, sample i of each block of N effective samples has (i+1) fields. + ** Except, each sample may be extended to ensure that it is greater than or + ** equal to the previous sample in the array. For example, in the above, + ** sample 2 is the first sample of a block of N samples, so at first it + ** appears that it should be 1 field in size. However, that would make it + ** smaller than sample 1, so the binary search would not work. As a result, + ** it is extended to two fields. The duplicates that this creates do not + ** cause any problems. + */ + nField = pRec->nField; + iCol = 0; + iSample = pIdx->nSample * nField; do{ - iTest = (iMin+i)/2; - res = sqlite3VdbeRecordCompare(aSample[iTest].n, aSample[iTest].p, pRec); - if( res<0 ){ - iMin = iTest+1; + int iSamp; /* Index in aSample[] of test sample */ + int n; /* Number of fields in test sample */ + + iTest = (iMin+iSample)/2; + iSamp = iTest / nField; + if( iSamp>0 ){ + /* The proposed effective sample is a prefix of sample aSample[iSamp]. + ** Specifically, the shortest prefix of at least (1 + iTest%nField) + ** fields that is greater than the previous effective sample. */ + for(n=(iTest % nField) + 1; nnField = n; + res = sqlite3VdbeRecordCompare(aSample[iSamp].n, aSample[iSamp].p, pRec); + if( res<0 ){ + iLower = aSample[iSamp].anLt[n-1] + aSample[iSamp].anEq[n-1]; + iMin = iTest+1; + }else if( res==0 && nnSample ); - assert( 0==sqlite3VdbeRecordCompare(aSample[i].n, aSample[i].p, pRec) - || pParse->db->mallocFailed ); - }else{ - /* Otherwise, pRec must be smaller than sample $i and larger than - ** sample ($i-1). */ - assert( i==pIdx->nSample - || sqlite3VdbeRecordCompare(aSample[i].n, aSample[i].p, pRec)>0 - || pParse->db->mallocFailed ); - assert( i==0 - || sqlite3VdbeRecordCompare(aSample[i-1].n, aSample[i-1].p, pRec)<0 - || pParse->db->mallocFailed ); + if( pParse->db->mallocFailed==0 ){ + if( res==0 ){ + /* If (res==0) is true, then pRec must be equal to sample i. */ + assert( inSample ); + assert( iCol==nField-1 ); + pRec->nField = nField; + assert( 0==sqlite3VdbeRecordCompare(aSample[i].n, aSample[i].p, pRec) + || pParse->db->mallocFailed + ); + }else{ + /* Unless i==pIdx->nSample, indicating that pRec is larger than + ** all samples in the aSample[] array, pRec must be smaller than the + ** (iCol+1) field prefix of sample i. */ + assert( i<=pIdx->nSample && i>=0 ); + pRec->nField = iCol+1; + assert( i==pIdx->nSample + || sqlite3VdbeRecordCompare(aSample[i].n, aSample[i].p, pRec)>0 + || pParse->db->mallocFailed ); + + /* if i==0 and iCol==0, then record pRec is smaller than all samples + ** in the aSample[] array. Otherwise, if (iCol>0) then pRec must + ** be greater than or equal to the (iCol) field prefix of sample i. + ** If (i>0), then pRec must also be greater than sample (i-1). */ + if( iCol>0 ){ + pRec->nField = iCol; + assert( sqlite3VdbeRecordCompare(aSample[i].n, aSample[i].p, pRec)<=0 + || pParse->db->mallocFailed ); + } + if( i>0 ){ + pRec->nField = nField; + assert( sqlite3VdbeRecordCompare(aSample[i-1].n, aSample[i-1].p, pRec)<0 + || pParse->db->mallocFailed ); + } + } } #endif /* ifdef SQLITE_DEBUG */ - /* At this point, aSample[i] is the first sample that is greater than - ** or equal to pVal. Or if i==pIdx->nSample, then all samples are less - ** than pVal. If aSample[i]==pVal, then res==0. - */ if( res==0 ){ + /* Record pRec is equal to sample i */ + assert( iCol==nField-1 ); aStat[0] = aSample[i].anLt[iCol]; aStat[1] = aSample[i].anEq[iCol]; }else{ - tRowcnt iLower, iUpper, iGap; - if( i==0 ){ - iLower = 0; - iUpper = aSample[0].anLt[iCol]; + /* At this point, the (iCol+1) field prefix of aSample[i] is the first + ** sample that is greater than pRec. Or, if i==pIdx->nSample then pRec + ** is larger than all samples in the array. */ + tRowcnt iUpper, iGap; + if( i>=pIdx->nSample ){ + iUpper = sqlite3LogEstToInt(pIdx->aiRowLogEst[0]); }else{ - i64 nRow0 = sqlite3LogEstToInt(pIdx->aiRowLogEst[0]); - iUpper = i>=pIdx->nSample ? nRow0 : aSample[i].anLt[iCol]; - iLower = aSample[i-1].anEq[iCol] + aSample[i-1].anLt[iCol]; + iUpper = aSample[i].anLt[iCol]; } - aStat[1] = pIdx->aAvgEq[iCol]; + if( iLower>=iUpper ){ iGap = 0; }else{ @@ -2018,7 +2112,11 @@ static int whereKeyStats( iGap = iGap/3; } aStat[0] = iLower + iGap; + aStat[1] = pIdx->aAvgEq[iCol]; } + + /* Restore the pRec->nField value before returning. */ + pRec->nField = nField; return i; } #endif /* SQLITE_ENABLE_STAT3_OR_STAT4 */ diff --git a/test/analyze9.test b/test/analyze9.test index 8572cbea00..6e85272ad6 100644 --- a/test/analyze9.test +++ b/test/analyze9.test @@ -1134,4 +1134,67 @@ ifcapable stat4&&cte { } } +#------------------------------------------------------------------------- +# Check that a problem in they way stat4 data is used has been +# resolved (see below). +# +reset_db +do_test 26.1 { + db transaction { + execsql { + CREATE TABLE t1(x, y, z); + CREATE INDEX t1xy ON t1(x, y); + CREATE INDEX t1z ON t1(z); + } + for {set i 0} {$i < 10000} {incr i} { + execsql { INSERT INTO t1(x, y) VALUES($i, $i) } + } + for {set i 0} {$i < 10} {incr i} { + execsql { + WITH cnt(x) AS (SELECT 1 UNION ALL SELECT x+1 FROM cnt WHERE x<100) + INSERT INTO t1(x, y) SELECT 10000+$i, x FROM cnt; + INSERT INTO t1(x, y) SELECT 10000+$i, 100; + } + } + execsql { + UPDATE t1 SET z = rowid / 20; + ANALYZE; + } + } +} {} + +do_execsql_test 26.2 { + SELECT count(*) FROM t1 WHERE x = 10000 AND y < 50; +} {49} +do_execsql_test 26.3 { + SELECT count(*) FROM t1 WHERE z = 444; +} {20} + +# The analyzer knows that any (z=?) expression matches 20 rows. So it +# will use index "t1z" if the estimate of hits for (x=10000 AND y<50) +# is greater than 20 rows. +# +# And it should be. The analyzer has a stat4 sample as follows: +# +# sample=(x=10000, y=100) nLt=(10000 10099) +# +# There should be no other samples that start with (x=10000). So it knows +# that (x=10000 AND y<50) must match somewhere between 0 and 99 rows, but +# know more than that. Guessing less than 20 is therefore unreasonable. +# +# At one point though, due to a problem in whereKeyStats(), the planner was +# estimating that (x=10000 AND y<50) would match only 2 rows. +# +do_eqp_test 26.4 { + SELECT * FROM t1 WHERE x = 10000 AND y < 50 AND z = 444; +} { + 0 0 0 {SEARCH TABLE t1 USING INDEX t1z (z=?)} +} + + + + finish_test + + + From a0d56aef1859e0d9ee46ca102cc28b2f5da6e756 Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 16 Mar 2015 09:21:30 +0000 Subject: [PATCH 17/63] Another test case for the planner change on this branch. FossilOrigin-Name: f2207a0691ed361061719f4dacf021a677a9d892 --- manifest | 15 +++++------- manifest.uuid | 2 +- test/analyze9.test | 57 ++++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 60 insertions(+), 14 deletions(-) diff --git a/manifest b/manifest index 4946d588ee..3b2c011b8e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C When\sestimating\sthe\snumber\sof\srows\svisited\sby\sa\srange\sscan\sfor\swhich\sthe\skeys\sconsist\sof\smore\sthan\sone\sfield,\sconsider\sprefixes\sof\sstat4\ssamples\sas\swell\sas\sthe\sfull\ssamples. -D 2015-03-14T18:59:58.801 +C Another\stest\scase\sfor\sthe\splanner\schange\son\sthis\sbranch. +D 2015-03-16T09:21:30.738 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -327,7 +327,7 @@ F test/analyze5.test 765c4e284aa69ca172772aa940946f55629bc8c4 F test/analyze6.test f1c552ce39cca4ec922a7e4e0e5d0203d6b3281f F test/analyze7.test bb1409afc9e8629e414387ef048b8e0e3e0bdc4f F test/analyze8.test c05a461d0a6b05991106467d0c47480f2e709c82 -F test/analyze9.test 2f6cfeae1fcc61cc531bd19f68e1e28fb6edafbf +F test/analyze9.test 3dd9e203fad353ec8027b18a6d9a92af59f4e727 F test/analyzeA.test 3335697f6700c7052295cfd0067fc5b2aacddf9a F test/analyzeB.test 8bf35ee0a548aea831bf56762cb8e7fdb1db083d F test/analyzeC.test 555a6cc388b9818b6eda6df816f01ce0a75d3a93 @@ -1244,10 +1244,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 1c2166cb2a387a0856f41b399c3648bf8c5fce73 -R f0473fc546184f7826d3d60610130f49 -T *branch * stat4-change -T *sym-stat4-change * -T -sym-trunk * +P e1caf93c9ad0ee15d42030af95619f212d3fcf9d +R de6873e674f8f1bad7ecb0349d34590a U dan -Z e2a2579617ea31b6dadba1e9a71ba744 +Z 76e12c27217f9a3f485e4cb06238c66e diff --git a/manifest.uuid b/manifest.uuid index 02ad1198b1..e21139d81b 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -e1caf93c9ad0ee15d42030af95619f212d3fcf9d \ No newline at end of file +f2207a0691ed361061719f4dacf021a677a9d892 \ No newline at end of file diff --git a/test/analyze9.test b/test/analyze9.test index 6e85272ad6..1ebd69c8d1 100644 --- a/test/analyze9.test +++ b/test/analyze9.test @@ -1139,7 +1139,7 @@ ifcapable stat4&&cte { # resolved (see below). # reset_db -do_test 26.1 { +do_test 26.1.1 { db transaction { execsql { CREATE TABLE t1(x, y, z); @@ -1163,10 +1163,10 @@ do_test 26.1 { } } {} -do_execsql_test 26.2 { +do_execsql_test 26.1.2 { SELECT count(*) FROM t1 WHERE x = 10000 AND y < 50; } {49} -do_execsql_test 26.3 { +do_execsql_test 26.1.3 { SELECT count(*) FROM t1 WHERE z = 444; } {20} @@ -1185,13 +1185,62 @@ do_execsql_test 26.3 { # At one point though, due to a problem in whereKeyStats(), the planner was # estimating that (x=10000 AND y<50) would match only 2 rows. # -do_eqp_test 26.4 { +do_eqp_test 26.1.4 { SELECT * FROM t1 WHERE x = 10000 AND y < 50 AND z = 444; } { 0 0 0 {SEARCH TABLE t1 USING INDEX t1z (z=?)} } +# This test - 26.2.* - tests that another manifestation of the same problem +# is no longer present in the library. Assuming: +# +# CREATE INDEX t1xy ON t1(x, y) +# +# and that have samples for index t1xy as follows: +# +# +# sample=('A', 70) nEq=(100, 2) nLt=(900, 970) +# sample=('B', 70) nEq=(100, 2) nLt=(1000, 1070) +# +# the planner should estimate that (x = 'B' AND y > 25) matches 76 rows +# (70 * 2/3 + 30). Before, due to the problem, the planner was estimating +# that this matched 100 rows. +# +reset_db +do_execsql_test 26.2.1 { + BEGIN; + CREATE TABLE t1(x, y, z); + CREATE INDEX i1 ON t1(x, y); + CREATE INDEX i2 ON t1(z); + + WITH + cnt(y) AS (SELECT 0 UNION ALL SELECT y+1 FROM cnt WHERE y<99), + letters(x) AS ( + SELECT 'A' UNION SELECT 'B' UNION SELECT 'C' UNION SELECT 'D' + ) + INSERT INTO t1(x, y) SELECT x, y FROM letters, cnt; + + WITH + letters(x) AS ( + SELECT 'A' UNION SELECT 'B' UNION SELECT 'C' UNION SELECT 'D' + ) + INSERT INTO t1(x, y) SELECT x, 70 FROM letters; + + WITH + cnt(i) AS (SELECT 0 UNION ALL SELECT i+1 FROM cnt WHERE i<9999) + INSERT INTO t1(x, y) SELECT i, i FROM cnt; + + UPDATE t1 SET z = (rowid / 95); + ANALYZE; + COMMIT; +} + +do_eqp_test 26.2.2 { + SELECT * FROM t1 WHERE x='B' AND y>25 AND z=?; +} { + 0 0 0 {SEARCH TABLE t1 USING INDEX i1 (x=? AND y>?)} +} finish_test From 8426636cdc284888098ecc77a5e2a25c242d4707 Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 16 Mar 2015 12:13:31 +0000 Subject: [PATCH 18/63] When a WHERE clause contains disjuncts with the same operands, try to combine them into a single operator. Example: (x=A OR x>A) becomes (x>=A). FossilOrigin-Name: 7a3097689d17625fb0dfc4372712f375f3bdb9a1 --- manifest | 18 +++++---- manifest.uuid | 2 +- src/where.c | 98 +++++++++++++++++++++++++++++++++++++++++++++++- test/whereK.test | 72 +++++++++++++++++++++++++++++++++++ 4 files changed, 180 insertions(+), 10 deletions(-) create mode 100644 test/whereK.test diff --git a/manifest b/manifest index e1d464f1a0..2c8ca54b79 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\stests\sto\sensure\s"PRAGMA\sincremental_vacuum"\sand\s"PRAGMA\sauto_vacuum\s=\sincremental"\shandle\scorrupt\sdatabases\scorrectly. -D 2015-03-13T15:44:36.085 +C When\sa\sWHERE\sclause\scontains\sdisjuncts\swith\sthe\ssame\soperands,\stry\sto\ncombine\sthem\sinto\sa\ssingle\soperator.\s\sExample:\s\s(x=A\sOR\sx>A)\sbecomes\n(x>=A). +D 2015-03-16T12:13:31.967 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -307,7 +307,7 @@ F src/vxworks.h c18586c8edc1bddbc15c004fa16aeb1e1342b4fb F src/wal.c 39303f2c9db02a4e422cd8eb2c8760420c6a51fe F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4 F src/walker.c c253b95b4ee44b21c406e2a1052636c31ea27804 -F src/where.c eb141b075776e9864d38f279333e2472a8653202 +F src/where.c b879a02e59c27f1447224fa2e79a7f2c7c345fd5 F src/whereInt.h cbe4aa57326998d89e7698ca65bb7c28541d483c F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2 @@ -1175,6 +1175,7 @@ F test/whereG.test 69f5ec4b15760a8c860f80e2d55525669390aab3 F test/whereH.test e4b07f7a3c2f5d31195cd33710054c78667573b2 F test/whereI.test 1d89199697919d4930be05a71e7fe620f114e622 F test/whereJ.test 55a3221706a7ab706293f17cc8f96da563bf0767 +F test/whereK.test 78fb50c74c9a91efc97a1daa39bcf7b8b68d8bff F test/wherelimit.test 5e9fd41e79bb2b2d588ed999d641d9c965619b31 F test/wild001.test bca33f499866f04c24510d74baf1e578d4e44b1c F test/win32heap.test ea19770974795cff26e11575e12d422dbd16893c @@ -1244,7 +1245,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 5aa522dcb9bfa18d49683f7cc889516984e2bcd2 -R a79445283a8ae7c7f85ae571d23bc239 -U dan -Z d6c136b9ed1be16533c60706d0427e82 +P 1c2166cb2a387a0856f41b399c3648bf8c5fce73 +R 298b36c87aaf9227b23b4ea3e9cfdff1 +T *branch * combine-disjuncts +T *sym-combine-disjuncts * +T -sym-trunk * +U drh +Z 6e64b74890b4611813f6eecbfdcaf110 diff --git a/manifest.uuid b/manifest.uuid index e474b58d5e..ebdd81be91 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -1c2166cb2a387a0856f41b399c3648bf8c5fce73 \ No newline at end of file +7a3097689d17625fb0dfc4372712f375f3bdb9a1 \ No newline at end of file diff --git a/src/where.c b/src/where.c index 8b9060b0a7..869ab8ed73 100644 --- a/src/where.c +++ b/src/where.c @@ -770,6 +770,79 @@ static void markTermAsChild(WhereClause *pWC, int iChild, int iParent){ pWC->a[iParent].nChild++; } +/* +** Return the N-th AND-connected subterm of pTerm. Or if pTerm is not +** a conjunction, then return just pTerm when N==0. If N is exceeds +** the number of available subterms, return NULL. +*/ +static WhereTerm *whereNthSubterm(WhereTerm *pTerm, int N){ + if( pTerm->eOperator!=WO_AND ){ + return N==0 ? pTerm : 0; + } + if( Nu.pAndInfo->wc.nTerm ){ + return &pTerm->u.pAndInfo->wc.a[N]; + } + return 0; +} + +/* +** Subterms pOne and pTwo are contained within WHERE clause pWC. The +** two subterms are in disjunction - they are OR-ed together. +** +** If these two terms are both of the form: "A op B" with the same +** A and B values but different operators and if the operators are +** compatible (if one is = and the other is <, for example) then +** add a new virtual term to pWC that is the combination of the +** two. +** +** Some examples: +** +** x x<=y +** x=y OR x=y --> x=y +** x<=y OR x x<=y +** +** The following is NOT generated: +** +** xy --> x!=y +*/ +static void whereCombineDisjuncts( + SrcList *pSrc, /* the FROM clause */ + WhereClause *pWC, /* The complete WHERE clause */ + WhereTerm *pOne, /* First disjunct */ + WhereTerm *pTwo /* Second disjunct */ +){ + u16 eOp = pOne->eOperator | pTwo->eOperator; + sqlite3 *db; /* Database connection (for malloc) */ + Expr *pNew; /* New virtual expression */ + int op; /* Operator for the combined expression */ + int idxNew; /* Index in pWC of the next virtual term */ + + if( (pOne->eOperator & (WO_EQ|WO_LT|WO_LE|WO_GT|WO_GE))==0 ) return; + if( (pTwo->eOperator & (WO_EQ|WO_LT|WO_LE|WO_GT|WO_GE))==0 ) return; + if( (eOp & (WO_EQ|WO_LT|WO_LE))!=eOp + && (eOp & (WO_EQ|WO_GT|WO_GE))!=eOp ) return; + assert( pOne->pExpr->pLeft!=0 && pOne->pExpr->pRight!=0 ); + assert( pTwo->pExpr->pLeft!=0 && pTwo->pExpr->pRight!=0 ); + if( sqlite3ExprCompare(pOne->pExpr->pLeft, pTwo->pExpr->pLeft, -1) ) return; + if( sqlite3ExprCompare(pOne->pExpr->pRight, pTwo->pExpr->pRight, -1) )return; + /* If we reach this point, it means the two subterms can be combined */ + if( (eOp & (eOp-1))!=0 ){ + if( eOp & (WO_LT|WO_LE) ){ + eOp = WO_LE; + }else{ + assert( eOp & (WO_GT|WO_GE) ); + eOp = WO_GE; + } + } + db = pWC->pWInfo->pParse->db; + pNew = sqlite3ExprDup(db, pOne->pExpr, 0); + if( pNew==0 ) return; + for(op=TK_EQ; eOp!=(WO_EQ<<(op-TK_EQ)); op++){ assert( opop = op; + idxNew = whereClauseInsert(pWC, pNew, TERM_VIRTUAL|TERM_DYNAMIC); + exprAnalyze(pSrc, pWC, idxNew); +} + #if !defined(SQLITE_OMIT_OR_OPTIMIZATION) && !defined(SQLITE_OMIT_SUBQUERY) /* ** Analyze a term that consists of two or more OR-connected @@ -794,6 +867,7 @@ static void markTermAsChild(WhereClause *pWC, int iChild, int iParent){ ** (C) t1.x=t2.y OR (t1.x=t2.z AND t1.y=15) ** (D) x=expr1 OR (y>11 AND y<22 AND z LIKE '*hello*') ** (E) (p.a=1 AND q.b=2 AND r.c=3) OR (p.x=4 AND q.y=5 AND r.z=6) +** (F) x>A OR (x=A AND y>=B) ** ** CASE 1: ** @@ -810,6 +884,12 @@ static void markTermAsChild(WhereClause *pWC, int iChild, int iParent){ ** ** CASE 2: ** +** If there is a two-way OR and one side has x>A and the other side +** has x=A (for the same x and A) then add a new virtual term to the +** WHERE clause of the form "x>=A". +** +** CASE 3: +** ** If all subterms are indexable by a single table T, then set ** ** WhereTerm.eOperator = WO_OR @@ -936,12 +1016,26 @@ static void exprAnalyzeOrTerm( } /* - ** Record the set of tables that satisfy case 2. The set might be + ** Record the set of tables that satisfy case 3. The set might be ** empty. */ pOrInfo->indexable = indexable; pTerm->eOperator = indexable==0 ? 0 : WO_OR; + /* For a two-way OR, attempt to implementation case 2. + */ + if( indexable && pOrWc->nTerm==2 ){ + int iOne = 0; + WhereTerm *pOne; + while( (pOne = whereNthSubterm(&pOrWc->a[0],iOne++))!=0 ){ + int iTwo = 0; + WhereTerm *pTwo; + while( (pTwo = whereNthSubterm(&pOrWc->a[1],iTwo++))!=0 ){ + whereCombineDisjuncts(pSrc, pWC, pOne, pTwo); + } + } + } + /* ** chngToIN holds a set of tables that *might* satisfy case 1. But ** we have to do some additional checking to see if case 1 really @@ -1071,7 +1165,7 @@ static void exprAnalyzeOrTerm( }else{ sqlite3ExprListDelete(db, pList); } - pTerm->eOperator = WO_NOOP; /* case 1 trumps case 2 */ + pTerm->eOperator = WO_NOOP; /* case 1 trumps case 3 */ } } } diff --git a/test/whereK.test b/test/whereK.test new file mode 100644 index 0000000000..8d294446a5 --- /dev/null +++ b/test/whereK.test @@ -0,0 +1,72 @@ +# 2015-03-16 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this file is testing OR expressions where terms can be +# factored from either side of the OR and combined into a single new +# AND term that is beneficial to the search. Examples: +# +# (x>A OR x=A) --> ... AND (x>=A) +# (x>A OR (x=A AND y>=B) --> ... AND (x>=A) +# + + + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set ::testprefix whereD + +do_execsql_test 1.1 { + CREATE TABLE t1(a,b,c); + WITH RECURSIVE c(x) AS (VALUES(0) UNION ALL SELECT x+1 FROM c WHERE x<99) + INSERT INTO t1(a,b,c) SELECT x, x/10, x%10 FROM c; + CREATE INDEX t1bc ON t1(b,c); + SELECT a FROM t1 WHERE b>9 OR b=9 ORDER BY +a; +} {90 91 92 93 94 95 96 97 98 99} +do_execsql_test 1.1eqp { + EXPLAIN QUERY PLAN + SELECT a FROM t1 WHERE b>9 OR b=9 ORDER BY +a; +} {/SEARCH TABLE t1 USING INDEX t1bc/} + +do_execsql_test 1.2 { + SELECT a FROM t1 WHERE b>8 OR (b=8 AND c>7) ORDER BY +a; +} {88 89 90 91 92 93 94 95 96 97 98 99} +do_execsql_test 1.2eqp { + EXPLAIN QUERY PLAN + SELECT a FROM t1 WHERE b>8 OR (b=8 AND c>7) ORDER BY +a; +} {/SEARCH TABLE t1 USING INDEX t1bc/} + +do_execsql_test 1.3 { + SELECT a FROM t1 WHERE (b=8 AND c>7) OR b>8 ORDER BY +a; +} {88 89 90 91 92 93 94 95 96 97 98 99} +do_execsql_test 1.3eqp { + EXPLAIN QUERY PLAN + SELECT a FROM t1 WHERE (b=8 AND c>7) OR b>8 ORDER BY +a; +} {/SEARCH TABLE t1 USING INDEX t1bc/} + +do_execsql_test 1.4 { + SELECT a FROM t1 WHERE (b=8 AND c>7) OR 87) OR 87) OR (b>8 AND c NOT IN (4,5,6)) + ORDER BY +a; +} {88 89 90 91 92 93 97 98 99} +do_execsql_test 1.5eqp { + EXPLAIN QUERY PLAN + SELECT a FROM t1 WHERE (b=8 AND c>7) OR (b>8 AND c NOT IN (4,5,6)) + ORDER BY +a; +} {/SEARCH TABLE t1 USING INDEX t1bc/} + +finish_test From c03acf2ea757e4c1c48ebeadb74912d96316c779 Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 16 Mar 2015 13:12:34 +0000 Subject: [PATCH 19/63] Improved comments. No code changes. FossilOrigin-Name: 23f71a26386ff2aff9800fe96cec1dc9c805b5b6 --- manifest | 15 ++++++--------- manifest.uuid | 2 +- src/where.c | 12 ++++++++---- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/manifest b/manifest index 2c8ca54b79..94c932d5b9 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C When\sa\sWHERE\sclause\scontains\sdisjuncts\swith\sthe\ssame\soperands,\stry\sto\ncombine\sthem\sinto\sa\ssingle\soperator.\s\sExample:\s\s(x=A\sOR\sx>A)\sbecomes\n(x>=A). -D 2015-03-16T12:13:31.967 +C Improved\scomments.\s\sNo\scode\schanges. +D 2015-03-16T13:12:34.265 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -307,7 +307,7 @@ F src/vxworks.h c18586c8edc1bddbc15c004fa16aeb1e1342b4fb F src/wal.c 39303f2c9db02a4e422cd8eb2c8760420c6a51fe F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4 F src/walker.c c253b95b4ee44b21c406e2a1052636c31ea27804 -F src/where.c b879a02e59c27f1447224fa2e79a7f2c7c345fd5 +F src/where.c 235b1f50ab851867dc2efc967824d1db571d68ac F src/whereInt.h cbe4aa57326998d89e7698ca65bb7c28541d483c F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2 @@ -1245,10 +1245,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 1c2166cb2a387a0856f41b399c3648bf8c5fce73 -R 298b36c87aaf9227b23b4ea3e9cfdff1 -T *branch * combine-disjuncts -T *sym-combine-disjuncts * -T -sym-trunk * +P 7a3097689d17625fb0dfc4372712f375f3bdb9a1 +R 8bbcc33deef1379ead8ffcee920df4a8 U drh -Z 6e64b74890b4611813f6eecbfdcaf110 +Z 9d40483b0a6890b27f9ba16787ef6d6d diff --git a/manifest.uuid b/manifest.uuid index ebdd81be91..86998486a3 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -7a3097689d17625fb0dfc4372712f375f3bdb9a1 \ No newline at end of file +23f71a26386ff2aff9800fe96cec1dc9c805b5b6 \ No newline at end of file diff --git a/src/where.c b/src/where.c index 869ab8ed73..624e16f7b6 100644 --- a/src/where.c +++ b/src/where.c @@ -792,7 +792,7 @@ static WhereTerm *whereNthSubterm(WhereTerm *pTerm, int N){ ** If these two terms are both of the form: "A op B" with the same ** A and B values but different operators and if the operators are ** compatible (if one is = and the other is <, for example) then -** add a new virtual term to pWC that is the combination of the +** add a new virtual AND term to pWC that is the combination of the ** two. ** ** Some examples: @@ -884,9 +884,13 @@ static void whereCombineDisjuncts( ** ** CASE 2: ** -** If there is a two-way OR and one side has x>A and the other side -** has x=A (for the same x and A) then add a new virtual term to the -** WHERE clause of the form "x>=A". +** If there are exactly two disjuncts one side has x>A and the other side +** has x=A (for the same x and A) then add a new virtual conjunct term to the +** WHERE clause of the form "x>=A". Example: +** +** x>A OR (x=A AND y>B) adds: x>=A +** +** The added conjunct can sometimes be helpful in query planning. ** ** CASE 3: ** From 8cdcd87c5339a9fde0136c9d8356e85b4d86ded8 Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 16 Mar 2015 13:48:23 +0000 Subject: [PATCH 20/63] Use #ifdef to omit code that is only used for STAT3 and STAT4. FossilOrigin-Name: f2c9c5b57b7739daafc44e8ec36d4a2beacd5f17 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/vdbemem.c | 2 ++ 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index e1d464f1a0..90bbcb29fd 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\stests\sto\sensure\s"PRAGMA\sincremental_vacuum"\sand\s"PRAGMA\sauto_vacuum\s=\sincremental"\shandle\scorrupt\sdatabases\scorrectly. -D 2015-03-13T15:44:36.085 +C Use\s#ifdef\sto\somit\scode\sthat\sis\sonly\sused\sfor\sSTAT3\sand\sSTAT4. +D 2015-03-16T13:48:23.259 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -299,7 +299,7 @@ F src/vdbeInt.h bb56fd199d8af1a2c1b9639ee2f70724b4338e3a F src/vdbeapi.c 583d56b129dd27f12bed518270de9ebe521e6a75 F src/vdbeaux.c 97911edb61074b871ec4aa2d6bb779071643dee5 F src/vdbeblob.c 4f2e8e075d238392df98c5e03a64342465b03f90 -F src/vdbemem.c 78aef62d0298e15485cb5a429c912c9c3ed054b8 +F src/vdbemem.c c0dc81285b7571b0a31c40f17846fe2397ec1cd9 F src/vdbesort.c 6d64c5448b64851b99931ede980addc3af70d5e2 F src/vdbetrace.c 7e4222955e07dd707a2f360c0eb73452be1cb010 F src/vtab.c 699f2b8d509cfe379c33dde33827875d5b030e01 @@ -1244,7 +1244,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 5aa522dcb9bfa18d49683f7cc889516984e2bcd2 -R a79445283a8ae7c7f85ae571d23bc239 -U dan -Z d6c136b9ed1be16533c60706d0427e82 +P 1c2166cb2a387a0856f41b399c3648bf8c5fce73 +R e7f2404f34b97aa8b45ff522e4adb3b6 +U drh +Z 2ec6c684a2b78379b1dfd597c8ec878e diff --git a/manifest.uuid b/manifest.uuid index e474b58d5e..f8a6086b6f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -1c2166cb2a387a0856f41b399c3648bf8c5fce73 \ No newline at end of file +f2c9c5b57b7739daafc44e8ec36d4a2beacd5f17 \ No newline at end of file diff --git a/src/vdbemem.c b/src/vdbemem.c index b92ec84337..76147442ab 100644 --- a/src/vdbemem.c +++ b/src/vdbemem.c @@ -1355,9 +1355,11 @@ static int valueFromExpr( } #endif +#ifdef SQLITE_ENABLE_STAT3_OR_STAT4 else if( op==TK_FUNCTION && pCtx!=0 ){ rc = valueFromFunction(db, pExpr, enc, affinity, &pVal, pCtx); } +#endif *ppVal = pVal; return rc; From 75a4d7c3da500ffd527603d5ec8906498f17c3f7 Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 16 Mar 2015 16:44:55 +0000 Subject: [PATCH 21/63] When deleting the master journal to commit a multi-database transaction, do not sync the directory if PRAGMA synchronous=OFF for all participating database files. FossilOrigin-Name: 018d7671402a0f8103d1306641655b69f9fa235d --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/vdbeaux.c | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index e7e9fb89d8..c965f4df6b 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C When\sestimating\sthe\snumber\sof\srows\svisited\sby\sa\srange\sscan\sfor\swhich\sthe\skeys\sconsist\sof\smore\sthan\sone\sfield,\sconsider\sprefixes\sof\sstat4\ssamples\sas\swell\sas\sthe\sfull\ssamples.\sThis\sgenerates\smore\saccurate\sestimates. -D 2015-03-16T16:28:43.573 +C When\sdeleting\sthe\smaster\sjournal\sto\scommit\sa\smulti-database\stransaction,\sdo\nnot\ssync\sthe\sdirectory\sif\sPRAGMA\ssynchronous=OFF\sfor\sall\sparticipating\ndatabase\sfiles. +D 2015-03-16T16:44:55.689 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -297,7 +297,7 @@ F src/vdbe.c a2725107658fd9572637e8e09d46dcfe851edb96 F src/vdbe.h 6fc69d9c5e146302c56e163cb4b31d1ee64a18c3 F src/vdbeInt.h bb56fd199d8af1a2c1b9639ee2f70724b4338e3a F src/vdbeapi.c 583d56b129dd27f12bed518270de9ebe521e6a75 -F src/vdbeaux.c 97911edb61074b871ec4aa2d6bb779071643dee5 +F src/vdbeaux.c 23390670e64f011f3fed8f38a2f25aaccacb74d2 F src/vdbeblob.c 4f2e8e075d238392df98c5e03a64342465b03f90 F src/vdbemem.c c0dc81285b7571b0a31c40f17846fe2397ec1cd9 F src/vdbesort.c 6d64c5448b64851b99931ede980addc3af70d5e2 @@ -1244,7 +1244,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P f2c9c5b57b7739daafc44e8ec36d4a2beacd5f17 f2207a0691ed361061719f4dacf021a677a9d892 -R 91b4618acc4046613febfb03ba644299 -U dan -Z a47ebefe49a8b31d8182fc2d2ef4fe70 +P 3e0590dee0e68cc1599858757c650a7378026170 +R b45bc6830f64f8858a6416472978aee0 +U drh +Z 7cd47bb94490a64601179f11e40a837c diff --git a/manifest.uuid b/manifest.uuid index 7834d3d08a..1d6abc47d5 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -3e0590dee0e68cc1599858757c650a7378026170 \ No newline at end of file +018d7671402a0f8103d1306641655b69f9fa235d \ No newline at end of file diff --git a/src/vdbeaux.c b/src/vdbeaux.c index cd9ecaa691..9c105cc9e7 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -2143,7 +2143,7 @@ static int vdbeCommit(sqlite3 *db, Vdbe *p){ ** doing this the directory is synced again before any individual ** transaction files are deleted. */ - rc = sqlite3OsDelete(pVfs, zMaster, 1); + rc = sqlite3OsDelete(pVfs, zMaster, needSync); sqlite3DbFree(db, zMaster); zMaster = 0; if( rc ){ From 07b38959a4db58e856d3cf208a3e064897794b63 Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 16 Mar 2015 17:07:09 +0000 Subject: [PATCH 22/63] Modify the fts3query.test script so that it works even when testfixture is built using a version of TCL that is unable to sort the integer -9223372036854775808 FossilOrigin-Name: f61fd24b4d3b686911ea578f77612309099f0cc6 --- manifest | 12 ++++++------ manifest.uuid | 2 +- test/fts3query.test | 14 +++++++++----- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/manifest b/manifest index c965f4df6b..cfdd9a1b92 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C When\sdeleting\sthe\smaster\sjournal\sto\scommit\sa\smulti-database\stransaction,\sdo\nnot\ssync\sthe\sdirectory\sif\sPRAGMA\ssynchronous=OFF\sfor\sall\sparticipating\ndatabase\sfiles. -D 2015-03-16T16:44:55.689 +C Modify\sthe\sfts3query.test\sscript\sso\sthat\sit\sworks\seven\swhen\stestfixture\sis\nbuilt\susing\sa\sversion\sof\sTCL\sthat\sis\sunable\sto\ssort\sthe\ninteger\s-9223372036854775808 +D 2015-03-16T17:07:09.229 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -594,7 +594,7 @@ F test/fts3matchinfo.test 58544fa4d254000fa4e7f494b0a832f7ba61d45e F test/fts3near.test 7e3354d46f155a822b59c0e957fd2a70c1d7e905 F test/fts3prefix.test b36d4f00b128a51e7b386cc013a874246d9d7dc1 F test/fts3prefix2.test e1f0a822ca661dced7f12ce392e14eaf65609dce -F test/fts3query.test d81ffb0ab1d4e1a2a330b8eb1e160b60603f4745 +F test/fts3query.test c838b18f2b859e15fd31c64be3d79ef1556803ca F test/fts3rnd.test 1320d8826a845e38a96e769562bf83d7a92a15d0 F test/fts3shared.test 57e26a801f21027b7530da77db54286a6fe4997e F test/fts3snippet.test 03c2f3be7d3b7c8bb105ed237f204833392bd57f @@ -1244,7 +1244,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 3e0590dee0e68cc1599858757c650a7378026170 -R b45bc6830f64f8858a6416472978aee0 +P 018d7671402a0f8103d1306641655b69f9fa235d +R 781e204d7688b0ad2593ede4825cc937 U drh -Z 7cd47bb94490a64601179f11e40a837c +Z 1bc9733af443d0b92b43469552bb99df diff --git a/manifest.uuid b/manifest.uuid index 1d6abc47d5..4001277083 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -018d7671402a0f8103d1306641655b69f9fa235d \ No newline at end of file +f61fd24b4d3b686911ea578f77612309099f0cc6 \ No newline at end of file diff --git a/test/fts3query.test b/test/fts3query.test index 0b3c2ce1bd..06019d14e6 100644 --- a/test/fts3query.test +++ b/test/fts3query.test @@ -252,15 +252,21 @@ foreach {tn iFirst iLast} [subst { do_execsql_test 7.2.$tn.1.[llength $res] { SELECT rowid FROM ft4 WHERE rowid BETWEEN $iFirst AND $iLast } $res + set res [db eval { + SELECT rowid FROM t4 WHERE rowid BETWEEN $iFirst AND $iLast + ORDER BY +rowid DESC + } ] do_execsql_test 7.2.$tn.2.[llength $res] { SELECT rowid FROM ft4 WHERE rowid BETWEEN $iFirst AND $iLast ORDER BY rowid DESC - } [lsort -decr -integer $res] + } $res } foreach ii [db eval {SELECT rowid FROM t4}] { set res1 [db eval {SELECT rowid FROM t4 WHERE rowid > $ii}] set res2 [db eval {SELECT rowid FROM t4 WHERE rowid < $ii}] + set res1s [db eval {SELECT rowid FROM t4 WHERE rowid > $ii ORDER BY +rowid DESC}] + set res2s [db eval {SELECT rowid FROM t4 WHERE rowid < $ii ORDER BY +rowid DESC}] do_execsql_test 7.3.$ii.1 { SELECT rowid FROM ft4 WHERE rowid > $ii @@ -272,13 +278,11 @@ foreach ii [db eval {SELECT rowid FROM t4}] { do_execsql_test 7.3.$ii.3 { SELECT rowid FROM ft4 WHERE rowid > $ii ORDER BY rowid DESC - } [lsort -integer -decr $res1] + } $res1s do_execsql_test 7.3.$ii.4 { SELECT rowid FROM ft4 WHERE rowid < $ii ORDER BY rowid DESC - } [lsort -integer -decr $res2] + } $res2s } finish_test - - From 05b6048dbd49fb9507221f34318a69c5d1253f34 Mon Sep 17 00:00:00 2001 From: mistachkin Date: Mon, 16 Mar 2015 18:08:56 +0000 Subject: [PATCH 23/63] Fix typo of test prefix in the new WHERE test file. FossilOrigin-Name: 34779c528f1817d6ec34216b58fb4277956b5167 --- manifest | 15 +++++++-------- manifest.uuid | 2 +- test/whereK.test | 2 +- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index c44128ac44..80af8718b8 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C When\sthe\sWHERE\sclause\scontains\stwo\sOR-connected\sterms\swith\sidentical\noperands\sbut\sdifferent\soperators,\stry\sto\scombine\sthem\sinto\sa\ssingle\sterm.\nExample:\s\s(X=A\sOR\sX>A)\sbecomes\s(X>=A). -D 2015-03-16T17:48:12.769 +C Fix\stypo\sof\stest\sprefix\sin\sthe\snew\sWHERE\stest\sfile. +D 2015-03-16T18:08:56.916 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -1175,7 +1175,7 @@ F test/whereG.test 69f5ec4b15760a8c860f80e2d55525669390aab3 F test/whereH.test e4b07f7a3c2f5d31195cd33710054c78667573b2 F test/whereI.test 1d89199697919d4930be05a71e7fe620f114e622 F test/whereJ.test 55a3221706a7ab706293f17cc8f96da563bf0767 -F test/whereK.test 78fb50c74c9a91efc97a1daa39bcf7b8b68d8bff +F test/whereK.test f8e3cf26a8513ecc7f514f54df9f0572c046c42b F test/wherelimit.test 5e9fd41e79bb2b2d588ed999d641d9c965619b31 F test/wild001.test bca33f499866f04c24510d74baf1e578d4e44b1c F test/win32heap.test ea19770974795cff26e11575e12d422dbd16893c @@ -1245,8 +1245,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P f61fd24b4d3b686911ea578f77612309099f0cc6 23f71a26386ff2aff9800fe96cec1dc9c805b5b6 -R 0810c9b992d63ac661e729a83d3536b4 -T +closed 23f71a26386ff2aff9800fe96cec1dc9c805b5b6 -U drh -Z f335a12b6cd889ae802417698f792d1a +P 8bdda827a3d268009297a0216e3d94bf0eceeb2e +R 5cfb4e6342c564787ed07b1b1007b605 +U mistachkin +Z 76cd4818fe183f76c64a28733f84e037 diff --git a/manifest.uuid b/manifest.uuid index ecc96888a0..b5adcae9f4 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -8bdda827a3d268009297a0216e3d94bf0eceeb2e \ No newline at end of file +34779c528f1817d6ec34216b58fb4277956b5167 \ No newline at end of file diff --git a/test/whereK.test b/test/whereK.test index 8d294446a5..13c86508f9 100644 --- a/test/whereK.test +++ b/test/whereK.test @@ -21,7 +21,7 @@ set testdir [file dirname $argv0] source $testdir/tester.tcl -set ::testprefix whereD +set ::testprefix whereK do_execsql_test 1.1 { CREATE TABLE t1(a,b,c); From f104abba8417ff2f971580cb1be400c0d6e5fbfe Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 16 Mar 2015 20:40:00 +0000 Subject: [PATCH 24/63] Make SQLite slightly more likely to use an auto-index within a sub-query. FossilOrigin-Name: ab832336f4a28193c4d2b61e833564822a7b86a8 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/where.c | 6 +++--- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index 80af8718b8..781a270193 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\stypo\sof\stest\sprefix\sin\sthe\snew\sWHERE\stest\sfile. -D 2015-03-16T18:08:56.916 +C Make\sSQLite\sslightly\smore\slikely\sto\suse\san\sauto-index\swithin\sa\ssub-query. +D 2015-03-16T20:40:00.496 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -307,7 +307,7 @@ F src/vxworks.h c18586c8edc1bddbc15c004fa16aeb1e1342b4fb F src/wal.c 39303f2c9db02a4e422cd8eb2c8760420c6a51fe F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4 F src/walker.c c253b95b4ee44b21c406e2a1052636c31ea27804 -F src/where.c 5ca2899f280c4259a07816f4395d0bea368cfbd7 +F src/where.c 42ce3fd5ec9fe050f623be358cfddee01c1f6286 F src/whereInt.h cbe4aa57326998d89e7698ca65bb7c28541d483c F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2 @@ -1245,7 +1245,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 8bdda827a3d268009297a0216e3d94bf0eceeb2e -R 5cfb4e6342c564787ed07b1b1007b605 -U mistachkin -Z 76cd4818fe183f76c64a28733f84e037 +P 34779c528f1817d6ec34216b58fb4277956b5167 +R 20e702b8205b517ce2cb7b49f472a434 +U dan +Z 33f45126f2bf7daffd881933acc4eaa9 diff --git a/manifest.uuid b/manifest.uuid index b5adcae9f4..cc066477d9 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -34779c528f1817d6ec34216b58fb4277956b5167 \ No newline at end of file +ab832336f4a28193c4d2b61e833564822a7b86a8 \ No newline at end of file diff --git a/src/where.c b/src/where.c index 2fe076ba6d..6a1f481d60 100644 --- a/src/where.c +++ b/src/where.c @@ -6001,10 +6001,10 @@ static int wherePathSolver(WhereInfo *pWInfo, LogEst nRowEst){ /* Seed the search with a single WherePath containing zero WhereLoops. ** - ** TUNING: Do not let the number of iterations go above 25. If the cost - ** of computing an automatic index is not paid back within the first 25 + ** TUNING: Do not let the number of iterations go above 28. If the cost + ** of computing an automatic index is not paid back within the first 28 ** rows, then do not use the automatic index. */ - aFrom[0].nRow = MIN(pParse->nQueryLoop, 46); assert( 46==sqlite3LogEst(25) ); + aFrom[0].nRow = MIN(pParse->nQueryLoop, 48); assert( 48==sqlite3LogEst(28) ); nFrom = 1; assert( aFrom[0].isOrdered==0 ); if( nOrderBy ){ From 363fc9e724d1597ef58ad699e6667917355f921d Mon Sep 17 00:00:00 2001 From: dan Date: Tue, 17 Mar 2015 16:01:29 +0000 Subject: [PATCH 25/63] Add a test for the change on this branch. FossilOrigin-Name: e22dde187eb0b389d6d93e2e39a26fd0f4e6196e --- manifest | 20 ++++---- manifest.uuid | 2 +- src/test_vfs.c | 13 +++-- test/lock_common.tcl | 58 +++++++++++++++------ test/walblock.test | 117 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 177 insertions(+), 33 deletions(-) create mode 100644 test/walblock.test diff --git a/manifest b/manifest index 881ae7d644..d62ee302a3 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Arrange\sfor\ssome\sof\sthe\stransient\slocks\sin\sWAL\smode\sto\sblock,\sas\sa\ssingle\nto\sthe\sOS\sto\sfix\spriority\sinversions. -D 2015-03-10T20:22:35.302 +C Add\sa\stest\sfor\sthe\schange\son\sthis\sbranch. +D 2015-03-17T16:01:29.508 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 2f643d6968dfc0b82d2e546a0525a39079f9e928 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -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 5a14c63da9579ba148138c1fb233100f2eb58ebb +F src/test_vfs.c b7e6831e6fcf04c5090accff30640ec5c9630739 F src/test_vfstrace.c bab9594adc976cbe696ff3970728830b4c5ed698 F src/test_wsd.c 41cadfd9d97fe8e3e4e44f61a4a8ccd6f7ca8fe9 F src/threads.c 6bbcc9fe50c917864d48287b4792d46d6e873481 @@ -702,7 +702,7 @@ F test/lock4.test e175ae13865bc87680607563bafba21f31a26f12 F test/lock5.test c6c5e0ebcb21c61a572870cc86c0cb9f14cede38 F test/lock6.test ad5b387a3a8096afd3c68a55b9535056431b0cf5 F test/lock7.test 49f1eaff1cdc491cc5dee3669f3c671d9f172431 -F test/lock_common.tcl 0c270b121d40959fa2f3add382200c27045b3d95 +F test/lock_common.tcl 7ffb45accf6ee91c736df9bafe0806a44358f035 F test/lookaside.test 93f07bac140c5bb1d49f3892d2684decafdc7af2 F test/main.test 16131264ea0c2b93b95201f0c92958e85f2ba11a F test/make-where7.tcl 05c16b5d4f5d6512881dfec560cb793915932ef9 @@ -1139,6 +1139,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/walcksum.test 9afeb96240296c08c72fc524d199c912cfe34daa F test/walcrash.test 451d79e528add5c42764cea74aa2750754171b25 F test/walcrash2.test a0edab4e5390f03b99a790de89aad15d6ec70b36 @@ -1241,10 +1242,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 8d0b11c96e15556dd65ced05708a832aef134e69 -R e3a6235cb886b3e146e5aa9fea4e9436 -T *branch * wal-blocking-lock -T *sym-wal-blocking-lock * -T -sym-trunk * -U drh -Z 53b7d268fee9eb6c03e124e757f212c1 +P c6e6d5f4e06c3ac0bfb620c0c728fbc7230c4a02 +R 15a95b25b03827505e198326f8e27a62 +U dan +Z 12b0ab91b3a13b6777d198c7ff155c7d diff --git a/manifest.uuid b/manifest.uuid index e908b35f97..21c37ab89a 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c6e6d5f4e06c3ac0bfb620c0c728fbc7230c4a02 \ No newline at end of file +e22dde187eb0b389d6d93e2e39a26fd0f4e6196e \ No newline at end of file diff --git a/src/test_vfs.c b/src/test_vfs.c index 561addfcc5..2277cf7eb5 100644 --- a/src/test_vfs.c +++ b/src/test_vfs.c @@ -967,16 +967,15 @@ static void tvfsShmBarrier(sqlite3_file *pFile){ TestvfsFd *pFd = tvfsGetFd(pFile); Testvfs *p = (Testvfs *)(pFd->pVfs->pAppData); + if( p->pScript && p->mask&TESTVFS_SHMBARRIER_MASK ){ + const char *z = pFd->pShm ? pFd->pShm->zFile : ""; + tvfsExecTcl(p, "xShmBarrier", Tcl_NewStringObj(z, -1), pFd->pShmId, 0, 0); + } + if( p->isFullshm ){ sqlite3OsShmBarrier(pFd->pReal); return; } - - if( p->pScript && p->mask&TESTVFS_SHMBARRIER_MASK ){ - tvfsExecTcl(p, "xShmBarrier", - Tcl_NewStringObj(pFd->pShm->zFile, -1), pFd->pShmId, 0, 0 - ); - } } static int tvfsShmUnmap( @@ -1532,7 +1531,7 @@ static int testvfs_cmd( return TCL_OK; bad_args: - Tcl_WrongNumArgs(interp, 1, objv, "VFSNAME ?-noshm BOOL? ?-default BOOL? ?-mxpathname INT? ?-szosfile INT? ?-iversion INT?"); + Tcl_WrongNumArgs(interp, 1, objv, "VFSNAME ?-noshm BOOL? ?-fullshm BOOL? ?-default BOOL? ?-mxpathname INT? ?-szosfile INT? ?-iversion INT?"); return TCL_ERROR; } diff --git a/test/lock_common.tcl b/test/lock_common.tcl index bc1eb86bdc..a758e7af2e 100644 --- a/test/lock_common.tcl +++ b/test/lock_common.tcl @@ -86,21 +86,51 @@ proc launch_testfixture {{prg ""}} { # Execute a command in a child testfixture process, connected by two-way # channel $chan. Return the result of the command, or an error message. # -proc testfixture {chan cmd} { - puts $chan $cmd - puts $chan OVER - set r "" - while { 1 } { +proc testfixture {chan cmd args} { + + if {[llength $args] == 0} { + fconfigure $chan -blocking 1 + puts $chan $cmd + puts $chan OVER + + set r "" + while { 1 } { + set line [gets $chan] + if { $line == "OVER" } { + set res [lindex $r 1] + if { [lindex $r 0] } { error $res } + return $res + } + if {[eof $chan]} { + return "ERROR: Child process hung up" + } + append r $line + } + return $r + } else { + set ::tfnb($chan) "" + fconfigure $chan -blocking 0 -buffering none + puts $chan $cmd + puts $chan OVER + fileevent $chan readable [list testfixture_script_cb $chan [lindex $args 0]] + return "" + } +} + +proc testfixture_script_cb {chan script} { + if {[eof $chan]} { + append ::tfnb($chan) "ERROR: Child process hung up" + set line "OVER" + } else { set line [gets $chan] - if { $line == "OVER" } { - set res [lindex $r 1] - if { [lindex $r 0] } { error $res } - return $res - } - if {[eof $chan]} { - return "ERROR: Child process hung up" - } - append r $line + } + + if { $line == "OVER" } { + uplevel #0 $script [list [lindex $::tfnb($chan) 1]] + unset ::tfnb($chan) + fileevent $chan readable "" + } else { + append ::tfnb($chan) $line } } diff --git a/test/walblock.test b/test/walblock.test new file mode 100644 index 0000000000..9a85ea4acc --- /dev/null +++ b/test/walblock.test @@ -0,0 +1,117 @@ +# 2015 Mar 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. +# +#*********************************************************************** +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +source $testdir/lock_common.tcl +source $testdir/wal_common.tcl + +ifcapable !wal {finish_test ; return } +if {$::tcl_platform(platform)!="unix"} { finish_test ; return } +set testprefix walblock + +catch { db close } +testvfs tvfs -fullshm 1 +foreach f [glob test.db*] { forcedelete $f } + +sqlite3 db test.db -vfs tvfs +do_execsql_test 1.1.0 { + CREATE TABLE t1(x, y); + INSERT INTO t1 VALUES(1, 2); + INSERT INTO t1 VALUES(3, 4); + INSERT INTO t1 VALUES(5, 6); + PRAGMA journal_mode = wal; + INSERT INTO t1 VALUES(7, 8); +} {wal} + +do_test 1.1.1 { + lsort [glob test.db*] +} {test.db test.db-shm test.db-wal} + +do_test 1.1.2 { + set C [launch_testfixture] + testfixture $C { + sqlite3 db test.db + db eval { SELECT * FROM t1 } + } +} {1 2 3 4 5 6 7 8} + +do_test 1.1.3 { + set ::out [list] + testfixture $C { + db eval { SELECT * FROM t1 } + } [list set ::out] + set ::out +} {} + +do_test 1.1.4 { + vwait ::out + set ::out +} {1 2 3 4 5 6 7 8} + +# +# Test that if a read client cannot read the wal-index header because a +# write client is in the middle of updating it, the reader blocks until +# the writer finishes. +# +# 1. Open a write transaction using client [db] in this process. +# +# 2. Attempt to commit the write transaction. Intercept the xShmBarrier() +# call made by the writer between updating the two copies of the +# wal-index header. +# +# 3. Within the xShmBarrier() callback, make an asynchronous request to +# the other process to read from the database. It should block, as it +# cannot get read the wal-index header. +# +# 4. Still in xShmBarrier(), wait for 5 seconds. Check that the other +# process has not answered the request. +# +# 5: Finish committing the transaction. Then wait for 0.5 seconds more. +# Ensure that the second process has by this stage read the database +# and that the snapshot it read included the transaction committed in +# step (4). +# +do_execsql_test 1.2.1 { + BEGIN; + INSERT INTO t1 VALUES(9, 10); +} {} + +tvfs script barrier_callback +tvfs filter xShmBarrier +proc barrier_callback {method args} { + set ::out "" + testfixture $::C { db eval { SELECT * FROM t1 } } {set ::out} + + do_test "1.2.2.(blocking 5 seconds)" { + set ::continue 0 + after 5000 {set ::continue 1} + vwait ::continue + set ::out + } {} +} + +execsql COMMIT + +do_test "1.2.3.(blocking 0.5 seconds)" { + set ::continue 0 + after 500 {set ::continue 1} + vwait ::continue + set ::out +} {1 2 3 4 5 6 7 8 9 10} + + +finish_test + + + + From d671e66337d40fe53625abe36404a155e95aa400 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 17 Mar 2015 20:39:11 +0000 Subject: [PATCH 26/63] Clarify the documentation on sqlite3_errcode(). No changes to code. FossilOrigin-Name: 2c0e0d87fb418d684fba1c83d9fd8e4e96588c54 --- manifest | 13 ++++++------- manifest.uuid | 2 +- src/sqlite.h.in | 12 +++++++----- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/manifest b/manifest index 47a6aa6b99..b57003d8ce 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Also\smerge\sthe\sWAL\sblocking\slock\stests\sthat\swere\ssomehow\smissed\son\sthe\nprevious\scheck-in. -D 2015-03-17T17:08:35.872 +C Clarify\sthe\sdocumentation\son\ssqlite3_errcode().\s\sNo\schanges\sto\scode. +D 2015-03-17T20:39:11.595 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 94e016b6733b1d39a2f4c8d431155b4c2897d907 F src/shell.c cce82ca26392578a4a1ee927dfe55ea3411c7c92 -F src/sqlite.h.in ce547ac4df17e8d996679f7a385911b3a0c52d48 +F src/sqlite.h.in 2d48e05677d0f9b06b7757662eef3cebea02d837 F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h 17d487c3c91b0b8c584a32fbeb393f6f795eea7d F src/sqliteInt.h fae682c2b4dfbe489b134d74521c41c088f16ab1 @@ -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 ec2f46de531ec8ef91981b19b48ab64db7727264 e22dde187eb0b389d6d93e2e39a26fd0f4e6196e -R 35d1aacb5b2efba4948b8dccdeab808c -T +closed e22dde187eb0b389d6d93e2e39a26fd0f4e6196e +P 7214dab7443d35c105904dd69635c1f8b45b2fc8 +R 2fa9dda445b6fbb66c03820d7f35f5b9 U drh -Z 7357efe8421db7654a103c304e504696 +Z b0621e44776b9609d48318da3b5f6489 diff --git a/manifest.uuid b/manifest.uuid index f8ce2770f1..99a0aa5cf4 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -7214dab7443d35c105904dd69635c1f8b45b2fc8 \ No newline at end of file +2c0e0d87fb418d684fba1c83d9fd8e4e96588c54 \ No newline at end of file diff --git a/src/sqlite.h.in b/src/sqlite.h.in index 483534e494..ed0318fe3a 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -3000,11 +3000,13 @@ sqlite3_int64 sqlite3_uri_int64(const char*, const char*, sqlite3_int64); /* ** CAPI3REF: Error Codes And Messages ** -** ^The sqlite3_errcode() interface returns the numeric [result code] or -** [extended result code] for the most recent failed sqlite3_* API call -** associated with a [database connection]. If a prior API call failed -** but the most recent API call succeeded, the return value from -** sqlite3_errcode() is undefined. ^The sqlite3_extended_errcode() +** ^If the most recent sqlite3_* API call associated with +** [database connection] D failed, then the sqlite3_errcode(D) interface +** returns the numeric [result code] or [extended result code] for that +** API call. +** If the most recent API call was successful, +** then the return value from sqlite3_errcode() is undefined. +** ^The sqlite3_extended_errcode() ** interface is the same except that it always returns the ** [extended result code] even when extended result codes are ** disabled. From 2b3f1409dbd7f4e0111ba6f11319cdec311f7a03 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 18 Mar 2015 16:00:44 +0000 Subject: [PATCH 27/63] Add another sqlite3FaultSim() to the multi-threaded sorter logic to improve testability. FossilOrigin-Name: 49ea2cded4a76596f85419c820cdaf4a1751d7ac --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/vdbesort.c | 1 + 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/manifest b/manifest index b57003d8ce..ca434d481c 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Clarify\sthe\sdocumentation\son\ssqlite3_errcode().\s\sNo\schanges\sto\scode. -D 2015-03-17T20:39:11.595 +C Add\sanother\ssqlite3FaultSim()\sto\sthe\smulti-threaded\ssorter\slogic\sto\nimprove\stestability. +D 2015-03-18T16:00:44.998 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 23390670e64f011f3fed8f38a2f25aaccacb74d2 F src/vdbeblob.c 4f2e8e075d238392df98c5e03a64342465b03f90 F src/vdbemem.c c0dc81285b7571b0a31c40f17846fe2397ec1cd9 -F src/vdbesort.c 6d64c5448b64851b99931ede980addc3af70d5e2 +F src/vdbesort.c 919717d7599fa31d343ec28bffd0f9e91a4ff5f6 F src/vdbetrace.c 7e4222955e07dd707a2f360c0eb73452be1cb010 F src/vtab.c 699f2b8d509cfe379c33dde33827875d5b030e01 F src/vxworks.h c18586c8edc1bddbc15c004fa16aeb1e1342b4fb @@ -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 7214dab7443d35c105904dd69635c1f8b45b2fc8 -R 2fa9dda445b6fbb66c03820d7f35f5b9 +P 2c0e0d87fb418d684fba1c83d9fd8e4e96588c54 +R 58ae90a14e230c20fd6999f0bc3305de U drh -Z b0621e44776b9609d48318da3b5f6489 +Z 224b0621dbed3257af56f4d91f4f2bf9 diff --git a/manifest.uuid b/manifest.uuid index 99a0aa5cf4..cc37f4c412 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -2c0e0d87fb418d684fba1c83d9fd8e4e96588c54 \ No newline at end of file +49ea2cded4a76596f85419c820cdaf4a1751d7ac \ No newline at end of file diff --git a/src/vdbesort.c b/src/vdbesort.c index 5a43a10542..bbdafa8230 100644 --- a/src/vdbesort.c +++ b/src/vdbesort.c @@ -1151,6 +1151,7 @@ static int vdbeSorterOpenTempFile( sqlite3_file **ppFd ){ int rc; + if( sqlite3FaultSim(202) ) return SQLITE_IOERR_ACCESS; rc = sqlite3OsOpenMalloc(db->pVfs, 0, ppFd, SQLITE_OPEN_TEMP_JOURNAL | SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | From 657b4a87e57148b16f876038ae1c61a9ca39d281 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 19 Mar 2015 13:30:41 +0000 Subject: [PATCH 28/63] Fix a bug in error handling in the ".trace" command of the command-line shell. FossilOrigin-Name: 6a48b5d794e891fdd167547c76835d677eb5e31d --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/shell.c | 2 +- test/shell4.test | 22 ++++++++++++++++++++-- 4 files changed, 29 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index ca434d481c..38d28bca9b 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sanother\ssqlite3FaultSim()\sto\sthe\smulti-threaded\ssorter\slogic\sto\nimprove\stestability. -D 2015-03-18T16:00:44.998 +C Fix\sa\sbug\sin\serror\shandling\sin\sthe\s".trace"\scommand\sof\sthe\scommand-line\sshell. +D 2015-03-19T13:30:41.360 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 94e016b6733b1d39a2f4c8d431155b4c2897d907 -F src/shell.c cce82ca26392578a4a1ee927dfe55ea3411c7c92 +F src/shell.c 3e8fc22bc1cd63fe595c84a880bd6184deb6c87b F src/sqlite.h.in 2d48e05677d0f9b06b7757662eef3cebea02d837 F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h 17d487c3c91b0b8c584a32fbeb393f6f795eea7d @@ -866,7 +866,7 @@ F test/sharedlock.test 5ede3c37439067c43b0198f580fd374ebf15d304 F test/shell1.test ca88b14a8fc8b1f3543a24e519d019585ac9c903 F test/shell2.test 12b8bf901b0e3a8ac58cf5c0c63a0a388d4d1862 F test/shell3.test 5e8545ec72c4413a0e8d4c6be56496e3c257ca29 -F test/shell4.test 8a9c08976291e6c6c808b4d718f4a8b299f339f5 +F test/shell4.test 4cd3bd50200bf2efd6a74175d98da65aa86daf26 F test/shell5.test c04e9f9f948305706b88377c464c7f08ce7479f9 F test/shortread1.test bb591ef20f0fd9ed26d0d12e80eee6d7ac8897a3 F test/show_speedtest1_rtree.tcl 32e6c5f073d7426148a6936a0408f4b5b169aba5 @@ -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 2c0e0d87fb418d684fba1c83d9fd8e4e96588c54 -R 58ae90a14e230c20fd6999f0bc3305de +P 49ea2cded4a76596f85419c820cdaf4a1751d7ac +R df8b9299e9511ef4e1117da2a3444343 U drh -Z 224b0621dbed3257af56f4d91f4f2bf9 +Z 8cda5daec6a5d1c3721d0a7774b9a78e diff --git a/manifest.uuid b/manifest.uuid index cc37f4c412..52200038fd 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -49ea2cded4a76596f85419c820cdaf4a1751d7ac \ No newline at end of file +6a48b5d794e891fdd167547c76835d677eb5e31d \ No newline at end of file diff --git a/src/shell.c b/src/shell.c index cf2481a37c..436c23d47b 100644 --- a/src/shell.c +++ b/src/shell.c @@ -3841,12 +3841,12 @@ static int do_meta_command(char *zLine, ShellState *p){ if( c=='t' && strncmp(azArg[0], "trace", n)==0 ){ open_db(p, 0); - output_file_close(p->traceOut); if( nArg!=2 ){ fprintf(stderr, "Usage: .trace FILE|off\n"); rc = 1; goto meta_command_exit; } + output_file_close(p->traceOut); p->traceOut = output_file_open(azArg[1]); #if !defined(SQLITE_OMIT_TRACE) && !defined(SQLITE_OMIT_FLOATING_POINT) if( p->traceOut==0 ){ diff --git a/test/shell4.test b/test/shell4.test index c29faf00cf..d1466f638c 100644 --- a/test/shell4.test +++ b/test/shell4.test @@ -12,12 +12,12 @@ # The focus of this file is testing the CLI shell tool. # These tests are specific to the .stats command. # -# $Id: shell4.test,v 1.7 2009/07/17 16:54:48 shaneh Exp $ -# +# 2015-03-19: Added tests for .trace # Test plan: # # shell4-1.*: Basic tests specific to the "stats" command. +# shell4-2.*: Basic tests for ".trace" # set testdir [file dirname $argv0] source $testdir/tester.tcl @@ -113,4 +113,22 @@ SELECT 1; [regexp {Autoindex Inserts} $res] } {1 1 1} +do_test shell4-2.1 { + catchcmd ":memory:" "CREATE TABLE t1(x);\n.trace" +} {1 {Usage: .trace FILE|off}} +do_test shell4-2.2 { + catchcmd ":memory:" "CREATE TABLE t1(x);\n.trace off\n.trace off\n" +} {0 {}} +do_test shell4-2.3 { + catchcmd ":memory:" ".trace stdout\n.trace\n.trace off\n.dump\n" +} {/^1 {PRAGMA.*Usage:.*}$/} +do_test shell4-2.4 { + catchcmd ":memory:" ".trace stdout\nCREATE TABLE t1(x);SELECT * FROM t1;" +} {0 {CREATE TABLE t1(x); +SELECT * FROM t1;}} +do_test shell4-2.5 { + catchcmd ":memory:" "CREATE TABLE t1(x);\n.trace stdout\nSELECT * FROM t1;" +} {0 {SELECT * FROM t1;}} + + finish_test From ba132c772843f484fcc7b5ccb182e1a6cd51eee0 Mon Sep 17 00:00:00 2001 From: mistachkin Date: Thu, 19 Mar 2015 14:48:38 +0000 Subject: [PATCH 29/63] Fix typo in shell error message. FossilOrigin-Name: 775a02d597549567a0634483525664643064b3fd --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/shell.c | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 38d28bca9b..ed4e0355ec 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sbug\sin\serror\shandling\sin\sthe\s".trace"\scommand\sof\sthe\scommand-line\sshell. -D 2015-03-19T13:30:41.360 +C Fix\stypo\sin\sshell\serror\smessage. +D 2015-03-19T14:48:38.750 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 94e016b6733b1d39a2f4c8d431155b4c2897d907 -F src/shell.c 3e8fc22bc1cd63fe595c84a880bd6184deb6c87b +F src/shell.c d1ecce877f899abc97cabdf6a0b8323b8c5a0b69 F src/sqlite.h.in 2d48e05677d0f9b06b7757662eef3cebea02d837 F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h 17d487c3c91b0b8c584a32fbeb393f6f795eea7d @@ -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 49ea2cded4a76596f85419c820cdaf4a1751d7ac -R df8b9299e9511ef4e1117da2a3444343 -U drh -Z 8cda5daec6a5d1c3721d0a7774b9a78e +P 6a48b5d794e891fdd167547c76835d677eb5e31d +R 979a11eba248fa38fa514a9555cd703f +U mistachkin +Z dce5b986584646110a469a810e885660 diff --git a/manifest.uuid b/manifest.uuid index 52200038fd..8875e55307 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -6a48b5d794e891fdd167547c76835d677eb5e31d \ No newline at end of file +775a02d597549567a0634483525664643064b3fd \ No newline at end of file diff --git a/src/shell.c b/src/shell.c index 436c23d47b..752106fcaf 100644 --- a/src/shell.c +++ b/src/shell.c @@ -2955,7 +2955,7 @@ static int do_meta_command(char *zLine, ShellState *p){ sCtx.nLine = 1; if( sCtx.zFile[0]=='|' ){ #ifdef SQLITE_OMIT_POPEN - fprintf(stderr, "Error: pipes are not supporte in this OS\n"); + fprintf(stderr, "Error: pipes are not supported in this OS\n"); return 1; #else sCtx.in = popen(sCtx.zFile+1, "r"); From b77009fdd98317e35545006da6b3e118abe3e2b8 Mon Sep 17 00:00:00 2001 From: dan Date: Thu, 19 Mar 2015 15:04:23 +0000 Subject: [PATCH 30/63] Add an assert() to check that the database mutex is held in sqlite3BtreeLeave(). FossilOrigin-Name: 31f54d7b0798e70da6a60b8ea3c5d9e35dce164c --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/btmutex.c | 1 + 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index ed4e0355ec..1ae225a00a 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\stypo\sin\sshell\serror\smessage. -D 2015-03-19T14:48:38.750 +C Add\san\sassert()\sto\scheck\sthat\sthe\sdatabase\smutex\sis\sheld\sin\ssqlite3BtreeLeave(). +D 2015-03-19T15:04:23.924 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -172,7 +172,7 @@ F src/attach.c 880f9b8641a829c563e52dd13c452ce457ae4dd8 F src/auth.c b56c78ebe40a2110fd361379f7e8162d23f92240 F src/backup.c ff743689c4d6c5cb55ad42ed9d174b2b3e71f1e3 F src/bitvec.c 19a4ba637bd85f8f63fc8c9bae5ade9fb05ec1cb -F src/btmutex.c 49ca66250c7dfa844a4d4cb8272b87420d27d3a5 +F src/btmutex.c 45a968cc85afed9b5e6cf55bf1f42f8d18107f79 F src/btree.c a31ac00e30fb7bb49e90e48ce29ef8a61591be96 F src/btree.h 9cbbb92aab22ef8b50493c40aa3f8de87c43a2fb F src/btreeInt.h 2bfefc01875d8da066504c233ec259fcb3b2ef72 @@ -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 6a48b5d794e891fdd167547c76835d677eb5e31d -R 979a11eba248fa38fa514a9555cd703f -U mistachkin -Z dce5b986584646110a469a810e885660 +P 775a02d597549567a0634483525664643064b3fd +R 7c7590b732697332c465fefcb5f1507b +U dan +Z 8ffeef564642b88e4dec32c8c3ec74e6 diff --git a/manifest.uuid b/manifest.uuid index 8875e55307..0d0a44cfdf 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -775a02d597549567a0634483525664643064b3fd \ No newline at end of file +31f54d7b0798e70da6a60b8ea3c5d9e35dce164c \ No newline at end of file diff --git a/src/btmutex.c b/src/btmutex.c index f9fe5b3dde..c9c8572dfb 100644 --- a/src/btmutex.c +++ b/src/btmutex.c @@ -141,6 +141,7 @@ static void SQLITE_NOINLINE btreeLockCarefully(Btree *p){ ** Exit the recursive mutex on a Btree. */ void sqlite3BtreeLeave(Btree *p){ + assert( sqlite3_mutex_held(p->db->mutex) ); if( p->sharable ){ assert( p->wantToLock>0 ); p->wantToLock--; From e0417626ea42db7a6857bc2c5eaf8aa3c5b9237f Mon Sep 17 00:00:00 2001 From: dan Date: Thu, 19 Mar 2015 15:52:07 +0000 Subject: [PATCH 31/63] Silently ignore any attempt to add a prefix index for prefixes zero bytes in size to an fts3/4 table. Or any prefix index size so large that it overflows a 32-bit signed integer. FossilOrigin-Name: ad4b19d2ac0889a23fe3b0fd844286efc10cdd82 --- ext/fts3/fts3.c | 9 +++++-- manifest | 14 +++++----- manifest.uuid | 2 +- test/fts3prefix.test | 64 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 79 insertions(+), 10 deletions(-) diff --git a/ext/fts3/fts3.c b/ext/fts3/fts3.c index a31d3f13fe..3c229403b4 100644 --- a/ext/fts3/fts3.c +++ b/ext/fts3/fts3.c @@ -957,7 +957,6 @@ static int fts3PrefixParameter( aIndex = sqlite3_malloc(sizeof(struct Fts3Index) * nIndex); *apIndex = aIndex; - *pnIndex = nIndex; if( !aIndex ){ return SQLITE_NOMEM; } @@ -969,11 +968,17 @@ static int fts3PrefixParameter( for(i=1; i Date: Thu, 19 Mar 2015 16:25:42 +0000 Subject: [PATCH 32/63] Fix an FTS3/4 problem with handling empty tokenizer declarations (e.g. "CREATE VIRTUAL TABLE t(tokenize=);"). FossilOrigin-Name: 26d2def8a53094356008861636d66f9ae8f2448a --- ext/fts3/fts3_tokenizer.c | 4 ++++ manifest | 16 ++++++++-------- manifest.uuid | 2 +- test/fts3atoken.test | 14 +++++++++++++- test/fts3prefix.test | 2 +- 5 files changed, 27 insertions(+), 11 deletions(-) diff --git a/ext/fts3/fts3_tokenizer.c b/ext/fts3/fts3_tokenizer.c index 04f84460e8..8bb8b178ba 100644 --- a/ext/fts3/fts3_tokenizer.c +++ b/ext/fts3/fts3_tokenizer.c @@ -161,6 +161,10 @@ int sqlite3Fts3InitTokenizer( zEnd = &zCopy[strlen(zCopy)]; z = (char *)sqlite3Fts3NextToken(zCopy, &n); + if( z==0 ){ + assert( n==0 ); + z = zCopy; + } z[n] = '\0'; sqlite3Fts3Dequote(z); diff --git a/manifest b/manifest index b99611d255..fdda3f5f6b 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Silently\signore\sany\sattempt\sto\sadd\sa\sprefix\sindex\sfor\sprefixes\szero\sbytes\sin\ssize\sto\san\sfts3/4\stable.\sOr\sany\sprefix\sindex\ssize\sso\slarge\sthat\sit\soverflows\sa\s32-bit\ssigned\sinteger. -D 2015-03-19T15:52:07.001 +C Fix\san\sFTS3/4\sproblem\swith\shandling\sempty\stokenizer\sdeclarations\s(e.g.\s"CREATE\sVIRTUAL\sTABLE\st(tokenize=);"). +D 2015-03-19T16:25:42.953 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 bbdc731bc91338050675c6d1da9ab82147391e16 +F ext/fts3/fts3_tokenizer.c 0f9e6e01de1e1fe2e79074e3cf70ed1b1ea848b7 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 fca30fd86db9241d571c637751e9a8a2f50f1451 +F test/fts3atoken.test 95c721d71acb141eb754701b15a8e60bb6eb4263 F test/fts3auto.test b981fea19b132b4e6878f50d7c1f369b28f68eb9 F test/fts3aux1.test f8f287a4a73f381f8fa15b6a70f36245f903d221 F test/fts3aux2.test 7ae2b2c13aefdf4169279a27a5f51780ce57f6ba @@ -592,7 +592,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 6bd3fc277769a373f90e96c04f8747bee823e4c5 +F test/fts3prefix.test 9f68e3598a139c23ec47d09299420e0fc4c72a83 F test/fts3prefix2.test e1f0a822ca661dced7f12ce392e14eaf65609dce F test/fts3query.test c838b18f2b859e15fd31c64be3d79ef1556803ca F test/fts3rnd.test 1320d8826a845e38a96e769562bf83d7a92a15d0 @@ -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 31f54d7b0798e70da6a60b8ea3c5d9e35dce164c -R c1ccfd4d897c82c68f9b103e55f1a682 +P ad4b19d2ac0889a23fe3b0fd844286efc10cdd82 +R c1e92c20bf07c55ca3aab820a2e7d65e U dan -Z 54b08ba960445bb515e6d618d815d203 +Z b1c155f5360e29835532ab6770165b81 diff --git a/manifest.uuid b/manifest.uuid index 1bc718e945..116f80cd03 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ad4b19d2ac0889a23fe3b0fd844286efc10cdd82 \ No newline at end of file +26d2def8a53094356008861636d66f9ae8f2448a \ No newline at end of file diff --git a/test/fts3atoken.test b/test/fts3atoken.test index b7722c7d04..904a9a3fc3 100644 --- a/test/fts3atoken.test +++ b/test/fts3atoken.test @@ -186,10 +186,22 @@ ifcapable icu { } {} } - do_test fts3token-internal { execsql { SELECT fts3_tokenizer_internal_test() } } {ok} +#------------------------------------------------------------------------- +# Test empty tokenizer names. +# +do_catchsql_test 6.1.1 { + CREATE VIRTUAL TABLE t3 USING fts4(tokenize=""); +} {1 {unknown tokenizer: }} +do_catchsql_test 6.1.2 { + CREATE VIRTUAL TABLE t3 USING fts4(tokenize=); +} {1 {unknown tokenizer: }} +do_catchsql_test 6.1.3 { + CREATE VIRTUAL TABLE t3 USING fts4(tokenize=" "); +} {1 {unknown tokenizer: }} + finish_test diff --git a/test/fts3prefix.test b/test/fts3prefix.test index 70f508ad9a..8ffabe8d65 100644 --- a/test/fts3prefix.test +++ b/test/fts3prefix.test @@ -266,7 +266,7 @@ do_execsql_test 6.4.2 { reset_db do_execsql_test 6.5.1 { CREATE VIRTUAL TABLE t1 USING fts4(prefix="2147483647,2147483648,2147483649"); - CREATE VIRTUAL TABLE t2 USING fts4(prefix=""); + CREATE VIRTUAL TABLE t2 USING fts4(prefix=); INSERT INTO t1 VALUES('He dressed himself in cycling clothes'); INSERT INTO t2 VALUES('He dressed himself in cycling clothes'); } {} From 7377945a7be8fb7afb742a35c0f31e61d6c8f0a5 Mon Sep 17 00:00:00 2001 From: dan Date: Thu, 19 Mar 2015 18:56:17 +0000 Subject: [PATCH 33/63] Fix a problem with creating virtual table with names specified using malformed utf-8 within utf-16 databases. FossilOrigin-Name: 9969cff2d0553c9bfa88a437e1bb0cc4200d49d7 --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/vdbe.c | 16 ++++++++++++---- src/vtab.c | 7 +++++-- test/vtab2.test | 20 +++++++++++++++++++- 5 files changed, 45 insertions(+), 16 deletions(-) diff --git a/manifest b/manifest index fdda3f5f6b..a1a8b5a964 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\san\sFTS3/4\sproblem\swith\shandling\sempty\stokenizer\sdeclarations\s(e.g.\s"CREATE\sVIRTUAL\sTABLE\st(tokenize=);"). -D 2015-03-19T16:25:42.953 +C Fix\sa\sproblem\swith\screating\svirtual\stable\swith\snames\sspecified\susing\smalformed\sutf-8\swithin\sutf-16\sdatabases. +D 2015-03-19T18:56:17.585 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 a2725107658fd9572637e8e09d46dcfe851edb96 +F src/vdbe.c 33f8e0b1bc928bf7a38526c4e58e0404617b09b9 F src/vdbe.h 6fc69d9c5e146302c56e163cb4b31d1ee64a18c3 F src/vdbeInt.h bb56fd199d8af1a2c1b9639ee2f70724b4338e3a F src/vdbeapi.c 583d56b129dd27f12bed518270de9ebe521e6a75 @@ -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 699f2b8d509cfe379c33dde33827875d5b030e01 +F src/vtab.c 1680f58978ae014a331d99b4c87316d079056c5e F src/vxworks.h c18586c8edc1bddbc15c004fa16aeb1e1342b4fb F src/wal.c 878c8e1a51cb2ec45c395d26b7d5cd9e1a098e4a F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4 @@ -1112,7 +1112,7 @@ F test/varint.test ab7b110089a08b9926ed7390e7e97bdefeb74102 F test/veryquick.test 57ab846bacf7b90cf4e9a672721ea5c5b669b661 F test/view.test f311691d696a5cc27e3c1b875cec1b0866b4ccd9 F test/vtab1.test 1cef14310144718812351a61c5cfb4ba8494a171 -F test/vtab2.test 7bcffc050da5c68f4f312e49e443063e2d391c0d +F test/vtab2.test 366256bee644d034cbe078fbe1ec5bbe6b13fe42 F test/vtab3.test b45f47d20f225ccc9c28dc915d92740c2dee311e F test/vtab4.test 942f8b8280b3ea8a41dae20e7822d065ca1cb275 F test/vtab5.test 889f444970393c73f1e077e2bdc5d845e157a391 @@ -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 ad4b19d2ac0889a23fe3b0fd844286efc10cdd82 -R c1e92c20bf07c55ca3aab820a2e7d65e +P 26d2def8a53094356008861636d66f9ae8f2448a +R d2ae591b867dc2d251eb915bd9224363 U dan -Z b1c155f5360e29835532ab6770165b81 +Z 0a1bb76f793e7ed736ebaafb02806892 diff --git a/manifest.uuid b/manifest.uuid index 116f80cd03..a2cd7b4ce8 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -26d2def8a53094356008861636d66f9ae8f2448a \ No newline at end of file +9969cff2d0553c9bfa88a437e1bb0cc4200d49d7 \ No newline at end of file diff --git a/src/vdbe.c b/src/vdbe.c index b67a3e766c..00b6cb5194 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -6009,13 +6009,21 @@ case OP_VBegin: { #endif /* SQLITE_OMIT_VIRTUALTABLE */ #ifndef SQLITE_OMIT_VIRTUALTABLE -/* Opcode: VCreate P1 * * P4 * +/* Opcode: VCreate P1 P2 * * * ** -** P4 is the name of a virtual table in database P1. Call the xCreate method -** for that table. +** P2 is a register that holds the name of a virtual table in database +** P1. Call the xCreate method for that table. */ case OP_VCreate: { - rc = sqlite3VtabCallCreate(db, pOp->p1, pOp->p4.z, &p->zErrMsg); + Mem sMem; /* For storing the record being decoded */ + memset(&sMem, 0, sizeof(sMem)); + sMem.db = db; + rc = sqlite3VdbeMemCopy(&sMem, &aMem[pOp->p2]); + if( rc==SQLITE_OK ){ + const char *zTab = (const char*)sqlite3_value_text(&sMem); + rc = sqlite3VtabCallCreate(db, pOp->p1, zTab, &p->zErrMsg); + } + sqlite3VdbeMemRelease(&sMem); break; } #endif /* SQLITE_OMIT_VIRTUALTABLE */ diff --git a/src/vtab.c b/src/vtab.c index 96a1289dea..4631a7d0d0 100644 --- a/src/vtab.c +++ b/src/vtab.c @@ -389,6 +389,7 @@ void sqlite3VtabFinishParse(Parse *pParse, Token *pEnd){ char *zStmt; char *zWhere; int iDb; + int iReg; Vdbe *v; /* Compute the complete text of the CREATE VIRTUAL TABLE statement */ @@ -423,8 +424,10 @@ void sqlite3VtabFinishParse(Parse *pParse, Token *pEnd){ sqlite3VdbeAddOp2(v, OP_Expire, 0, 0); zWhere = sqlite3MPrintf(db, "name='%q' AND type='table'", pTab->zName); sqlite3VdbeAddParseSchemaOp(v, iDb, zWhere); - sqlite3VdbeAddOp4(v, OP_VCreate, iDb, 0, 0, - pTab->zName, sqlite3Strlen30(pTab->zName) + 1); + + iReg = ++pParse->nMem; + sqlite3VdbeAddOp4(v, OP_String8, 0, iReg, 0, pTab->zName, 0); + sqlite3VdbeAddOp2(v, OP_VCreate, iDb, iReg); } /* If we are rereading the sqlite_master table create the in-memory diff --git a/test/vtab2.test b/test/vtab2.test index 05a4834a1b..42b9da4670 100644 --- a/test/vtab2.test +++ b/test/vtab2.test @@ -10,10 +10,10 @@ #*********************************************************************** # This file implements regression tests for SQLite library. # -# $Id: vtab2.test,v 1.9 2008/10/13 10:37:50 danielk1977 Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl +set testprefix vtab2 ifcapable !vtab||!schema_pragmas { finish_test @@ -133,4 +133,22 @@ do_test vtab2-4.5 { execsql { SELECT * FROM fkey } } {t1 a} +#------------------------------------------------------------------------- +# +reset_db +do_execsql_test 5.1 { + PRAGMA encoding='UTF16'; +} + +do_test 5.2 { + sqlite3_exec_hex db { CREATE VIRTUAL TABLE %C8 USING fts3 } +} {0 {}} + +do_test 5.3 { + sqlite3_exec_hex db { CREATE VIRTUAL TABLE %C9 USING s } +} {/1 {malformed database schema.* already exists}/} + + + finish_test + From 8b3c0ae47c775e6e1064f9ad4b016d1a72106401 Mon Sep 17 00:00:00 2001 From: dan Date: Thu, 19 Mar 2015 19:59:30 +0000 Subject: [PATCH 34/63] Fix a crash that can occur following an OOM condition within a CREATE VIRTUAL TABLE statement on a utf-16 database. FossilOrigin-Name: 9453e7da046c55715631f10f018e97a336197969 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/vdbe.c | 5 ++++- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index a1a8b5a964..0e2648fb01 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sproblem\swith\screating\svirtual\stable\swith\snames\sspecified\susing\smalformed\sutf-8\swithin\sutf-16\sdatabases. -D 2015-03-19T18:56:17.585 +C Fix\sa\scrash\sthat\scan\soccur\sfollowing\san\sOOM\scondition\swithin\sa\sCREATE\sVIRTUAL\sTABLE\sstatement\son\sa\sutf-16\sdatabase. +D 2015-03-19T19:59:30.542 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 33f8e0b1bc928bf7a38526c4e58e0404617b09b9 +F src/vdbe.c b32dc2efe94a2c31ab4584066d47af2b56391f39 F src/vdbe.h 6fc69d9c5e146302c56e163cb4b31d1ee64a18c3 F src/vdbeInt.h bb56fd199d8af1a2c1b9639ee2f70724b4338e3a F src/vdbeapi.c 583d56b129dd27f12bed518270de9ebe521e6a75 @@ -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 26d2def8a53094356008861636d66f9ae8f2448a -R d2ae591b867dc2d251eb915bd9224363 +P 9969cff2d0553c9bfa88a437e1bb0cc4200d49d7 +R 8dbccb3b8b8000074fd25bdffb4c9d6a U dan -Z 0a1bb76f793e7ed736ebaafb02806892 +Z 868f2b8fd59504f6d90032dd8002c42b diff --git a/manifest.uuid b/manifest.uuid index a2cd7b4ce8..0492fcd8e8 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -9969cff2d0553c9bfa88a437e1bb0cc4200d49d7 \ No newline at end of file +9453e7da046c55715631f10f018e97a336197969 \ No newline at end of file diff --git a/src/vdbe.c b/src/vdbe.c index 00b6cb5194..82c3269e73 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -6021,7 +6021,10 @@ case OP_VCreate: { rc = sqlite3VdbeMemCopy(&sMem, &aMem[pOp->p2]); if( rc==SQLITE_OK ){ const char *zTab = (const char*)sqlite3_value_text(&sMem); - rc = sqlite3VtabCallCreate(db, pOp->p1, zTab, &p->zErrMsg); + assert( zTab || db->mallocFailed ); + if( zTab ){ + rc = sqlite3VtabCallCreate(db, pOp->p1, zTab, &p->zErrMsg); + } } sqlite3VdbeMemRelease(&sMem); break; From 80103fc614e42c8fb20c39a5b3091ab680c9cd00 Mon Sep 17 00:00:00 2001 From: dan Date: Fri, 20 Mar 2015 08:43:59 +0000 Subject: [PATCH 35/63] Fix a problem causing collation sequence names to be dequoted multiple times under some circumstances. FossilOrigin-Name: eddc05e7bb31fae74daa86e0504a3478b99fa0f2 --- manifest | 23 +++++++++--------- manifest.uuid | 2 +- src/expr.c | 7 +++--- src/parse.y | 6 ++--- src/sqliteInt.h | 2 +- src/where.c | 9 ++++--- test/collate1.test | 58 ++++++++++++++++++++++++++++++++++++++++++++-- 7 files changed, 80 insertions(+), 27 deletions(-) diff --git a/manifest b/manifest index 21259bb489..6ee57b552e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C If\sa\svirtual\stable\sis\screated\swith\sa\smalformed\sUTF8\sname\sin\sa\sUTF16\sdatabase,\nmake\ssure\sthat\sdoes\snot\scause\sproblems. -D 2015-03-19T20:09:16.788 +C Fix\sa\sproblem\scausing\scollation\ssequence\snames\sto\sbe\sdequoted\smultiple\stimes\sunder\ssome\scircumstances. +D 2015-03-20T08:43:59.683 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 3ef111b88ae2941b84b6b6ea4be8d501ba1af0cb +F src/expr.c eb4d795abca1e876726aecc7aeb95ceb29e73fe7 F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb F src/fkey.c e0444b61bed271a76840cbe6182df93a9baa3f12 F src/func.c 1414c24c873c48796ad45942257a179a423ba42f @@ -219,7 +219,7 @@ F src/os_win.c 8223e7db5b7c4a81d8b161098ac3959400434cdb F src/os_win.h eb7a47aa17b26b77eb97e4823f20a00b8bda12ca F src/pager.c 4120a49ecd37697e28f5ed807f470b9c0b88410c F src/pager.h c3476e7c89cdf1c6914e50a11f3714e30b4e0a77 -F src/parse.y 0f8e7d60f0ab3cb53d270adef69259ac307d83a8 +F src/parse.y 1299c66e7b1707322ccd8af43a359b8fb0d46d72 F src/pcache.c 10539fb959849ad6efff80050541cab3d25089d4 F src/pcache.h b44658c9c932d203510279439d891a2a83e12ba8 F src/pcache1.c 1e77432b40b7d3288327d9cdf399dcdfd2b6d3bf @@ -235,7 +235,7 @@ F src/shell.c d1ecce877f899abc97cabdf6a0b8323b8c5a0b69 F src/sqlite.h.in 2d48e05677d0f9b06b7757662eef3cebea02d837 F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h 17d487c3c91b0b8c584a32fbeb393f6f795eea7d -F src/sqliteInt.h fae682c2b4dfbe489b134d74521c41c088f16ab1 +F src/sqliteInt.h 0f36b72dbaee2306cd4df055e5e6125b3d7a2420 F src/sqliteLimit.h 216557999cb45f2e3578ed53ebefe228d779cb46 F src/status.c 81712116e826b0089bb221b018929536b2b5406f F src/table.c e7a09215315a978057fb42c640f890160dbcc45e @@ -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 42ce3fd5ec9fe050f623be358cfddee01c1f6286 +F src/where.c 6dc10d180e88dc0b3655296d0d1059cbaf4e237a F src/whereInt.h cbe4aa57326998d89e7698ca65bb7c28541d483c F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2 @@ -398,7 +398,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 73b91005f264b7c403e2d63a6708d150679ac99a +F test/collate1.test 7fcfe78f9613dc4a7e247d6bd27749955f108741 F test/collate2.test 9aaa410a00734e48bcb27f3872617d6f69b2a621 F test/collate3.test 79558a286362cb9ed603c6fa543f1cda7f563f0f F test/collate4.test f04d5168685f2eef637ecfa2d4ddf8ec0d600177 @@ -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 26d2def8a53094356008861636d66f9ae8f2448a 9453e7da046c55715631f10f018e97a336197969 -R 8dbccb3b8b8000074fd25bdffb4c9d6a -T +closed 9453e7da046c55715631f10f018e97a336197969 -U drh -Z 13302cbb890b9301083b42d23158dd80 +P b74cb0a92bba69f8ea705adf4695d03ea4470984 +R 0d4dc41d235c1c2ad9a38ee6dff0fe2f +U dan +Z 56b5996883845a15ff92eed0154203c2 diff --git a/manifest.uuid b/manifest.uuid index 2d9aece060..d98d8ad752 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -b74cb0a92bba69f8ea705adf4695d03ea4470984 \ No newline at end of file +eddc05e7bb31fae74daa86e0504a3478b99fa0f2 \ No newline at end of file diff --git a/src/expr.c b/src/expr.c index 5457a9c065..fe09b4b50b 100644 --- a/src/expr.c +++ b/src/expr.c @@ -69,10 +69,11 @@ char sqlite3ExprAffinity(Expr *pExpr){ Expr *sqlite3ExprAddCollateToken( Parse *pParse, /* Parsing context */ Expr *pExpr, /* Add the "COLLATE" clause to this expression */ - const Token *pCollName /* Name of collating sequence */ + const Token *pCollName, /* Name of collating sequence */ + int dequote /* True to dequote pCollName */ ){ if( pCollName->n>0 ){ - Expr *pNew = sqlite3ExprAlloc(pParse->db, TK_COLLATE, pCollName, 1); + Expr *pNew = sqlite3ExprAlloc(pParse->db, TK_COLLATE, pCollName, dequote); if( pNew ){ pNew->pLeft = pExpr; pNew->flags |= EP_Collate|EP_Skip; @@ -86,7 +87,7 @@ Expr *sqlite3ExprAddCollateString(Parse *pParse, Expr *pExpr, const char *zC){ assert( zC!=0 ); s.z = zC; s.n = sqlite3Strlen30(s.z); - return sqlite3ExprAddCollateToken(pParse, pExpr, &s); + return sqlite3ExprAddCollateToken(pParse, pExpr, &s, 0); } /* diff --git a/src/parse.y b/src/parse.y index 78e79cd361..b8ef26810c 100644 --- a/src/parse.y +++ b/src/parse.y @@ -860,7 +860,7 @@ expr(A) ::= VARIABLE(X). { spanSet(&A, &X, &X); } expr(A) ::= expr(E) COLLATE ids(C). { - A.pExpr = sqlite3ExprAddCollateToken(pParse, E.pExpr, &C); + A.pExpr = sqlite3ExprAddCollateToken(pParse, E.pExpr, &C, 1); A.zStart = E.zStart; A.zEnd = &C.z[C.n]; } @@ -1206,14 +1206,14 @@ uniqueflag(A) ::= . {A = OE_None;} idxlist_opt(A) ::= . {A = 0;} idxlist_opt(A) ::= LP idxlist(X) RP. {A = X;} idxlist(A) ::= idxlist(X) COMMA nm(Y) collate(C) sortorder(Z). { - Expr *p = sqlite3ExprAddCollateToken(pParse, 0, &C); + Expr *p = sqlite3ExprAddCollateToken(pParse, 0, &C, 1); A = sqlite3ExprListAppend(pParse,X, p); sqlite3ExprListSetName(pParse,A,&Y,1); sqlite3ExprListCheckLength(pParse, A, "index"); if( A ) A->a[A->nExpr-1].sortOrder = (u8)Z; } idxlist(A) ::= nm(Y) collate(C) sortorder(Z). { - Expr *p = sqlite3ExprAddCollateToken(pParse, 0, &C); + Expr *p = sqlite3ExprAddCollateToken(pParse, 0, &C, 1); A = sqlite3ExprListAppend(pParse,0, p); sqlite3ExprListSetName(pParse, A, &Y, 1); sqlite3ExprListCheckLength(pParse, A, "index"); diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 865976659c..7a4afd2240 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -3479,7 +3479,7 @@ int sqlite3ReadSchema(Parse *pParse); CollSeq *sqlite3FindCollSeq(sqlite3*,u8 enc, const char*,int); CollSeq *sqlite3LocateCollSeq(Parse *pParse, const char*zName); CollSeq *sqlite3ExprCollSeq(Parse *pParse, Expr *pExpr); -Expr *sqlite3ExprAddCollateToken(Parse *pParse, Expr*, const Token*); +Expr *sqlite3ExprAddCollateToken(Parse *pParse, Expr*, const Token*, int); Expr *sqlite3ExprAddCollateString(Parse*,Expr*,const char*); Expr *sqlite3ExprSkipCollate(Expr*); int sqlite3CheckCollSeq(Parse *, CollSeq *); diff --git a/src/where.c b/src/where.c index 6a1f481d60..4d65a14bcc 100644 --- a/src/where.c +++ b/src/where.c @@ -1364,7 +1364,7 @@ static void exprAnalyze( Expr *pNewExpr2; int idxNew1; int idxNew2; - Token sCollSeqName; /* Name of collating sequence */ + const char *zCollSeqName; /* Name of collating sequence */ const u16 wtFlags = TERM_LIKEOPT | TERM_VIRTUAL | TERM_DYNAMIC; pLeft = pExpr->x.pList->a[1].pExpr; @@ -1400,11 +1400,10 @@ static void exprAnalyze( } *pC = c + 1; } - sCollSeqName.z = noCase ? "NOCASE" : "BINARY"; - sCollSeqName.n = 6; + zCollSeqName = noCase ? "NOCASE" : "BINARY"; pNewExpr1 = sqlite3ExprDup(db, pLeft, 0); pNewExpr1 = sqlite3PExpr(pParse, TK_GE, - sqlite3ExprAddCollateToken(pParse,pNewExpr1,&sCollSeqName), + sqlite3ExprAddCollateString(pParse,pNewExpr1,zCollSeqName), pStr1, 0); transferJoinMarkings(pNewExpr1, pExpr); idxNew1 = whereClauseInsert(pWC, pNewExpr1, wtFlags); @@ -1412,7 +1411,7 @@ static void exprAnalyze( exprAnalyze(pSrc, pWC, idxNew1); pNewExpr2 = sqlite3ExprDup(db, pLeft, 0); pNewExpr2 = sqlite3PExpr(pParse, TK_LT, - sqlite3ExprAddCollateToken(pParse,pNewExpr2,&sCollSeqName), + sqlite3ExprAddCollateString(pParse,pNewExpr2,zCollSeqName), pStr2, 0); transferJoinMarkings(pNewExpr2, pExpr); idxNew2 = whereClauseInsert(pWC, pNewExpr2, wtFlags); diff --git a/test/collate1.test b/test/collate1.test index 20854157d3..0716ac743f 100644 --- a/test/collate1.test +++ b/test/collate1.test @@ -10,12 +10,12 @@ # #*********************************************************************** # This file implements regression tests for SQLite library. The -# focus of this script is page cache subsystem. +# focus of this script is testing collation sequences. # -# $Id: collate1.test,v 1.5 2007/02/01 23:02:46 drh Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl +set testprefix collate1 # # Tests are roughly organised as follows: @@ -333,4 +333,58 @@ do_test collate1-5.3 { } } {1 2} + + +#------------------------------------------------------------------------- +# Fix problems with handling collation sequences named '"""'. +# +do_execsql_test 6.1 { + SELECT """"""""; +} {\"\"\"} + +do_catchsql_test 6.2 { + CREATE TABLE x1(a); + SELECT a FROM x1 ORDER BY a COLLATE """"""""; +} {1 {no such collation sequence: """}} + +do_catchsql_test 6.3 { + SELECT a FROM x1 ORDER BY 1 COLLATE """"""""; +} {1 {no such collation sequence: """}} + +do_catchsql_test 6.4 { + SELECT 0 UNION SELECT 0 ORDER BY 1 COLLATE """"""""; +} {1 {no such collation sequence: """}} + +db collate {"""} [list string compare -nocase] + +do_execsql_test 6.5 { + PRAGMA foreign_keys = ON; + CREATE TABLE p1(a PRIMARY KEY COLLATE '"""'); + CREATE TABLE c1(x, y REFERENCES p1); +} {} + +do_execsql_test 6.6 { + INSERT INTO p1 VALUES('abc'); + INSERT INTO c1 VALUES(1, 'ABC'); +} + +ifcapable foreignkey { + do_catchsql_test 6.7 { + DELETE FROM p1 WHERE rowid = 1 + } {1 {FOREIGN KEY constraint failed}} +} + +do_execsql_test 6.8 { + INSERT INTO p1 VALUES('abb'); + INSERT INTO p1 VALUES('wxz'); + INSERT INTO p1 VALUES('wxy'); + + INSERT INTO c1 VALUES(2, 'abb'); + INSERT INTO c1 VALUES(3, 'wxz'); + INSERT INTO c1 VALUES(4, 'WXY'); + SELECT x, y FROM c1 ORDER BY y COLLATE """"""""; +} {2 abb 1 ABC 4 WXY 3 wxz} + finish_test + + From e0997b341b1ee889e05acf07e80e5d2fc80d71b1 Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 20 Mar 2015 14:57:50 +0000 Subject: [PATCH 36/63] Provide the BTREE_SEEK_EQ hint to the b-tree layer. FossilOrigin-Name: e750830f1e61160c0c67e35b13e50b35a95b50e1 --- manifest | 22 +++++++++++----------- manifest.uuid | 2 +- src/btree.c | 18 ++++++++++++++---- src/btree.h | 15 ++++++++++++++- src/sqliteInt.h | 3 ++- src/vdbe.c | 33 ++++++++++++++++++++++++++------- src/where.c | 6 ++++++ 7 files changed, 74 insertions(+), 25 deletions(-) diff --git a/manifest b/manifest index 6ee57b552e..58f3acff6f 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sproblem\scausing\scollation\ssequence\snames\sto\sbe\sdequoted\smultiple\stimes\sunder\ssome\scircumstances. -D 2015-03-20T08:43:59.683 +C Provide\sthe\sBTREE_SEEK_EQ\shint\sto\sthe\sb-tree\slayer. +D 2015-03-20T14:57:50.128 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -173,8 +173,8 @@ F src/auth.c b56c78ebe40a2110fd361379f7e8162d23f92240 F src/backup.c ff743689c4d6c5cb55ad42ed9d174b2b3e71f1e3 F src/bitvec.c 19a4ba637bd85f8f63fc8c9bae5ade9fb05ec1cb F src/btmutex.c 45a968cc85afed9b5e6cf55bf1f42f8d18107f79 -F src/btree.c a31ac00e30fb7bb49e90e48ce29ef8a61591be96 -F src/btree.h 9cbbb92aab22ef8b50493c40aa3f8de87c43a2fb +F src/btree.c d4d52fb14e863cff9dbc7c746e9048ec0967a555 +F src/btree.h 969adc948e89e449220ff0ff724c94bb2a52e9f1 F src/btreeInt.h 2bfefc01875d8da066504c233ec259fcb3b2ef72 F src/build.c ba45ebd02904e84d98839a6ea74c3eb948596587 F src/callback.c 7b44ce59674338ad48b0e84e7b72f935ea4f68b0 @@ -235,7 +235,7 @@ F src/shell.c d1ecce877f899abc97cabdf6a0b8323b8c5a0b69 F src/sqlite.h.in 2d48e05677d0f9b06b7757662eef3cebea02d837 F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h 17d487c3c91b0b8c584a32fbeb393f6f795eea7d -F src/sqliteInt.h 0f36b72dbaee2306cd4df055e5e6125b3d7a2420 +F src/sqliteInt.h f2300529f3592323a98fd7acccec63d0e9082dc5 F src/sqliteLimit.h 216557999cb45f2e3578ed53ebefe228d779cb46 F src/status.c 81712116e826b0089bb221b018929536b2b5406f F src/table.c e7a09215315a978057fb42c640f890160dbcc45e @@ -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 b32dc2efe94a2c31ab4584066d47af2b56391f39 +F src/vdbe.c 64d8325aed2020a8aa3bd1f6352d0b129299b2fa F src/vdbe.h 6fc69d9c5e146302c56e163cb4b31d1ee64a18c3 F src/vdbeInt.h bb56fd199d8af1a2c1b9639ee2f70724b4338e3a F src/vdbeapi.c 583d56b129dd27f12bed518270de9ebe521e6a75 @@ -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 6dc10d180e88dc0b3655296d0d1059cbaf4e237a +F src/where.c 85d832efa5ef57de542db7f430b72fecd3af8b38 F src/whereInt.h cbe4aa57326998d89e7698ca65bb7c28541d483c F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2 @@ -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 b74cb0a92bba69f8ea705adf4695d03ea4470984 -R 0d4dc41d235c1c2ad9a38ee6dff0fe2f -U dan -Z 56b5996883845a15ff92eed0154203c2 +P eddc05e7bb31fae74daa86e0504a3478b99fa0f2 +R 6b21b0e98ee76d198c2b5163fdb0b4f7 +U drh +Z 5cff4e9435b6ae28710f92cbaff291bb diff --git a/manifest.uuid b/manifest.uuid index d98d8ad752..58a06b41de 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -eddc05e7bb31fae74daa86e0504a3478b99fa0f2 \ No newline at end of file +e750830f1e61160c0c67e35b13e50b35a95b50e1 \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index 8957b74c19..1d82a2b625 100644 --- a/src/btree.c +++ b/src/btree.c @@ -7480,7 +7480,8 @@ static int balance(BtCursor *pCur){ ** pSpace buffer passed to the latter call to balance_nonroot(). */ u8 *pSpace = sqlite3PageMalloc(pCur->pBt->pageSize); - rc = balance_nonroot(pParent, iIdx, pSpace, iPage==1, pCur->hints); + rc = balance_nonroot(pParent, iIdx, pSpace, iPage==1, + pCur->hints&BTREE_BULKLOAD); if( pFree ){ /* If pFree is not NULL, it points to the pSpace buffer used ** by a previous call to balance_nonroot(). Its contents are @@ -9143,14 +9144,23 @@ int sqlite3BtreeSetVersion(Btree *pBtree, int iVersion){ } /* -** set the mask of hint flags for cursor pCsr. Currently the only valid -** values are 0 and BTREE_BULKLOAD. +** set the mask of hint flags for cursor pCsr. */ void sqlite3BtreeCursorHints(BtCursor *pCsr, unsigned int mask){ - assert( mask==BTREE_BULKLOAD || mask==0 ); + assert( mask==BTREE_BULKLOAD || mask==BTREE_SEEK_EQ || mask==0 ); pCsr->hints = mask; } +#ifdef SQLITE_DEBUG +/* +** Return true if the cursor has a hint specified. This routine is +** only used from within assert() statements +*/ +int sqlite3BtreeCursorHasHint(BtCursor *pCsr, unsigned int mask){ + return (pCsr->hints & mask)!=0; +} +#endif + /* ** Return true if the given Btree is read-only. */ diff --git a/src/btree.h b/src/btree.h index 77d12f78d3..3edc2b3b57 100644 --- a/src/btree.h +++ b/src/btree.h @@ -152,8 +152,18 @@ int sqlite3BtreeNewDb(Btree *p); /* ** Values that may be OR'd together to form the second argument of an ** sqlite3BtreeCursorHints() call. +** +** The BTREE_BULKLOAD flag is set on index cursors when the index is going +** to be filled with content that is already in sorted order. +** +** The BTREE_SEEK_EQ flag is set on cursors that will get OP_SeekGE or +** OP_SeekLE opcodes for a range search, but where the range of entries +** selected will all have the same key. In other words, the cursor will +** be used only for equality key searches. +** */ -#define BTREE_BULKLOAD 0x00000001 +#define BTREE_BULKLOAD 0x00000001 /* Used to full index in sorted order */ +#define BTREE_SEEK_EQ 0x00000002 /* EQ seeks only - no range seeks */ int sqlite3BtreeCursor( Btree*, /* BTree containing table to open */ @@ -199,6 +209,9 @@ void sqlite3BtreeIncrblobCursor(BtCursor *); void sqlite3BtreeClearCursor(BtCursor *); int sqlite3BtreeSetVersion(Btree *pBt, int iVersion); void sqlite3BtreeCursorHints(BtCursor *, unsigned int mask); +#ifdef SQLITE_DEBUG +int sqlite3BtreeCursorHasHint(BtCursor*, unsigned int mask); +#endif int sqlite3BtreeIsReadonly(Btree *pBt); int sqlite3HeaderSizeBtree(void); diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 7a4afd2240..9e174d6f4c 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -2692,7 +2692,8 @@ struct AuthContext { #define OPFLAG_LENGTHARG 0x40 /* OP_Column only used for length() */ #define OPFLAG_TYPEOFARG 0x80 /* OP_Column only used for typeof() */ #define OPFLAG_BULKCSR 0x01 /* OP_Open** used to open bulk cursor */ -#define OPFLAG_P2ISREG 0x02 /* P2 to OP_Open** is a register number */ +#define OPFLAG_SEEKEQ 0x02 /* OP_Open** cursor uses EQ seek only */ +#define OPFLAG_P2ISREG 0x04 /* P2 to OP_Open** is a register number */ #define OPFLAG_PERMUTE 0x01 /* OP_Compare: use the permutation */ /* diff --git a/src/vdbe.c b/src/vdbe.c index 82c3269e73..9a9503967a 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -3237,12 +3237,12 @@ case OP_SetCookie: { /* in3 */ case OP_ReopenIdx: { VdbeCursor *pCur; - assert( pOp->p5==0 ); + assert( pOp->p5==0 || pOp->p5==OPFLAG_SEEKEQ ); assert( pOp->p4type==P4_KEYINFO ); pCur = p->apCsr[pOp->p1]; if( pCur && pCur->pgnoRoot==(u32)pOp->p2 ){ assert( pCur->iDb==pOp->p3 ); /* Guaranteed by the code generator */ - break; + goto open_cursor_set_hints; } /* If the cursor is not currently open or is open on a different ** index, then fall through into OP_OpenRead to force a reopen */ @@ -3258,8 +3258,8 @@ case OP_OpenWrite: { VdbeCursor *pCur; Db *pDb; - assert( (pOp->p5&(OPFLAG_P2ISREG|OPFLAG_BULKCSR))==pOp->p5 ); - assert( pOp->opcode==OP_OpenWrite || pOp->p5==0 ); + assert( (pOp->p5&(OPFLAG_P2ISREG|OPFLAG_BULKCSR|OPFLAG_SEEKEQ))==pOp->p5 ); + assert( pOp->opcode==OP_OpenWrite || pOp->p5==0 || pOp->p5==OPFLAG_SEEKEQ ); assert( p->bIsReader ); assert( pOp->opcode==OP_OpenRead || pOp->opcode==OP_ReopenIdx || p->readOnly==0 ); @@ -3322,14 +3322,17 @@ case OP_OpenWrite: { pCur->pgnoRoot = p2; rc = sqlite3BtreeCursor(pX, p2, wrFlag, pKeyInfo, pCur->pCursor); pCur->pKeyInfo = pKeyInfo; - assert( OPFLAG_BULKCSR==BTREE_BULKLOAD ); - sqlite3BtreeCursorHints(pCur->pCursor, (pOp->p5 & OPFLAG_BULKCSR)); - /* Set the VdbeCursor.isTable variable. Previous versions of ** SQLite used to check if the root-page flags were sane at this point ** and report database corruption if they were not, but this check has ** since moved into the btree layer. */ pCur->isTable = pOp->p4type!=P4_KEYINFO; + +open_cursor_set_hints: + assert( OPFLAG_BULKCSR==BTREE_BULKLOAD ); + assert( OPFLAG_SEEKEQ==BTREE_SEEK_EQ ); + sqlite3BtreeCursorHints(pCur->pCursor, + (pOp->p5 & (OPFLAG_BULKCSR|OPFLAG_SEEKEQ))); break; } @@ -3590,6 +3593,22 @@ case OP_SeekGT: { /* jump, in3 */ #ifdef SQLITE_DEBUG pC->seekOp = pOp->opcode; #endif + + /* For a cursor with the BTREE_SEEK_EQ hint, only the OP_SeekGE and + ** OP_SeekLE opcodes are allowed, and these must be immediately followed + ** by an OP_IdxGT or OP_IdxLT opcode, respectively, with the same key. + */ +#ifdef SQLITE_DEBUG + if( sqlite3BtreeCursorHasHint(pC->pCursor, BTREE_SEEK_EQ) ){ + assert( pOp->opcode==OP_SeekGE || pOp->opcode==OP_SeekLE ); + assert( pOp[1].opcode==OP_IdxLT || pOp[1].opcode==OP_IdxGT ); + assert( pOp[1].p1==pOp[0].p1 ); + assert( pOp[1].p2==pOp[0].p2 ); + assert( pOp[1].p3==pOp[0].p3 ); + assert( pOp[1].p4.i==pOp[0].p4.i ); + } +#endif + if( pC->isTable ){ /* The input value in P3 might be of any type: integer, real, string, ** blob, or NULL. But it needs to be an integer before we can do diff --git a/src/where.c b/src/where.c index 4d65a14bcc..921e683d98 100644 --- a/src/where.c +++ b/src/where.c @@ -6801,6 +6801,12 @@ WhereInfo *sqlite3WhereBegin( if( op ){ sqlite3VdbeAddOp3(v, op, iIndexCur, pIx->tnum, iDb); sqlite3VdbeSetP4KeyInfo(pParse, pIx); + if( (pLoop->wsFlags & WHERE_CONSTRAINT)!=0 + && (pLoop->wsFlags & (WHERE_COLUMN_RANGE|WHERE_SKIPSCAN))==0 + && (pWInfo->wctrlFlags&WHERE_ORDERBY_MIN)==0 + ){ + sqlite3VdbeChangeP5(v, OPFLAG_SEEKEQ); /* Hint to COMDB2 */ + } VdbeComment((v, "%s", pIx->zName)); } } From 1fa509afa16471c37d92b8114c5cc9bce2c61c4d Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 20 Mar 2015 16:34:49 +0000 Subject: [PATCH 37/63] Fix to get SQLITE_SMALL_STACK working correctly again after the previous change. FossilOrigin-Name: 78df0ce13d4f35226f2571bd7de78484ccbee4bb --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/vdbe.c | 18 ++++++++---------- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/manifest b/manifest index 58f3acff6f..a1897009ed 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Provide\sthe\sBTREE_SEEK_EQ\shint\sto\sthe\sb-tree\slayer. -D 2015-03-20T14:57:50.128 +C Fix\sto\sget\sSQLITE_SMALL_STACK\sworking\scorrectly\sagain\safter\sthe\sprevious\schange. +D 2015-03-20T16:34:49.236 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 64d8325aed2020a8aa3bd1f6352d0b129299b2fa +F src/vdbe.c 3d96875d883c2bf53a4806c9d4c5abff18511da4 F src/vdbe.h 6fc69d9c5e146302c56e163cb4b31d1ee64a18c3 F src/vdbeInt.h bb56fd199d8af1a2c1b9639ee2f70724b4338e3a F src/vdbeapi.c 583d56b129dd27f12bed518270de9ebe521e6a75 @@ -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 eddc05e7bb31fae74daa86e0504a3478b99fa0f2 -R 6b21b0e98ee76d198c2b5163fdb0b4f7 +P e750830f1e61160c0c67e35b13e50b35a95b50e1 +R 05881cbceea02fa7c850b941dd3796f0 U drh -Z 5cff4e9435b6ae28710f92cbaff291bb +Z 82007846a68ff2bd965c38cd8d002f35 diff --git a/manifest.uuid b/manifest.uuid index 58a06b41de..49f8754294 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -e750830f1e61160c0c67e35b13e50b35a95b50e1 \ No newline at end of file +78df0ce13d4f35226f2571bd7de78484ccbee4bb \ No newline at end of file diff --git a/src/vdbe.c b/src/vdbe.c index 9a9503967a..8eb7721085 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -3235,7 +3235,14 @@ case OP_SetCookie: { /* in3 */ ** See also OpenRead. */ case OP_ReopenIdx: { + int nField; + KeyInfo *pKeyInfo; + int p2; + int iDb; + int wrFlag; + Btree *pX; VdbeCursor *pCur; + Db *pDb; assert( pOp->p5==0 || pOp->p5==OPFLAG_SEEKEQ ); assert( pOp->p4type==P4_KEYINFO ); @@ -3246,17 +3253,8 @@ case OP_ReopenIdx: { } /* If the cursor is not currently open or is open on a different ** index, then fall through into OP_OpenRead to force a reopen */ -} case OP_OpenRead: -case OP_OpenWrite: { - int nField; - KeyInfo *pKeyInfo; - int p2; - int iDb; - int wrFlag; - Btree *pX; - VdbeCursor *pCur; - Db *pDb; +case OP_OpenWrite: assert( (pOp->p5&(OPFLAG_P2ISREG|OPFLAG_BULKCSR|OPFLAG_SEEKEQ))==pOp->p5 ); assert( pOp->opcode==OP_OpenWrite || pOp->p5==0 || pOp->p5==OPFLAG_SEEKEQ ); From 44723ce0960cd7906053fb7028418604f974a228 Mon Sep 17 00:00:00 2001 From: mistachkin Date: Sat, 21 Mar 2015 02:22:37 +0000 Subject: [PATCH 38/63] Improvements to the MSVC build. Fix harmless compiler warnings. Enable use of 'stdcall'. FossilOrigin-Name: 737630b87314283b2c38790ace9d25ec05f81f4a --- Makefile.msc | 380 +++++++++++++++++++++++++-------------- ext/fts3/fts3_write.c | 5 +- ext/fts3/tool/fts3view.c | 4 +- manifest | 29 ++- manifest.uuid | 2 +- mptest/mptest.c | 2 +- src/shell.c | 10 +- src/sqlite.h.in | 7 + tool/build-all-msvc.bat | 67 ++++++- tool/showdb.c | 2 +- 10 files changed, 343 insertions(+), 165 deletions(-) diff --git a/Makefile.msc b/Makefile.msc index 58d370fcde..c9df10557b 100644 --- a/Makefile.msc +++ b/Makefile.msc @@ -22,8 +22,22 @@ USE_AMALGAMATION = 1 USE_FULLWARN = 0 !ENDIF +# Set this non-0 to use "stdcall" calling convention for the core library +# and shell executable. +# +!IFNDEF USE_STDCALL +USE_STDCALL = 0 +!ENDIF + +# Set this non-0 to have the shell executable link against the core dynamic +# link library. +# +!IFNDEF DYNAMIC_SHELL +DYNAMIC_SHELL = 0 +!ENDIF + # If necessary, create a list of harmless compiler warnings to disable when -# compiling the build tools. For the SQLite source code itself, warnings, +# compiling the various tools. For the SQLite source code itself, warnings, # if any, will be disabled from within it. # !IFNDEF NO_WARN @@ -256,9 +270,9 @@ NSDKLIBPATH = $(NSDKLIBPATH:\\=\) # will run on the platform that is doing the build. # !IF $(USE_FULLWARN)!=0 -BCC = $(NCC) -W4 +BCC = $(NCC) -nologo -W4 !ELSE -BCC = $(NCC) -W3 +BCC = $(NCC) -nologo -W3 !ENDIF # Check if assembly code listings should be generated for the source @@ -281,14 +295,106 @@ NLTLIBPATHS = "/LIBPATH:$(NCRTLIBPATH)" "/LIBPATH:$(NSDKLIBPATH)" # same unless your are cross-compiling.) # !IF $(USE_FULLWARN)!=0 -TCC = $(CC) -W4 -DINCLUDE_MSVC_H=1 +TCC = $(CC) -nologo -W4 -DINCLUDE_MSVC_H=1 !ELSE -TCC = $(CC) -W3 +TCC = $(CC) -nologo -W3 !ENDIF TCC = $(TCC) -DSQLITE_OS_WIN=1 -I. -I$(TOP) -I$(TOP)\src -fp:precise RCC = $(RC) -DSQLITE_OS_WIN=1 -I$(TOP) -I$(TOP)\src +# Check if we want to use the "stdcall" calling convention when compiling. +# This is not supported by the compilers for non-x86 platforms. It should +# also be noted here that building any target with these "stdcall" options +# will most likely fail if the Tcl library is also required. This is due +# to how the Tcl library functions are declared and exported (i.e. without +# an explicit calling convention, which results in "cdecl"). +# +!IF $(USE_STDCALL)!=0 +!IF "$(PLATFORM)"=="x86" +CORE_CCONV_OPTS = -Gz -DUSE_STDCALL=1 -DSQLITE_CDECL=__cdecl +SHELL_CCONV_OPTS = -Gz -DUSE_STDCALL=1 -DSQLITE_CDECL=__cdecl +!ELSE +!IFNDEF PLATFORM +CORE_CCONV_OPTS = -Gz -DUSE_STDCALL=1 -DSQLITE_CDECL=__cdecl +SHELL_CCONV_OPTS = -Gz -DUSE_STDCALL=1 -DSQLITE_CDECL=__cdecl +!ELSE +CORE_CCONV_OPTS = +SHELL_CCONV_OPTS = +!ENDIF +!ENDIF +!ELSE +CORE_CCONV_OPTS = +SHELL_CCONV_OPTS = +!ENDIF + +# These are additional compiler options used for the core library. +# +!IFNDEF CORE_COMPILE_OPTS +!IF $(USE_STDCALL)!=0 +CORE_COMPILE_OPTS = $(CORE_CCONV_OPTS) -DSQLITE_API=__declspec(dllexport) +!ELSE +CORE_COMPILE_OPTS = $(CORE_CCONV_OPTS) +!ENDIF +!ENDIF + +# These are the additional targets that the core library should depend on +# when linking. +# +!IFNDEF CORE_LINK_DEP +!IF $(USE_STDCALL)!=0 +CORE_LINK_DEP = +!ELSE +CORE_LINK_DEP = sqlite3.def +!ENDIF +!ENDIF + +# These are additional linker options used for the core library. +# +!IFNDEF CORE_LINK_OPTS +!IF $(USE_STDCALL)!=0 +CORE_LINK_OPTS = +!ELSE +CORE_LINK_OPTS = /DEF:sqlite3.def +!ENDIF +!ENDIF + +# These are additional compiler options used for the shell executable. +# +!IFNDEF SHELL_COMPILE_OPTS +!IF $(DYNAMIC_SHELL)!=0 +SHELL_COMPILE_OPTS = $(SHELL_CCONV_OPTS) -DSQLITE_API=__declspec(dllimport) +!ELSE +SHELL_COMPILE_OPTS = $(SHELL_CCONV_OPTS) +!ENDIF +!ENDIF + +# This is the core library that the shell executable should depend on. +# +!IFNDEF SHELL_CORE_DEP +!IF $(DYNAMIC_SHELL)!=0 +SHELL_CORE_DEP = sqlite3.dll +!ELSE +SHELL_CORE_DEP = libsqlite3.lib +!ENDIF +!ENDIF + +# This is the core library that the shell executable should link with. +# +!IFNDEF SHELL_CORE_LIB +!IF $(DYNAMIC_SHELL)!=0 +SHELL_CORE_LIB = sqlite3.lib +!ELSE +SHELL_CORE_LIB = libsqlite3.lib +!ENDIF +!ENDIF + +# These are additional linker options used for the shell executable. +# +!IFNDEF SHELL_LINK_OPTS +SHELL_LINK_OPTS = $(SHELL_CORE_LIB) +!ENDIF + # Check if assembly code listings should be generated for the source # code files to be compiled. # @@ -587,8 +693,11 @@ LTLINK = $(LTLINK) rpcrt4.lib # set this for you. Otherwise, the linker will attempt # to deduce the binary type based on the object files. !IFDEF PLATFORM -LTLINKOPTS = /MACHINE:$(PLATFORM) -LTLIBOPTS = /MACHINE:$(PLATFORM) +LTLINKOPTS = /NOLOGO /MACHINE:$(PLATFORM) +LTLIBOPTS = /NOLOGO /MACHINE:$(PLATFORM) +!ELSE +LTLINKOPTS = /NOLOGO +LTLIBOPTS = /NOLOGO !ENDIF # When compiling for use in the WinRT environment, the following @@ -1041,13 +1150,13 @@ libsqlite3.lib: $(LIBOBJ) libtclsqlite3.lib: tclsqlite.lo libsqlite3.lib $(LTLIB) $(LTLIBOPTS) $(LTLIBPATHS) /OUT:$@ tclsqlite.lo libsqlite3.lib $(LIBTCL:tcl=tclstub) $(TLIBS) -sqlite3.exe: $(TOP)\src\shell.c libsqlite3.lib $(LIBRESOBJS) sqlite3.h - $(LTLINK) $(READLINE_FLAGS) $(TOP)\src\shell.c \ - /link $(LTLINKOPTS) $(LTLIBPATHS) libsqlite3.lib $(LIBRESOBJS) $(LIBREADLINE) $(LTLIBS) $(TLIBS) +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) -mptester.exe: $(TOP)\mptest\mptest.c libsqlite3.lib $(LIBRESOBJS) sqlite3.h - $(LTLINK) $(TOP)\mptest\mptest.c \ - /link $(LTLINKOPTS) $(LTLIBPATHS) libsqlite3.lib $(LIBRESOBJS) $(LIBREADLINE) $(LTLIBS) $(TLIBS) +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) # This target creates a directory named "tsrc" and fills it with # copies of all of the C source code and header files needed to @@ -1056,14 +1165,14 @@ mptester.exe: $(TOP)\mptest\mptest.c libsqlite3.lib $(LIBRESOBJS) sqlite3.h # all that automatic generation. # .target_source: $(SRC) $(TOP)\tool\vdbe-compress.tcl - -rmdir /S/Q tsrc + -rmdir /Q/S tsrc 2>NUL -mkdir tsrc for %i in ($(SRC1)) do copy /Y %i tsrc for %i in ($(SRC2)) do copy /Y %i tsrc for %i in ($(SRC3)) do copy /Y %i tsrc for %i in ($(SRC4)) do copy /Y %i tsrc for %i in ($(SRC5)) do copy /Y %i tsrc - del /Q tsrc\sqlite.h.in tsrc\parse.y + del /Q tsrc\sqlite.h.in tsrc\parse.y 2>NUL $(TCLSH_CMD) $(TOP)\tool\vdbe-compress.tcl $(OPTS) < tsrc\vdbe.c > vdbe.new move vdbe.new tsrc\vdbe.c echo > .target_source @@ -1088,7 +1197,7 @@ SQLITE3C = sqlite3.c # Rule to build the amalgamation # sqlite3.lo: $(SQLITE3C) - $(LTCOMPILE) -c $(SQLITE3C) + $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(SQLITE3C) # Rules to build the LEMON compiler generator # @@ -1106,10 +1215,10 @@ lemon.exe: $(TOP)\tool\lemon.c lempar.c # opcodes.lo # parse.lo: parse.c $(HDR) - $(LTCOMPILE) -c parse.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c parse.c opcodes.lo: opcodes.c - $(LTCOMPILE) -c opcodes.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c opcodes.c # Rule to build the Win32 resources object file. # @@ -1127,223 +1236,223 @@ $(LIBRESOBJS): $(TOP)\src\sqlite3.rc $(HDR) # Rules to build individual *.lo files from files in the src directory. # alter.lo: $(TOP)\src\alter.c $(HDR) - $(LTCOMPILE) -c $(TOP)\src\alter.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\alter.c analyze.lo: $(TOP)\src\analyze.c $(HDR) - $(LTCOMPILE) -c $(TOP)\src\analyze.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\analyze.c attach.lo: $(TOP)\src\attach.c $(HDR) - $(LTCOMPILE) -c $(TOP)\src\attach.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\attach.c auth.lo: $(TOP)\src\auth.c $(HDR) - $(LTCOMPILE) -c $(TOP)\src\auth.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\auth.c backup.lo: $(TOP)\src\backup.c $(HDR) - $(LTCOMPILE) -c $(TOP)\src\backup.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\backup.c bitvec.lo: $(TOP)\src\bitvec.c $(HDR) - $(LTCOMPILE) -c $(TOP)\src\bitvec.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\bitvec.c btmutex.lo: $(TOP)\src\btmutex.c $(HDR) - $(LTCOMPILE) -c $(TOP)\src\btmutex.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\btmutex.c btree.lo: $(TOP)\src\btree.c $(HDR) $(TOP)\src\pager.h - $(LTCOMPILE) -c $(TOP)\src\btree.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\btree.c build.lo: $(TOP)\src\build.c $(HDR) - $(LTCOMPILE) -c $(TOP)\src\build.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\build.c callback.lo: $(TOP)\src\callback.c $(HDR) - $(LTCOMPILE) -c $(TOP)\src\callback.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\callback.c complete.lo: $(TOP)\src\complete.c $(HDR) - $(LTCOMPILE) -c $(TOP)\src\complete.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\complete.c ctime.lo: $(TOP)\src\ctime.c $(HDR) - $(LTCOMPILE) -c $(TOP)\src\ctime.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\ctime.c date.lo: $(TOP)\src\date.c $(HDR) - $(LTCOMPILE) -c $(TOP)\src\date.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\date.c delete.lo: $(TOP)\src\delete.c $(HDR) - $(LTCOMPILE) -c $(TOP)\src\delete.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\delete.c expr.lo: $(TOP)\src\expr.c $(HDR) - $(LTCOMPILE) -c $(TOP)\src\expr.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\expr.c fault.lo: $(TOP)\src\fault.c $(HDR) - $(LTCOMPILE) -c $(TOP)\src\fault.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\fault.c fkey.lo: $(TOP)\src\fkey.c $(HDR) - $(LTCOMPILE) -c $(TOP)\src\fkey.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\fkey.c func.lo: $(TOP)\src\func.c $(HDR) - $(LTCOMPILE) -c $(TOP)\src\func.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\func.c global.lo: $(TOP)\src\global.c $(HDR) - $(LTCOMPILE) -c $(TOP)\src\global.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\global.c hash.lo: $(TOP)\src\hash.c $(HDR) - $(LTCOMPILE) -c $(TOP)\src\hash.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\hash.c insert.lo: $(TOP)\src\insert.c $(HDR) - $(LTCOMPILE) -c $(TOP)\src\insert.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\insert.c journal.lo: $(TOP)\src\journal.c $(HDR) - $(LTCOMPILE) -c $(TOP)\src\journal.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\journal.c legacy.lo: $(TOP)\src\legacy.c $(HDR) - $(LTCOMPILE) -c $(TOP)\src\legacy.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\legacy.c loadext.lo: $(TOP)\src\loadext.c $(HDR) - $(LTCOMPILE) -c $(TOP)\src\loadext.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\loadext.c main.lo: $(TOP)\src\main.c $(HDR) - $(LTCOMPILE) -c $(TOP)\src\main.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\main.c malloc.lo: $(TOP)\src\malloc.c $(HDR) - $(LTCOMPILE) -c $(TOP)\src\malloc.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\malloc.c mem0.lo: $(TOP)\src\mem0.c $(HDR) - $(LTCOMPILE) -c $(TOP)\src\mem0.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\mem0.c mem1.lo: $(TOP)\src\mem1.c $(HDR) - $(LTCOMPILE) -c $(TOP)\src\mem1.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\mem1.c mem2.lo: $(TOP)\src\mem2.c $(HDR) - $(LTCOMPILE) -c $(TOP)\src\mem2.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\mem2.c mem3.lo: $(TOP)\src\mem3.c $(HDR) - $(LTCOMPILE) -c $(TOP)\src\mem3.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\mem3.c mem5.lo: $(TOP)\src\mem5.c $(HDR) - $(LTCOMPILE) -c $(TOP)\src\mem5.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\mem5.c memjournal.lo: $(TOP)\src\memjournal.c $(HDR) - $(LTCOMPILE) -c $(TOP)\src\memjournal.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\memjournal.c mutex.lo: $(TOP)\src\mutex.c $(HDR) - $(LTCOMPILE) -c $(TOP)\src\mutex.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\mutex.c mutex_noop.lo: $(TOP)\src\mutex_noop.c $(HDR) - $(LTCOMPILE) -c $(TOP)\src\mutex_noop.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\mutex_noop.c mutex_unix.lo: $(TOP)\src\mutex_unix.c $(HDR) - $(LTCOMPILE) -c $(TOP)\src\mutex_unix.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\mutex_unix.c mutex_w32.lo: $(TOP)\src\mutex_w32.c $(HDR) - $(LTCOMPILE) -c $(TOP)\src\mutex_w32.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\mutex_w32.c notify.lo: $(TOP)\src\notify.c $(HDR) - $(LTCOMPILE) -c $(TOP)\src\notify.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\notify.c pager.lo: $(TOP)\src\pager.c $(HDR) $(TOP)\src\pager.h - $(LTCOMPILE) -c $(TOP)\src\pager.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\pager.c pcache.lo: $(TOP)\src\pcache.c $(HDR) $(TOP)\src\pcache.h - $(LTCOMPILE) -c $(TOP)\src\pcache.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\pcache.c pcache1.lo: $(TOP)\src\pcache1.c $(HDR) $(TOP)\src\pcache.h - $(LTCOMPILE) -c $(TOP)\src\pcache1.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\pcache1.c os.lo: $(TOP)\src\os.c $(HDR) - $(LTCOMPILE) -c $(TOP)\src\os.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\os.c os_unix.lo: $(TOP)\src\os_unix.c $(HDR) - $(LTCOMPILE) -c $(TOP)\src\os_unix.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\os_unix.c os_win.lo: $(TOP)\src\os_win.c $(HDR) - $(LTCOMPILE) -c $(TOP)\src\os_win.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\os_win.c pragma.lo: $(TOP)\src\pragma.c $(HDR) - $(LTCOMPILE) -c $(TOP)\src\pragma.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\pragma.c prepare.lo: $(TOP)\src\prepare.c $(HDR) - $(LTCOMPILE) -c $(TOP)\src\prepare.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\prepare.c printf.lo: $(TOP)\src\printf.c $(HDR) - $(LTCOMPILE) -c $(TOP)\src\printf.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\printf.c random.lo: $(TOP)\src\random.c $(HDR) - $(LTCOMPILE) -c $(TOP)\src\random.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\random.c resolve.lo: $(TOP)\src\resolve.c $(HDR) - $(LTCOMPILE) -c $(TOP)\src\resolve.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\resolve.c rowset.lo: $(TOP)\src\rowset.c $(HDR) - $(LTCOMPILE) -c $(TOP)\src\rowset.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\rowset.c select.lo: $(TOP)\src\select.c $(HDR) - $(LTCOMPILE) -c $(TOP)\src\select.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\select.c status.lo: $(TOP)\src\status.c $(HDR) - $(LTCOMPILE) -c $(TOP)\src\status.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\status.c table.lo: $(TOP)\src\table.c $(HDR) - $(LTCOMPILE) -c $(TOP)\src\table.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\table.c threads.lo: $(TOP)\src\threads.c $(HDR) - $(LTCOMPILE) -c $(TOP)\src\threads.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\threads.c tokenize.lo: $(TOP)\src\tokenize.c keywordhash.h $(HDR) - $(LTCOMPILE) -c $(TOP)\src\tokenize.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\tokenize.c trigger.lo: $(TOP)\src\trigger.c $(HDR) - $(LTCOMPILE) -c $(TOP)\src\trigger.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\trigger.c update.lo: $(TOP)\src\update.c $(HDR) - $(LTCOMPILE) -c $(TOP)\src\update.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\update.c utf.lo: $(TOP)\src\utf.c $(HDR) - $(LTCOMPILE) -c $(TOP)\src\utf.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\utf.c util.lo: $(TOP)\src\util.c $(HDR) - $(LTCOMPILE) -c $(TOP)\src\util.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\util.c vacuum.lo: $(TOP)\src\vacuum.c $(HDR) - $(LTCOMPILE) -c $(TOP)\src\vacuum.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\vacuum.c vdbe.lo: $(TOP)\src\vdbe.c $(HDR) - $(LTCOMPILE) -c $(TOP)\src\vdbe.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\vdbe.c vdbeapi.lo: $(TOP)\src\vdbeapi.c $(HDR) - $(LTCOMPILE) -c $(TOP)\src\vdbeapi.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\vdbeapi.c vdbeaux.lo: $(TOP)\src\vdbeaux.c $(HDR) - $(LTCOMPILE) -c $(TOP)\src\vdbeaux.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\vdbeaux.c vdbeblob.lo: $(TOP)\src\vdbeblob.c $(HDR) - $(LTCOMPILE) -c $(TOP)\src\vdbeblob.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\vdbeblob.c vdbemem.lo: $(TOP)\src\vdbemem.c $(HDR) - $(LTCOMPILE) -c $(TOP)\src\vdbemem.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\vdbemem.c vdbesort.lo: $(TOP)\src\vdbesort.c $(HDR) - $(LTCOMPILE) -c $(TOP)\src\vdbesort.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\vdbesort.c vdbetrace.lo: $(TOP)\src\vdbetrace.c $(HDR) - $(LTCOMPILE) -c $(TOP)\src\vdbetrace.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\vdbetrace.c vtab.lo: $(TOP)\src\vtab.c $(HDR) - $(LTCOMPILE) -c $(TOP)\src\vtab.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\vtab.c wal.lo: $(TOP)\src\wal.c $(HDR) - $(LTCOMPILE) -c $(TOP)\src\wal.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\wal.c walker.lo: $(TOP)\src\walker.c $(HDR) - $(LTCOMPILE) -c $(TOP)\src\walker.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\walker.c where.lo: $(TOP)\src\where.c $(HDR) - $(LTCOMPILE) -c $(TOP)\src\where.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\where.c tclsqlite.lo: $(TOP)\src\tclsqlite.c $(HDR) - $(LTCOMPILE) -DUSE_TCL_STUBS=1 -DBUILD_sqlite -I$(TCLINCDIR) -c $(TOP)\src\tclsqlite.c + $(LTCOMPILE) $(NO_WARN) -DUSE_TCL_STUBS=1 -DBUILD_sqlite -I$(TCLINCDIR) -c $(TOP)\src\tclsqlite.c tclsqlite-shell.lo: $(TOP)\src\tclsqlite.c $(HDR) - $(LTCOMPILE) -DTCLSH=1 -DBUILD_sqlite -I$(TCLINCDIR) -c $(TOP)\src\tclsqlite.c + $(LTCOMPILE) $(NO_WARN) -DTCLSH=1 -DBUILD_sqlite -I$(TCLINCDIR) -c $(TOP)\src\tclsqlite.c -tclsqlite3.exe: tclsqlite-shell.lo libsqlite3.lib $(LIBRESOBJS) - $(LD) $(LDFLAGS) $(LTLINKOPTS) $(LTLIBPATHS) /OUT:$@ libsqlite3.lib tclsqlite-shell.lo $(LIBRESOBJS) $(LTLIBS) $(TLIBS) +tclsqlite3.exe: tclsqlite-shell.lo $(SQLITE3C) $(LIBRESOBJS) + $(LTLINK) $(SQLITE3C) /link $(LTLINKOPTS) $(LTLIBPATHS) /OUT:$@ tclsqlite-shell.lo $(LIBRESOBJS) $(LTLIBS) $(TLIBS) # Rules to build opcodes.c and opcodes.h # @@ -1358,7 +1467,7 @@ opcodes.h: parse.h $(TOP)\src\vdbe.c $(TOP)\mkopcodeh.awk parse.h: parse.c parse.c: $(TOP)\src\parse.y lemon.exe $(TOP)\addopcodes.awk - del /Q parse.y parse.h parse.h.temp + del /Q parse.y parse.h parse.h.temp 2>NUL copy $(TOP)\src\parse.y . .\lemon.exe $(REQ_FEATURE_FLAGS) $(OPT_FEATURE_FLAGS) $(OPTS) parse.y move parse.h parse.h.temp @@ -1379,67 +1488,67 @@ keywordhash.h: $(TOP)\tool\mkkeywordhash.c mkkeywordhash.exe # Rules to build the extension objects. # icu.lo: $(TOP)\ext\icu\icu.c $(HDR) $(EXTHDR) - $(LTCOMPILE) -DSQLITE_CORE -c $(TOP)\ext\icu\icu.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) $(NO_WARN) -DSQLITE_CORE -c $(TOP)\ext\icu\icu.c fts2.lo: $(TOP)\ext\fts2\fts2.c $(HDR) $(EXTHDR) - $(LTCOMPILE) -DSQLITE_CORE -c $(TOP)\ext\fts2\fts2.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) $(NO_WARN) -DSQLITE_CORE -c $(TOP)\ext\fts2\fts2.c fts2_hash.lo: $(TOP)\ext\fts2\fts2_hash.c $(HDR) $(EXTHDR) - $(LTCOMPILE) -DSQLITE_CORE -c $(TOP)\ext\fts2\fts2_hash.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) $(NO_WARN) -DSQLITE_CORE -c $(TOP)\ext\fts2\fts2_hash.c fts2_icu.lo: $(TOP)\ext\fts2\fts2_icu.c $(HDR) $(EXTHDR) - $(LTCOMPILE) -DSQLITE_CORE -c $(TOP)\ext\fts2\fts2_icu.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) $(NO_WARN) -DSQLITE_CORE -c $(TOP)\ext\fts2\fts2_icu.c fts2_porter.lo: $(TOP)\ext\fts2\fts2_porter.c $(HDR) $(EXTHDR) - $(LTCOMPILE) -DSQLITE_CORE -c $(TOP)\ext\fts2\fts2_porter.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) $(NO_WARN) -DSQLITE_CORE -c $(TOP)\ext\fts2\fts2_porter.c fts2_tokenizer.lo: $(TOP)\ext\fts2\fts2_tokenizer.c $(HDR) $(EXTHDR) - $(LTCOMPILE) -DSQLITE_CORE -c $(TOP)\ext\fts2\fts2_tokenizer.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) $(NO_WARN) -DSQLITE_CORE -c $(TOP)\ext\fts2\fts2_tokenizer.c fts2_tokenizer1.lo: $(TOP)\ext\fts2\fts2_tokenizer1.c $(HDR) $(EXTHDR) - $(LTCOMPILE) -DSQLITE_CORE -c $(TOP)\ext\fts2\fts2_tokenizer1.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) $(NO_WARN) -DSQLITE_CORE -c $(TOP)\ext\fts2\fts2_tokenizer1.c fts3.lo: $(TOP)\ext\fts3\fts3.c $(HDR) $(EXTHDR) - $(LTCOMPILE) -DSQLITE_CORE -c $(TOP)\ext\fts3\fts3.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) $(NO_WARN) -DSQLITE_CORE -c $(TOP)\ext\fts3\fts3.c fts3_aux.lo: $(TOP)\ext\fts3\fts3_aux.c $(HDR) $(EXTHDR) - $(LTCOMPILE) -DSQLITE_CORE -c $(TOP)\ext\fts3\fts3_aux.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) $(NO_WARN) -DSQLITE_CORE -c $(TOP)\ext\fts3\fts3_aux.c fts3_expr.lo: $(TOP)\ext\fts3\fts3_expr.c $(HDR) $(EXTHDR) - $(LTCOMPILE) -DSQLITE_CORE -c $(TOP)\ext\fts3\fts3_expr.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) $(NO_WARN) -DSQLITE_CORE -c $(TOP)\ext\fts3\fts3_expr.c fts3_hash.lo: $(TOP)\ext\fts3\fts3_hash.c $(HDR) $(EXTHDR) - $(LTCOMPILE) -DSQLITE_CORE -c $(TOP)\ext\fts3\fts3_hash.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) $(NO_WARN) -DSQLITE_CORE -c $(TOP)\ext\fts3\fts3_hash.c fts3_icu.lo: $(TOP)\ext\fts3\fts3_icu.c $(HDR) $(EXTHDR) - $(LTCOMPILE) -DSQLITE_CORE -c $(TOP)\ext\fts3\fts3_icu.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) $(NO_WARN) -DSQLITE_CORE -c $(TOP)\ext\fts3\fts3_icu.c fts3_snippet.lo: $(TOP)\ext\fts3\fts3_snippet.c $(HDR) $(EXTHDR) - $(LTCOMPILE) -DSQLITE_CORE -c $(TOP)\ext\fts3\fts3_snippet.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) $(NO_WARN) -DSQLITE_CORE -c $(TOP)\ext\fts3\fts3_snippet.c fts3_porter.lo: $(TOP)\ext\fts3\fts3_porter.c $(HDR) $(EXTHDR) - $(LTCOMPILE) -DSQLITE_CORE -c $(TOP)\ext\fts3\fts3_porter.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) $(NO_WARN) -DSQLITE_CORE -c $(TOP)\ext\fts3\fts3_porter.c fts3_tokenizer.lo: $(TOP)\ext\fts3\fts3_tokenizer.c $(HDR) $(EXTHDR) - $(LTCOMPILE) -DSQLITE_CORE -c $(TOP)\ext\fts3\fts3_tokenizer.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) $(NO_WARN) -DSQLITE_CORE -c $(TOP)\ext\fts3\fts3_tokenizer.c fts3_tokenizer1.lo: $(TOP)\ext\fts3\fts3_tokenizer1.c $(HDR) $(EXTHDR) - $(LTCOMPILE) -DSQLITE_CORE -c $(TOP)\ext\fts3\fts3_tokenizer1.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) $(NO_WARN) -DSQLITE_CORE -c $(TOP)\ext\fts3\fts3_tokenizer1.c fts3_tokenize_vtab.lo: $(TOP)\ext\fts3\fts3_tokenize_vtab.c $(HDR) $(EXTHDR) - $(LTCOMPILE) -DSQLITE_CORE -c $(TOP)\ext\fts3\fts3_tokenize_vtab.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) $(NO_WARN) -DSQLITE_CORE -c $(TOP)\ext\fts3\fts3_tokenize_vtab.c fts3_unicode.lo: $(TOP)\ext\fts3\fts3_unicode.c $(HDR) $(EXTHDR) - $(LTCOMPILE) -DSQLITE_CORE -c $(TOP)\ext\fts3\fts3_unicode.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) $(NO_WARN) -DSQLITE_CORE -c $(TOP)\ext\fts3\fts3_unicode.c fts3_unicode2.lo: $(TOP)\ext\fts3\fts3_unicode2.c $(HDR) $(EXTHDR) - $(LTCOMPILE) -DSQLITE_CORE -c $(TOP)\ext\fts3\fts3_unicode2.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) $(NO_WARN) -DSQLITE_CORE -c $(TOP)\ext\fts3\fts3_unicode2.c fts3_write.lo: $(TOP)\ext\fts3\fts3_write.c $(HDR) $(EXTHDR) - $(LTCOMPILE) -DSQLITE_CORE -c $(TOP)\ext\fts3\fts3_write.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) $(NO_WARN) -DSQLITE_CORE -c $(TOP)\ext\fts3\fts3_write.c rtree.lo: $(TOP)\ext\rtree\rtree.c $(HDR) $(EXTHDR) - $(LTCOMPILE) -DSQLITE_CORE -c $(TOP)\ext\rtree\rtree.c + $(LTCOMPILE) $(CORE_COMPILE_OPTS) $(NO_WARN) -DSQLITE_CORE -c $(TOP)\ext\rtree\rtree.c # Rules to build the 'testfixture' application. @@ -1453,7 +1562,7 @@ TESTFIXTURE_FLAGS = -DTCLSH=1 -DSQLITE_TEST=1 -DSQLITE_CRASH_TEST=1 TESTFIXTURE_FLAGS = $(TESTFIXTURE_FLAGS) -DSQLITE_SERVER=1 -DSQLITE_PRIVATE="" TESTFIXTURE_FLAGS = $(TESTFIXTURE_FLAGS) -DSQLITE_CORE $(NO_WARN) -TESTFIXTURE_SRC0 = $(TESTEXT) $(TESTSRC2) libsqlite3.lib +TESTFIXTURE_SRC0 = $(TESTEXT) $(TESTSRC2) $(SHELL_CORE_DEP) TESTFIXTURE_SRC1 = $(TESTEXT) $(SQLITE3C) !IF $(USE_AMALGAMATION)==0 TESTFIXTURE_SRC = $(TESTSRC) $(TOP)\src\tclsqlite.c $(TESTFIXTURE_SRC0) @@ -1493,52 +1602,52 @@ sqlite3_analyzer.c: $(SQLITE3C) $(TOP)\src\test_stat.c $(TOP)\src\tclsqlite.c $( echo ; return zMainloop; } >> $@ sqlite3_analyzer.exe: sqlite3_analyzer.c $(LIBRESOBJS) - $(LTLINK) -DBUILD_sqlite -DTCLSH=2 -I$(TCLINCDIR) sqlite3_analyzer.c \ + $(LTLINK) $(NO_WARN) -DBUILD_sqlite -DTCLSH=2 -I$(TCLINCDIR) sqlite3_analyzer.c \ /link $(LTLINKOPTS) $(LTLIBPATHS) $(LIBRESOBJS) $(LTLIBS) $(TLIBS) testloadext.lo: $(TOP)\src\test_loadext.c - $(LTCOMPILE) -c $(TOP)\src\test_loadext.c + $(LTCOMPILE) $(NO_WARN) -c $(TOP)\src\test_loadext.c testloadext.dll: testloadext.lo $(LD) $(LDFLAGS) $(LTLINKOPTS) $(LTLIBPATHS) /DLL /OUT:$@ testloadext.lo showdb.exe: $(TOP)\tool\showdb.c $(SQLITE3C) - $(LTLINK) -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION -Fe$@ \ + $(LTLINK) $(NO_WARN) -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION -Fe$@ \ $(TOP)\tool\showdb.c $(SQLITE3C) showstat4.exe: $(TOP)\tool\showstat4.c $(SQLITE3C) - $(LTLINK) -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION -Fe$@ \ + $(LTLINK) $(NO_WARN) -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION -Fe$@ \ $(TOP)\tool\showstat4.c $(SQLITE3C) showjournal.exe: $(TOP)\tool\showjournal.c $(SQLITE3C) - $(LTLINK) -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION -Fe$@ \ + $(LTLINK) $(NO_WARN) -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION -Fe$@ \ $(TOP)\tool\showjournal.c $(SQLITE3C) showwal.exe: $(TOP)\tool\showwal.c $(SQLITE3C) - $(LTLINK) -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION -Fe$@ \ + $(LTLINK) $(NO_WARN) -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION -Fe$@ \ $(TOP)\tool\showwal.c $(SQLITE3C) fts3view.exe: $(TOP)\ext\fts3\tool\fts3view.c $(SQLITE3C) - $(LTLINK) -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION -Fe$@ \ + $(LTLINK) $(NO_WARN) -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION -Fe$@ \ $(TOP)\ext\fts3\tool\fts3view.c $(SQLITE3C) rollback-test.exe: $(TOP)\tool\rollback-test.c $(SQLITE3C) - $(LTLINK) -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION -Fe$@ \ + $(LTLINK) $(NO_WARN) -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION -Fe$@ \ $(TOP)\tool\rollback-test.c $(SQLITE3C) LogEst.exe: $(TOP)\tool\logest.c sqlite3.h - $(LTLINK) -Fe$@ $(TOP)\tool\LogEst.c + $(LTLINK) $(NO_WARN) -Fe$@ $(TOP)\tool\LogEst.c wordcount.exe: $(TOP)\test\wordcount.c $(SQLITE3C) - $(LTLINK) -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION -Fe$@ \ + $(LTLINK) $(NO_WARN) -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION -Fe$@ \ $(TOP)\test\wordcount.c $(SQLITE3C) speedtest1.exe: $(TOP)\test\speedtest1.c $(SQLITE3C) - $(LTLINK) -DSQLITE_OMIT_LOAD_EXTENSION -Fe$@ \ + $(LTLINK) $(NO_WARN) -DSQLITE_OMIT_LOAD_EXTENSION -Fe$@ \ $(TOP)\test\speedtest1.c $(SQLITE3C) clean: - del /Q *.lo *.ilk *.lib *.obj *.pdb sqlite3.exe libsqlite3.lib 2>NUL + del /Q *.exp *.lo *.ilk *.lib *.obj *.pdb 2>NUL del /Q *.cod *.da *.bb *.bbg gmon.out 2>NUL del /Q sqlite3.h opcodes.c opcodes.h 2>NUL del /Q lemon.* lempar.c parse.* 2>NUL @@ -1551,19 +1660,18 @@ clean: -rmdir /Q/S quota2c 2>NUL -rmdir /Q/S tsrc 2>NUL del /Q .target_source 2>NUL - del /Q tclsqlite3.exe tclsqlite3.exp 2>NUL - del /Q testloadext.dll testloadext.exp 2>NUL - del /Q testfixture.exe testfixture.exp test.db 2>NUL + del /Q tclsqlite3.exe 2>NUL + del /Q testloadext.dll 2>NUL + del /Q testfixture.exe test.db 2>NUL del /Q LogEst.exe fts3view.exe rollback-test.exe showdb.exe 2>NUL del /Q showjournal.exe showstat4.exe showwal.exe speedtest1.exe 2>NUL - del /Q wordcount.exe 2>NUL - del /Q sqlite3.dll sqlite3.lib sqlite3.exp sqlite3.def 2>NUL + del /Q mptester.exe wordcount.exe 2>NUL + del /Q sqlite3.exe sqlite3.dll sqlite3.def 2>NUL del /Q sqlite3.c sqlite3-*.c 2>NUL del /Q sqlite3rc.h 2>NUL del /Q shell.c sqlite3ext.h 2>NUL - del /Q sqlite3_analyzer.exe sqlite3_analyzer.exp sqlite3_analyzer.c 2>NUL + del /Q sqlite3_analyzer.exe sqlite3_analyzer.c 2>NUL del /Q sqlite-*-output.vsix 2>NUL - del /Q mptester.exe 2>NUL # Dynamic link library section. # @@ -1575,5 +1683,5 @@ sqlite3.def: libsqlite3.lib | $(NAWK) "/ 1 _?sqlite3_/ { sub(/^.* _?/,\"\");print }" \ | sort >> sqlite3.def -sqlite3.dll: $(LIBOBJ) $(LIBRESOBJS) sqlite3.def - $(LD) $(LDFLAGS) $(LTLINKOPTS) $(LTLIBPATHS) /DLL /DEF:sqlite3.def /OUT:$@ $(LIBOBJ) $(LIBRESOBJS) $(LTLIBS) $(TLIBS) +sqlite3.dll: $(LIBOBJ) $(LIBRESOBJS) $(CORE_LINK_DEP) + $(LD) $(LDFLAGS) $(LTLINKOPTS) $(LTLIBPATHS) /DLL $(CORE_LINK_OPTS) /OUT:$@ $(LIBOBJ) $(LIBRESOBJS) $(LTLIBS) $(TLIBS) diff --git a/ext/fts3/fts3_write.c b/ext/fts3/fts3_write.c index 09294bc45a..a16070766f 100644 --- a/ext/fts3/fts3_write.c +++ b/ext/fts3/fts3_write.c @@ -1625,7 +1625,10 @@ int sqlite3Fts3SegReaderNew( ** an array of pending terms by term. This occurs as part of flushing ** the contents of the pending-terms hash table to the database. */ -static int fts3CompareElemByTerm(const void *lhs, const void *rhs){ +static int SQLITE_CDECL fts3CompareElemByTerm( + const void *lhs, + const void *rhs +){ char *z1 = fts3HashKey(*(Fts3HashElem **)lhs); char *z2 = fts3HashKey(*(Fts3HashElem **)rhs); int n1 = fts3HashKeysize(*(Fts3HashElem **)lhs); diff --git a/ext/fts3/tool/fts3view.c b/ext/fts3/tool/fts3view.c index 3dc1ba80fe..6dada352b3 100644 --- a/ext/fts3/tool/fts3view.c +++ b/ext/fts3/tool/fts3view.c @@ -504,7 +504,7 @@ static void showSegdirMap(sqlite3 *db, const char *zTab){ sqlite3_column_int64(pStmt,5)); printf(" root %9s\n", rtag); if( iLEnd>iStart ){ - sqlite3_int64 iLower, iPrev, iX; + sqlite3_int64 iLower, iPrev = 0, iX; if( iLEnd+1<=iEnd ){ sqlite3_bind_int64(pStmt2, 1, iLEnd+1); sqlite3_bind_int64(pStmt2, 2, iEnd); @@ -548,7 +548,7 @@ static void decodeSegment( const unsigned char *aData, /* Content to print */ int nData /* Number of bytes of content */ ){ - sqlite3_int64 iChild; + sqlite3_int64 iChild = 0; sqlite3_int64 iPrefix; sqlite3_int64 nTerm; sqlite3_int64 n; diff --git a/manifest b/manifest index fdb6dee09d..e5751c5093 100644 --- a/manifest +++ b/manifest @@ -1,9 +1,9 @@ -C Provide\sthe\sBTREE_SEEK_EQ\shint\sto\sthe\sb-tree\slayer. -D 2015-03-20T16:54:29.996 +C Improvements\sto\sthe\sMSVC\sbuild.\s\sFix\sharmless\scompiler\swarnings.\s\sEnable\suse\sof\s'stdcall'. +D 2015-03-21T02:22:37.291 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 -F Makefile.msc 529e61cd9d29a3934758b4b3a0bb649b6c653481 +F Makefile.msc e8614ec3a5f84c92bc70eaf99a2d6cb622494706 F Makefile.vxworks e1b65dea203f054e71653415bd8f96dcaed47858 F README.md d58e3bebc0a4145e0f2a87994015fdb575a8e866 F VERSION 319eb1ced4b4d17a67730f2b7b85f15c1346cb60 @@ -96,10 +96,10 @@ F ext/fts3/fts3_tokenizer.h 64c6ef6c5272c51ebe60fc607a896e84288fcbc3 F ext/fts3/fts3_tokenizer1.c 5c98225a53705e5ee34824087478cf477bdb7004 F ext/fts3/fts3_unicode.c a93f5edc0aff44ef8b06d7cb55b52026541ca145 F ext/fts3/fts3_unicode2.c c3d01968d497bd7001e7dc774ba75b372738c057 -F ext/fts3/fts3_write.c 9b3a32cbecf40a1f41cb08c00df8c066c23c7a25 +F ext/fts3/fts3_write.c 7104ec015474ee61a8a570349b925f35c6b0a294 F ext/fts3/fts3speed.tcl b54caf6a18d38174f1a6e84219950d85e98bb1e9 F ext/fts3/mkfts3amal.tcl 252ecb7fe6467854f2aa237bf2c390b74e71f100 -F ext/fts3/tool/fts3view.c 3986531f2fc0ceca0c89c31ec7d0589b6adb19d6 +F ext/fts3/tool/fts3view.c 8e53d0190a7b3443764bbd32ad47be2bd852026d F ext/fts3/unicode/CaseFolding.txt 8c678ca52ecc95e16bc7afc2dbf6fc9ffa05db8c F ext/fts3/unicode/UnicodeData.txt cd07314edb62d49fde34debdaf92fa2aa69011e7 F ext/fts3/unicode/mkunicode.tcl a2567f9d6ad6779879a2e394c120ad8718557e65 @@ -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 0c0c82c1d9aea0b1a60ef9456a04c35ab1106622 +F mptest/mptest.c 1e464f41f1bbc6578d6925043da56170f83aea96 F mptest/multiwrite01.test dab5c5f8f9534971efce679152c5146da265222d F spec.template 86a4a43b99ebb3e75e6b9a735d5fd293a24e90ca F sqlite.pc.in 42b7bf0d02e08b9e77734a47798d1a55a9e0716b @@ -231,8 +231,8 @@ F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c f4d79e31ffa5820c2e3d1740baa5e9b190425f2b F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e F src/select.c 94e016b6733b1d39a2f4c8d431155b4c2897d907 -F src/shell.c d1ecce877f899abc97cabdf6a0b8323b8c5a0b69 -F src/sqlite.h.in 2d48e05677d0f9b06b7757662eef3cebea02d837 +F src/shell.c 9c1589c8271c04c02d23cdbc2c07bb40752fa9eb +F src/sqlite.h.in c7c9111477b76c82c46bf851b619df4dd35cc095 F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h 17d487c3c91b0b8c584a32fbeb393f6f795eea7d F src/sqliteInt.h f2300529f3592323a98fd7acccec63d0e9082dc5 @@ -1194,7 +1194,7 @@ F test/without_rowid6.test deddb78ef539c355bddec00cdfaea6c56efd8b3f F test/wordcount.c 9915e06cb33d8ca8109b8700791afe80d305afda F test/zeroblob.test caaecfb4f908f7bc086ed238668049f96774d688 F test/zerodamage.test cf6748bad89553cc1632be51a6f54e487e4039ac -F tool/build-all-msvc.bat a0534c971b86fe95f1983f445db5b896d3394818 x +F tool/build-all-msvc.bat 62785b25bf7ea82dc016b3233a896151c786cfbb x F tool/build-shell.sh 950f47c6174f1eea171319438b93ba67ff5bf367 F tool/checkSpacing.c 810e51703529a204fc4e1eb060e9ab663e3c06d2 F tool/diffdb.c 7524b1b5df217c20cd0431f6789851a4e0cb191b @@ -1223,7 +1223,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 bd073a78bce714a0e42d92ea474b3eb8cb53be5d +F tool/showdb.c 63cdef19e7fbca0c164b096ef8aef3bb9e9dd222 F tool/showjournal.c 053eb1cc774710c6890b7dd6293300cc297b16a5 F tool/showstat4.c 9515faa8ec176599d4a8288293ba8ec61f7b728a F tool/showwal.c 85cb36d4fe3e93e2fbd63e786e0d1ce42d0c4fad @@ -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 eddc05e7bb31fae74daa86e0504a3478b99fa0f2 78df0ce13d4f35226f2571bd7de78484ccbee4bb -R 05881cbceea02fa7c850b941dd3796f0 -T +closed 78df0ce13d4f35226f2571bd7de78484ccbee4bb -U drh -Z 56e9c50c3a6de45bb59df03b69a9852f +P 3c367004dab0a1a24d955482c97b0f2d84129ab6 +R 80f691e361888d14a716e1419942fc85 +U mistachkin +Z 872c461d0c616b6e0a705e4083626167 diff --git a/manifest.uuid b/manifest.uuid index 2068f03662..2ad63efd49 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -3c367004dab0a1a24d955482c97b0f2d84129ab6 \ No newline at end of file +737630b87314283b2c38790ace9d25ec05f81f4a \ No newline at end of file diff --git a/mptest/mptest.c b/mptest/mptest.c index fdfe5f4a9d..40c14bc87a 100644 --- a/mptest/mptest.c +++ b/mptest/mptest.c @@ -1252,7 +1252,7 @@ static void unrecognizedArguments( exit(1); } -int main(int argc, char **argv){ +int SQLITE_CDECL main(int argc, char **argv){ const char *zClient; int iClient; int n, i; diff --git a/src/shell.c b/src/shell.c index 752106fcaf..d5a8a3fe95 100644 --- a/src/shell.c +++ b/src/shell.c @@ -2143,7 +2143,7 @@ static void import_append_char(ImportCtx *p, int c){ ** EOF on end-of-file. ** + Report syntax errors on stderr */ -static char *csv_read_one_field(ImportCtx *p){ +static char *SQLITE_CDECL csv_read_one_field(ImportCtx *p){ int c; int cSep = p->cColSep; int rSep = p->cRowSep; @@ -2217,7 +2217,7 @@ static char *csv_read_one_field(ImportCtx *p){ ** EOF on end-of-file. ** + Report syntax errors on stderr */ -static char *ascii_read_one_field(ImportCtx *p){ +static char *SQLITE_CDECL ascii_read_one_field(ImportCtx *p){ int c; int cSep = p->cColSep; int rSep = p->cRowSep; @@ -2911,8 +2911,8 @@ static int do_meta_command(char *zLine, ShellState *p){ int nSep; /* Number of bytes in p->colSeparator[] */ char *zSql; /* An SQL statement */ ImportCtx sCtx; /* Reader context */ - char *(*xRead)(ImportCtx*); /* Procedure to read one value */ - int (*xCloser)(FILE*); /* Procedure to close th3 connection */ + char *(SQLITE_CDECL *xRead)(ImportCtx*); /* Func to read one value */ + int (SQLITE_CDECL *xCloser)(FILE*); /* Func to close file */ if( nArg!=3 ){ fprintf(stderr, "Usage: .import FILE TABLE\n"); @@ -4354,7 +4354,7 @@ static char *cmdline_option_value(int argc, char **argv, int i){ return argv[i]; } -int main(int argc, char **argv){ +int SQLITE_CDECL main(int argc, char **argv){ char *zErrMsg = 0; ShellState data; const char *zInitFile = 0; diff --git a/src/sqlite.h.in b/src/sqlite.h.in index ed0318fe3a..9e48620c66 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -49,6 +49,13 @@ 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/build-all-msvc.bat b/tool/build-all-msvc.bat index 1fb61d4df8..2ae202620a 100755 --- a/tool/build-all-msvc.bat +++ b/tool/build-all-msvc.bat @@ -58,6 +58,9 @@ IF NOT DEFINED _AECHO (SET _AECHO=REM) IF NOT DEFINED _CECHO (SET _CECHO=REM) IF NOT DEFINED _VECHO (SET _VECHO=REM) +SET REDIRECT=^> +IF DEFINED __ECHO SET REDIRECT=^^^> + %_AECHO% Running %0 %* REM SET DFLAGS=/L @@ -420,11 +423,11 @@ FOR %%P IN (%PLATFORMS%) DO ( ) ELSE ( REM REM NOTE: Even when the cleaning step has been disabled, we still - REM need to remove the build output for the files we are + REM need to remove the build output for all the files we are REM specifically wanting to build for each platform. REM - %_AECHO% Cleaning final output files only... - %__ECHO% DEL /Q *.lo sqlite3.dll sqlite3.lib sqlite3.pdb + %_AECHO% Cleaning final core library output files only... + %__ECHO% DEL /Q *.lo sqlite3.dll sqlite3.lib sqlite3.pdb 2%REDIRECT% NUL ) REM @@ -476,6 +479,64 @@ FOR %%P IN (%PLATFORMS%) DO ( GOTO errors ) ) + + REM + REM NOTE: If requested, also build the shell executable. + REM + IF DEFINED BUILD_ALL_SHELL ( + REM + REM NOTE: If necessary, make sure any previous build output for the + REM shell executable is deleted. + REM + IF DEFINED NOCLEAN ( + REM + REM NOTE: Even when the cleaning step has been disabled, we still + REM need to remove the build output for all the files we are + REM specifically wanting to build for each platform. + REM + %_AECHO% Cleaning final shell executable output files only... + %__ECHO% DEL /Q sqlite3.exe sqlite3sh.pdb 2%REDIRECT% NUL + ) + + REM + REM NOTE: Call NMAKE with the MSVC makefile to build the "sqlite3.exe" + REM binary. The x86 compiler will be used to compile the native + REM command line tools needed during the build process itself. + REM Also, disable looking for and/or linking to the native Tcl + REM runtime library. + REM + %__ECHO% %NMAKE_CMD% sqlite3.exe XCOMPILE=1 USE_NATIVE_LIBPATHS=1 NO_TCL=1 %NMAKE_ARGS% + + IF ERRORLEVEL 1 ( + ECHO Failed to build %%B "sqlite3.exe" for platform %%P. + GOTO errors + ) + + REM + REM NOTE: Copy the "sqlite3.exe" file to the appropriate directory + REM for the build and platform beneath the binary directory. + REM + %__ECHO% XCOPY sqlite3.exe "%BINARYDIRECTORY%\%%B\%%D\" %FFLAGS% %DFLAGS% + + IF ERRORLEVEL 1 ( + ECHO Failed to copy "sqlite3.exe" to "%BINARYDIRECTORY%\%%B\%%D\". + GOTO errors + ) + + REM + REM NOTE: Copy the "sqlite3sh.pdb" file to the appropriate directory + REM for the build and platform beneath the binary directory + REM unless we are prevented from doing so. + REM + IF NOT DEFINED NOSYMBOLS ( + %__ECHO% XCOPY sqlite3sh.pdb "%BINARYDIRECTORY%\%%B\%%D\" %FFLAGS% %DFLAGS% + + IF ERRORLEVEL 1 ( + ECHO Failed to copy "sqlite3sh.pdb" to "%BINARYDIRECTORY%\%%B\%%D\". + GOTO errors + ) + ) + ) ) ) ) diff --git a/tool/showdb.c b/tool/showdb.c index 82b8c9f14f..7fdf7c91ad 100644 --- a/tool/showdb.c +++ b/tool/showdb.c @@ -375,7 +375,7 @@ static void decodeCell( int szPgHdr, /* Size of the page header. 0 or 100 */ int ofst /* Cell begins at a[ofst] */ ){ - int i, j; + int i, j = 0; int leftChild; i64 k; i64 nPayload; From 299903c6a62a54c67723040c115893c21b23b325 Mon Sep 17 00:00:00 2001 From: mistachkin Date: Sat, 21 Mar 2015 02:25:29 +0000 Subject: [PATCH 39/63] Remove superfluous define from the MSVC makefile. FossilOrigin-Name: 880d2513a0fb084fae82080401b108fb13e61478 --- Makefile.msc | 8 ++++---- manifest | 12 ++++++------ manifest.uuid | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Makefile.msc b/Makefile.msc index c9df10557b..249e3c284d 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 -DUSE_STDCALL=1 -DSQLITE_CDECL=__cdecl -SHELL_CCONV_OPTS = -Gz -DUSE_STDCALL=1 -DSQLITE_CDECL=__cdecl +CORE_CCONV_OPTS = -Gz -DSQLITE_CDECL=__cdecl +SHELL_CCONV_OPTS = -Gz -DSQLITE_CDECL=__cdecl !ELSE !IFNDEF PLATFORM -CORE_CCONV_OPTS = -Gz -DUSE_STDCALL=1 -DSQLITE_CDECL=__cdecl -SHELL_CCONV_OPTS = -Gz -DUSE_STDCALL=1 -DSQLITE_CDECL=__cdecl +CORE_CCONV_OPTS = -Gz -DSQLITE_CDECL=__cdecl +SHELL_CCONV_OPTS = -Gz -DSQLITE_CDECL=__cdecl !ELSE CORE_CCONV_OPTS = SHELL_CCONV_OPTS = diff --git a/manifest b/manifest index e5751c5093..e2d910ce70 100644 --- a/manifest +++ b/manifest @@ -1,9 +1,9 @@ -C Improvements\sto\sthe\sMSVC\sbuild.\s\sFix\sharmless\scompiler\swarnings.\s\sEnable\suse\sof\s'stdcall'. -D 2015-03-21T02:22:37.291 +C Remove\ssuperfluous\sdefine\sfrom\sthe\sMSVC\smakefile. +D 2015-03-21T02:25:29.401 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 -F Makefile.msc e8614ec3a5f84c92bc70eaf99a2d6cb622494706 +F Makefile.msc cd626b52ebeec0e2c0dd929243bdd25b0df19a71 F Makefile.vxworks e1b65dea203f054e71653415bd8f96dcaed47858 F README.md d58e3bebc0a4145e0f2a87994015fdb575a8e866 F VERSION 319eb1ced4b4d17a67730f2b7b85f15c1346cb60 @@ -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 3c367004dab0a1a24d955482c97b0f2d84129ab6 -R 80f691e361888d14a716e1419942fc85 +P 737630b87314283b2c38790ace9d25ec05f81f4a +R bbf7713d7bc160a26b464271593d133d U mistachkin -Z 872c461d0c616b6e0a705e4083626167 +Z d79979d0d3fded9d4339ee09acdaf62b diff --git a/manifest.uuid b/manifest.uuid index 2ad63efd49..81fc012beb 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -737630b87314283b2c38790ace9d25ec05f81f4a \ No newline at end of file +880d2513a0fb084fae82080401b108fb13e61478 \ No newline at end of file From f063685079e709c5c20235b1324babff9c0a0334 Mon Sep 17 00:00:00 2001 From: drh Date: Sat, 21 Mar 2015 02:58:20 +0000 Subject: [PATCH 40/63] If a column is both UNIQUE and a PRIMARY KEY, make sure the PRIMARY KEY designation takes precedence. FossilOrigin-Name: d871a7921722bb0fef6d51e1110a9703ddff78c8 --- manifest | 16 ++++----- manifest.uuid | 2 +- src/build.c | 1 + test/without_rowid6.test | 76 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 86 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index e2d910ce70..6b5b474365 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Remove\ssuperfluous\sdefine\sfrom\sthe\sMSVC\smakefile. -D 2015-03-21T02:25:29.401 +C If\sa\scolumn\sis\sboth\sUNIQUE\sand\sa\sPRIMARY\sKEY,\smake\ssure\sthe\sPRIMARY\sKEY\ndesignation\stakes\sprecedence. +D 2015-03-21T02:58:20.771 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 d4d52fb14e863cff9dbc7c746e9048ec0967a555 F src/btree.h 969adc948e89e449220ff0ff724c94bb2a52e9f1 F src/btreeInt.h 2bfefc01875d8da066504c233ec259fcb3b2ef72 -F src/build.c ba45ebd02904e84d98839a6ea74c3eb948596587 +F src/build.c 0419bba592c22f6d00e6d57a2ca7136720d02c1a F src/callback.c 7b44ce59674338ad48b0e84e7b72f935ea4f68b0 F src/complete.c 198a0066ba60ab06fc00fba1998d870a4d575463 F src/ctime.c 98f89724adc891a1a4c655bee04e33e716e05887 @@ -1190,7 +1190,7 @@ F test/without_rowid2.test af260339f79d13cb220288b67cd287fbcf81ad99 F test/without_rowid3.test 1081aabf60a1e1123b7f9a8f6ae19954351843b0 F test/without_rowid4.test 4e08bcbaee0399f35d58b5581881e7a6243d458a F test/without_rowid5.test 61256715b686359df48ca1742db50cc7e3e7b862 -F test/without_rowid6.test deddb78ef539c355bddec00cdfaea6c56efd8b3f +F test/without_rowid6.test db0dbf03c49030aa3c1ba5f618620334bd2baf5f F test/wordcount.c 9915e06cb33d8ca8109b8700791afe80d305afda F test/zeroblob.test caaecfb4f908f7bc086ed238668049f96774d688 F test/zerodamage.test cf6748bad89553cc1632be51a6f54e487e4039ac @@ -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 737630b87314283b2c38790ace9d25ec05f81f4a -R bbf7713d7bc160a26b464271593d133d -U mistachkin -Z d79979d0d3fded9d4339ee09acdaf62b +P 880d2513a0fb084fae82080401b108fb13e61478 +R 705f61dec20eb9df7c2db39aa0eef35e +U drh +Z 19c081d9e2a5c29193a61d5955352cbc diff --git a/manifest.uuid b/manifest.uuid index 81fc012beb..46bb30739d 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -880d2513a0fb084fae82080401b108fb13e61478 \ No newline at end of file +d871a7921722bb0fef6d51e1110a9703ddff78c8 \ No newline at end of file diff --git a/src/build.c b/src/build.c index 54dd526b56..fcf96bd42c 100644 --- a/src/build.c +++ b/src/build.c @@ -3183,6 +3183,7 @@ Index *sqlite3CreateIndex( pIdx->onError = pIndex->onError; } } + pRet = pIdx; goto exit_create_index; } } diff --git a/test/without_rowid6.test b/test/without_rowid6.test index e827ccab90..8ca78ba63a 100644 --- a/test/without_rowid6.test +++ b/test/without_rowid6.test @@ -37,5 +37,81 @@ do_execsql_test without_rowid6-140 { SELECT c FROM t1 ORDER BY b LIMIT 5; } {x1y x2y x3y x4y x5y} +# Column t1.b starts out as a unique index, but that index is +# subsequently converted into a PRIMARY KEY. +# +do_execsql_test without_rowid6-200 { + DROP TABLE IF EXISTS t1; + CREATE TABLE t1( + a UNIQUE, + b UNIQUE, + c UNIQUE, + PRIMARY KEY(b) + ) WITHOUT ROWID; + INSERT INTO t1(a,b,c) VALUES(1,8,3),(4,5,6),(7,2,9); + SELECT a FROM t1 WHERE b>3 ORDER BY b; +} {4 1} +do_execsql_test without_rowid6-210 { + EXPLAIN QUERY PLAN + SELECT a FROM t1 WHERE b>3 ORDER BY b; +} {/SEARCH TABLE t1 USING PRIMARY KEY .b>../} +do_execsql_test without_rowid6-220 { + PRAGMA index_list(t1); +} {/sqlite_autoindex_t1_2 1 pk/} + +do_execsql_test without_rowid6-300 { + DROP TABLE IF EXISTS t1; + CREATE TABLE t1( + a UNIQUE, + b PRIMARY KEY, + c UNIQUE, + UNIQUE(b) + ) WITHOUT ROWID; + INSERT INTO t1(a,b,c) VALUES(1,8,3),(4,5,6),(7,2,9); + SELECT a FROM t1 WHERE b>3 ORDER BY b; +} {4 1} +do_execsql_test without_rowid6-310 { + EXPLAIN QUERY PLAN + SELECT a FROM t1 WHERE b>3 ORDER BY b; +} {/SEARCH TABLE t1 USING PRIMARY KEY .b>../} +do_execsql_test without_rowid6-320 { + PRAGMA index_list(t1); +} {/sqlite_autoindex_t1_2 1 pk/} + +do_execsql_test without_rowid6-400 { + DROP TABLE IF EXISTS t1; + CREATE TABLE t1( + a UNIQUE, + b UNIQUE PRIMARY KEY, + c UNIQUE + ) WITHOUT ROWID; + INSERT INTO t1(a,b,c) VALUES(1,8,3),(4,5,6),(7,2,9); + SELECT a FROM t1 WHERE b>3 ORDER BY b; +} {4 1} +do_execsql_test without_rowid6-410 { + EXPLAIN QUERY PLAN + SELECT a FROM t1 WHERE b>3 ORDER BY b; +} {/SEARCH TABLE t1 USING PRIMARY KEY .b>../} +do_execsql_test without_rowid6-420 { + PRAGMA index_list(t1); +} {/sqlite_autoindex_t1_2 1 pk/} + +do_execsql_test without_rowid6-500 { + DROP TABLE IF EXISTS t1; + CREATE TABLE t1(a,b,c, + UNIQUE(b,c), + PRIMARY KEY(b,c) + ) WITHOUT ROWID; + INSERT INTO t1(a,b,c) VALUES(1,8,3),(4,5,6),(7,2,9); + SELECT a FROM t1 WHERE b>3 ORDER BY b; +} {4 1} +do_execsql_test without_rowid6-510 { + EXPLAIN QUERY PLAN + SELECT a FROM t1 WHERE b>3 ORDER BY b; +} {/SEARCH TABLE t1 USING PRIMARY KEY .b>../} +do_execsql_test without_rowid6-520 { + PRAGMA index_list(t1); +} {/sqlite_autoindex_t1_1 1 pk/} + finish_test From 8f9d0b2b2513311770b7c9bd23d0eb7ceaeb587e Mon Sep 17 00:00:00 2001 From: drh Date: Sat, 21 Mar 2015 03:18:22 +0000 Subject: [PATCH 41/63] Correctly detect the error of having a "*" wildcard on a SELECT without a FROM clause on the left-hand side of a recursive CTE. FossilOrigin-Name: b11d1793a06a44931edcbf12a615b49794d53a62 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/select.c | 2 +- test/with1.test | 15 +++++++++++++++ 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 6b5b474365..537a662c65 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C If\sa\scolumn\sis\sboth\sUNIQUE\sand\sa\sPRIMARY\sKEY,\smake\ssure\sthe\sPRIMARY\sKEY\ndesignation\stakes\sprecedence. -D 2015-03-21T02:58:20.771 +C Correctly\sdetect\sthe\serror\sof\shaving\sa\s"*"\swildcard\son\sa\sSELECT\swithout\na\sFROM\sclause\son\sthe\sleft-hand\sside\sof\sa\srecursive\sCTE. +D 2015-03-21T03:18:22.783 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -230,7 +230,7 @@ F src/printf.c 8da9a2687a396daa19860f4dc90975d319304744 F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c f4d79e31ffa5820c2e3d1740baa5e9b190425f2b F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e -F src/select.c 94e016b6733b1d39a2f4c8d431155b4c2897d907 +F src/select.c 72ffb62e2879956302140e9f6e6ae88aee36b0e5 F src/shell.c 9c1589c8271c04c02d23cdbc2c07bb40752fa9eb F src/sqlite.h.in c7c9111477b76c82c46bf851b619df4dd35cc095 F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad @@ -1182,7 +1182,7 @@ F test/wild001.test bca33f499866f04c24510d74baf1e578d4e44b1c F test/win32heap.test ea19770974795cff26e11575e12d422dbd16893c F test/win32lock.test 71642fa56e9b06e5cfffe6bad67cb8c1eb2c555a F test/win32longpath.test 169c75a3b2e43481f4a62122510210c67b08f26d -F test/with1.test 268081a6b14817a262ced4d0ee34d4d2a1dd2068 +F test/with1.test 9df5cd8a62148b3d9ef8597aea563e3863018bcd F test/with2.test ee227a663586aa09771cafd4fa269c5217eaf775 F test/withM.test e97f2a8c506ab3ea9eab94e6f6072f6cc924c991 F test/without_rowid1.test 7862e605753c8d25329f665fa09072e842183151 @@ -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 880d2513a0fb084fae82080401b108fb13e61478 -R 705f61dec20eb9df7c2db39aa0eef35e +P d871a7921722bb0fef6d51e1110a9703ddff78c8 +R abf39ccde1b147748baa7108926922a2 U drh -Z 19c081d9e2a5c29193a61d5955352cbc +Z f5732dddfb21185ad5af5f2eb0f9450a diff --git a/manifest.uuid b/manifest.uuid index 46bb30739d..3fc8b41ecb 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -d871a7921722bb0fef6d51e1110a9703ddff78c8 \ No newline at end of file +b11d1793a06a44931edcbf12a615b49794d53a62 \ No newline at end of file diff --git a/src/select.c b/src/select.c index a9cecaa390..8fd0f15918 100644 --- a/src/select.c +++ b/src/select.c @@ -4035,7 +4035,7 @@ static int withExpand( for(pLeft=pSel; pLeft->pPrior; pLeft=pLeft->pPrior); pEList = pLeft->pEList; if( pCte->pCols ){ - if( pEList->nExpr!=pCte->pCols->nExpr ){ + if( pEList && pEList->nExpr!=pCte->pCols->nExpr ){ sqlite3ErrorMsg(pParse, "table %s has %d values for %d columns", pCte->zName, pEList->nExpr, pCte->pCols->nExpr ); diff --git a/test/with1.test b/test/with1.test index 42d2277aef..ad88a67c22 100644 --- a/test/with1.test +++ b/test/with1.test @@ -827,5 +827,20 @@ WITH RECURSIVE SELECT x FROM t1 EXCEPT SELECT y FROM t2 ORDER BY 1; } {2 4 8 10 14 16 20} +# 2015-03-21 +# Column wildcards on the LHS of a recursive table expression +# +do_catchsql_test 13.1 { + WITH RECURSIVE c(i) AS (SELECT * UNION ALL SELECT i+1 FROM c WHERE i<10) + SELECT i FROM c; +} {1 {no tables specified}} +do_catchsql_test 13.2 { + WITH RECURSIVE c(i) AS (SELECT 5,* UNION ALL SELECT i+1 FROM c WHERE i<10) + SELECT i FROM c; +} {1 {no tables specified}} +do_catchsql_test 13.3 { + WITH RECURSIVE c(i,j) AS (SELECT 5,* UNION ALL SELECT i+1,11 FROM c WHERE i<10) + SELECT i FROM c; +} {1 {table c has 1 values for 2 columns}} finish_test From e56f53ef7c808ab4e1425edaf6106daf0ef5cca6 Mon Sep 17 00:00:00 2001 From: dan Date: Sat, 21 Mar 2015 10:53:01 +0000 Subject: [PATCH 42/63] Add a missing "ifcapable fts3" to a test case in vtab2.test. FossilOrigin-Name: d845b0f69093178517d66e1fc5060e8f62c681c7 --- manifest | 14 +++++++------- manifest.uuid | 2 +- test/vtab2.test | 24 +++++++++++++----------- 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/manifest b/manifest index 537a662c65..666fc38ffc 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Correctly\sdetect\sthe\serror\sof\shaving\sa\s"*"\swildcard\son\sa\sSELECT\swithout\na\sFROM\sclause\son\sthe\sleft-hand\sside\sof\sa\srecursive\sCTE. -D 2015-03-21T03:18:22.783 +C Add\sa\smissing\s"ifcapable\sfts3"\sto\sa\stest\scase\sin\svtab2.test. +D 2015-03-21T10:53:01.184 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -1112,7 +1112,7 @@ F test/varint.test ab7b110089a08b9926ed7390e7e97bdefeb74102 F test/veryquick.test 57ab846bacf7b90cf4e9a672721ea5c5b669b661 F test/view.test f311691d696a5cc27e3c1b875cec1b0866b4ccd9 F test/vtab1.test 1cef14310144718812351a61c5cfb4ba8494a171 -F test/vtab2.test 366256bee644d034cbe078fbe1ec5bbe6b13fe42 +F test/vtab2.test 3644649aa8d1daac57fd541f6a5f914cac59203e F test/vtab3.test b45f47d20f225ccc9c28dc915d92740c2dee311e F test/vtab4.test 942f8b8280b3ea8a41dae20e7822d065ca1cb275 F test/vtab5.test 889f444970393c73f1e077e2bdc5d845e157a391 @@ -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 d871a7921722bb0fef6d51e1110a9703ddff78c8 -R abf39ccde1b147748baa7108926922a2 -U drh -Z f5732dddfb21185ad5af5f2eb0f9450a +P b11d1793a06a44931edcbf12a615b49794d53a62 +R 55729177793663a0c48c1beb22d1dc2b +U dan +Z c52b93c6a8110abb696022d137cc00a4 diff --git a/manifest.uuid b/manifest.uuid index 3fc8b41ecb..435dcf9c12 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -b11d1793a06a44931edcbf12a615b49794d53a62 \ No newline at end of file +d845b0f69093178517d66e1fc5060e8f62c681c7 \ No newline at end of file diff --git a/test/vtab2.test b/test/vtab2.test index 42b9da4670..3884ec57df 100644 --- a/test/vtab2.test +++ b/test/vtab2.test @@ -135,19 +135,21 @@ do_test vtab2-4.5 { #------------------------------------------------------------------------- # -reset_db -do_execsql_test 5.1 { - PRAGMA encoding='UTF16'; +ifcapable fts3 { + reset_db + do_execsql_test 5.1 { + PRAGMA encoding='UTF16'; + } + + do_test 5.2 { + sqlite3_exec_hex db { CREATE VIRTUAL TABLE %C8 USING fts3 } + } {0 {}} + + do_test 5.3 { + sqlite3_exec_hex db { CREATE VIRTUAL TABLE %C9 USING s } + } {/1 {malformed database schema.* already exists}/} } -do_test 5.2 { - sqlite3_exec_hex db { CREATE VIRTUAL TABLE %C8 USING fts3 } -} {0 {}} - -do_test 5.3 { - sqlite3_exec_hex db { CREATE VIRTUAL TABLE %C9 USING s } -} {/1 {malformed database schema.* already exists}/} - finish_test From 474640638da26ee9a22447a37839d333e8285bf0 Mon Sep 17 00:00:00 2001 From: drh Date: Sat, 21 Mar 2015 12:22:16 +0000 Subject: [PATCH 43/63] Remove an unreachable branch from the OP_VCreate opcode. FossilOrigin-Name: 5fca41a3811766b48f5f23d5d49cc4e6e79fa867 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/vdbe.c | 17 +++++++++++------ 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/manifest b/manifest index 666fc38ffc..05da0070b5 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sa\smissing\s"ifcapable\sfts3"\sto\sa\stest\scase\sin\svtab2.test. -D 2015-03-21T10:53:01.184 +C Remove\san\sunreachable\sbranch\sfrom\sthe\sOP_VCreate\sopcode. +D 2015-03-21T12:22:16.937 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 3d96875d883c2bf53a4806c9d4c5abff18511da4 +F src/vdbe.c bd793ed436edccaf264ec969ac92c9b5f4b41d64 F src/vdbe.h 6fc69d9c5e146302c56e163cb4b31d1ee64a18c3 F src/vdbeInt.h bb56fd199d8af1a2c1b9639ee2f70724b4338e3a F src/vdbeapi.c 583d56b129dd27f12bed518270de9ebe521e6a75 @@ -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 b11d1793a06a44931edcbf12a615b49794d53a62 -R 55729177793663a0c48c1beb22d1dc2b -U dan -Z c52b93c6a8110abb696022d137cc00a4 +P d845b0f69093178517d66e1fc5060e8f62c681c7 +R 33e37ff5951445c194f8f62b65ec1d8a +U drh +Z f47a30263eba86ab7824497d08f8b218 diff --git a/manifest.uuid b/manifest.uuid index 435dcf9c12..9d0d2f5b15 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -d845b0f69093178517d66e1fc5060e8f62c681c7 \ No newline at end of file +5fca41a3811766b48f5f23d5d49cc4e6e79fa867 \ No newline at end of file diff --git a/src/vdbe.c b/src/vdbe.c index 8eb7721085..7d6d2b4f5d 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -6033,15 +6033,20 @@ case OP_VBegin: { */ case OP_VCreate: { Mem sMem; /* For storing the record being decoded */ + const char *zTab; /* Name of the virtual table */ + memset(&sMem, 0, sizeof(sMem)); sMem.db = db; + /* Because P2 is always a static string, it is impossible for the + ** sqlite3VdbeMemCopy() to fail */ + assert( (aMem[pOp->p2].flags & MEM_Str)!=0 ); + assert( (aMem[pOp->p2].flags & MEM_Static)!=0 ); rc = sqlite3VdbeMemCopy(&sMem, &aMem[pOp->p2]); - if( rc==SQLITE_OK ){ - const char *zTab = (const char*)sqlite3_value_text(&sMem); - assert( zTab || db->mallocFailed ); - if( zTab ){ - rc = sqlite3VtabCallCreate(db, pOp->p1, zTab, &p->zErrMsg); - } + assert( rc==SQLITE_OK ); + zTab = (const char*)sqlite3_value_text(&sMem); + assert( zTab || db->mallocFailed ); + if( zTab ){ + rc = sqlite3VtabCallCreate(db, pOp->p1, zTab, &p->zErrMsg); } sqlite3VdbeMemRelease(&sMem); break; From 998aaa03ea52f20804ce9bec5a2920ff9583877e Mon Sep 17 00:00:00 2001 From: dan Date: Sat, 21 Mar 2015 12:22:51 +0000 Subject: [PATCH 44/63] Avoid an integer overflow in fts3 causing gcc 4.7.1 with -O2 to behave counter-intuitively (perhaps because the behaviour is undefined). Add an "ifcapable trace" to a test in shell4.test. FossilOrigin-Name: e3e234649616f20610abce9ae9da1c572d3a4377 --- ext/fts3/fts3.c | 10 ++++++++-- manifest | 14 +++++++------- manifest.uuid | 2 +- test/shell4.test | 2 ++ 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/ext/fts3/fts3.c b/ext/fts3/fts3.c index 3c229403b4..3c2e5adc01 100644 --- a/ext/fts3/fts3.c +++ b/ext/fts3/fts3.c @@ -910,11 +910,16 @@ 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 char *p; /* Iterator pointer */ int nInt = 0; /* Output value */ for(p=*pp; p[0]>='0' && p[0]<='9'; p++){ nInt = nInt * 10 + (p[0] - '0'); + if( nInt>MAX_NPREFIX ){ + nInt = 0; + break; + } } if( p==*pp ) return SQLITE_ERROR; *pnOut = nInt; @@ -966,9 +971,10 @@ static int fts3PrefixParameter( const char *p = zParam; int i; for(i=1; i=0 ); + if( nPrefix==0 ){ nIndex--; i--; }else{ diff --git a/manifest b/manifest index 666fc38ffc..b682535cbf 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sa\smissing\s"ifcapable\sfts3"\sto\sa\stest\scase\sin\svtab2.test. -D 2015-03-21T10:53:01.184 +C Avoid\san\sinteger\soverflow\sin\sfts3\scausing\sgcc\s4.7.1\swith\s-O2\sto\sbehave\scounter-intuitively\s(perhaps\sbecause\sthe\sbehaviour\sis\sundefined).\sAdd\san\s"ifcapable\strace"\sto\sa\stest\sin\sshell4.test. +D 2015-03-21T12:22:51.140 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 022915f30538b40b584c5abb27cae47d07cb3465 +F ext/fts3/fts3.c e2c7e61d676ce7b9383d1078c9774a2f22947d57 F ext/fts3/fts3.h 3a10a0af180d502cecc50df77b1b22df142817fe F ext/fts3/fts3Int.h 394858c12a17740f7a1f6bd372c4606d4425a8d1 F ext/fts3/fts3_aux.c 5c211e17a64885faeb16b9ba7772f9d5445c2365 @@ -866,7 +866,7 @@ F test/sharedlock.test 5ede3c37439067c43b0198f580fd374ebf15d304 F test/shell1.test ca88b14a8fc8b1f3543a24e519d019585ac9c903 F test/shell2.test 12b8bf901b0e3a8ac58cf5c0c63a0a388d4d1862 F test/shell3.test 5e8545ec72c4413a0e8d4c6be56496e3c257ca29 -F test/shell4.test 4cd3bd50200bf2efd6a74175d98da65aa86daf26 +F test/shell4.test ddf0a99044e2245a87fc17423e3aaa1445b3243b F test/shell5.test c04e9f9f948305706b88377c464c7f08ce7479f9 F test/shortread1.test bb591ef20f0fd9ed26d0d12e80eee6d7ac8897a3 F test/show_speedtest1_rtree.tcl 32e6c5f073d7426148a6936a0408f4b5b169aba5 @@ -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 b11d1793a06a44931edcbf12a615b49794d53a62 -R 55729177793663a0c48c1beb22d1dc2b +P d845b0f69093178517d66e1fc5060e8f62c681c7 +R 7a07a789329b4f516d02a691b70e458c U dan -Z c52b93c6a8110abb696022d137cc00a4 +Z 3ae65dad7900f82b42a270fbfd21fd80 diff --git a/manifest.uuid b/manifest.uuid index 435dcf9c12..2e8412f795 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -d845b0f69093178517d66e1fc5060e8f62c681c7 \ No newline at end of file +e3e234649616f20610abce9ae9da1c572d3a4377 \ No newline at end of file diff --git a/test/shell4.test b/test/shell4.test index d1466f638c..fcb0b2b715 100644 --- a/test/shell4.test +++ b/test/shell4.test @@ -122,6 +122,7 @@ do_test shell4-2.2 { do_test shell4-2.3 { catchcmd ":memory:" ".trace stdout\n.trace\n.trace off\n.dump\n" } {/^1 {PRAGMA.*Usage:.*}$/} +ifcapable trace { do_test shell4-2.4 { catchcmd ":memory:" ".trace stdout\nCREATE TABLE t1(x);SELECT * FROM t1;" } {0 {CREATE TABLE t1(x); @@ -129,6 +130,7 @@ SELECT * FROM t1;}} do_test shell4-2.5 { catchcmd ":memory:" "CREATE TABLE t1(x);\n.trace stdout\nSELECT * FROM t1;" } {0 {SELECT * FROM t1;}} +} finish_test From c435cf75a57292833696920189f416e923e4a85d Mon Sep 17 00:00:00 2001 From: drh Date: Sat, 21 Mar 2015 16:36:03 +0000 Subject: [PATCH 45/63] 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 46/63] 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 47/63] 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 48/63] 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 49/63] 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 50/63] 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 51/63] 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 52/63] 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 53/63] 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 54/63] 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 55/63] 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 56/63] 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 57/63] 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 58/63] 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 59/63] 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 60/63] 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 61/63] 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 62/63] 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 63/63] 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