/ Check-in [86e39123]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Merge the fix to PRAGMA data_version and testing improvements from trunk.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | sessions
Files: files | file ages | folders
SHA1:86e39123c1bca457672bc63eff00a823745077e5
User & Date: drh 2014-12-31 14:27:29
Context
2015-01-08
20:06
Merge recent enhancements from trunk, including test scripts enhancements and the removal of limits on the number of terms in a VALUES clause. check-in: 5a2dec55 user: drh tags: sessions
2014-12-31
14:27
Merge the fix to PRAGMA data_version and testing improvements from trunk. check-in: 86e39123 user: drh tags: sessions
14:18
Make sure PRAGMA data_version is updated even if the cache is empty when another connection changes the database. check-in: cf48eb60 user: drh tags: trunk
2014-12-22
18:48
Merge the PRAGMA data_version redefinition and other fixes from trunk. check-in: 315243e4 user: drh tags: sessions
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to Makefile.in.

   535    535   		-o $@ $(TOP)/src/shell.c libsqlite3.la \
   536    536   		$(LIBREADLINE) $(TLIBS) -rpath "$(libdir)"
   537    537   
   538    538   mptester$(EXE):	sqlite3.c $(TOP)/mptest/mptest.c
   539    539   	$(LTLINK) -o $@ -I. $(TOP)/mptest/mptest.c sqlite3.c \
   540    540   		$(TLIBS) -rpath "$(libdir)"
   541    541   
          542  +mptest:	mptester$(EXE)
          543  +	rm -f mptest1.db
          544  +	./mptester$(EXE) mptest1.db $(TOP)/mptest/crash01.test
          545  +	rm -f mptest2.db
          546  +	./mptester$(EXE) mptest2.db $(TOP)/mptest/multiwrite01.test
   542    547   
   543    548   # This target creates a directory named "tsrc" and fills it with
   544    549   # copies of all of the C source code and header files needed to
   545    550   # build on the target system.  Some of the C source code and header
   546    551   # files are automatically generated.  This target takes care of
   547    552   # all that automatic generation.
   548    553   #
................................................................................
   980    985   	$(LTLINK) -I. -o $@ $(TOP)/tool/logest.c
   981    986   
   982    987   wordcount$(TEXE):	$(TOP)/test/wordcount.c sqlite3.c
   983    988   	$(LTLINK) -o $@ $(TOP)/test/wordcount.c sqlite3.c $(TLIBS)
   984    989   
   985    990   speedtest1$(TEXE):	$(TOP)/test/wordcount.c sqlite3.lo
   986    991   	$(LTLINK) -o $@ $(TOP)/test/speedtest1.c sqlite3.lo $(TLIBS)
          992  +
          993  +# This target will fail if the SQLite amalgamation contains any exported
          994  +# symbols that do not begin with "sqlite3_". It is run as part of the
          995  +# releasetest.tcl script.
          996  +#
          997  +checksymbols: sqlite3.lo
          998  +	nm -g --defined-only sqlite3.o | grep -v " sqlite3_" ; test $$? -ne 0
          999  +	echo '0 errors out of 1 tests'
         1000  +
         1001  +# The next two rules are used to support the "threadtest" target. Building
         1002  +# threadtest runs a few thread-safety tests that are implemented in C. This
         1003  +# target is invoked by the releasetest.tcl script.
         1004  +# 
         1005  +THREADTEST3_SRC = $(TOP)/test/threadtest3.c    \
         1006  +                  $(TOP)/test/tt3_checkpoint.c \
         1007  +                  $(TOP)/test/tt3_index.c      \
         1008  +                  $(TOP)/test/tt3_vacuum.c      \
         1009  +                  $(TOP)/test/tt3_stress.c      \
         1010  +                  $(TOP)/test/tt3_lookaside1.c
         1011  +
         1012  +threadtest3$(TEXE): sqlite3.lo $(THREADTEST3_SRC)
         1013  +	$(LTLINK) $(TOP)/test/threadtest3.c sqlite3.lo -o $@ $(TLIBS)
         1014  +
         1015  +threadtest: threadtest3$(TEXE)
         1016  +	./threadtest3$(TEXE)
         1017  +
         1018  +releasetest:	
         1019  +	$(TCLSH_CMD) $(TOP)/test/releasetest.tcl
   987   1020   
   988   1021   # Standard install and cleanup targets
   989   1022   #
   990   1023   lib_install:	libsqlite3.la
   991   1024   	$(INSTALL) -d $(DESTDIR)$(libdir)
   992   1025   	$(LTINSTALL) libsqlite3.la $(DESTDIR)$(libdir)
   993   1026   	

Changes to mptest/mptest.c.

  1391   1391       }
  1392   1392       sqlite3_finalize(pStmt);
  1393   1393     }
  1394   1394     sqlite3_close(g.db);  
  1395   1395     maybeClose(g.pLog);
  1396   1396     maybeClose(g.pErrLog);
  1397   1397     if( iClient==0 ){
  1398         -    printf("Summary: %d errors in %d tests\n", g.nError, g.nTest);
         1398  +    printf("Summary: %d errors out of %d tests\n", g.nError, g.nTest);
  1399   1399     }
  1400   1400     return g.nError>0;
  1401   1401   }

Changes to src/btree.c.

  6861   6861           memcpy(apCell[nCell], &pOld->aData[8], 4);
  6862   6862         }else{
  6863   6863           assert( leafCorrection==4 );
  6864   6864           if( szCell[nCell]<4 ){
  6865   6865             /* Do not allow any cells smaller than 4 bytes. If a smaller cell
  6866   6866             ** does exist, pad it with 0x00 bytes. */
  6867   6867             assert( szCell[nCell]==3 );
  6868         -          assert( apCell[nCell]==&pTemp[iSpace1-3] );
  6869         -          pTemp[iSpace1++] = 0x00;
         6868  +          assert( apCell[nCell]==&aSpace1[iSpace1-3] );
         6869  +          aSpace1[iSpace1++] = 0x00;
  6870   6870             szCell[nCell] = 4;
  6871   6871           }
  6872   6872         }
  6873   6873         nCell++;
  6874   6874       }
  6875   6875     }
  6876   6876   
................................................................................
  9142   9142   int sqlite3BtreeIsReadonly(Btree *p){
  9143   9143     return (p->pBt->btsFlags & BTS_READ_ONLY)!=0;
  9144   9144   }
  9145   9145   
  9146   9146   /*
  9147   9147   ** Return the size of the header added to each page by this module.
  9148   9148   */
  9149         -int sqlite3HeaderSizeBtree(void){ return sizeof(MemPage); }
         9149  +int sqlite3HeaderSizeBtree(void){ return ROUND8(sizeof(MemPage)); }

Changes to src/build.c.

  1709   1709       assert( pParse->pNewTable==pTab );
  1710   1710       pPk = sqlite3CreateIndex(pParse, 0, 0, 0, pList, pTab->keyConf, 0, 0, 0, 0);
  1711   1711       if( pPk==0 ) return;
  1712   1712       pPk->idxType = SQLITE_IDXTYPE_PRIMARYKEY;
  1713   1713       pTab->iPKey = -1;
  1714   1714     }else{
  1715   1715       pPk = sqlite3PrimaryKeyIndex(pTab);
         1716  +    /*
         1717  +    ** Remove all redundant columns from the PRIMARY KEY.  For example, change
         1718  +    ** "PRIMARY KEY(a,b,a,b,c,b,c,d)" into just "PRIMARY KEY(a,b,c,d)".  Later
         1719  +    ** code assumes the PRIMARY KEY contains no repeated columns.
         1720  +    */
         1721  +    for(i=j=1; i<pPk->nKeyCol; i++){
         1722  +      if( hasColumn(pPk->aiColumn, j, pPk->aiColumn[i]) ){
         1723  +        pPk->nColumn--;
         1724  +      }else{
         1725  +        pPk->aiColumn[j++] = pPk->aiColumn[i];
         1726  +      }
         1727  +    }
         1728  +    pPk->nKeyCol = j;
  1716   1729     }
  1717   1730     pPk->isCovering = 1;
  1718   1731     assert( pPk!=0 );
  1719   1732     nPk = pPk->nKeyCol;
  1720   1733   
  1721   1734     /* Make sure every column of the PRIMARY KEY is NOT NULL */
  1722   1735     for(i=0; i<nPk; i++){

Changes to src/main.c.

    58     58   #if !defined(SQLITE_OMIT_TRACE) && defined(SQLITE_ENABLE_IOTRACE)
    59     59   /*
    60     60   ** If the following function pointer is not NULL and if
    61     61   ** SQLITE_ENABLE_IOTRACE is enabled, then messages describing
    62     62   ** I/O active are written using this function.  These messages
    63     63   ** are intended for debugging activity only.
    64     64   */
    65         -void (*sqlite3IoTrace)(const char*, ...) = 0;
           65  +/* not-private */ void (*sqlite3IoTrace)(const char*, ...) = 0;
    66     66   #endif
    67     67   
    68     68   /*
    69     69   ** If the following global variable points to a string which is the
    70     70   ** name of a directory, then that directory will be used to store
    71     71   ** temporary files.
    72     72   **
................................................................................
   267    267   ** there are outstanding database connections or memory allocations or
   268    268   ** while any part of SQLite is otherwise in use in any thread.  This
   269    269   ** routine is not threadsafe.  But it is safe to invoke this routine
   270    270   ** on when SQLite is already shut down.  If SQLite is already shut down
   271    271   ** when this routine is invoked, then this routine is a harmless no-op.
   272    272   */
   273    273   int sqlite3_shutdown(void){
          274  +#ifdef SQLITE_OMIT_WSD
          275  +  int rc = sqlite3_wsd_init(4096, 24);
          276  +  if( rc!=SQLITE_OK ){
          277  +    return rc;
          278  +  }
          279  +#endif
          280  +
   274    281     if( sqlite3GlobalConfig.isInit ){
   275    282   #ifdef SQLITE_EXTRA_SHUTDOWN
   276    283       void SQLITE_EXTRA_SHUTDOWN(void);
   277    284       SQLITE_EXTRA_SHUTDOWN();
   278    285   #endif
   279    286       sqlite3_os_end();
   280    287       sqlite3_reset_auto_extension();

Changes to src/os_unix.c.

  3705   3705         ** or an error number on  failure". See the manpage for details. */
  3706   3706         int err;
  3707   3707         do{
  3708   3708           err = osFallocate(pFile->h, buf.st_size, nSize-buf.st_size);
  3709   3709         }while( err==EINTR );
  3710   3710         if( err ) return SQLITE_IOERR_WRITE;
  3711   3711   #else
  3712         -      /* If the OS does not have posix_fallocate(), fake it. First use
  3713         -      ** ftruncate() to set the file size, then write a single byte to
  3714         -      ** the last byte in each block within the extended region. This
  3715         -      ** is the same technique used by glibc to implement posix_fallocate()
  3716         -      ** on systems that do not have a real fallocate() system call.
         3712  +      /* If the OS does not have posix_fallocate(), fake it. Write a 
         3713  +      ** single byte to the last byte in each block that falls entirely
         3714  +      ** within the extended region. Then, if required, a single byte
         3715  +      ** at offset (nSize-1), to set the size of the file correctly.
         3716  +      ** This is a similar technique to that used by glibc on systems
         3717  +      ** that do not have a real fallocate() call.
  3717   3718         */
  3718   3719         int nBlk = buf.st_blksize;  /* File-system block size */
  3719   3720         i64 iWrite;                 /* Next offset to write to */
  3720   3721   
  3721         -      if( robust_ftruncate(pFile->h, nSize) ){
  3722         -        pFile->lastErrno = errno;
  3723         -        return unixLogError(SQLITE_IOERR_TRUNCATE, "ftruncate", pFile->zPath);
  3724         -      }
  3725   3722         iWrite = ((buf.st_size + 2*nBlk - 1)/nBlk)*nBlk-1;
  3726         -      while( iWrite<nSize ){
         3723  +      assert( iWrite>=buf.st_size );
         3724  +      assert( (iWrite/nBlk)==((buf.st_size+nBlk-1)/nBlk) );
         3725  +      assert( ((iWrite+1)%nBlk)==0 );
         3726  +      for(/*no-op*/; iWrite<nSize; iWrite+=nBlk ){
  3727   3727           int nWrite = seekAndWrite(pFile, iWrite, "", 1);
  3728   3728           if( nWrite!=1 ) return SQLITE_IOERR_WRITE;
  3729         -        iWrite += nBlk;
         3729  +      }
         3730  +      if( nSize%nBlk ){
         3731  +        int nWrite = seekAndWrite(pFile, nSize-1, "", 1);
         3732  +        if( nWrite!=1 ) return SQLITE_IOERR_WRITE;
  3730   3733         }
  3731   3734   #endif
  3732   3735       }
  3733   3736     }
  3734   3737   
  3735   3738   #if SQLITE_MAX_MMAP_SIZE>0
  3736   3739     if( pFile->mmapSizeMax>0 && nByte>pFile->mmapSize ){

Changes to src/pager.c.

   643    643     u8 eState;                  /* Pager state (OPEN, READER, WRITER_LOCKED..) */
   644    644     u8 eLock;                   /* Current lock held on database file */
   645    645     u8 changeCountDone;         /* Set after incrementing the change-counter */
   646    646     u8 setMaster;               /* True if a m-j name has been written to jrnl */
   647    647     u8 doNotSpill;              /* Do not spill the cache when non-zero */
   648    648     u8 subjInMemory;            /* True to use in-memory sub-journals */
   649    649     u8 bUseFetch;               /* True to use xFetch() */
          650  +  u8 hasBeenUsed;             /* True if any content previously read from this pager*/
   650    651     Pgno dbSize;                /* Number of pages in the database */
   651    652     Pgno dbOrigSize;            /* dbSize before the current transaction */
   652    653     Pgno dbFileSize;            /* Number of pages in the database file */
   653    654     Pgno dbHintSize;            /* Value passed to FCNTL_SIZE_HINT call */
   654    655     int errCode;                /* One of several kinds of errors */
   655    656     int nRec;                   /* Pages journalled since last j-header written */
   656    657     u32 cksumInit;              /* Quasi-random value added to every checksum */
................................................................................
  3893   3894   static int pagerAcquireMapPage(
  3894   3895     Pager *pPager,                  /* Pager object */
  3895   3896     Pgno pgno,                      /* Page number */
  3896   3897     void *pData,                    /* xFetch()'d data for this page */
  3897   3898     PgHdr **ppPage                  /* OUT: Acquired page object */
  3898   3899   ){
  3899   3900     PgHdr *p;                       /* Memory mapped page to return */
  3900         -
         3901  +  
  3901   3902     if( pPager->pMmapFreelist ){
  3902   3903       *ppPage = p = pPager->pMmapFreelist;
  3903   3904       pPager->pMmapFreelist = p->pDirty;
  3904   3905       p->pDirty = 0;
  3905   3906       memset(p->pExtra, 0, pPager->nExtra);
  3906   3907     }else{
  3907   3908       *ppPage = p = (PgHdr *)sqlite3MallocZero(sizeof(PgHdr) + pPager->nExtra);
................................................................................
  5124   5125   
  5125   5126         assert( pPager->eState==PAGER_OPEN );
  5126   5127         assert( (pPager->eLock==SHARED_LOCK)
  5127   5128              || (pPager->exclusiveMode && pPager->eLock>SHARED_LOCK)
  5128   5129         );
  5129   5130       }
  5130   5131   
  5131         -    if( !pPager->tempFile && (
  5132         -        pPager->pBackup 
  5133         -     || sqlite3PcachePagecount(pPager->pPCache)>0 
  5134         -     || USEFETCH(pPager)
  5135         -    )){
  5136         -      /* The shared-lock has just been acquired on the database file
  5137         -      ** and there are already pages in the cache (from a previous
  5138         -      ** read or write transaction).  Check to see if the database
  5139         -      ** has been modified.  If the database has changed, flush the
  5140         -      ** cache.
         5132  +    if( !pPager->tempFile && pPager->hasBeenUsed ){
         5133  +      /* The shared-lock has just been acquired then check to
         5134  +      ** see if the database has been modified.  If the database has changed,
         5135  +      ** flush the cache.  The pPager->hasBeenUsed flag prevents this from
         5136  +      ** occurring on the very first access to a file, in order to save a
         5137  +      ** single unnecessary sqlite3OsRead() call at the start-up.
  5141   5138         **
  5142   5139         ** Database changes is detected by looking at 15 bytes beginning
  5143   5140         ** at offset 24 into the file.  The first 4 of these 16 bytes are
  5144   5141         ** a 32-bit counter that is incremented with each change.  The
  5145   5142         ** other bytes change randomly with each file change when
  5146   5143         ** a codec is in use.
  5147   5144         ** 
................................................................................
  5298   5295     assert( pPager->eState>=PAGER_READER );
  5299   5296     assert( assert_pager_state(pPager) );
  5300   5297     assert( noContent==0 || bMmapOk==0 );
  5301   5298   
  5302   5299     if( pgno==0 ){
  5303   5300       return SQLITE_CORRUPT_BKPT;
  5304   5301     }
         5302  +  pPager->hasBeenUsed = 1;
  5305   5303   
  5306   5304     /* If the pager is in the error state, return an error immediately. 
  5307   5305     ** Otherwise, request the page from the PCache layer. */
  5308   5306     if( pPager->errCode!=SQLITE_OK ){
  5309   5307       rc = pPager->errCode;
  5310   5308     }else{
  5311   5309       if( bMmapOk && pagerUseWal(pPager) ){
................................................................................
  5447   5445   */
  5448   5446   DbPage *sqlite3PagerLookup(Pager *pPager, Pgno pgno){
  5449   5447     sqlite3_pcache_page *pPage;
  5450   5448     assert( pPager!=0 );
  5451   5449     assert( pgno!=0 );
  5452   5450     assert( pPager->pPCache!=0 );
  5453   5451     pPage = sqlite3PcacheFetch(pPager->pPCache, pgno, 0);
         5452  +  assert( pPage==0 || pPager->hasBeenUsed );
  5454   5453     return sqlite3PcacheFetchFinish(pPager->pPCache, pgno, pPage);
  5455   5454   }
  5456   5455   
  5457   5456   /*
  5458   5457   ** Release a page reference.
  5459   5458   **
  5460   5459   ** If the number of references to the page drop to zero, then the

Changes to src/pcache.c.

   192    192   ** are no outstanding page references when this function is called.
   193    193   */
   194    194   int sqlite3PcacheSetPageSize(PCache *pCache, int szPage){
   195    195     assert( pCache->nRef==0 && pCache->pDirty==0 );
   196    196     if( pCache->szPage ){
   197    197       sqlite3_pcache *pNew;
   198    198       pNew = sqlite3GlobalConfig.pcache2.xCreate(
   199         -                szPage, pCache->szExtra + sizeof(PgHdr), pCache->bPurgeable
          199  +                szPage, pCache->szExtra + ROUND8(sizeof(PgHdr)),
          200  +                pCache->bPurgeable
   200    201       );
   201    202       if( pNew==0 ) return SQLITE_NOMEM;
   202    203       sqlite3GlobalConfig.pcache2.xCachesize(pNew, numberOfCachePages(pCache));
   203    204       if( pCache->pCache ){
   204    205         sqlite3GlobalConfig.pcache2.xDestroy(pCache->pCache);
   205    206       }
   206    207       pCache->pCache = pNew;
................................................................................
   651    652     sqlite3GlobalConfig.pcache2.xShrink(pCache->pCache);
   652    653   }
   653    654   
   654    655   /*
   655    656   ** Return the size of the header added by this middleware layer
   656    657   ** in the page-cache hierarchy.
   657    658   */
   658         -int sqlite3HeaderSizePcache(void){ return sizeof(PgHdr); }
          659  +int sqlite3HeaderSizePcache(void){ return ROUND8(sizeof(PgHdr)); }
   659    660   
   660    661   
   661    662   #if defined(SQLITE_CHECK_PAGES) || defined(SQLITE_DEBUG)
   662    663   /*
   663    664   ** For all dirty pages currently in the cache, invoke the specified
   664    665   ** callback. This is only used if the SQLITE_CHECK_PAGES macro is
   665    666   ** defined.

Changes to src/pcache1.c.

   292    292     p = sqlite3Malloc(sizeof(PgHdr1) + pCache->szExtra);
   293    293     if( !pPg || !p ){
   294    294       pcache1Free(pPg);
   295    295       sqlite3_free(p);
   296    296       pPg = 0;
   297    297     }
   298    298   #else
   299         -  pPg = pcache1Alloc(sizeof(PgHdr1) + pCache->szPage + pCache->szExtra);
          299  +  pPg = pcache1Alloc(ROUND8(sizeof(PgHdr1)) + pCache->szPage + pCache->szExtra);
   300    300     p = (PgHdr1 *)&((u8 *)pPg)[pCache->szPage];
   301    301   #endif
   302    302     pcache1EnterMutex(pCache->pGroup);
   303    303   
   304    304     if( pPg ){
   305    305       p->page.pBuf = pPg;
   306    306       p->page.pExtra = &p[1];
................................................................................
   980    980     };
   981    981     sqlite3_config(SQLITE_CONFIG_PCACHE2, &defaultMethods);
   982    982   }
   983    983   
   984    984   /*
   985    985   ** Return the size of the header on each page of this PCACHE implementation.
   986    986   */
   987         -int sqlite3HeaderSizePcache1(void){ return sizeof(PgHdr1); }
          987  +int sqlite3HeaderSizePcache1(void){ return ROUND8(sizeof(PgHdr1)); }
   988    988   
   989    989   #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
   990    990   /*
   991    991   ** This function is called to free superfluous dynamically allocated memory
   992    992   ** held by the pager system. Memory in use by any SQLite pager allocated
   993    993   ** by the current thread may be sqlite3_free()ed.
   994    994   **

Changes to src/sqlite.h.in.

  1561   1561   ** This configuration should not be used if an application-define page
  1562   1562   ** cache implementation is loaded using the [SQLITE_CONFIG_PCACHE2]
  1563   1563   ** configuration option.
  1564   1564   ** ^There are three arguments to SQLITE_CONFIG_PAGECACHE: A pointer to
  1565   1565   ** 8-byte aligned
  1566   1566   ** memory, the size of each page buffer (sz), and the number of pages (N).
  1567   1567   ** The sz argument should be the size of the largest database page
  1568         -** (a power of two between 512 and 32768) plus some extra bytes for each
         1568  +** (a power of two between 512 and 65536) plus some extra bytes for each
  1569   1569   ** page header.  ^The number of extra bytes needed by the page header
  1570   1570   ** can be determined using the [SQLITE_CONFIG_PCACHE_HDRSZ] option 
  1571   1571   ** to [sqlite3_config()].
  1572   1572   ** ^It is harmless, apart from the wasted memory,
  1573   1573   ** for the sz parameter to be larger than necessary.  The first
  1574   1574   ** argument should pointer to an 8-byte aligned block of memory that
  1575   1575   ** is at least sz*N bytes of memory, otherwise subsequent behavior is

Changes to src/test1.c.

  3666   3666     rc = sqlite3_prepare_v2(db, zCopy, bytes, &pStmt, objc>=5 ? &zTail : 0);
  3667   3667     free(zCopy);
  3668   3668     zTail = &zSql[(zTail - zCopy)];
  3669   3669   
  3670   3670     assert(rc==SQLITE_OK || pStmt==0);
  3671   3671     Tcl_ResetResult(interp);
  3672   3672     if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR;
  3673         -  if( zTail && objc>=5 ){
         3673  +  if( rc==SQLITE_OK && zTail && objc>=5 ){
  3674   3674       if( bytes>=0 ){
  3675   3675         bytes = bytes - (int)(zTail-zSql);
  3676   3676       }
  3677   3677       Tcl_ObjSetVar2(interp, objv[4], 0, Tcl_NewStringObj(zTail, bytes), 0);
  3678   3678     }
  3679   3679     if( rc!=SQLITE_OK ){
  3680   3680       assert( pStmt==0 );

Changes to src/vdbesort.c.

  1128   1128   ** the VFS has memory mapped it.
  1129   1129   **
  1130   1130   ** Whether or not the file does end up memory mapped of course depends on
  1131   1131   ** the specific VFS implementation.
  1132   1132   */
  1133   1133   static void vdbeSorterExtendFile(sqlite3 *db, sqlite3_file *pFd, i64 nByte){
  1134   1134     if( nByte<=(i64)(db->nMaxSorterMmap) && pFd->pMethods->iVersion>=3 ){
  1135         -    int rc = sqlite3OsTruncate(pFd, nByte);
  1136         -    if( rc==SQLITE_OK ){
  1137         -      void *p = 0;
  1138         -      sqlite3OsFetch(pFd, 0, (int)nByte, &p);
  1139         -      sqlite3OsUnfetch(pFd, 0, p);
  1140         -    }
         1135  +    void *p = 0;
         1136  +    int chunksize = 4*1024;
         1137  +    sqlite3OsFileControlHint(pFd, SQLITE_FCNTL_CHUNK_SIZE, &chunksize);
         1138  +    sqlite3OsFileControlHint(pFd, SQLITE_FCNTL_SIZE_HINT, &nByte);
         1139  +    sqlite3OsFetch(pFd, 0, (int)nByte, &p);
         1140  +    sqlite3OsUnfetch(pFd, 0, p);
  1141   1141     }
  1142   1142   }
  1143   1143   #else
  1144   1144   # define vdbeSorterExtendFile(x,y,z)
  1145   1145   #endif
  1146   1146   
  1147   1147   /*

Changes to src/wal.c.

  2408   2408       if( rc!=SQLITE_OK ){
  2409   2409         return rc;
  2410   2410       }
  2411   2411       nCollide = HASHTABLE_NSLOT;
  2412   2412       for(iKey=walHash(pgno); aHash[iKey]; iKey=walNextHash(iKey)){
  2413   2413         u32 iFrame = aHash[iKey] + iZero;
  2414   2414         if( iFrame<=iLast && aPgno[aHash[iKey]]==pgno ){
  2415         -        /* assert( iFrame>iRead ); -- not true if there is corruption */
         2415  +        assert( iFrame>iRead || CORRUPT_DB );
  2416   2416           iRead = iFrame;
  2417   2417         }
  2418   2418         if( (nCollide--)==0 ){
  2419   2419           return SQLITE_CORRUPT_BKPT;
  2420   2420         }
  2421   2421       }
  2422   2422     }

Changes to test/e_walauto.test.

    62     62       }
    63     63     }
    64     64   } {
    65     65   
    66     66     eval $code
    67     67   
    68     68     reset_db
           69  +  execsql { PRAGMA auto_vacuum = 0 }
    69     70     do_execsql_test 1.$tn.0 { PRAGMA journal_mode = WAL } {wal}
    70     71     do_execsql_test 1.$tn.1 { CREATE TABLE t1(a, b) }
    71     72     set shmfd [open "test.db-shm" rb]
    72     73   
    73     74     # EVIDENCE-OF: R-41531-51083 Every new database connection defaults to
    74     75     # having the auto-checkpoint enabled with a threshold of 1000 or
    75     76     # SQLITE_DEFAULT_WAL_AUTOCHECKPOINT pages.

Changes to test/e_walckpt.test.

   243    243     testvfs tvfs
   244    244     tvfs filter xWrite
   245    245     sqlite3 db test.db -vfs tvfs
   246    246     sqlite3 db2 test.db -vfs tvfs
   247    247   
   248    248     do_test $tn.3.2.1 {
   249    249       db2 eval {
          250  +      PRAGMA auto_vacuum = 0;
   250    251         PRAGMA journal_mode = WAL;
   251    252         CREATE TABLE t1(x, y);
   252    253         INSERT INTO t1 VALUES(1,2);
   253    254         INSERT INTO t1 VALUES(3,4);
   254    255         INSERT INTO t1 VALUES(5,6);
   255    256       }
   256    257       file size test.db-wal
................................................................................
   702    703   }
   703    704   
   704    705   reset_db
   705    706   sqlite3 db2 test.db
   706    707   
   707    708   do_test 6.1 {
   708    709     execsql {
          710  +    PRAGMA auto_vacuum = 0; 
   709    711       PRAGMA journal_mode = WAL;
   710    712       CREATE TABLE t1(a, b);
   711    713       INSERT INTO t1 VALUES(1, 2);
   712    714     }
   713    715     file size test.db-wal
   714    716   } [wal_file_size 3 1024]
   715    717   

Changes to test/notify2.test.

    97     97     opendb
    98     98   
    99     99     #after 2000
   100    100   
   101    101     # This loop runs for ~20 seconds.
   102    102     #
   103    103     set iStart [clock_seconds]
          104  +  set nOp 0
          105  +  set nAttempt 0
   104    106     while { ([clock_seconds]-$iStart) < $nSecond } {
   105    107   
   106    108       # Each transaction does 3 operations. Each operation is either a read
   107    109       # or write of a randomly selected table (t1, t2 or t3). Set the variables
   108    110       # $SQL(1), $SQL(2) and $SQL(3) to the SQL commands used to implement
   109    111       # each operation.
   110    112       #
................................................................................
   124    126               DROP INDEX IF EXISTS yyy.xxx_i;
   125    127         }
   126    128         ]]
   127    129       }
   128    130   
   129    131       # Execute the SQL transaction.
   130    132       #
          133  +    incr nAttempt
   131    134       set rc [catch { execsql_blocking $::DB "
   132    135           BEGIN;
   133    136             $SQL(1);
   134    137             $SQL(2);
   135    138             $SQL(3);
   136    139           COMMIT;
   137    140         "
................................................................................
   150    153         # Hit some other kind of error. This is a malfunction.
   151    154         error $msg
   152    155       } else {
   153    156         # No error occurred. Check that any SELECT statements in the transaction
   154    157         # returned "1". Otherwise, the invariant was false, indicating that
   155    158         # some malfunction has occurred.
   156    159         foreach r $msg { if {$r != 1} { puts "Invariant check failed: $msg" } }
          160  +      incr nOp
   157    161       }
   158    162     }
   159    163   
   160    164     # Close the database connection and return 0.
   161    165     #
   162    166     sqlite3_close $::DB
   163         -  expr 0
          167  +  list $nOp $nAttempt
   164    168   }
   165    169   
   166    170   foreach {iTest xStep xPrepare} {
   167    171     1 sqlite3_blocking_step sqlite3_blocking_prepare_v2
   168    172     2 sqlite3_step          sqlite3_nonblocking_prepare_v2
   169    173   } {
   170    174     forcedelete test.db test2.db test3.db
................................................................................
   200    204     unset -nocomplain finished
   201    205     for {set ii 0} {$ii < $nThread} {incr ii} {
   202    206       thread_spawn finished($ii) $ThreadSetup $ThreadProgram
   203    207     }
   204    208     for {set ii 0} {$ii < $nThread} {incr ii} {
   205    209       do_test notify2-$iTest.2.$ii {
   206    210         if {![info exists finished($ii)]} { vwait finished($ii) }
   207         -      set finished($ii)
          211  +      incr anSuccess($xStep) [lindex $finished($ii) 0]
          212  +      incr anAttempt($xStep) [lindex $finished($ii) 1]
          213  +      expr 0
   208    214       } {0}
   209    215     }
   210    216   
   211    217     # Count the total number of succesful writes.
   212    218     do_test notify2-$iTest.3.1 {
   213    219       sqlite3 db test.db
   214    220       execsql {
................................................................................
   221    227              + (SELECT max(a) FROM t3)
   222    228       }]
   223    229       db close
   224    230     } {}
   225    231   }
   226    232   
   227    233   # The following tests checks to make sure sqlite3_blocking_step() is
   228         -# faster than sqlite3_step().  blocking_step() is always faster on
   229         -# multi-core and is usually faster on single-core.  But sometimes, by
   230         -# chance, step() will be faster on a single core, in which case the
          234  +# faster than sqlite3_step(). "Faster" in this case means uses fewer
          235  +# CPU cycles. This is not always the same as faster in wall-clock time 
          236  +# for this type of test. The number of CPU cycles per transaction is 
          237  +# roughly proportional to the number of attempts made (i.e. one plus the 
          238  +# number of SQLITE_BUSY or SQLITE_LOCKED errors that require the transaction 
          239  +# to be retried). So this test just measures that a greater percentage of
          240  +# transactions attempted using blocking_step() succeed.
          241  +#
          242  +# The blocking_step() function is almost always faster on multi-core and is
          243  +# usually faster on single-core.  But sometimes, by chance, step() will be
          244  +# faster on a single core, in which case the
   231    245   # following test will fail.
   232    246   #
   233    247   puts "The following test seeks to demonstrate that the sqlite3_unlock_notify()"
   234         -puts "interface helps multi-core systems to run faster.  This test sometimes"
   235         -puts "fails on single-core machines."
          248  +puts "interface helps multi-core systems to run more efficiently.  This test"
          249  +puts "sometimes fails on single-core machines."
   236    250   puts [array get anWrite]
   237    251   do_test notify2-3 {
   238         -  expr {$anWrite(sqlite3_blocking_step) > $anWrite(sqlite3_step)}
          252  +  set blocking [expr {
          253  +    double($anSuccess(sqlite3_blocking_step)) /
          254  +    double($anAttempt(sqlite3_blocking_step)) 
          255  +  }]
          256  +  set non [expr {
          257  +    double($anSuccess(sqlite3_step)) /
          258  +    double($anAttempt(sqlite3_step)) 
          259  +  }]
          260  +  puts -nonewline [format " blocking: %.1f%% non-blocking %.1f%% ..." \
          261  +    [expr $blocking*100.0] [expr $non*100.0]]
          262  +
          263  +  expr {$blocking > $non}
   239    264   } {1}
   240    265   
   241    266   sqlite3_enable_shared_cache $::enable_shared_cache
   242    267   finish_test

Changes to test/permutations.test.

   140    140     This test suite is the same as the "quick" tests, except that some files
   141    141     that test malloc and IO errors are omitted.
   142    142   } -files [
   143    143     test_set $allquicktests -exclude *malloc* *ioerr* *fault*
   144    144   ]
   145    145   
   146    146   test_suite "mmap" -prefix "mm-" -description {
   147         -  Similar to veryquick. Except with memory mapping disabled.
          147  +  Similar to veryquick. Except with memory mapping enabled.
   148    148   } -presql {
   149    149     pragma mmap_size = 268435456;
   150    150   } -files [
   151         -  test_set $allquicktests -exclude *malloc* *ioerr* *fault* -include malloc.test
          151  +  # Do not run pragma3.test, as it depends on the values returned by
          152  +  # "PRAGMA data_version". And if mmap is being used these are often,
          153  +  # but not always, one greater than if it were not.
          154  +  test_set $allquicktests -exclude *malloc* *ioerr* *fault* pragma3.test \
          155  +    -include malloc.test
   152    156   ]
   153    157   
   154    158   test_suite "valgrind" -prefix "" -description {
   155    159     Run the "veryquick" test suite with a couple of multi-process tests (that
   156    160     fail under valgrind) omitted.
   157    161   } -files [
   158    162     test_set $allquicktests -exclude *malloc* *ioerr* *fault* wal.test atof1.test
................................................................................
   689    693   
   690    694     # Exclude stmt.test, which expects sub-journals to use temporary files.
   691    695     stmt.test
   692    696   
   693    697     zerodamage.test
   694    698   
   695    699     # WAL mode is different.
   696         -  wal* tkt-2d1a5c67d.test backcompat.test
          700  +  wal* tkt-2d1a5c67d.test backcompat.test e_wal*
   697    701   }]
   698    702   
   699    703   ifcapable mem3 {
   700    704     test_suite "memsys3" -description {
   701    705       Run tests using the allocator in mem3.c.
   702    706     } -files [test_set $::allquicktests -exclude {
   703    707       autovacuum.test           delete3.test              manydb.test

Changes to test/pragma3.test.

    28     28     PRAGMA main.data_version=1234;
    29     29     PRAGMA main.data_version;
    30     30   } {1 1}
    31     31   
    32     32   # EVIDENCE-OF: R-27726-60934 The "PRAGMA data_version" command provides
    33     33   # an indication that the database file has been modified.
    34     34   #
    35         -# EVIDENCE-OF: R-25838-33704 The "PRAGMA data_version" value is
    36         -# unchanced for commits made on the same database connection.
           35  +# EVIDENCE-OF: R-47505-58569 The "PRAGMA data_version" value is
           36  +# unchanged for commits made on the same database connection.
    37     37   #
    38     38   do_execsql_test pragma3-110 {
    39     39     PRAGMA data_version;
    40     40     BEGIN IMMEDIATE;
    41     41     PRAGMA data_version;
    42     42     CREATE TABLE t1(a);
    43     43     INSERT INTO t1 VALUES(100),(200),(300);
................................................................................
    60     60     BEGIN IMMEDIATE;
    61     61     PRAGMA data_version;
    62     62     INSERT INTO t1 VALUES(400),(500);
    63     63     PRAGMA data_version;
    64     64     COMMIT;
    65     65     SELECT * FROM t1;
    66     66     PRAGMA data_version;
           67  +  PRAGMA shrink_memory;
    67     68   } {1 1 1 100 200 300 400 500 1}
    68     69   
    69     70   # EVIDENCE-OF: R-63005-41812 The integer values returned by two
    70     71   # invocations of "PRAGMA data_version" from the same connection will be
    71     72   # different if changes were committed to the database by any other
    72     73   # connection in the interim.
    73     74   #
................................................................................
   212    213     db2 close
   213    214     db close
   214    215     sqlite3_enable_shared_cache $::enable_shared_cache
   215    216   }
   216    217   
   217    218   # Make sure this also works in WAL mode
   218    219   #
          220  +# This will not work with the in-memory journal permutation, as opening
          221  +# [db2] switches the journal mode back to "memory"
          222  +#
   219    223   ifcapable wal {
          224  +if {[permutation]!="inmemory_journal"} {
          225  +
   220    226     sqlite3 db test.db
   221    227     db eval {PRAGMA journal_mode=WAL}
   222    228     sqlite3 db2 test.db
   223    229     do_test pragma3-400 {
   224    230       db eval {
   225    231         PRAGMA data_version;
   226    232         PRAGMA journal_mode;
................................................................................
   237    243     do_test pragma3-420 {
   238    244       db eval {UPDATE t1 SET a=111*(a/100); PRAGMA data_version; SELECT * FROM t1}
   239    245     } {2 111 222}
   240    246     do_test pragma3-430 {
   241    247       db2 eval {PRAGMA data_version; SELECT * FROM t1;}
   242    248     } {3 111 222}
   243    249     db2 close
          250  +}
   244    251   }
   245    252   
   246    253   finish_test

Deleted test/releasetest.mk.

     1         -########################################################
     2         -TOP=/home/drh/sqlite/sqlite
     3         -
     4         -TCL_FLAGS=-I/home/drh/tcltk/86linux
     5         -LIBTCL=/home/drh/tcltk/86linux/libtcl8.6.a -lm -ldl -lpthread
     6         -
     7         -BCC = gcc
     8         -TCC = gcc -ansi -g $(CFLAGS)
     9         -NAWK   = awk
    10         -AR     = ar cr
    11         -RANLIB = ranlib
    12         -THREADLIB = -lpthread -ldl -lz
    13         -include $(TOP)/main.mk
    14         -########################################################

Changes to test/releasetest.tcl.

     1         -
     2         -set rcsid {$Id: $}
     3         -
            1  +#!/usr/bin/tclsh
            2  +#
     4      3   # Documentation for this script. This may be output to stderr
     5      4   # if the script is invoked incorrectly. See the [process_options]
     6      5   # proc below.
     7      6   #
     8      7   set ::USAGE_MESSAGE {
     9      8   This Tcl script is used to test the various configurations required
    10         -before releasing a new version. Supported command line options (all 
            9  +before releasing a new version. Supported command line options (all
    11     10   optional) are:
    12     11   
    13         -    -makefile PATH-TO-MAKEFILE           (default "releasetest.mk")
    14         -    -platform PLATFORM                   (see below)
    15         -    -quick    BOOLEAN                    (default "0")
    16         -    -config   CONFIGNAME                 (Run only CONFIGNAME)
           12  +    --srcdir   TOP-OF-SQLITE-TREE      (see below)
           13  +    --platform PLATFORM                (see below)
           14  +    --config   CONFIGNAME              (Run only CONFIGNAME)
           15  +    --quick                            (Run "veryquick.test" only)
           16  +    --buildonly                        (Just build testfixture - do not run)
           17  +    --dryrun                           (Print what would have happened)
           18  +    --info                             (Show diagnostic info)
    17     19   
    18         -The default value for -makefile is "./releasetest.mk".
           20  +The default value for --srcdir is the parent of the directory holding
           21  +this script.
    19     22   
    20         -The script determines the default value for -platform using the
    21         -$tcl_platform(os) and $tcl_platform(machine) variables. Supported 
           23  +The script determines the default value for --platform using the
           24  +$tcl_platform(os) and $tcl_platform(machine) variables. Supported
    22     25   platforms are "Linux-x86", "Linux-x86_64" and "Darwin-i386".
    23     26   
    24         -If the -quick option is set to true, then the "veryquick.test" script
    25         -is run for all compilation configurations. Otherwise, sometimes "all.test"
    26         -is run, sometimes "veryquick.test".
    27         -
    28         -Almost any SQLite makefile (except those generated by configure - see below)
    29         -should work. The following properties are required:
    30         -
    31         -  * The makefile should support the "fulltest" target.
    32         -  * The makefile should support the variable "OPTS" as a way to pass
    33         -    options from the make command line to lemon and the C compiler.
    34         -
    35         -More precisely, the following invocation must be supported:
    36         -
    37         -  make -f $::MAKEFILE fulltest OPTS="-DSQLITE_SECURE_DELETE=1 -DSQLITE_DEBUG=1"
    38         -
    39         -Makefiles generated by the sqlite configure program cannot be used as
    40         -they do not respect the OPTS variable.
    41         -
    42         -Example Makefile contents:
    43         -
    44         -  ########################################################
    45         -  TOP=/home/dan/work/sqlite/sqlite
    46         -
    47         -  TCL_FLAGS=-I/home/dan/tcl/include
    48         -  LIBTCL=-L/home/dan/tcl/lib -ltcl
    49         -
    50         -  BCC = gcc
    51         -  TCC = gcc -ansi -g $(CFLAGS)
    52         -  NAWK   = awk
    53         -  AR     = ar cr
    54         -  RANLIB = ranlib
    55         -  THREADLIB = -lpthread -ldl
    56         -  include $(TOP)/main.mk
    57         -  ########################################################
           27  +Every test begins with a fresh run of the configure script at the top
           28  +of the SQLite source tree.
    58     29   }
    59     30   
    60     31   array set ::Configs {
    61     32     "Default" {
    62     33       -O2
    63     34     }
    64     35     "Ftrapv" {
................................................................................
    90     61       -DSQLITE_ENABLE_MEMSYS5=1
    91     62       -DSQLITE_ENABLE_MEMSYS3=1
    92     63       -DSQLITE_ENABLE_COLUMN_METADATA=1
    93     64       -DSQLITE_ENABLE_UPDATE_DELETE_LIMIT=1
    94     65       -DSQLITE_SECURE_DELETE=1
    95     66       -DSQLITE_SOUNDEX=1
    96     67       -DSQLITE_ENABLE_ATOMIC_WRITE=1
    97         -    -DSQLITE_ENABLE_IOTRACE=1
    98     68       -DSQLITE_ENABLE_MEMORY_MANAGEMENT=1
    99     69       -DSQLITE_ENABLE_OVERSIZE_CELL_CHECK=1
   100     70     }
   101     71     "Debug-One" {
   102     72       -O2
   103     73       -DSQLITE_DEBUG=1
   104     74       -DSQLITE_MEMDEBUG=1
................................................................................
   157    127       -DUSE_PREAD=1
   158    128       -DSQLITE_ENABLE_RTREE=1
   159    129       -DSQLITE_ENABLE_FTS3=1
   160    130       -DSQLITE_ENABLE_FTS3_PARENTHESIS=1
   161    131       -DSQLITE_DEFAULT_CACHE_SIZE=1000
   162    132       -DSQLITE_MAX_LENGTH=2147483645
   163    133       -DSQLITE_MAX_VARIABLE_NUMBER=500000
   164         -    -DSQLITE_DEBUG=1 
          134  +    -DSQLITE_DEBUG=1
   165    135       -DSQLITE_PREFER_PROXY_LOCKING=1
   166    136     }
   167    137     "Extra-Robustness" {
   168    138       -DSQLITE_ENABLE_OVERSIZE_CELL_CHECK=1
   169    139       -DSQLITE_MAX_ATTACHED=62
   170    140     }
   171    141     "Devkit" {
................................................................................
   184    154       -DHAVE_USLEEP=1
   185    155     }
   186    156   }
   187    157   
   188    158   array set ::Platforms {
   189    159     Linux-x86_64 {
   190    160       "Check-Symbols"           checksymbols
   191         -    "Debug-One"               test
          161  +    "Debug-One"               "mptest test"
   192    162       "Secure-Delete"           test
   193    163       "Unlock-Notify"           "QUICKTEST_INCLUDE=notify2.test test"
   194    164       "Update-Delete-Limit"     test
   195    165       "Extra-Robustness"        test
   196    166       "Device-Two"              test
   197    167       "Ftrapv"                  test
   198    168       "No-lookaside"            test
................................................................................
   204    174       "Devkit"                  test
   205    175       "Unlock-Notify"           "QUICKTEST_INCLUDE=notify2.test test"
   206    176       "Device-One"              test
   207    177       "Device-Two"              test
   208    178       "Default"                 "threadtest fulltest"
   209    179     }
   210    180     Darwin-i386 {
   211         -    "Locking-Style"           test
          181  +    "Locking-Style"           "mptest test"
   212    182       "OS-X"                    "threadtest fulltest"
   213    183     }
          184  +  "Windows NT-intel" {
          185  +    "Default"                 "mptest fulltestonly"
          186  +  }
   214    187   }
   215    188   
   216    189   
   217    190   # End of configuration section.
   218    191   #########################################################################
   219    192   #########################################################################
   220    193   
................................................................................
   222    195     foreach {v t} $value {
   223    196       if {0==[info exists ::Configs($v)]} {
   224    197         puts stderr "No such configuration: \"$v\""
   225    198         exit -1
   226    199       }
   227    200     }
   228    201   }
          202  +
          203  +# Open the file $logfile and look for a report on the number of errors
          204  +# and the number of test cases run.  Add these values to the global
          205  +# $::NERRCASE and $::NTESTCASE variables.
          206  +#
          207  +# If any errors occur, then write into $errmsgVar the text of an appropriate
          208  +# one-line error message to show on the output.
          209  +#
          210  +proc count_tests_and_errors {logfile rcVar errmsgVar} {
          211  +  if {$::DRYRUN} return
          212  +  upvar 1 $rcVar rc $errmsgVar errmsg
          213  +  set fd [open $logfile rb]
          214  +  set seen 0
          215  +  while {![eof $fd]} {
          216  +    set line [gets $fd]
          217  +    if {[regexp {(\d+) errors out of (\d+) tests} $line all nerr ntest]} {
          218  +      incr ::NERRCASE $nerr
          219  +      incr ::NTESTCASE $ntest
          220  +      set seen 1
          221  +      if {$nerr>0} {
          222  +        set rc 1
          223  +        set errmsg $line
          224  +      }
          225  +    }
          226  +  }
          227  +  close $fd
          228  +  if {!$seen} {
          229  +    set rc 1
          230  +    set errmsg "Test did not complete"
          231  +  }
          232  +}
   229    233   
   230    234   proc run_test_suite {name testtarget config} {
   231         -  
   232         -  # Tcl variable $opts is used to build up the value used to set the 
          235  +  # Tcl variable $opts is used to build up the value used to set the
   233    236     # OPTS Makefile variable. Variable $cflags holds the value for
   234    237     # CFLAGS. The makefile will pass OPTS to both gcc and lemon, but
   235    238     # CFLAGS is only passed to gcc.
   236    239     #
   237         -  set cflags ""
          240  +  set cflags "-g"
   238    241     set opts ""
   239    242     foreach arg $config {
   240    243       if {[string match -D* $arg]} {
   241    244         lappend opts $arg
   242    245       } else {
   243    246         lappend cflags $arg
   244    247       }
................................................................................
   254    257   
   255    258     if {$::tcl_platform(platform)=="windows"} {
   256    259       append opts " -DSQLITE_OS_WIN=1"
   257    260     } else {
   258    261       append opts " -DSQLITE_OS_UNIX=1"
   259    262     }
   260    263   
   261         -  # Run the test.
   262         -  #
   263         -  set makefile [file normalize $::MAKEFILE]
   264         -  file mkdir $dir
   265         -  puts -nonewline "Testing configuration \"$name\" (logfile=$dir/test.log)..."
   266         -  flush stdout
          264  +  dryrun file mkdir $dir
          265  +  if {!$::DRYRUN} {
          266  +    set title ${name}($testtarget)
          267  +    set n [string length $title]
          268  +    puts -nonewline "${title}[string repeat . [expr {54-$n}]]"
          269  +    flush stdout
          270  +  }
   267    271   
   268         -  set makecmd [concat                                  \
   269         -    [list exec make -C $dir -f $makefile clean]        \
   270         -    $testtarget                                        \
   271         -    [list CFLAGS=$cflags OPTS=$opts >& $dir/test.log]  \
   272         -  ]
   273         -
   274         -  set tm1 [clock seconds] 
   275         -  set rc [catch $makecmd]
          272  +  set tm1 [clock seconds]
          273  +  set origdir [pwd]
          274  +  dryrun cd $dir
          275  +  set errmsg {}
          276  +  set rc [catch [configureCommand]]
          277  +  if {!$rc} {
          278  +    set rc [catch [makeCommand $testtarget $cflags $opts]]
          279  +    count_tests_and_errors test.log rc errmsg
          280  +  }
   276    281     set tm2 [clock seconds]
          282  +  dryrun cd $origdir
   277    283   
   278         -  set minutes [expr {($tm2-$tm1)/60}]
   279         -  set seconds [expr {($tm2-$tm1)%60}]
   280         -  puts -nonewline [format " (%d:%.2d) " $minutes $seconds]
   281         -  if {$rc} {
   282         -    puts "FAILED."
          284  +  if {!$::DRYRUN} {
          285  +    set hours [expr {($tm2-$tm2)/3600}]
          286  +    set minutes [expr {(($tm2-$tm1)/60)%60}]
          287  +    set seconds [expr {($tm2-$tm1)%60}]
          288  +    set tm [format (%02d:%02d:%02d) $hours $minutes $seconds]
          289  +    if {$rc} {
          290  +      puts " FAIL $tm"
          291  +      incr ::NERR
          292  +      if {$errmsg!=""} {puts "     $errmsg"}
          293  +    } else {
          294  +      puts " Ok   $tm"
          295  +    }
          296  +  }
          297  +}
          298  +
          299  +# The following procedure returns the "configure" command to be exectued for
          300  +# the current platform, which may be Windows (via MinGW, etc).
          301  +#
          302  +proc configureCommand {} {
          303  +  set result [list dryrun exec]
          304  +  if {$::tcl_platform(platform)=="windows"} {
          305  +    lappend result sh
          306  +  }
          307  +  lappend result $::SRCDIR/configure -enable-load-extension >& test.log
          308  +}
          309  +
          310  +# The following procedure returns the "make" command to be executed for the
          311  +# specified targets, compiler flags, and options.
          312  +#
          313  +proc makeCommand { targets cflags opts } {
          314  +  set result [list dryrun exec make clean]
          315  +  foreach target $targets {
          316  +    lappend result $target
          317  +  }
          318  +  lappend result CFLAGS=$cflags OPTS=$opts >>& test.log
          319  +}
          320  +
          321  +# The following procedure either prints its arguments (if ::DRYRUN is true)
          322  +# or executes the command of its arguments in the calling context
          323  +# (if ::DRYRUN is false).
          324  +#
          325  +proc dryrun {args} {
          326  +  if {$::DRYRUN} {
          327  +    puts $args
   283    328     } else {
   284         -    puts "Ok."
          329  +    uplevel 1 $args
   285    330     }
   286    331   }
   287    332   
   288    333   
   289    334   # This proc processes the command line options passed to this script.
   290    335   # Currently the only option supported is "-makefile", default
   291    336   # "releasetest.mk". Set the ::MAKEFILE variable to the value of this
   292    337   # option.
   293    338   #
   294    339   proc process_options {argv} {
   295         -  set ::MAKEFILE releasetest.mk                       ;# Default value
   296         -  set ::QUICK    0                                    ;# Default value
          340  +  set ::SRCDIR    [file normalize [file dirname [file dirname $::argv0]]]
          341  +  set ::QUICK     0
          342  +  set ::BUILDONLY 0
          343  +  set ::DRYRUN    0
          344  +  set ::EXEC      exec
   297    345     set config {}
   298    346     set platform $::tcl_platform(os)-$::tcl_platform(machine)
   299    347   
   300    348     for {set i 0} {$i < [llength $argv]} {incr i} {
   301         -    switch -- [lindex $argv $i] {
   302         -      -makefile {
          349  +    set x [lindex $argv $i]
          350  +    if {[regexp {^--[a-z]} $x]} {set x [string range $x 1 end]}
          351  +    switch -- $x {
          352  +      -srcdir {
   303    353           incr i
   304         -        set ::MAKEFILE [lindex $argv $i]
          354  +        set ::SRCDIR [file normalize [lindex $argv $i]]
   305    355         }
   306    356   
   307    357         -platform {
   308    358           incr i
   309    359           set platform [lindex $argv $i]
   310    360         }
   311    361   
   312    362         -quick {
   313         -        incr i
   314         -        set ::QUICK [lindex $argv $i]
          363  +        set ::QUICK 1
   315    364         }
   316    365   
   317    366         -config {
   318    367           incr i
   319    368           set config [lindex $argv $i]
   320    369         }
   321         -  
          370  +
          371  +      -buildonly {
          372  +        set ::BUILDONLY 1
          373  +      }
          374  +
          375  +      -dryrun {
          376  +        set ::DRYRUN 1
          377  +      }
          378  +
          379  +      -info {
          380  +        puts "Command-line Options:"
          381  +        puts "   --srcdir $::SRCDIR"
          382  +        puts "   --platform [list $platform]"
          383  +        puts "   --config [list $config]"
          384  +        if {$::QUICK}     {puts "   --quick"}
          385  +        if {$::BUILDONLY} {puts "   --buildonly"}
          386  +        if {$::DRYRUN}    {puts "   --dryrun"}
          387  +        puts "\nAvailable --platform options:"
          388  +        foreach y [lsort [array names ::Platforms]] {
          389  +          puts "   [list $y]"
          390  +        }
          391  +        puts "\nAvailable --config options:"
          392  +        foreach y [lsort [array names ::Configs]] {
          393  +          puts "   [list $y]"
          394  +        }
          395  +        exit
          396  +      }
          397  +
   322    398         default {
   323    399           puts stderr ""
   324    400           puts stderr [string trim $::USAGE_MESSAGE]
   325    401           exit -1
   326    402         }
   327    403       }
   328    404     }
   329    405   
   330         -  set ::MAKEFILE [file normalize $::MAKEFILE]
   331         -
   332    406     if {0==[info exists ::Platforms($platform)]} {
   333    407       puts "Unknown platform: $platform"
   334    408       puts -nonewline "Set the -platform option to "
   335    409       set print [list]
   336    410       foreach p [array names ::Platforms] {
   337    411         lappend print "\"$p\""
   338    412       }
................................................................................
   343    417   
   344    418     if {$config!=""} {
   345    419       if {[llength $config]==1} {lappend config fulltest}
   346    420       set ::CONFIGLIST $config
   347    421     } else {
   348    422       set ::CONFIGLIST $::Platforms($platform)
   349    423     }
   350         -  puts "Running the following configurations for $platform:"
          424  +  puts "Running the following test configurations for $platform:"
   351    425     puts "    [string trim $::CONFIGLIST]"
          426  +  puts -nonewline "Flags:"
          427  +  if {$::DRYRUN} {puts -nonewline " --dryrun"}
          428  +  if {$::BUILDONLY} {puts -nonewline " --buildonly"}
          429  +  if {$::QUICK} {puts -nonewline " --quick"}
          430  +  puts ""
   352    431   }
   353    432   
   354    433   # Main routine.
   355    434   #
   356    435   proc main {argv} {
   357    436   
   358    437     # Process any command line options.
   359    438     process_options $argv
          439  +  puts [string repeat * 70]
   360    440   
          441  +  set ::NERR 0
          442  +  set ::NTEST 0
          443  +  set ::NTESTCASE 0
          444  +  set ::NERRCASE 0
          445  +  set STARTTIME [clock seconds]
   361    446     foreach {zConfig target} $::CONFIGLIST {
   362    447       if {$::QUICK} {set target test}
          448  +    if {$::BUILDONLY} {set target testfixture}
   363    449       set config_options $::Configs($zConfig)
   364    450   
          451  +    incr NTEST
   365    452       run_test_suite $zConfig $target $config_options
   366    453   
   367    454       # If the configuration included the SQLITE_DEBUG option, then remove
   368    455       # it and run veryquick.test. If it did not include the SQLITE_DEBUG option
   369    456       # add it and run veryquick.test.
   370         -    if {$target!="checksymbols"} {
          457  +    if {$target!="checksymbols" && !$::BUILDONLY} {
   371    458         set debug_idx [lsearch -glob $config_options -DSQLITE_DEBUG*]
          459  +      set xtarget $target
          460  +      regsub -all {fulltest[a-z]+} $xtarget test xtarget
   372    461         if {$debug_idx < 0} {
   373         -        run_test_suite "${zConfig}_debug" test [
   374         -          concat $config_options -DSQLITE_DEBUG=1
   375         -        ]
          462  +        incr NTEST
          463  +        append config_options " -DSQLITE_DEBUG=1"
          464  +        run_test_suite "${zConfig}_debug" $xtarget $config_options
   376    465         } else {
   377         -        run_test_suite "${zConfig}_ndebug" test [
   378         -          lreplace $config_options $debug_idx $debug_idx
   379         -        ]
          466  +        incr NTEST
          467  +        regsub { *-DSQLITE_MEMDEBUG[^ ]* *} $config_options { } config_options
          468  +        regsub { *-DSQLITE_DEBUG[^ ]* *} $config_options { } config_options
          469  +        run_test_suite "${zConfig}_ndebug" $xtarget $config_options
   380    470         }
   381    471       }
   382         -
   383    472     }
          473  +
          474  +  set elapsetime [expr {[clock seconds]-$STARTTIME}]
          475  +  set hr [expr {$elapsetime/3600}]
          476  +  set min [expr {($elapsetime/60)%60}]
          477  +  set sec [expr {$elapsetime%60}]
          478  +  set etime [format (%02d:%02d:%02d) $hr $min $sec]
          479  +  puts [string repeat * 70]
          480  +  puts "$::NERRCASE failures of $::NTESTCASE tests run in $etime"
   384    481   }
   385    482   
   386    483   main $argv

Changes to test/threadtest3.c.

     1         -
     2      1   /*
            2  +** 2010-07-22
            3  +**
            4  +** The author disclaims copyright to this source code.  In place of
            5  +** a legal notice, here is a blessing:
            6  +**
            7  +**    May you do good and not evil.
            8  +**    May you find forgiveness for yourself and forgive others.
            9  +**    May you share freely, never taking more than you give.
           10  +**
           11  +*************************************************************************
           12  +**
     3     13   ** The code in this file runs a few multi-threaded test cases using the
     4     14   ** SQLite library. It can be compiled to an executable on unix using the
     5     15   ** following command:
     6     16   **
     7     17   **   gcc -O2 threadtest3.c sqlite3.c -ldl -lpthread -lm
     8     18   **
     9         -** Then run the compiled program. The exit status is non-zero if any tests
    10         -** failed (hopefully there is also some output to stdout to clarify what went
    11         -** wrong).
           19  +** Even though threadtest3.c is the only C source code file mentioned on
           20  +** the compiler command-line, #include macros are used to pull in additional
           21  +** C code files named "tt3_*.c".
    12     22   **
    13         -** There are three parts to the code in this file, in the following order:
           23  +** After compiling, run this program with an optional argument telling
           24  +** which test to run.  All tests are run if no argument is given.  The
           25  +** argument can be a glob pattern to match multiple tests.  Examples:
    14     26   **
    15         -**   1. Code for the SQL aggregate function md5sum() copied from 
    16         -**      tclsqlite.c in the SQLite distribution. The names of all the 
    17         -**      types and functions in this section begin with "MD5" or "md5".
    18         -**
    19         -**   2. A set of utility functions that may be used to implement
    20         -**      multi-threaded test cases. These are all called by test code
    21         -**      via macros that help with error reporting. The macros are defined
    22         -**      immediately below this comment.
           27  +**        ./a.out                 -- Run all tests
           28  +**        ./a.out walthread3      -- Run the "walthread3" test
           29  +**        ./a.out 'wal*'          -- Run all of the wal* tests
           30  +**        ./a.out --help          -- List all available tests
    23     31   **
    24         -**   3. The test code itself. And a main() routine to drive the test 
    25         -**      code.
           32  +** The exit status is non-zero if any test fails.
           33  +*/
           34  +
           35  +/* 
           36  +** The "Set Error Line" macro.
    26     37   */
    27         -
    28         -/*************************************************************************
    29         -** Start of test code/infrastructure interface macros.
    30         -**
    31         -** The following macros constitute the interface between the test
    32         -** programs and the test infrastructure. Test infrastructure code 
    33         -** does not itself use any of these macros. Test code should not
    34         -** call any of the macroname_x() functions directly.
    35         -**
    36         -** See the header comments above the corresponding macroname_x()
    37         -** function for a description of each interface.
    38         -*/
           38  +#define SEL(e) ((e)->iLine = ((e)->rc ? (e)->iLine : __LINE__))
    39     39   
    40     40   /* Database functions */
    41     41   #define opendb(w,x,y,z)         (SEL(w), opendb_x(w,x,y,z))
    42     42   #define closedb(y,z)            (SEL(y), closedb_x(y,z))
    43     43   
    44     44   /* Functions to execute SQL */
    45     45   #define sql_script(x,y,z)       (SEL(x), sql_script_x(x,y,z))
................................................................................
   387    387     char zBuf[33];
   388    388     p = sqlite3_aggregate_context(context, sizeof(*p));
   389    389     MD5Final(digest,p);
   390    390     MD5DigestToBase16(digest, zBuf);
   391    391     sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT);
   392    392   }
   393    393   
   394         -/*************************************************************************
          394  +/*
   395    395   ** End of copied md5sum() code.
   396         -*/
          396  +**************************************************************************/
   397    397   
   398    398   typedef sqlite3_int64 i64;
   399    399   
   400    400   typedef struct Error Error;
   401    401   typedef struct Sqlite Sqlite;
   402    402   typedef struct Statement Statement;
   403    403   
................................................................................
   444    444     p->zErr = 0;
   445    445     p->rc = 0;
   446    446   }
   447    447   
   448    448   static void print_err(Error *p){
   449    449     if( p->rc!=SQLITE_OK ){
   450    450       printf("Error: (%d) \"%s\" at line %d\n", p->rc, p->zErr, p->iLine);
   451         -    nGlobalErr++;
          451  +    if( sqlite3_strglob("* - no such table: *",p->zErr)!=0 ) nGlobalErr++;
          452  +    fflush(stdout);
   452    453     }
   453    454   }
   454    455   
   455    456   static void print_and_free_err(Error *p){
   456    457     print_err(p);
   457    458     free_err(p);
   458    459   }
................................................................................
   781    782       pNext = p->pNext;
   782    783       int rc;
   783    784       rc = pthread_join(p->tid, &ret);
   784    785       if( rc!=0 ){
   785    786         if( pErr->rc==SQLITE_OK ) system_error(pErr, rc);
   786    787       }else{
   787    788         printf("Thread %d says: %s\n", p->iTid, (ret==0 ? "..." : (char *)ret));
          789  +      fflush(stdout);
   788    790       }
   789    791       sqlite3_free(p);
   790    792     }
   791    793     pThreads->pThread = 0;
   792    794   }
   793    795   
   794    796   static i64 filesize_x(
................................................................................
   894    896       }else{
   895    897         ret = (t >= timelimit);
   896    898       }
   897    899     }
   898    900     return ret;
   899    901   }
   900    902   
   901         -/* 
   902         -** The "Set Error Line" macro.
   903         -*/
   904         -#define SEL(e) ((e)->iLine = ((e)->rc ? (e)->iLine : __LINE__))
   905         -
   906    903   
   907    904   /*************************************************************************
   908    905   **************************************************************************
   909    906   **************************************************************************
   910    907   ** End infrastructure. Begin tests.
   911    908   */
   912    909   
................................................................................
  1423   1420   #include "tt3_index.c"
  1424   1421   #include "tt3_lookaside1.c"
  1425   1422   #include "tt3_vacuum.c"
  1426   1423   #include "tt3_stress.c"
  1427   1424   
  1428   1425   int main(int argc, char **argv){
  1429   1426     struct ThreadTest {
  1430         -    void (*xTest)(int);
  1431         -    const char *zTest;
  1432         -    int nMs;
         1427  +    void (*xTest)(int);   /* Routine for running this test */
         1428  +    const char *zTest;    /* Name of this test */
         1429  +    int nMs;              /* How long to run this test, in milliseconds */
  1433   1430     } aTest[] = {
  1434   1431       { walthread1, "walthread1", 20000 },
  1435   1432       { walthread2, "walthread2", 20000 },
  1436   1433       { walthread3, "walthread3", 20000 },
  1437   1434       { walthread4, "walthread4", 20000 },
  1438   1435       { walthread5, "walthread5",  1000 },
  1439   1436       { walthread5, "walthread5",  1000 },
................................................................................
  1448   1445       { lookaside1,          "lookaside1", 10000 },
  1449   1446       { vacuum1,             "vacuum1", 10000 },
  1450   1447       { stress1,             "stress1", 10000 },
  1451   1448       { stress2,             "stress2", 60000 },
  1452   1449     };
  1453   1450   
  1454   1451     int i;
  1455         -  int bTestfound = 0;
         1452  +  int nTestfound = 0;
  1456   1453   
  1457   1454     sqlite3_config(SQLITE_CONFIG_MULTITHREAD);
  1458   1455     sqlite3_config(SQLITE_CONFIG_MULTITHREAD);
  1459   1456   
  1460   1457     for(i=0; i<sizeof(aTest)/sizeof(aTest[0]); i++){
  1461   1458       char const *z = aTest[i].zTest;
  1462   1459       if( argc>1 ){
................................................................................
  1464   1461         for(iArg=1; iArg<argc; iArg++){
  1465   1462           if( 0==sqlite3_strglob(argv[iArg], z) ) break;
  1466   1463         }
  1467   1464         if( iArg==argc ) continue;
  1468   1465       }
  1469   1466   
  1470   1467       printf("Running %s for %d seconds...\n", z, aTest[i].nMs/1000);
         1468  +    fflush(stdout);
  1471   1469       aTest[i].xTest(aTest[i].nMs);
  1472         -    bTestfound++;
         1470  +    nTestfound++;
  1473   1471     }
  1474         -  if( bTestfound==0 ) goto usage;
         1472  +  if( nTestfound==0 ) goto usage;
  1475   1473   
  1476         -  printf("Total of %d errors across all tests\n", nGlobalErr);
         1474  +  printf("%d errors out of %d tests\n", nGlobalErr, nTestfound);
  1477   1475     return (nGlobalErr>0 ? 255 : 0);
  1478   1476   
  1479   1477    usage:
  1480   1478     printf("Usage: %s [testname|testprefix*]...\n", argv[0]);
  1481   1479     printf("Available tests are:\n");
  1482   1480     for(i=0; i<sizeof(aTest)/sizeof(aTest[0]); i++){
  1483   1481       printf("   %s\n", aTest[i].zTest);
  1484   1482     }
  1485   1483   
  1486   1484     return 254;
  1487   1485   }
  1488         -
  1489         -

Changes to test/tt3_checkpoint.c.

     1      1   /*
     2         -** 2001 September 15
            2  +** 2011-02-02
     3      3   **
     4      4   ** The author disclaims copyright to this source code.  In place of
     5      5   ** a legal notice, here is a blessing:
     6      6   **
     7      7   **    May you do good and not evil.
     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
................................................................................
   142    142     CheckpointStarvationCtx ctx = { SQLITE_CHECKPOINT_RESTART, 0 };
   143    143     checkpoint_starvation_main(nMs, &ctx);
   144    144     if( ctx.nMaxFrame>CHECKPOINT_STARVATION_FRAMELIMIT+10 ){
   145    145       test_error(&err, "WAL grew too large - %d frames", ctx.nMaxFrame);
   146    146     }
   147    147     print_and_free_err(&err);
   148    148   }
   149         -
   150         -

Changes to test/wal5.test.

   359    359     #
   360    360     do_multiclient_test tn {
   361    361   
   362    362       code1 $do_wal_checkpoint
   363    363       code2 $do_wal_checkpoint
   364    364       code3 $do_wal_checkpoint
   365    365   
   366         -    do_test 3.$tn.1 {
          366  +    do_test 4.$tn.1 {
   367    367         sql1 {
   368    368           PRAGMA page_size = 1024;
          369  +        PRAGMA auto_vacuum = 0;
   369    370           PRAGMA journal_mode = WAL;
   370    371           PRAGMA synchronous = normal;
   371    372           CREATE TABLE t1(x, y);
   372    373           CREATE INDEX i1 ON t1(x, y);
   373    374           INSERT INTO t1 VALUES(1, 2);
   374    375           INSERT INTO t1 VALUES(3, 4);
   375    376         }
   376    377         file size test.db-wal
   377    378       } [wal_file_size 8 1024]
   378    379   
   379         -    do_test 3.$tn.2 { do_wal_checkpoint db -mode truncate } {0 0 0}
   380         -    do_test 3.$tn.3 { file size test.db-wal } 0
          380  +    do_test 4.$tn.2 { do_wal_checkpoint db -mode truncate } {0 0 0}
          381  +    do_test 4.$tn.3 { file size test.db-wal } 0
   381    382   
   382         -    do_test 3.$tn.4 {
          383  +    do_test 4.$tn.4 {
   383    384         sql2 { SELECT * FROM t1 }
   384    385       } {1 2 3 4}
   385    386   
   386         -    do_test 3.$tn.5 {
          387  +    do_test 4.$tn.5 {
   387    388         sql2 { INSERT INTO t1 VALUES('a', 'b') }
   388    389         file size test.db-wal
   389    390       } [wal_file_size 2 1024]
   390    391   
   391    392     }
   392    393   }
   393    394   
   394    395   
   395    396   finish_test

Added test/without_rowid6.test.

            1  +# 2014-12-28
            2  +#
            3  +# The author disclaims copyright to this source code.  In place of
            4  +# a legal notice, here is a blessing:
            5  +#
            6  +#    May you do good and not evil.
            7  +#    May you find forgiveness for yourself and forgive others.
            8  +#    May you share freely, never taking more than you give.
            9  +#
           10  +#***********************************************************************
           11  +#
           12  +# Verify that WITHOUT ROWID tables work correctly when the PRIMARY KEY
           13  +# has redundant columns.
           14  +#
           15  +
           16  +set testdir [file dirname $argv0]
           17  +source $testdir/tester.tcl
           18  +
           19  +do_execsql_test without_rowid6-100 {
           20  +  CREATE TABLE t1(a,b,c,d,e, PRIMARY KEY(a,b,c,a,b,c,d,a,b,c)) WITHOUT ROWID;
           21  +  CREATE INDEX t1a ON t1(b, b);
           22  +  WITH RECURSIVE
           23  +    c(i) AS (VALUES(1) UNION ALL SELECT i+1 FROM c WHERE i<1000)
           24  +  INSERT INTO t1(a,b,c,d,e) SELECT i, i+1000, printf('x%dy',i), 0, 0 FROM c;
           25  +  ANALYZE;
           26  +} {}
           27  +do_execsql_test without_rowid6-110 {
           28  +  SELECT c FROM t1 WHERE a=123;
           29  +} {x123y}
           30  +do_execsql_test without_rowid6-120 {
           31  +  SELECT c FROM t1 WHERE b=1123;
           32  +} {x123y}
           33  +do_execsql_test without_rowid6-130 {
           34  +  SELECT c FROM t1 ORDER BY a DESC LIMIT 5;
           35  +} {x1000y x999y x998y x997y x996y}
           36  +do_execsql_test without_rowid6-140 {
           37  +  SELECT c FROM t1 ORDER BY b LIMIT 5;
           38  +} {x1y x2y x3y x4y x5y}
           39  +
           40  +
           41  +finish_test

Changes to tool/mksqlite3c.tcl.

   210    210               set line {const char sqlite3_version[] = SQLITE_VERSION;}
   211    211             }
   212    212             regsub {^SQLITE_EXTERN } $line {} line
   213    213             puts $out "SQLITE_API $line"
   214    214           }
   215    215         } elseif {[regexp {^(SQLITE_EXTERN )?void \(\*sqlite3IoTrace\)} $line]} {
   216    216           regsub {^SQLITE_EXTERN } $line {} line
   217         -        puts $out "SQLITE_PRIVATE $line"
          217  +        puts $out $line
   218    218         } elseif {[regexp {^void \(\*sqlite3Os} $line]} {
   219    219           puts $out "SQLITE_PRIVATE $line"
   220    220         } else {
   221    221           puts $out $line
   222    222         }
   223    223       } else {
   224    224         puts $out $line