/ Check-in [5a2dec55]
Login

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

Overview
Comment:Merge recent enhancements from trunk, including test scripts enhancements and the removal of limits on the number of terms in a VALUES clause.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | sessions
Files: files | file ages | folders
SHA1: 5a2dec55bfadc328b430a5231a037b37831a5530
User & Date: drh 2015-01-08 20:06:06
Context
2015-01-14
17:16
Merge trunk 3.8.8 beta changes into the sessions branch check-in: 0ba12454 user: drh tags: sessions
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
16:47
Try to fix up the "valgrindtest" target in Makefile.in so that it avoids misuse testing that can trigger false errors. check-in: 50b5a8af user: drh tags: trunk
2014-12-31
14:27
Merge the fix to PRAGMA data_version and testing improvements from trunk. check-in: 86e39123 user: drh tags: sessions
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to Makefile.in.

    18     18   TOP = @srcdir@
    19     19   
    20     20   # C Compiler and options for use in building executables that
    21     21   # will run on the platform that is doing the build.
    22     22   #
    23     23   BCC = @BUILD_CC@ @BUILD_CFLAGS@
    24     24   
    25         -# C Compile and options for use in building executables that 
           25  +# TCC is the C Compile and options for use in building executables that 
    26     26   # will run on the target platform.  (BCC and TCC are usually the
    27         -# same unless your are cross-compiling.)
           27  +# same unless your are cross-compiling.)  Separate CC and CFLAGS macros
           28  +# are provide so that these aspects of the build process can be changed
           29  +# on the "make" command-line.  Ex:  "make CC=clang CFLAGS=-fsanitize=undefined"
    28     30   #
    29         -TCC = @CC@ @CPPFLAGS@ @CFLAGS@ -I. -I${TOP}/src -I${TOP}/ext/rtree -I${TOP}/ext/icu
           31  +CC = @CC@
           32  +CFLAGS = @CPPFLAGS@ @CFLAGS@
           33  +TCC = ${CC} ${CFLAGS} -I. -I${TOP}/src -I${TOP}/ext/rtree -I${TOP}/ext/icu
    30     34   TCC += -I${TOP}/ext/fts3 -I${TOP}/ext/async -I${TOP}/ext/session
    31     35   
    32     36   # Define this for the autoconf-based build, so that the code knows it can
    33     37   # include the generated config.h
    34     38   # 
    35     39   TCC += -D_HAVE_SQLITE_CONFIG_H -DBUILD_sqlite
    36     40   
................................................................................
   935    939   TESTFIXTURE_SRC = $(TESTSRC) $(TOP)/src/tclsqlite.c
   936    940   TESTFIXTURE_SRC += $(TESTFIXTURE_SRC$(USE_AMALGAMATION))
   937    941   
   938    942   testfixture$(TEXE):	$(TESTFIXTURE_SRC)
   939    943   	$(LTLINK) -DSQLITE_NO_SYNC=1 $(TEMP_STORE) $(TESTFIXTURE_FLAGS) \
   940    944   		-o $@ $(TESTFIXTURE_SRC) $(LIBTCL) $(TLIBS)
   941    945   
   942         -
          946  +# A very detailed test running most or all test cases
   943    947   fulltest:	testfixture$(TEXE) sqlite3$(TEXE)
   944    948   	./testfixture$(TEXE) $(TOP)/test/all.test
   945    949   
          950  +# Really really long testing
   946    951   soaktest:	testfixture$(TEXE) sqlite3$(TEXE)
   947    952   	./testfixture$(TEXE) $(TOP)/test/all.test -soak=1
   948    953   
          954  +# Do extra testing but not aeverything.
   949    955   fulltestonly:	testfixture$(TEXE) sqlite3$(TEXE)
   950    956   	./testfixture$(TEXE) $(TOP)/test/full.test
   951    957   
          958  +# This is the common case.  Run many tests but not those that take
          959  +# a really long time.
          960  +#
   952    961   test:	testfixture$(TEXE) sqlite3$(TEXE)
   953    962   	./testfixture$(TEXE) $(TOP)/test/veryquick.test
          963  +
          964  +# Run a test using valgrind.  This can take a really long time
          965  +# because valgrind is so much slower than a native machine.
          966  +#
          967  +valgrindtest:	testfixture$(TEXE) sqlite3$(TEXE)
          968  +	OMIT_MISUSE=1 valgrind -v ./testfixture$(TEXE) $(TOP)/test/permutations.test valgrind
          969  +
          970  +# A very fast test that checks basic sanity.  The name comes from
          971  +# the 60s-era electronics testing:  "Turn it on and see if smoke
          972  +# comes out."
          973  +#
          974  +smoketest:	testfixture$(TEXE)
          975  +	./testfixture$(TEXE) $(TOP)/test/main.test
   954    976   
   955    977   sqlite3_analyzer.c: sqlite3.c $(TOP)/src/test_stat.c $(TOP)/src/tclsqlite.c $(TOP)/tool/spaceanal.tcl
   956    978   	echo "#define TCLSH 2" > $@
   957    979   	cat sqlite3.c $(TOP)/src/test_stat.c $(TOP)/src/tclsqlite.c >> $@
   958    980   	echo "static const char *tclsh_main_loop(void){" >> $@
   959    981   	echo "static const char *zMainloop = " >> $@
   960    982   	$(NAWK) -f $(TOP)/tool/tostr.awk $(TOP)/tool/spaceanal.tcl >> $@

Changes to ext/misc/fuzzer.c.

   338    338     }else{
   339    339   
   340    340       pRule = sqlite3_malloc( sizeof(*pRule) + nFrom + nTo );
   341    341       if( pRule==0 ){
   342    342         rc = SQLITE_NOMEM;
   343    343       }else{
   344    344         memset(pRule, 0, sizeof(*pRule));
   345         -      pRule->zFrom = &pRule->zTo[nTo+1];
          345  +      pRule->zFrom = pRule->zTo;
          346  +      pRule->zFrom += nTo + 1;
   346    347         pRule->nFrom = nFrom;
   347    348         memcpy(pRule->zFrom, zFrom, nFrom+1);
   348    349         memcpy(pRule->zTo, zTo, nTo+1);
   349    350         pRule->nTo = nTo;
   350    351         pRule->rCost = nCost;
   351    352         pRule->iRuleset = (int)iRuleset;
   352    353       }

Changes to ext/rtree/rtree.c.

  1178   1178       pCur->aPoint = pNew;
  1179   1179       pCur->nPointAlloc = nNew;
  1180   1180     }
  1181   1181     i = pCur->nPoint++;
  1182   1182     pNew = pCur->aPoint + i;
  1183   1183     pNew->rScore = rScore;
  1184   1184     pNew->iLevel = iLevel;
  1185         -  assert( iLevel>=0 && iLevel<=RTREE_MAX_DEPTH );
         1185  +  assert( iLevel<=RTREE_MAX_DEPTH );
  1186   1186     while( i>0 ){
  1187   1187       RtreeSearchPoint *pParent;
  1188   1188       j = (i-1)/2;
  1189   1189       pParent = pCur->aPoint + j;
  1190   1190       if( rtreeSearchPointCompare(pNew, pParent)>=0 ) break;
  1191   1191       rtreeSearchPointSwap(pCur, j, i);
  1192   1192       i = j;

Changes to src/analyze.c.

   444    444       u8 *pSpace;                     /* Allocated space not yet assigned */
   445    445       int i;                          /* Used to iterate through p->aSample[] */
   446    446   
   447    447       p->iGet = -1;
   448    448       p->mxSample = mxSample;
   449    449       p->nPSample = (tRowcnt)(sqlite3_value_int64(argv[2])/(mxSample/3+1) + 1);
   450    450       p->current.anLt = &p->current.anEq[nColUp];
   451         -    p->iPrn = nCol*0x689e962d ^ sqlite3_value_int(argv[2])*0xd0944565;
          451  +    p->iPrn = 0x689e962d*(u32)nCol ^ 0xd0944565*(u32)sqlite3_value_int(argv[2]);
   452    452     
   453    453       /* Set up the Stat4Accum.a[] and aBest[] arrays */
   454    454       p->a = (struct Stat4Sample*)&p->current.anLt[nColUp];
   455    455       p->aBest = &p->a[mxSample];
   456    456       pSpace = (u8*)(&p->a[mxSample+nCol]);
   457    457       for(i=0; i<(mxSample+nCol); i++){
   458    458         p->a[i].anEq = (tRowcnt *)pSpace; pSpace += (sizeof(tRowcnt) * nColUp);

Changes to src/global.c.

   148    148   ** SQLITE_ALLOW_COVERING_INDEX_SCAN compile-time option, or is "on" if
   149    149   ** that compile-time option is omitted.
   150    150   */
   151    151   #ifndef SQLITE_ALLOW_COVERING_INDEX_SCAN
   152    152   # define SQLITE_ALLOW_COVERING_INDEX_SCAN 1
   153    153   #endif
   154    154   
          155  +/* The minimum PMA size is set to this value multiplied by the database
          156  +** page size in bytes.
          157  +*/
          158  +#ifndef SQLITE_SORTER_PMASZ
          159  +# define SQLITE_SORTER_PMASZ 250
          160  +#endif
          161  +
   155    162   /*
   156    163   ** The following singleton contains the global configuration for
   157    164   ** the SQLite library.
   158    165   */
   159    166   SQLITE_WSD struct Sqlite3Config sqlite3Config = {
   160    167      SQLITE_DEFAULT_MEMSTATUS,  /* bMemstat */
   161    168      1,                         /* bCoreMutex */
................................................................................
   178    185      0,                         /* szScratch */
   179    186      0,                         /* nScratch */
   180    187      (void*)0,                  /* pPage */
   181    188      0,                         /* szPage */
   182    189      0,                         /* nPage */
   183    190      0,                         /* mxParserStack */
   184    191      0,                         /* sharedCacheEnabled */
          192  +   SQLITE_SORTER_PMASZ,       /* szPma */
   185    193      /* All the rest should always be initialized to zero */
   186    194      0,                         /* isInit */
   187    195      0,                         /* inProgress */
   188    196      0,                         /* isMutexInit */
   189    197      0,                         /* isMallocInit */
   190    198      0,                         /* isPCacheInit */
   191    199      0,                         /* nRefInitMutex */

Changes to src/main.c.

   589    589         /* EVIDENCE-OF: R-34926-03360 SQLITE_CONFIG_WIN32_HEAPSIZE takes a 32-bit
   590    590         ** unsigned integer value that specifies the maximum size of the created
   591    591         ** heap. */
   592    592         sqlite3GlobalConfig.nHeap = va_arg(ap, int);
   593    593         break;
   594    594       }
   595    595   #endif
          596  +
          597  +    case SQLITE_CONFIG_PMASZ: {
          598  +      sqlite3GlobalConfig.szPma = va_arg(ap, unsigned int);
          599  +      break;
          600  +    }
   596    601   
   597    602       default: {
   598    603         rc = SQLITE_ERROR;
   599    604         break;
   600    605       }
   601    606     }
   602    607     va_end(ap);

Changes to src/os_unix.c.

  3713   3713         ** single byte to the last byte in each block that falls entirely
  3714   3714         ** within the extended region. Then, if required, a single byte
  3715   3715         ** at offset (nSize-1), to set the size of the file correctly.
  3716   3716         ** This is a similar technique to that used by glibc on systems
  3717   3717         ** that do not have a real fallocate() call.
  3718   3718         */
  3719   3719         int nBlk = buf.st_blksize;  /* File-system block size */
         3720  +      int nWrite = 0;             /* Number of bytes written by seekAndWrite */
  3720   3721         i64 iWrite;                 /* Next offset to write to */
  3721   3722   
  3722   3723         iWrite = ((buf.st_size + 2*nBlk - 1)/nBlk)*nBlk-1;
  3723   3724         assert( iWrite>=buf.st_size );
  3724   3725         assert( (iWrite/nBlk)==((buf.st_size+nBlk-1)/nBlk) );
  3725   3726         assert( ((iWrite+1)%nBlk)==0 );
  3726   3727         for(/*no-op*/; iWrite<nSize; iWrite+=nBlk ){
  3727         -        int nWrite = seekAndWrite(pFile, iWrite, "", 1);
         3728  +        nWrite = seekAndWrite(pFile, iWrite, "", 1);
  3728   3729           if( nWrite!=1 ) return SQLITE_IOERR_WRITE;
  3729   3730         }
  3730         -      if( nSize%nBlk ){
  3731         -        int nWrite = seekAndWrite(pFile, nSize-1, "", 1);
         3731  +      if( nWrite==0 || (nSize%nBlk) ){
         3732  +        nWrite = seekAndWrite(pFile, nSize-1, "", 1);
  3732   3733           if( nWrite!=1 ) return SQLITE_IOERR_WRITE;
  3733   3734         }
  3734   3735   #endif
  3735   3736       }
  3736   3737     }
  3737   3738   
  3738   3739   #if SQLITE_MAX_MMAP_SIZE>0

Changes to src/parse.y.

   411    411   
   412    412   select(A) ::= with(W) selectnowith(X). {
   413    413     Select *p = X, *pNext, *pLoop;
   414    414     if( p ){
   415    415       int cnt = 0, mxSelect;
   416    416       p->pWith = W;
   417    417       if( p->pPrior ){
          418  +      u16 allValues = SF_Values;
   418    419         pNext = 0;
   419    420         for(pLoop=p; pLoop; pNext=pLoop, pLoop=pLoop->pPrior, cnt++){
   420    421           pLoop->pNext = pNext;
   421    422           pLoop->selFlags |= SF_Compound;
          423  +        allValues &= pLoop->selFlags;
   422    424         }
   423         -      mxSelect = pParse->db->aLimit[SQLITE_LIMIT_COMPOUND_SELECT];
   424         -      if( mxSelect && cnt>mxSelect ){
          425  +      if( allValues ){
          426  +        p->selFlags |= SF_AllValues;
          427  +      }else if(
          428  +        (mxSelect = pParse->db->aLimit[SQLITE_LIMIT_COMPOUND_SELECT])>0
          429  +        && cnt>mxSelect
          430  +      ){
   425    431           sqlite3ErrorMsg(pParse, "too many terms in compound SELECT");
   426    432         }
   427    433       }
   428    434     }else{
   429    435       sqlite3WithDelete(pParse->db, W);
   430    436     }
   431    437     A = p;

Changes to src/select.c.

    54     54     int labelBkOut;       /* Start label for the block-output subroutine */
    55     55     int addrSortIndex;    /* Address of the OP_SorterOpen or OP_OpenEphemeral */
    56     56     u8 sortFlags;         /* Zero or more SORTFLAG_* bits */
    57     57   };
    58     58   #define SORTFLAG_UseSorter  0x01   /* Use SorterOpen instead of OpenEphemeral */
    59     59   
    60     60   /*
    61         -** Delete all the content of a Select structure but do not deallocate
    62         -** the select structure itself.
           61  +** Delete all the content of a Select structure.  Deallocate the structure
           62  +** itself only if bFree is true.
    63     63   */
    64         -static void clearSelect(sqlite3 *db, Select *p){
    65         -  sqlite3ExprListDelete(db, p->pEList);
    66         -  sqlite3SrcListDelete(db, p->pSrc);
    67         -  sqlite3ExprDelete(db, p->pWhere);
    68         -  sqlite3ExprListDelete(db, p->pGroupBy);
    69         -  sqlite3ExprDelete(db, p->pHaving);
    70         -  sqlite3ExprListDelete(db, p->pOrderBy);
    71         -  sqlite3SelectDelete(db, p->pPrior);
    72         -  sqlite3ExprDelete(db, p->pLimit);
    73         -  sqlite3ExprDelete(db, p->pOffset);
    74         -  sqlite3WithDelete(db, p->pWith);
           64  +static void clearSelect(sqlite3 *db, Select *p, int bFree){
           65  +  while( p ){
           66  +    Select *pPrior = p->pPrior;
           67  +    sqlite3ExprListDelete(db, p->pEList);
           68  +    sqlite3SrcListDelete(db, p->pSrc);
           69  +    sqlite3ExprDelete(db, p->pWhere);
           70  +    sqlite3ExprListDelete(db, p->pGroupBy);
           71  +    sqlite3ExprDelete(db, p->pHaving);
           72  +    sqlite3ExprListDelete(db, p->pOrderBy);
           73  +    sqlite3ExprDelete(db, p->pLimit);
           74  +    sqlite3ExprDelete(db, p->pOffset);
           75  +    sqlite3WithDelete(db, p->pWith);
           76  +    if( bFree ) sqlite3DbFree(db, p);
           77  +    p = pPrior;
           78  +    bFree = 1;
           79  +  }
    75     80   }
    76     81   
    77     82   /*
    78     83   ** Initialize a SelectDest structure.
    79     84   */
    80     85   void sqlite3SelectDestInit(SelectDest *pDest, int eDest, int iParm){
    81     86     pDest->eDest = (u8)eDest;
................................................................................
   126    131     pNew->op = TK_SELECT;
   127    132     pNew->pLimit = pLimit;
   128    133     pNew->pOffset = pOffset;
   129    134     assert( pOffset==0 || pLimit!=0 );
   130    135     pNew->addrOpenEphm[0] = -1;
   131    136     pNew->addrOpenEphm[1] = -1;
   132    137     if( db->mallocFailed ) {
   133         -    clearSelect(db, pNew);
   134         -    if( pNew!=&standin ) sqlite3DbFree(db, pNew);
          138  +    clearSelect(db, pNew, pNew!=&standin);
   135    139       pNew = 0;
   136    140     }else{
   137    141       assert( pNew->pSrc!=0 || pParse->nErr>0 );
   138    142     }
   139    143     assert( pNew!=&standin );
   140    144     return pNew;
   141    145   }
................................................................................
   152    156   #endif
   153    157   
   154    158   
   155    159   /*
   156    160   ** Delete the given Select structure and all of its substructures.
   157    161   */
   158    162   void sqlite3SelectDelete(sqlite3 *db, Select *p){
   159         -  if( p ){
   160         -    clearSelect(db, p);
   161         -    sqlite3DbFree(db, p);
   162         -  }
          163  +  clearSelect(db, p, 1);
   163    164   }
   164    165   
   165    166   /*
   166    167   ** Return a pointer to the right-most SELECT statement in a compound.
   167    168   */
   168    169   static Select *findRightmost(Select *p){
   169    170     while( p->pNext ) p = p->pNext;
................................................................................
  2071   2072   /* Forward references */
  2072   2073   static int multiSelectOrderBy(
  2073   2074     Parse *pParse,        /* Parsing context */
  2074   2075     Select *p,            /* The right-most of SELECTs to be coded */
  2075   2076     SelectDest *pDest     /* What to do with query results */
  2076   2077   );
  2077   2078   
         2079  +/*
         2080  +** Error message for when two or more terms of a compound select have different
         2081  +** size result sets.
         2082  +*/
         2083  +static void selectWrongNumTermsError(Parse *pParse, Select *p){
         2084  +  if( p->selFlags & SF_Values ){
         2085  +    sqlite3ErrorMsg(pParse, "all VALUES must have the same number of terms");
         2086  +  }else{
         2087  +    sqlite3ErrorMsg(pParse, "SELECTs to the left and right of %s"
         2088  +      " do not have the same number of result columns", selectOpName(p->op));
         2089  +  }
         2090  +}
         2091  +
         2092  +/*
         2093  +** Handle the special case of a compound-select that originates from a
         2094  +** VALUES clause.  By handling this as a special case, we avoid deep
         2095  +** recursion, and thus do not need to enforce the SQLITE_LIMIT_COMPOUND_SELECT
         2096  +** on a VALUES clause.
         2097  +**
         2098  +** Because the Select object originates from a VALUES clause:
         2099  +**   (1) It has no LIMIT or OFFSET
         2100  +**   (2) All terms are UNION ALL
         2101  +**   (3) There is no ORDER BY clause
         2102  +*/
         2103  +static int multiSelectValues(
         2104  +  Parse *pParse,        /* Parsing context */
         2105  +  Select *p,            /* The right-most of SELECTs to be coded */
         2106  +  SelectDest *pDest     /* What to do with query results */
         2107  +){
         2108  +  Select *pPrior;
         2109  +  int nExpr = p->pEList->nExpr;
         2110  +  int nRow = 1;
         2111  +  int rc = 0;
         2112  +  assert( p->pNext==0 );
         2113  +  assert( p->selFlags & SF_AllValues );
         2114  +  do{
         2115  +    assert( p->selFlags & SF_Values );
         2116  +    assert( p->op==TK_ALL || (p->op==TK_SELECT && p->pPrior==0) );
         2117  +    assert( p->pLimit==0 );
         2118  +    assert( p->pOffset==0 );
         2119  +    if( p->pEList->nExpr!=nExpr ){
         2120  +      selectWrongNumTermsError(pParse, p);
         2121  +      return 1;
         2122  +    }
         2123  +    if( p->pPrior==0 ) break;
         2124  +    assert( p->pPrior->pNext==p );
         2125  +    p = p->pPrior;
         2126  +    nRow++;
         2127  +  }while(1);
         2128  +  while( p ){
         2129  +    pPrior = p->pPrior;
         2130  +    p->pPrior = 0;
         2131  +    rc = sqlite3Select(pParse, p, pDest);
         2132  +    p->pPrior = pPrior;
         2133  +    if( rc ) break;
         2134  +    p->nSelectRow = nRow;
         2135  +    p = p->pNext;
         2136  +  }
         2137  +  return rc;
         2138  +}
  2078   2139   
  2079   2140   /*
  2080   2141   ** This routine is called to process a compound query form from
  2081   2142   ** two or more separate queries using UNION, UNION ALL, EXCEPT, or
  2082   2143   ** INTERSECT
  2083   2144   **
  2084   2145   ** "p" points to the right-most of the two queries.  the query on the
................................................................................
  2151   2212     */
  2152   2213     if( dest.eDest==SRT_EphemTab ){
  2153   2214       assert( p->pEList );
  2154   2215       sqlite3VdbeAddOp2(v, OP_OpenEphemeral, dest.iSDParm, p->pEList->nExpr);
  2155   2216       sqlite3VdbeChangeP5(v, BTREE_UNORDERED);
  2156   2217       dest.eDest = SRT_Table;
  2157   2218     }
         2219  +
         2220  +  /* Special handling for a compound-select that originates as a VALUES clause.
         2221  +  */
         2222  +  if( p->selFlags & SF_AllValues ){
         2223  +    rc = multiSelectValues(pParse, p, &dest);
         2224  +    goto multi_select_end;
         2225  +  }
  2158   2226   
  2159   2227     /* Make sure all SELECTs in the statement have the same number of elements
  2160   2228     ** in their result sets.
  2161   2229     */
  2162   2230     assert( p->pEList && pPrior->pEList );
  2163   2231     if( p->pEList->nExpr!=pPrior->pEList->nExpr ){
  2164         -    if( p->selFlags & SF_Values ){
  2165         -      sqlite3ErrorMsg(pParse, "all VALUES must have the same number of terms");
  2166         -    }else{
  2167         -      sqlite3ErrorMsg(pParse, "SELECTs to the left and right of %s"
  2168         -        " do not have the same number of result columns", selectOpName(p->op));
  2169         -    }
         2232  +    selectWrongNumTermsError(pParse, p);
  2170   2233       rc = 1;
  2171   2234       goto multi_select_end;
  2172   2235     }
  2173   2236   
  2174   2237   #ifndef SQLITE_OMIT_CTE
  2175   2238     if( p->selFlags & SF_Recursive ){
  2176   2239       generateWithRecursiveQuery(pParse, p, &dest);
................................................................................
  4048   4111       return WRC_Abort;
  4049   4112     }
  4050   4113     if( NEVER(p->pSrc==0) || (selFlags & SF_Expanded)!=0 ){
  4051   4114       return WRC_Prune;
  4052   4115     }
  4053   4116     pTabList = p->pSrc;
  4054   4117     pEList = p->pEList;
  4055         -  sqlite3WithPush(pParse, findRightmost(p)->pWith, 0);
         4118  +  if( pWalker->xSelectCallback2==selectPopWith ){
         4119  +    sqlite3WithPush(pParse, findRightmost(p)->pWith, 0);
         4120  +  }
  4056   4121   
  4057   4122     /* Make sure cursor numbers have been assigned to all entries in
  4058   4123     ** the FROM clause of the SELECT statement.
  4059   4124     */
  4060   4125     sqlite3SrcListAssignCursors(pParse, pTabList);
  4061   4126   
  4062   4127     /* Look up every table named in the FROM clause of the select.  If
................................................................................
  4339   4404     w.xExprCallback = exprWalkNoop;
  4340   4405     w.pParse = pParse;
  4341   4406     if( pParse->hasCompound ){
  4342   4407       w.xSelectCallback = convertCompoundSelectToSubquery;
  4343   4408       sqlite3WalkSelect(&w, pSelect);
  4344   4409     }
  4345   4410     w.xSelectCallback = selectExpander;
  4346         -  w.xSelectCallback2 = selectPopWith;
         4411  +  if( (pSelect->selFlags & SF_AllValues)==0 ){
         4412  +    w.xSelectCallback2 = selectPopWith;
         4413  +  }
  4347   4414     sqlite3WalkSelect(&w, pSelect);
  4348   4415   }
  4349   4416   
  4350   4417   
  4351   4418   #ifndef SQLITE_OMIT_SUBQUERY
  4352   4419   /*
  4353   4420   ** This is a Walker.xSelectCallback callback for the sqlite3SelectTypeInfo()

Changes to src/sqlite.h.in.

  1741   1741   ** [[SQLITE_CONFIG_PCACHE_HDRSZ]]
  1742   1742   ** <dt>SQLITE_CONFIG_PCACHE_HDRSZ
  1743   1743   ** <dd>^The SQLITE_CONFIG_PCACHE_HDRSZ option takes a single parameter which
  1744   1744   ** is a pointer to an integer and writes into that integer the number of extra
  1745   1745   ** bytes per page required for each page in [SQLITE_CONFIG_PAGECACHE].
  1746   1746   ** The amount of extra space required can change depending on the compiler,
  1747   1747   ** target platform, and SQLite version.
         1748  +**
         1749  +** [[SQLITE_CONFIG_PMASZ]]
         1750  +** <dt>SQLITE_CONFIG_PMASZ
         1751  +** <dd>^The SQLITE_CONFIG_PMASZ option takes a single parameter which
         1752  +** is an unsigned integer and sets the "Minimum PMA Size" for the multithreaded
         1753  +** sorter to that integer.  The default minimum PMA Size is set by the
         1754  +** [SQLITE_SORTER_PMASZ] compile-time option.  New threads are launched
         1755  +** to help with sort operations when multithreaded sorting
         1756  +** is enabled (using the [PRAGMA threads] command) and the amount of content
         1757  +** to be sorted exceeds the page size times the minimum of the
         1758  +** [PRAGMA cache_size] setting and this value.
  1748   1759   ** </dl>
  1749   1760   */
  1750   1761   #define SQLITE_CONFIG_SINGLETHREAD  1  /* nil */
  1751   1762   #define SQLITE_CONFIG_MULTITHREAD   2  /* nil */
  1752   1763   #define SQLITE_CONFIG_SERIALIZED    3  /* nil */
  1753   1764   #define SQLITE_CONFIG_MALLOC        4  /* sqlite3_mem_methods* */
  1754   1765   #define SQLITE_CONFIG_GETMALLOC     5  /* sqlite3_mem_methods* */
................................................................................
  1767   1778   #define SQLITE_CONFIG_PCACHE2      18  /* sqlite3_pcache_methods2* */
  1768   1779   #define SQLITE_CONFIG_GETPCACHE2   19  /* sqlite3_pcache_methods2* */
  1769   1780   #define SQLITE_CONFIG_COVERING_INDEX_SCAN 20  /* int */
  1770   1781   #define SQLITE_CONFIG_SQLLOG       21  /* xSqllog, void* */
  1771   1782   #define SQLITE_CONFIG_MMAP_SIZE    22  /* sqlite3_int64, sqlite3_int64 */
  1772   1783   #define SQLITE_CONFIG_WIN32_HEAPSIZE      23  /* int nByte */
  1773   1784   #define SQLITE_CONFIG_PCACHE_HDRSZ        24  /* int *psz */
         1785  +#define SQLITE_CONFIG_PMASZ               25  /* unsigned int szPma */
  1774   1786   
  1775   1787   /*
  1776   1788   ** CAPI3REF: Database Connection Configuration Options
  1777   1789   **
  1778   1790   ** These constants are the available integer configuration options that
  1779   1791   ** can be passed as the second argument to the [sqlite3_db_config()] interface.
  1780   1792   **

Changes to src/sqliteInt.h.

  2353   2353   #define SF_Resolved        0x0002  /* Identifiers have been resolved */
  2354   2354   #define SF_Aggregate       0x0004  /* Contains aggregate functions */
  2355   2355   #define SF_UsesEphemeral   0x0008  /* Uses the OpenEphemeral opcode */
  2356   2356   #define SF_Expanded        0x0010  /* sqlite3SelectExpand() called on this */
  2357   2357   #define SF_HasTypeInfo     0x0020  /* FROM subqueries have Table metadata */
  2358   2358   #define SF_Compound        0x0040  /* Part of a compound query */
  2359   2359   #define SF_Values          0x0080  /* Synthesized from VALUES clause */
  2360         -                    /*     0x0100  NOT USED */
         2360  +#define SF_AllValues       0x0100  /* All terms of compound are VALUES */
  2361   2361   #define SF_NestedFrom      0x0200  /* Part of a parenthesized FROM clause */
  2362   2362   #define SF_MaybeConvert    0x0400  /* Need convertCompoundSelectToSubquery() */
  2363   2363   #define SF_Recursive       0x0800  /* The recursive part of a recursive CTE */
  2364   2364   #define SF_MinMaxAgg       0x1000  /* Aggregate containing min() or max() */
  2365   2365   
  2366   2366   
  2367   2367   /*
................................................................................
  2847   2847     int szScratch;                    /* Size of each scratch buffer */
  2848   2848     int nScratch;                     /* Number of scratch buffers */
  2849   2849     void *pPage;                      /* Page cache memory */
  2850   2850     int szPage;                       /* Size of each page in pPage[] */
  2851   2851     int nPage;                        /* Number of pages in pPage[] */
  2852   2852     int mxParserStack;                /* maximum depth of the parser stack */
  2853   2853     int sharedCacheEnabled;           /* true if shared-cache mode enabled */
         2854  +  u32 szPma;                        /* Maximum Sorter PMA size */
  2854   2855     /* The above might be initialized to non-zero.  The following need to always
  2855   2856     ** initially be zero, however. */
  2856   2857     int isInit;                       /* True after initialization has finished */
  2857   2858     int inProgress;                   /* True while initialization in progress */
  2858   2859     int isMutexInit;                  /* True after mutexes are initialized */
  2859   2860     int isMallocInit;                 /* True after malloc is initialized */
  2860   2861     int isPCacheInit;                 /* True after malloc is initialized */

Changes to src/test1.c.

   257    257   }
   258    258   
   259    259   /*
   260    260   ** Usage:  clang_sanitize_address 
   261    261   **
   262    262   ** Returns true if the program was compiled using clang with the 
   263    263   ** -fsanitize=address switch on the command line. False otherwise.
          264  +**
          265  +** Also return true if the OMIT_MISUSE environment variable exists.
   264    266   */
   265    267   static int clang_sanitize_address(
   266    268     void *NotUsed,
   267    269     Tcl_Interp *interp,    /* The TCL interpreter that invoked this command */
   268    270     int argc,              /* Number of arguments */
   269    271     char **argv            /* Text of each argument */
   270    272   ){
   271    273     int res = 0;
   272    274   #if defined(__has_feature)
   273    275   # if __has_feature(address_sanitizer)
   274    276     res = 1;
   275    277   # endif
   276    278   #endif
          279  +  if( res==0 && getenv("OMIT_MISUSE")!=0 ) res = 1;
   277    280     Tcl_SetObjResult(interp, Tcl_NewIntObj(res));
   278    281     return TCL_OK;
   279    282   }
   280    283     
   281    284   /*
   282    285   ** Usage:  sqlite3_exec_printf  DB  FORMAT  STRING
   283    286   **
................................................................................
  6600   6603     zUser = Tcl_GetString(objv[2]);
  6601   6604     rc = sqlite3_user_delete(db, zUser);
  6602   6605     Tcl_SetResult(interp, (char *)t1ErrorName(rc), TCL_STATIC);
  6603   6606     return TCL_OK;
  6604   6607   }
  6605   6608   #endif /* SQLITE_USER_AUTHENTICATION */
  6606   6609   
         6610  +/*
         6611  +** tclcmd: bad_behavior TYPE
         6612  +**
         6613  +** Do some things that should trigger a valgrind or -fsanitize=undefined
         6614  +** warning.  This is used to verify that errors and warnings output by those
         6615  +** tools are detected by the test scripts.
         6616  +**
         6617  +**       TYPE       BEHAVIOR
         6618  +**       1          Overflow a signed integer
         6619  +**       2          Jump based on an uninitialized variable
         6620  +**       3          Read after free
         6621  +*/
         6622  +static int test_bad_behavior(
         6623  +  ClientData clientData, /* Pointer to an integer containing zero */
         6624  +  Tcl_Interp *interp,    /* The TCL interpreter that invoked this command */
         6625  +  int objc,              /* Number of arguments */
         6626  +  Tcl_Obj *CONST objv[]  /* Command arguments */
         6627  +){
         6628  +  int iType;
         6629  +  int xyz;
         6630  +  int i = *(int*)clientData;
         6631  +  int j;
         6632  +  int w[10];
         6633  +  int *a;
         6634  +  if( objc!=2 ){
         6635  +    Tcl_WrongNumArgs(interp, 1, objv, "TYPE");
         6636  +    return TCL_ERROR;
         6637  +  }
         6638  +  if( Tcl_GetIntFromObj(interp, objv[1], &iType) ) return TCL_ERROR;
         6639  +  switch( iType ){
         6640  +    case 1: {
         6641  +      xyz = 0x7fffff00 - i;
         6642  +      xyz += 0x100;
         6643  +      Tcl_SetObjResult(interp, Tcl_NewIntObj(xyz));
         6644  +      break;
         6645  +    }
         6646  +    case 2: {
         6647  +      w[1] = 5;
         6648  +      if( w[i]>0 ) w[1]++;
         6649  +      Tcl_SetObjResult(interp, Tcl_NewIntObj(w[1]));
         6650  +      break;
         6651  +    }
         6652  +    case 3: {
         6653  +      a = malloc( sizeof(int)*10 );
         6654  +      for(j=0; j<10; j++) a[j] = j;
         6655  +      free(a);
         6656  +      Tcl_SetObjResult(interp, Tcl_NewIntObj(a[i]));
         6657  +      break;
         6658  +    }
         6659  +  }
         6660  +  return TCL_OK;
         6661  +}  
         6662  +  
         6663  +
  6607   6664   /*
  6608   6665   ** Register commands with the TCL interpreter.
  6609   6666   */
  6610   6667   int Sqlitetest1_Init(Tcl_Interp *interp){
  6611   6668     extern int sqlite3_search_count;
  6612   6669     extern int sqlite3_found_count;
  6613   6670     extern int sqlite3_interrupt_count;
................................................................................
  6616   6673     extern int sqlite3_current_time;
  6617   6674   #if SQLITE_OS_UNIX && defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE
  6618   6675     extern int sqlite3_hostid_num;
  6619   6676   #endif
  6620   6677     extern int sqlite3_max_blobsize;
  6621   6678     extern int sqlite3BtreeSharedCacheReport(void*,
  6622   6679                                             Tcl_Interp*,int,Tcl_Obj*CONST*);
         6680  +  static int iZero = 0;
  6623   6681     static struct {
  6624   6682        char *zName;
  6625   6683        Tcl_CmdProc *xProc;
  6626   6684     } aCmd[] = {
  6627   6685        { "db_enter",                      (Tcl_CmdProc*)db_enter               },
  6628   6686        { "db_leave",                      (Tcl_CmdProc*)db_leave               },
  6629   6687        { "sqlite3_mprintf_int",           (Tcl_CmdProc*)sqlite3_mprintf_int    },
................................................................................
  6668   6726        { "clang_sanitize_address",        (Tcl_CmdProc*)clang_sanitize_address },
  6669   6727     };
  6670   6728     static struct {
  6671   6729        char *zName;
  6672   6730        Tcl_ObjCmdProc *xProc;
  6673   6731        void *clientData;
  6674   6732     } aObjCmd[] = {
         6733  +     { "bad_behavior",                  test_bad_behavior,  (void*)&iZero },
  6675   6734        { "sqlite3_connection_pointer",    get_sqlite_pointer, 0 },
  6676   6735        { "sqlite3_bind_int",              test_bind_int,      0 },
  6677   6736        { "sqlite3_bind_zeroblob",         test_bind_zeroblob, 0 },
  6678   6737        { "sqlite3_bind_int64",            test_bind_int64,    0 },
  6679   6738        { "sqlite3_bind_double",           test_bind_double,   0 },
  6680   6739        { "sqlite3_bind_null",             test_bind_null     ,0 },
  6681   6740        { "sqlite3_bind_text",             test_bind_text     ,0 },

Changes to src/test8.c.

   644    644   ** This module uses only sqlite3_index_info.idxStr, not 
   645    645   ** sqlite3_index_info.idxNum. So to test idxNum, when idxStr is set
   646    646   ** in echoBestIndex(), idxNum is set to the corresponding hash value.
   647    647   ** In echoFilter(), code assert()s that the supplied idxNum value is
   648    648   ** indeed the hash of the supplied idxStr.
   649    649   */
   650    650   static int hashString(const char *zString){
   651         -  int val = 0;
          651  +  u32 val = 0;
   652    652     int ii;
   653    653     for(ii=0; zString[ii]; ii++){
   654    654       val = (val << 3) + (int)zString[ii];
   655    655     }
   656         -  return val;
          656  +  return (int)(val&0x7fffffff);
   657    657   }
   658    658   
   659    659   /* 
   660    660   ** Echo virtual table module xFilter method.
   661    661   */
   662    662   static int echoFilter(
   663    663     sqlite3_vtab_cursor *pVtabCursor, 

Changes to src/test_malloc.c.

  1256   1256   
  1257   1257     rc = sqlite3_config(SQLITE_CONFIG_COVERING_INDEX_SCAN, bUseCis);
  1258   1258     Tcl_SetResult(interp, (char *)sqlite3ErrName(rc), TCL_VOLATILE);
  1259   1259   
  1260   1260     return TCL_OK;
  1261   1261   }
  1262   1262   
         1263  +/*
         1264  +** Usage:    sqlite3_config_pmasz  INTEGER
         1265  +**
         1266  +** Set the minimum PMA size.
         1267  +*/
         1268  +static int test_config_pmasz(
         1269  +  void * clientData, 
         1270  +  Tcl_Interp *interp,
         1271  +  int objc,
         1272  +  Tcl_Obj *CONST objv[]
         1273  +){
         1274  +  int rc;
         1275  +  int iPmaSz;
         1276  +
         1277  +  if( objc!=2 ){
         1278  +    Tcl_WrongNumArgs(interp, 1, objv, "BOOL");
         1279  +    return TCL_ERROR;
         1280  +  }
         1281  +  if( Tcl_GetIntFromObj(interp, objv[1], &iPmaSz) ){
         1282  +    return TCL_ERROR;
         1283  +  }
         1284  +
         1285  +  rc = sqlite3_config(SQLITE_CONFIG_PMASZ, iPmaSz);
         1286  +  Tcl_SetResult(interp, (char *)sqlite3ErrName(rc), TCL_VOLATILE);
         1287  +
         1288  +  return TCL_OK;
         1289  +}
         1290  +
  1263   1291   
  1264   1292   /*
  1265   1293   ** Usage:    sqlite3_dump_memsys3  FILENAME
  1266   1294   **           sqlite3_dump_memsys5  FILENAME
  1267   1295   **
  1268   1296   ** Write a summary of unfreed memsys3 allocations to FILENAME.
  1269   1297   */
................................................................................
  1510   1538        { "sqlite3_config_heap",        test_config_heap              ,0 },
  1511   1539        { "sqlite3_config_heap_size",   test_config_heap_size         ,0 },
  1512   1540        { "sqlite3_config_memstatus",   test_config_memstatus         ,0 },
  1513   1541        { "sqlite3_config_lookaside",   test_config_lookaside         ,0 },
  1514   1542        { "sqlite3_config_error",       test_config_error             ,0 },
  1515   1543        { "sqlite3_config_uri",         test_config_uri               ,0 },
  1516   1544        { "sqlite3_config_cis",         test_config_cis               ,0 },
         1545  +     { "sqlite3_config_pmasz",       test_config_pmasz             ,0 },
  1517   1546        { "sqlite3_db_config_lookaside",test_db_config_lookaside      ,0 },
  1518   1547        { "sqlite3_dump_memsys3",       test_dump_memsys3             ,3 },
  1519   1548        { "sqlite3_dump_memsys5",       test_dump_memsys3             ,5 },
  1520   1549        { "sqlite3_install_memsys3",    test_install_memsys3          ,0 },
  1521   1550        { "sqlite3_memdebug_vfs_oom_test", test_vfs_oom_test          ,0 },
  1522   1551     };
  1523   1552     int i;

Changes to src/threads.c.

    22     22   ** or sqlite3ThreadJoin() call.  This is, in fact, what happens in
    23     23   ** single threaded systems.  Nothing in SQLite requires multiple threads.
    24     24   ** This interface exists so that applications that want to take advantage
    25     25   ** of multiple cores can do so, while also allowing applications to stay
    26     26   ** single-threaded if desired.
    27     27   */
    28     28   #include "sqliteInt.h"
           29  +#if SQLITE_OS_WIN
           30  +#  include "os_win.h"
           31  +#endif
    29     32   
    30     33   #if SQLITE_MAX_WORKER_THREADS>0
    31     34   
    32     35   /********************************* Unix Pthreads ****************************/
    33     36   #if SQLITE_OS_UNIX && defined(SQLITE_MUTEX_PTHREADS) && SQLITE_THREADSAFE>0
    34     37   
    35     38   #define SQLITE_THREADS_IMPLEMENTED 1  /* Prevent the single-thread code below */

Changes to src/vdbesort.c.

   148    148   #endif
   149    149   
   150    150   /*
   151    151   ** Hard-coded maximum amount of data to accumulate in memory before flushing
   152    152   ** to a level 0 PMA. The purpose of this limit is to prevent various integer
   153    153   ** overflows. 512MiB.
   154    154   */
   155         -#define SQLITE_MAX_MXPMASIZE    (1<<29)
          155  +#define SQLITE_MAX_PMASZ    (1<<29)
   156    156   
   157    157   /*
   158    158   ** Private objects used by the sorter
   159    159   */
   160    160   typedef struct MergeEngine MergeEngine;     /* Merge PMAs together */
   161    161   typedef struct PmaReader PmaReader;         /* Incrementally read one PMA */
   162    162   typedef struct PmaWriter PmaWriter;         /* Incrementally write one PMA */
................................................................................
   444    444   /* Return a pointer to the buffer containing the record data for SorterRecord
   445    445   ** object p. Should be used as if:
   446    446   **
   447    447   **   void *SRVAL(SorterRecord *p) { return (void*)&p[1]; }
   448    448   */
   449    449   #define SRVAL(p) ((void*)((SorterRecord*)(p) + 1))
   450    450   
   451         -/* The minimum PMA size is set to this value multiplied by the database
   452         -** page size in bytes.  */
   453         -#ifndef SQLITE_SORTER_PMASZ
   454         -# define SQLITE_SORTER_PMASZ 10
   455         -#endif
   456    451   
   457    452   /* Maximum number of PMAs that a single MergeEngine can merge */
   458    453   #define SORTER_MAX_MERGE_COUNT 16
   459    454   
   460    455   static int vdbeIncrSwap(IncrMerger*);
   461    456   static void vdbeIncrFree(IncrMerger *);
   462    457   
................................................................................
   847    842       pSorter->db = db;
   848    843       for(i=0; i<pSorter->nTask; i++){
   849    844         SortSubtask *pTask = &pSorter->aTask[i];
   850    845         pTask->pSorter = pSorter;
   851    846       }
   852    847   
   853    848       if( !sqlite3TempInMemory(db) ){
   854         -      pSorter->mnPmaSize = SQLITE_SORTER_PMASZ * pgsz;
          849  +      u32 szPma = sqlite3GlobalConfig.szPma;
          850  +      pSorter->mnPmaSize = szPma * pgsz;
   855    851         mxCache = db->aDb[0].pSchema->cache_size;
   856         -      if( mxCache<SQLITE_SORTER_PMASZ ) mxCache = SQLITE_SORTER_PMASZ;
   857         -      pSorter->mxPmaSize = MIN((i64)mxCache*pgsz, SQLITE_MAX_MXPMASIZE);
          852  +      if( mxCache<(int)szPma ) mxCache = (int)szPma;
          853  +      pSorter->mxPmaSize = MIN((i64)mxCache*pgsz, SQLITE_MAX_PMASZ);
   858    854   
   859    855         /* EVIDENCE-OF: R-26747-61719 When the application provides any amount of
   860    856         ** scratch memory using SQLITE_CONFIG_SCRATCH, SQLite avoids unnecessary
   861    857         ** large heap allocations.
   862    858         */
   863    859         if( sqlite3GlobalConfig.pScratch==0 ){
   864    860           assert( pSorter->iMemory==0 );

Changes to test/bigsort.test.

    16     16   
    17     17   #--------------------------------------------------------------------
    18     18   # At one point there was an overflow problem if the product of the 
    19     19   # cache-size and page-size was larger than 2^31. Causing an infinite 
    20     20   # loop if the product was also an integer multiple of 2^32, or 
    21     21   # inefficiency otherwise.
    22     22   #
           23  +# This test causes thrashing on machines with smaller amounts of
           24  +# memory.  Make sure the host has at least 8GB available before running
           25  +# this test.
           26  +#
           27  +if {[catch {exec free | grep Mem:} out] || [lindex $out 1]<8000000} {
           28  +  finish_test
           29  +  return
           30  +}
           31  +
    23     32   do_execsql_test 1.0 {
    24     33     PRAGMA page_size = 1024;
    25     34     CREATE TABLE t1(a, b);
    26     35     BEGIN;
    27     36     WITH data(x,y) AS (
    28     37       SELECT 1, zeroblob(10000)
    29     38       UNION ALL
................................................................................
    35     44   do_execsql_test 1.1 {
    36     45     PRAGMA cache_size = 4194304;
    37     46     CREATE INDEX i1 ON t1(a, b);
    38     47   }
    39     48   
    40     49   
    41     50   finish_test
    42         -
    43         -

Changes to test/fkey5.test.

   248    248   do_test fkey5-6.5 {
   249    249     db eval {
   250    250       PRAGMA foreign_key_check(c12);
   251    251     }
   252    252   } {c12 1 p4 0 c12 3 p4 0 c12 6 p4 0}
   253    253   
   254    254   do_test fkey5-7.1 {
          255  +  set res {}
   255    256     db eval {
   256    257       INSERT OR IGNORE INTO c13 SELECT * FROM c12;
   257    258       INSERT OR IGNORE INTO C14 SELECT * FROM c12;
   258    259       DELETE FROM c12;
   259    260       PRAGMA foreign_key_check;
          261  +  } {
          262  +    lappend res [list $table $rowid $fkid $parent]
   260    263     }
   261         -} {c14 1 p4 0 c14 3 p4 0 c14 6 p4 0 c13 1 p3 0 c13 2 p3 0 c13 3 p3 0 c13 4 p3 0 c13 5 p3 0 c13 6 p3 0}
          264  +  lsort $res
          265  +} {{c13 1 0 p3} {c13 2 0 p3} {c13 3 0 p3} {c13 4 0 p3} {c13 5 0 p3} {c13 6 0 p3} {c14 1 0 p4} {c14 3 0 p4} {c14 6 0 p4}}
   262    266   do_test fkey5-7.2 {
   263    267     db eval {
   264    268       PRAGMA foreign_key_check(c14);
   265    269     }
   266    270   } {c14 1 p4 0 c14 3 p4 0 c14 6 p4 0}
   267    271   do_test fkey5-7.3 {
   268    272     db eval {

Changes to test/main.test.

   510    510       } {1 {no such vfs: crash}}
   511    511       do_test main-4.3 {
   512    512         set rc [catch {sqlite3 db test.db -vfs async} msg]
   513    513         list $rc $msg
   514    514       } {1 {no such vfs: async}}
   515    515     }
   516    516   }
          517  +
          518  +# Print the version number so that it can be picked up by releasetest.tcl.
          519  +#
          520  +puts [db one {SELECT 'VERSION: ' ||
          521  +                  sqlite_version() || ' ' ||
          522  +                  sqlite_source_id();}]
          523  +
          524  +# Do deliberate failures if the TEST_FAILURE environment variable is set.
          525  +# This is done to verify that failure notifications are detected by the
          526  +# releasetest.tcl script, or possibly by other scripts involved in automatic
          527  +# testing.
          528  +#
          529  +if {[info exists ::env(TEST_FAILURE)]} {
          530  +  set res 123
          531  +  if {$::env(TEST_FAILURE)==0} {set res 234}
          532  +  do_test main-99.1 {
          533  +     bad_behavior $::env(TEST_FAILURE)
          534  +     set x 123
          535  +  } $res
          536  +}
   517    537       
   518    538   finish_test

Changes to test/memsubsys1.test.

   172    172     set maxreq [lindex [sqlite3_status SQLITE_STATUS_MALLOC_SIZE 0] 2]
   173    173     expr {$maxreq<7000}
   174    174   } 1
   175    175   do_test memsubsys1-4.6 {
   176    176     set s_used [lindex [sqlite3_status SQLITE_STATUS_SCRATCH_USED 0] 2]
   177    177   } 1
   178    178   
   179         -# Test 5:  Activate both PAGECACHE and SCRATCH.  But make the page size
          179  +# Test 5:  Activate both PAGECACHE and SCRATCH.  But make the page size is
   180    180   # such that the SCRATCH allocations are too small.
   181    181   #
   182    182   db close
   183    183   sqlite3_shutdown
   184    184   sqlite3_config_pagecache [expr 4096+$xtra_size] 24
   185         -sqlite3_config_scratch 6000 2
          185  +sqlite3_config_scratch 4000 2
   186    186   sqlite3_initialize
   187    187   reset_highwater_marks
   188    188   build_test_db memsubsys1-5 {PRAGMA page_size=4096}
   189    189   #show_memstats
   190    190   do_test memsubsys1-5.3 {
   191    191     set pg_used [lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_USED 0] 2]
   192         -} 24
          192  +} {/^2[34]$/}
   193    193   do_test memsubsys1-5.4 {
   194    194     set maxreq [lindex [sqlite3_status SQLITE_STATUS_MALLOC_SIZE 0] 2]
   195    195     expr {$maxreq>4096}
   196    196   } 1
   197    197   do_test memsubsys1-5.5 {
   198    198     set s_used [lindex [sqlite3_status SQLITE_STATUS_SCRATCH_USED 0] 2]
   199    199   } 0
................................................................................
   211    211   sqlite3_config_scratch 25300 1
   212    212   sqlite3_initialize
   213    213   reset_highwater_marks
   214    214   build_test_db memsubsys1-6 {PRAGMA page_size=4096}
   215    215   #show_memstats
   216    216   do_test memsubsys1-6.3 {
   217    217     set pg_used [lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_USED 0] 2]
   218         -} 24
          218  +} {/^2[34]$/}
   219    219   #do_test memsubsys1-6.4 {
   220    220   #  set maxreq [lindex [sqlite3_status SQLITE_STATUS_MALLOC_SIZE 0] 2]
   221    221   #  expr {$maxreq>4096 && $maxreq<=(4096+$xtra_size)}
   222    222   #} 1
   223    223   do_test memsubsys1-6.5 {
   224    224     set s_used [lindex [sqlite3_status SQLITE_STATUS_SCRATCH_USED 0] 2]
   225    225   } 1

Changes to test/oserror.test.

    47     47   # Test a failure in open() due to too many files. 
    48     48   #
    49     49   # The xOpen() method of the unix VFS calls getcwd() as well as open().
    50     50   # Although this does not appear to be documented in the man page, on OSX
    51     51   # a call to getcwd() may fail if there are no free file descriptors. So
    52     52   # an error may be reported for either open() or getcwd() here.
    53     53   #
    54         -puts "Possible valgrind error about invalid file descriptor follows:"
    55         -do_test 1.1.1 {
    56         -  set ::log [list]
    57         -  list [catch {
    58         -    for {set i 0} {$i < 2000} {incr i} { sqlite3 dbh_$i test.db -readonly 1 }
    59         -  } msg] $msg
    60         -} {1 {unable to open database file}}
    61         -do_test 1.1.2 {
    62         -  catch { for {set i 0} {$i < 2000} {incr i} { dbh_$i close } }
    63         -} {1}
    64         -do_re_test 1.1.3 { 
    65         -  lindex $::log 0 
    66         -} {^os_unix.c:\d+: \(\d+\) (open|getcwd)\(.*test.db\) - }
           54  +if {![clang_sanitize_address]} {
           55  +  do_test 1.1.1 {
           56  +    set ::log [list]
           57  +    list [catch {
           58  +      for {set i 0} {$i < 2000} {incr i} { sqlite3 dbh_$i test.db -readonly 1 }
           59  +    } msg] $msg
           60  +  } {1 {unable to open database file}}
           61  +  do_test 1.1.2 {
           62  +    catch { for {set i 0} {$i < 2000} {incr i} { dbh_$i close } }
           63  +  } {1}
           64  +  do_re_test 1.1.3 { 
           65  +    lindex $::log 0 
           66  +  } {^os_unix.c:\d+: \(\d+\) (open|getcwd)\(.*test.db\) - }
           67  +}
    67     68   
    68     69   
    69     70   # Test a failure in open() due to the path being a directory.
    70     71   #
    71     72   do_test 1.2.1 {
    72     73     file mkdir dir.db
    73     74     set ::log [list]

Changes to test/percentile.test.

   196    196         0          0.0
   197    197       100    9999990.0
   198    198        50    2749999.5
   199    199        10      99999.9
   200    200     } {
   201    201       do_test percentile-2.1.$in {
   202    202         execsql {
   203         -        SELECT percentile(x, $in) from t3;
          203  +        SELECT round(percentile(x, $in),1) from t3;
   204    204         }
   205    205       } $out
   206    206     }
   207    207   }
   208    208   
   209    209   finish_test

Changes to test/permutations.test.

   117    117     walthread.test rtree3.test indexfault.test securedel2.test
   118    118     sort3.test sort4.test fts4growth.test fts4growth2.test
   119    119     bigsort.test
   120    120   }]
   121    121   if {[info exists ::env(QUICKTEST_INCLUDE)]} {
   122    122     set allquicktests [concat $allquicktests $::env(QUICKTEST_INCLUDE)]
   123    123   }
          124  +if {[info exists ::env(QUICKTEST_OMIT)]} {
          125  +  foreach x [split $::env(QUICKTEST_OMIT) ,] {
          126  +    regsub -all \\y$x\\y $allquicktests {} allquicktests
          127  +  }
          128  +}
          129  +
          130  +# If the TEST_FAILURE environment variable is set, it means that we what to
          131  +# deliberately provoke test failures in order to test the test infrastructure.
          132  +# Only the main.test module is needed for this.
          133  +#
          134  +if {[info exists ::env(TEST_FAILURE)]} {
          135  +  set allquicktests main.test
          136  +}
   124    137   
   125    138   #############################################################################
   126    139   # Start of tests
   127    140   #
   128    141   
   129    142   #-------------------------------------------------------------------------
   130    143   # Define the generic test suites:
................................................................................
   144    157   ]
   145    158   
   146    159   test_suite "mmap" -prefix "mm-" -description {
   147    160     Similar to veryquick. Except with memory mapping enabled.
   148    161   } -presql {
   149    162     pragma mmap_size = 268435456;
   150    163   } -files [
   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
          164  +  test_set $allquicktests -exclude *malloc* *ioerr* *fault* -include malloc.test
   156    165   ]
   157    166   
   158    167   test_suite "valgrind" -prefix "" -description {
   159    168     Run the "veryquick" test suite with a couple of multi-process tests (that
   160    169     fail under valgrind) omitted.
   161    170   } -files [
   162    171     test_set $allquicktests -exclude *malloc* *ioerr* *fault* wal.test atof1.test

Changes to test/releasetest.tcl.

     9      9   before releasing a new version. Supported command line options (all
    10     10   optional) are:
    11     11   
    12     12       --srcdir   TOP-OF-SQLITE-TREE      (see below)
    13     13       --platform PLATFORM                (see below)
    14     14       --config   CONFIGNAME              (Run only CONFIGNAME)
    15     15       --quick                            (Run "veryquick.test" only)
           16  +    --veryquick                        (Run "make smoketest" only)
    16     17       --buildonly                        (Just build testfixture - do not run)
    17     18       --dryrun                           (Print what would have happened)
    18     19       --info                             (Show diagnostic info)
    19     20   
    20     21   The default value for --srcdir is the parent of the directory holding
    21     22   this script.
    22     23   
................................................................................
    27     28   Every test begins with a fresh run of the configure script at the top
    28     29   of the SQLite source tree.
    29     30   }
    30     31   
    31     32   array set ::Configs {
    32     33     "Default" {
    33     34       -O2
           35  +    --disable-amalgamation --disable-shared
    34     36     }
    35         -  "Ftrapv" {
    36         -    -O2 -ftrapv
    37         -    -DSQLITE_MAX_ATTACHED=55
    38         -    -DSQLITE_TCL_DEFAULT_FULLMUTEX=1
           37  +  "Sanitize" {
           38  +    CC=clang -fsanitize=undefined
           39  +    -DSQLITE_ENABLE_STAT4
    39     40     }
    40     41     "Unlock-Notify" {
    41     42       -O2
    42     43       -DSQLITE_ENABLE_UNLOCK_NOTIFY
    43     44       -DSQLITE_THREADSAFE
    44     45       -DSQLITE_TCL_DEFAULT_FULLMUTEX=1
    45     46     }
................................................................................
    63     64       -DSQLITE_ENABLE_COLUMN_METADATA=1
    64     65       -DSQLITE_ENABLE_UPDATE_DELETE_LIMIT=1
    65     66       -DSQLITE_SECURE_DELETE=1
    66     67       -DSQLITE_SOUNDEX=1
    67     68       -DSQLITE_ENABLE_ATOMIC_WRITE=1
    68     69       -DSQLITE_ENABLE_MEMORY_MANAGEMENT=1
    69     70       -DSQLITE_ENABLE_OVERSIZE_CELL_CHECK=1
           71  +    -DSQLITE_ENABLE_STAT4
    70     72     }
    71     73     "Debug-One" {
           74  +    --disable-shared
    72     75       -O2
    73     76       -DSQLITE_DEBUG=1
    74     77       -DSQLITE_MEMDEBUG=1
    75     78       -DSQLITE_MUTEX_NOOP=1
    76     79       -DSQLITE_TCL_DEFAULT_FULLMUTEX=1
    77     80       -DSQLITE_ENABLE_FTS3=1
    78     81       -DSQLITE_ENABLE_RTREE=1
    79     82       -DSQLITE_ENABLE_MEMSYS5=1
    80     83       -DSQLITE_ENABLE_MEMSYS3=1
    81     84       -DSQLITE_ENABLE_COLUMN_METADATA=1
           85  +    -DSQLITE_ENABLE_STAT4
           86  +    -DSQLITE_MAX_ATTACHED=125
    82     87     }
    83     88     "Device-One" {
    84     89       -O2
    85     90       -DSQLITE_DEBUG=1
    86     91       -DSQLITE_DEFAULT_AUTOVACUUM=1
    87     92       -DSQLITE_DEFAULT_CACHE_SIZE=64
    88     93       -DSQLITE_DEFAULT_PAGE_SIZE=1024
................................................................................
   115    120       -DSQLITE_THREADSAFE=2
   116    121     }
   117    122     "Locking-Style" {
   118    123       -O2
   119    124       -DSQLITE_ENABLE_LOCKING_STYLE=1
   120    125     }
   121    126     "OS-X" {
          127  +    -O1   # Avoid a compiler bug in gcc 4.2.1 build 5658
   122    128       -DSQLITE_OMIT_LOAD_EXTENSION=1
   123    129       -DSQLITE_DEFAULT_MEMSTATUS=0
   124    130       -DSQLITE_THREADSAFE=2
   125    131       -DSQLITE_OS_UNIX=1
   126    132       -DSQLITE_ENABLE_LOCKING_STYLE=1
   127    133       -DUSE_PREAD=1
   128    134       -DSQLITE_ENABLE_RTREE=1
................................................................................
   129    135       -DSQLITE_ENABLE_FTS3=1
   130    136       -DSQLITE_ENABLE_FTS3_PARENTHESIS=1
   131    137       -DSQLITE_DEFAULT_CACHE_SIZE=1000
   132    138       -DSQLITE_MAX_LENGTH=2147483645
   133    139       -DSQLITE_MAX_VARIABLE_NUMBER=500000
   134    140       -DSQLITE_DEBUG=1
   135    141       -DSQLITE_PREFER_PROXY_LOCKING=1
          142  +    -DSQLITE_ENABLE_API_ARMOR=1
   136    143     }
   137    144     "Extra-Robustness" {
   138    145       -DSQLITE_ENABLE_OVERSIZE_CELL_CHECK=1
   139    146       -DSQLITE_MAX_ATTACHED=62
   140    147     }
   141    148     "Devkit" {
   142    149       -DSQLITE_DEFAULT_FILE_FORMAT=4
................................................................................
   143    150       -DSQLITE_MAX_ATTACHED=30
   144    151       -DSQLITE_ENABLE_COLUMN_METADATA
   145    152       -DSQLITE_ENABLE_FTS4
   146    153       -DSQLITE_ENABLE_FTS4_PARENTHESIS
   147    154       -DSQLITE_DISABLE_FTS4_DEFERRED
   148    155       -DSQLITE_ENABLE_RTREE
   149    156     }
   150         -
   151    157     "No-lookaside" {
   152    158       -DSQLITE_TEST_REALLOC_STRESS=1
   153    159       -DSQLITE_OMIT_LOOKASIDE=1
   154    160       -DHAVE_USLEEP=1
   155    161     }
          162  +  "Valgrind" {
          163  +    -DSQLITE_ENABLE_STAT4
          164  +    -DSQLITE_ENABLE_FTS4
          165  +    -DSQLITE_ENABLE_RTREE
          166  +  }
          167  +  Fail0 {-O0}
          168  +  Fail2 {-O0}
          169  +  Fail3 {-O0}
   156    170   }
   157    171   
   158    172   array set ::Platforms {
   159    173     Linux-x86_64 {
   160    174       "Check-Symbols"           checksymbols
   161    175       "Debug-One"               "mptest test"
   162    176       "Secure-Delete"           test
   163    177       "Unlock-Notify"           "QUICKTEST_INCLUDE=notify2.test test"
   164    178       "Update-Delete-Limit"     test
   165    179       "Extra-Robustness"        test
   166    180       "Device-Two"              test
   167         -    "Ftrapv"                  test
   168    181       "No-lookaside"            test
   169    182       "Devkit"                  test
          183  +    "Sanitize"                {QUICKTEST_OMIT=func4.test,nan.test test}
          184  +    "Valgrind"                valgrindtest
   170    185       "Default"                 "threadtest fulltest"
   171    186       "Device-One"              fulltest
   172    187     }
   173    188     Linux-i686 {
   174    189       "Devkit"                  test
   175    190       "Unlock-Notify"           "QUICKTEST_INCLUDE=notify2.test test"
   176    191       "Device-One"              test
................................................................................
   177    192       "Device-Two"              test
   178    193       "Default"                 "threadtest fulltest"
   179    194     }
   180    195     Darwin-i386 {
   181    196       "Locking-Style"           "mptest test"
   182    197       "OS-X"                    "threadtest fulltest"
   183    198     }
          199  +  Darwin-x86_64 {
          200  +    "Locking-Style"           "mptest test"
          201  +    "OS-X"                    "threadtest fulltest"
          202  +  }
   184    203     "Windows NT-intel" {
   185    204       "Default"                 "mptest fulltestonly"
   186    205     }
          206  +  Failure-Detection {
          207  +    Fail0     "TEST_FAILURE=0 test"
          208  +    Sanitize  "TEST_FAILURE=1 test"
          209  +    Fail2     "TEST_FAILURE=2 valgrindtest"
          210  +    Fail3     "TEST_FAILURE=3 valgrindtest"
          211  +  }
   187    212   }
   188    213   
   189    214   
   190    215   # End of configuration section.
   191    216   #########################################################################
   192    217   #########################################################################
   193    218   
................................................................................
   219    244         incr ::NTESTCASE $ntest
   220    245         set seen 1
   221    246         if {$nerr>0} {
   222    247           set rc 1
   223    248           set errmsg $line
   224    249         }
   225    250       }
          251  +    if {[regexp {runtime error: +(.*)} $line all msg]} {
          252  +      incr ::NERRCASE
          253  +      if {$rc==0} {
          254  +        set rc 1
          255  +        set errmsg $msg
          256  +      }
          257  +    }
          258  +    if {[regexp {ERROR SUMMARY: (\d+) errors.*} $line all cnt] && $cnt>0} {
          259  +      incr ::NERRCASE
          260  +      if {$rc==0} {
          261  +        set rc 1
          262  +        set errmsg $all
          263  +      }
          264  +    }
          265  +    if {[regexp {^VERSION: 3\.\d+.\d+} $line]} {
          266  +      set v [string range $line 9 end]
          267  +      if {$::SQLITE_VERSION eq ""} {
          268  +        set ::SQLITE_VERSION $v
          269  +      } elseif {$::SQLITE_VERSION ne $v} {
          270  +        set rc 1
          271  +        set errmsg "version conflict: {$::SQLITE_VERSION} vs. {$v}"
          272  +      }
          273  +    }
   226    274     }
   227    275     close $fd
   228    276     if {!$seen} {
   229    277       set rc 1
   230    278       set errmsg "Test did not complete"
   231    279     }
   232    280   }
................................................................................
   235    283     # Tcl variable $opts is used to build up the value used to set the
   236    284     # OPTS Makefile variable. Variable $cflags holds the value for
   237    285     # CFLAGS. The makefile will pass OPTS to both gcc and lemon, but
   238    286     # CFLAGS is only passed to gcc.
   239    287     #
   240    288     set cflags "-g"
   241    289     set opts ""
          290  +  set title ${name}($testtarget)
          291  +  set configOpts ""
          292  +
          293  +  regsub -all {#[^\n]*\n} $config \n config
   242    294     foreach arg $config {
   243    295       if {[string match -D* $arg]} {
   244    296         lappend opts $arg
          297  +    } elseif {[string match CC=* $arg]} {
          298  +      lappend testtarget $arg
          299  +    } elseif {[regexp {^--(enable|disable)-} $arg]} {
          300  +      lappend configOpts $arg
   245    301       } else {
   246    302         lappend cflags $arg
   247    303       }
   248    304     }
   249    305   
   250    306     set cflags [join $cflags " "]
   251    307     set opts   [join $opts " "]
................................................................................
   257    313   
   258    314     if {$::tcl_platform(platform)=="windows"} {
   259    315       append opts " -DSQLITE_OS_WIN=1"
   260    316     } else {
   261    317       append opts " -DSQLITE_OS_UNIX=1"
   262    318     }
   263    319   
   264         -  dryrun file mkdir $dir
   265         -  if {!$::DRYRUN} {
   266         -    set title ${name}($testtarget)
          320  +  if {!$::TRACE} {
   267    321       set n [string length $title]
   268         -    puts -nonewline "${title}[string repeat . [expr {54-$n}]]"
          322  +    puts -nonewline "${title}[string repeat . [expr {63-$n}]]"
   269    323       flush stdout
   270    324     }
   271    325   
          326  +  set rc 0
   272    327     set tm1 [clock seconds]
   273    328     set origdir [pwd]
   274         -  dryrun cd $dir
          329  +  trace_cmd file mkdir $dir
          330  +  trace_cmd cd $dir
   275    331     set errmsg {}
   276         -  set rc [catch [configureCommand]]
          332  +  set rc [catch [configureCommand $configOpts]]
   277    333     if {!$rc} {
   278    334       set rc [catch [makeCommand $testtarget $cflags $opts]]
   279    335       count_tests_and_errors test.log rc errmsg
   280    336     }
          337  +  trace_cmd cd $origdir
   281    338     set tm2 [clock seconds]
   282         -  dryrun cd $origdir
   283    339   
   284         -  if {!$::DRYRUN} {
   285         -    set hours [expr {($tm2-$tm2)/3600}]
          340  +  if {!$::TRACE} {
          341  +    set hours [expr {($tm2-$tm1)/3600}]
   286    342       set minutes [expr {(($tm2-$tm1)/60)%60}]
   287    343       set seconds [expr {($tm2-$tm1)%60}]
   288    344       set tm [format (%02d:%02d:%02d) $hours $minutes $seconds]
   289    345       if {$rc} {
   290    346         puts " FAIL $tm"
   291    347         incr ::NERR
   292    348         if {$errmsg!=""} {puts "     $errmsg"}
................................................................................
   295    351       }
   296    352     }
   297    353   }
   298    354   
   299    355   # The following procedure returns the "configure" command to be exectued for
   300    356   # the current platform, which may be Windows (via MinGW, etc).
   301    357   #
   302         -proc configureCommand {} {
   303         -  set result [list dryrun exec]
          358  +proc configureCommand {opts} {
          359  +  set result [list trace_cmd exec]
   304    360     if {$::tcl_platform(platform)=="windows"} {
   305    361       lappend result sh
   306    362     }
   307         -  lappend result $::SRCDIR/configure -enable-load-extension >& test.log
          363  +  lappend result $::SRCDIR/configure --enable-load-extension
          364  +  foreach x $opts {lappend result $x}
          365  +  lappend result >& test.log
   308    366   }
   309    367   
   310    368   # The following procedure returns the "make" command to be executed for the
   311    369   # specified targets, compiler flags, and options.
   312    370   #
   313    371   proc makeCommand { targets cflags opts } {
   314         -  set result [list dryrun exec make clean]
          372  +  set result [list trace_cmd exec make clean]
   315    373     foreach target $targets {
   316    374       lappend result $target
   317    375     }
   318    376     lappend result CFLAGS=$cflags OPTS=$opts >>& test.log
   319    377   }
   320    378   
   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).
          379  +# The following procedure prints its arguments if ::TRACE is true.
          380  +# And it executes the command of its arguments in the calling context
          381  +# if ::DRYRUN is false.
   324    382   #
   325         -proc dryrun {args} {
   326         -  if {$::DRYRUN} {
          383  +proc trace_cmd {args} {
          384  +  if {$::TRACE} {
   327    385       puts $args
   328         -  } else {
          386  +  }
          387  +  if {!$::DRYRUN} {
   329    388       uplevel 1 $args
   330    389     }
   331    390   }
   332    391   
   333    392   
   334    393   # This proc processes the command line options passed to this script.
   335    394   # Currently the only option supported is "-makefile", default
................................................................................
   338    397   #
   339    398   proc process_options {argv} {
   340    399     set ::SRCDIR    [file normalize [file dirname [file dirname $::argv0]]]
   341    400     set ::QUICK     0
   342    401     set ::BUILDONLY 0
   343    402     set ::DRYRUN    0
   344    403     set ::EXEC      exec
          404  +  set ::TRACE     0
   345    405     set config {}
   346    406     set platform $::tcl_platform(os)-$::tcl_platform(machine)
   347    407   
   348    408     for {set i 0} {$i < [llength $argv]} {incr i} {
   349    409       set x [lindex $argv $i]
   350    410       if {[regexp {^--[a-z]} $x]} {set x [string range $x 1 end]}
   351         -    switch -- $x {
          411  +    switch -glob -- $x {
   352    412         -srcdir {
   353    413           incr i
   354    414           set ::SRCDIR [file normalize [lindex $argv $i]]
   355    415         }
   356    416   
   357    417         -platform {
   358    418           incr i
   359    419           set platform [lindex $argv $i]
   360    420         }
   361    421   
   362    422         -quick {
   363    423           set ::QUICK 1
   364    424         }
          425  +      -veryquick {
          426  +        set ::QUICK 2
          427  +      }
   365    428   
   366    429         -config {
   367    430           incr i
   368    431           set config [lindex $argv $i]
   369    432         }
   370    433   
   371    434         -buildonly {
   372    435           set ::BUILDONLY 1
   373    436         }
   374    437   
   375    438         -dryrun {
   376    439           set ::DRYRUN 1
   377    440         }
          441  +
          442  +      -trace {
          443  +        set ::TRACE 1
          444  +      }
   378    445   
   379    446         -info {
   380    447           puts "Command-line Options:"
   381    448           puts "   --srcdir $::SRCDIR"
   382    449           puts "   --platform [list $platform]"
   383    450           puts "   --config [list $config]"
   384    451           if {$::QUICK}     {puts "   --quick"}
   385    452           if {$::BUILDONLY} {puts "   --buildonly"}
   386    453           if {$::DRYRUN}    {puts "   --dryrun"}
          454  +        if {$::TRACE}     {puts "   --trace"}
   387    455           puts "\nAvailable --platform options:"
   388    456           foreach y [lsort [array names ::Platforms]] {
   389    457             puts "   [list $y]"
   390    458           }
   391    459           puts "\nAvailable --config options:"
   392    460           foreach y [lsort [array names ::Configs]] {
   393    461             puts "   [list $y]"
   394    462           }
   395    463           exit
   396    464         }
          465  +      -g -
          466  +      -D* -
          467  +      -O* -
          468  +      -enable-* -
          469  +      -disable-* -
          470  +      *=* {
          471  +        lappend ::EXTRACONFIG [lindex $argv $i]
          472  +      }
   397    473   
   398    474         default {
   399    475           puts stderr ""
   400    476           puts stderr [string trim $::USAGE_MESSAGE]
   401    477           exit -1
   402    478         }
   403    479       }
................................................................................
   422    498       set ::CONFIGLIST $::Platforms($platform)
   423    499     }
   424    500     puts "Running the following test configurations for $platform:"
   425    501     puts "    [string trim $::CONFIGLIST]"
   426    502     puts -nonewline "Flags:"
   427    503     if {$::DRYRUN} {puts -nonewline " --dryrun"}
   428    504     if {$::BUILDONLY} {puts -nonewline " --buildonly"}
   429         -  if {$::QUICK} {puts -nonewline " --quick"}
          505  +  switch -- $::QUICK {
          506  +     1 {puts -nonewline " --quick"}
          507  +     2 {puts -nonewline " --veryquick"}
          508  +  }
   430    509     puts ""
   431    510   }
   432    511   
   433    512   # Main routine.
   434    513   #
   435    514   proc main {argv} {
   436    515   
   437    516     # Process any command line options.
          517  +  set ::EXTRACONFIG {}
   438    518     process_options $argv
   439         -  puts [string repeat * 70]
          519  +  puts [string repeat * 79]
   440    520   
   441    521     set ::NERR 0
   442    522     set ::NTEST 0
   443    523     set ::NTESTCASE 0
   444    524     set ::NERRCASE 0
          525  +  set ::SQLITE_VERSION {}
   445    526     set STARTTIME [clock seconds]
   446    527     foreach {zConfig target} $::CONFIGLIST {
   447         -    if {$::QUICK} {set target test}
   448         -    if {$::BUILDONLY} {set target testfixture}
   449         -    set config_options $::Configs($zConfig)
          528  +    if {$target ne "checksymbols"} {
          529  +      switch -- $::QUICK {
          530  +         1 {set target test}
          531  +         2 {set target smoketest}
          532  +      }
          533  +      if {$::BUILDONLY} {set target testfixture}
          534  +    }
          535  +    set config_options [concat $::Configs($zConfig) $::EXTRACONFIG]
   450    536   
   451    537       incr NTEST
   452    538       run_test_suite $zConfig $target $config_options
   453    539   
   454    540       # If the configuration included the SQLITE_DEBUG option, then remove
   455    541       # it and run veryquick.test. If it did not include the SQLITE_DEBUG option
   456    542       # add it and run veryquick.test.
   457         -    if {$target!="checksymbols" && !$::BUILDONLY} {
          543  +    if {$target!="checksymbols" && $target!="valgrindtest"
          544  +           && !$::BUILDONLY && $::QUICK<2} {
   458    545         set debug_idx [lsearch -glob $config_options -DSQLITE_DEBUG*]
   459    546         set xtarget $target
   460         -      regsub -all {fulltest[a-z]+} $xtarget test xtarget
          547  +      regsub -all {fulltest[a-z]*} $xtarget test xtarget
   461    548         if {$debug_idx < 0} {
   462    549           incr NTEST
   463    550           append config_options " -DSQLITE_DEBUG=1"
   464    551           run_test_suite "${zConfig}_debug" $xtarget $config_options
   465    552         } else {
   466    553           incr NTEST
   467    554           regsub { *-DSQLITE_MEMDEBUG[^ ]* *} $config_options { } config_options
................................................................................
   472    559     }
   473    560   
   474    561     set elapsetime [expr {[clock seconds]-$STARTTIME}]
   475    562     set hr [expr {$elapsetime/3600}]
   476    563     set min [expr {($elapsetime/60)%60}]
   477    564     set sec [expr {$elapsetime%60}]
   478    565     set etime [format (%02d:%02d:%02d) $hr $min $sec]
   479         -  puts [string repeat * 70]
   480         -  puts "$::NERRCASE failures of $::NTESTCASE tests run in $etime"
          566  +  puts [string repeat * 79]
          567  +  puts "$::NERRCASE failures out of $::NTESTCASE tests in $etime"
          568  +  if {$::SQLITE_VERSION ne ""} {
          569  +    puts "SQLite $::SQLITE_VERSION"
          570  +  }
   481    571   }
   482    572   
   483    573   main $argv

Added test/selectG.test.

            1  +# 2015-01-05
            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  +# This file verifies that INSERT operations with a very large number of
           13  +# VALUE terms works and does not hit the SQLITE_LIMIT_COMPOUND_SELECT limit.
           14  +#
           15  +
           16  +set testdir [file dirname $argv0]
           17  +source $testdir/tester.tcl
           18  +set testprefix selectG
           19  +
           20  +# Do an INSERT with a VALUES clause that contains 100,000 entries.  Verify
           21  +# that this insert happens quickly (in less than 10 seconds).  Actually, the
           22  +# insert will normally happen in less than 0.5 seconds on a workstation, but
           23  +# we allow plenty of overhead for slower machines.  The speed test checks
           24  +# for an O(N*N) inefficiency that was once in the code and that would make
           25  +# the insert run for over a minute.
           26  +#
           27  +do_test 100 {
           28  +  set sql "CREATE TABLE t1(x);\nINSERT INTO t1(x) VALUES"
           29  +  for {set i 1} {$i<100000} {incr i} {
           30  +    append sql "($i),"
           31  +  }
           32  +  append sql "($i);"
           33  +  set microsec [lindex [time {db eval $sql}] 0]
           34  +  db eval {
           35  +    SELECT count(x), sum(x), avg(x), $microsec<10000000 FROM t1;
           36  +  }
           37  +} {100000 5000050000 50000.5 1}
           38  +  
           39  +finish_test

Changes to test/sort.test.

    12     12   # This file implements regression tests for SQLite library.  The
    13     13   # focus of this file is testing the sorter (code in vdbesort.c).
    14     14   #
    15     15   
    16     16   set testdir [file dirname $argv0]
    17     17   source $testdir/tester.tcl
    18     18   set testprefix sort
           19  +db close
           20  +sqlite3_shutdown
           21  +sqlite3_config_pmasz 10
           22  +sqlite3_initialize
           23  +sqlite3 db test.db
    19     24   
    20     25   # Create a bunch of data to sort against
    21     26   #
    22     27   do_test sort-1.0 {
    23     28     execsql {
    24     29       CREATE TABLE t1(
    25     30          n int,

Changes to test/sort2.test.

    13     13   # Specifically, the tests in this file attempt to verify that 
    14     14   # multi-threaded sorting works.
    15     15   #
    16     16   
    17     17   set testdir [file dirname $argv0]
    18     18   source $testdir/tester.tcl
    19     19   set testprefix sort2
           20  +db close
           21  +sqlite3_shutdown
           22  +sqlite3_config_pmasz 10
           23  +sqlite3_initialize
           24  +sqlite3 db test.db
    20     25   
    21     26   foreach {tn script} {
    22     27     1 { }
    23     28     2 {
    24     29       catch { db close }
    25     30       reset_db
    26     31       catch { db eval {PRAGMA threads=7} }

Changes to test/sort4.test.

    13     13   # The tests in this file are brute force tests of the multi-threaded
    14     14   # sorter.
    15     15   #
    16     16   
    17     17   set testdir [file dirname $argv0]
    18     18   source $testdir/tester.tcl
    19     19   set testprefix sort4
           20  +db close
           21  +sqlite3_shutdown
           22  +sqlite3_config_pmasz 10
           23  +sqlite3_initialize
           24  +sqlite3 db test.db
           25  +
    20     26   
    21     27   # Configure the sorter to use 3 background threads.
    22     28   db eval {PRAGMA threads=3}
    23     29   
    24     30   # Minimum number of seconds to run for. If the value is 0, each test
    25     31   # is run exactly once. Otherwise, tests are repeated until the timeout
    26     32   # expires.

Changes to test/sortfault.test.

    13     13   # Specifically, it tests the effects of fault injection on the sorter
    14     14   # module (code in vdbesort.c).
    15     15   #
    16     16   
    17     17   set testdir [file dirname $argv0]
    18     18   source $testdir/tester.tcl
    19     19   set testprefix sortfault
           20  +db close
           21  +sqlite3_shutdown
           22  +sqlite3_config_pmasz 10
           23  +sqlite3_initialize
           24  +sqlite3 db test.db
           25  +
    20     26   
    21     27   do_execsql_test 1.0 {
    22     28     PRAGMA cache_size = 5;
    23     29   }
    24     30   
    25     31   foreach {tn mmap_limit nWorker tmpstore threadsmode fakeheap lookaside} {
    26     32             1          0       0     file multithread    false     false

Changes to test/threadtest3.c.

   443    443     sqlite3_free(p->zErr);
   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         -    printf("Error: (%d) \"%s\" at line %d\n", p->rc, p->zErr, p->iLine);
   451         -    if( sqlite3_strglob("* - no such table: *",p->zErr)!=0 ) nGlobalErr++;
          450  +    int isWarn = 0;
          451  +    if( p->rc==SQLITE_SCHEMA ) isWarn = 1;
          452  +    if( sqlite3_strglob("* - no such table: *",p->zErr)==0 ) isWarn = 1;
          453  +    printf("%s: (%d) \"%s\" at line %d\n", isWarn ? "Warning" : "Error",
          454  +            p->rc, p->zErr, p->iLine);
          455  +    if( !isWarn ) nGlobalErr++;
   452    456       fflush(stdout);
   453    457     }
   454    458   }
   455    459   
   456    460   static void print_and_free_err(Error *p){
   457    461     print_err(p);
   458    462     free_err(p);
................................................................................
   977    981     sql_script(&err, &db,
   978    982         "PRAGMA journal_mode = WAL;"
   979    983         "CREATE TABLE t1(x PRIMARY KEY);"
   980    984         "INSERT INTO t1 VALUES(randomblob(100));"
   981    985         "INSERT INTO t1 VALUES(randomblob(100));"
   982    986         "INSERT INTO t1 SELECT md5sum(x) FROM t1;"
   983    987     );
          988  +  closedb(&err, &db);
   984    989   
   985    990     setstoptime(&err, nMs);
   986    991     for(i=0; i<WALTHREAD1_NTHREAD; i++){
   987    992       launch_thread(&err, &threads, walthread1_thread, 0);
   988    993     }
   989    994     launch_thread(&err, &threads, walthread1_ckpt_thread, 0);
   990    995     join_all_threads(&err, &threads);
................................................................................
  1429   1434       int nMs;              /* How long to run this test, in milliseconds */
  1430   1435     } aTest[] = {
  1431   1436       { walthread1, "walthread1", 20000 },
  1432   1437       { walthread2, "walthread2", 20000 },
  1433   1438       { walthread3, "walthread3", 20000 },
  1434   1439       { walthread4, "walthread4", 20000 },
  1435   1440       { walthread5, "walthread5",  1000 },
  1436         -    { walthread5, "walthread5",  1000 },
  1437   1441       
  1438   1442       { cgt_pager_1,      "cgt_pager_1", 0 },
  1439   1443       { dynamic_triggers, "dynamic_triggers", 20000 },
  1440   1444   
  1441   1445       { checkpoint_starvation_1, "checkpoint_starvation_1", 10000 },
  1442   1446       { checkpoint_starvation_2, "checkpoint_starvation_2", 10000 },
  1443   1447   
  1444   1448       { create_drop_index_1, "create_drop_index_1", 10000 },
  1445   1449       { lookaside1,          "lookaside1", 10000 },
  1446   1450       { vacuum1,             "vacuum1", 10000 },
  1447   1451       { stress1,             "stress1", 10000 },
  1448   1452       { stress2,             "stress2", 60000 },
  1449   1453     };
  1450         -
  1451         -  int i;
         1454  +  static char *substArgv[] = { 0, "*", 0 };
         1455  +  int i, iArg;
  1452   1456     int nTestfound = 0;
  1453   1457   
  1454   1458     sqlite3_config(SQLITE_CONFIG_MULTITHREAD);
  1455         -  sqlite3_config(SQLITE_CONFIG_MULTITHREAD);
  1456         -
  1457         -  for(i=0; i<sizeof(aTest)/sizeof(aTest[0]); i++){
  1458         -    char const *z = aTest[i].zTest;
  1459         -    if( argc>1 ){
  1460         -      int iArg;
  1461         -      for(iArg=1; iArg<argc; iArg++){
  1462         -        if( 0==sqlite3_strglob(argv[iArg], z) ) break;
  1463         -      }
  1464         -      if( iArg==argc ) continue;
         1459  +  if( argc<2 ){
         1460  +    argc = 2;
         1461  +    argv = substArgv;
         1462  +  }
         1463  +  for(iArg=1; iArg<argc; iArg++){
         1464  +    for(i=0; i<sizeof(aTest)/sizeof(aTest[0]); i++){
         1465  +      if( sqlite3_strglob(argv[iArg],aTest[i].zTest)==0 ) break;
  1465   1466       }
  1466         -
  1467         -    printf("Running %s for %d seconds...\n", z, aTest[i].nMs/1000);
  1468         -    fflush(stdout);
  1469         -    aTest[i].xTest(aTest[i].nMs);
  1470         -    nTestfound++;
         1467  +    if( i>=sizeof(aTest)/sizeof(aTest[0]) ) goto usage;   
         1468  +  }
         1469  +  for(iArg=1; iArg<argc; iArg++){
         1470  +    for(i=0; i<sizeof(aTest)/sizeof(aTest[0]); i++){
         1471  +      char const *z = aTest[i].zTest;
         1472  +      if( sqlite3_strglob(argv[iArg],z)==0 ){
         1473  +        printf("Running %s for %d seconds...\n", z, aTest[i].nMs/1000);
         1474  +        fflush(stdout);
         1475  +        aTest[i].xTest(aTest[i].nMs);
         1476  +        nTestfound++;
         1477  +      }
         1478  +    }
  1471   1479     }
  1472   1480     if( nTestfound==0 ) goto usage;
  1473   1481   
  1474   1482     printf("%d errors out of %d tests\n", nGlobalErr, nTestfound);
  1475   1483     return (nGlobalErr>0 ? 255 : 0);
  1476   1484   
  1477   1485    usage:

Changes to tool/lemon.c.

  1493   1493     static int mhflag = 0;
  1494   1494     static int nolinenosflag = 0;
  1495   1495     static int noResort = 0;
  1496   1496     static struct s_options options[] = {
  1497   1497       {OPT_FLAG, "b", (char*)&basisflag, "Print only the basis in report."},
  1498   1498       {OPT_FLAG, "c", (char*)&compress, "Don't compress the action table."},
  1499   1499       {OPT_FSTR, "D", (char*)handle_D_option, "Define an %ifdef macro."},
  1500         -    {OPT_FSTR, "T", (char*)handle_T_option, "Specify a template file."},
         1500  +    {OPT_FSTR, "f", 0, "Ignored.  (Placeholder for -f compiler options.)"},
  1501   1501       {OPT_FLAG, "g", (char*)&rpflag, "Print grammar without actions."},
         1502  +    {OPT_FSTR, "I", 0, "Ignored.  (Placeholder for '-I' compiler options.)"},
  1502   1503       {OPT_FLAG, "m", (char*)&mhflag, "Output a makeheaders compatible file."},
  1503   1504       {OPT_FLAG, "l", (char*)&nolinenosflag, "Do not print #line statements."},
         1505  +    {OPT_FSTR, "O", 0, "Ignored.  (Placeholder for '-O' compiler options.)"},
  1504   1506       {OPT_FLAG, "p", (char*)&showPrecedenceConflict,
  1505   1507                       "Show conflicts resolved by precedence rules"},
  1506   1508       {OPT_FLAG, "q", (char*)&quiet, "(Quiet) Don't print the report file."},
  1507   1509       {OPT_FLAG, "r", (char*)&noResort, "Do not sort or renumber states"},
  1508   1510       {OPT_FLAG, "s", (char*)&statistics,
  1509   1511                                      "Print parser stats to standard output."},
  1510   1512       {OPT_FLAG, "x", (char*)&version, "Print the version number."},
         1513  +    {OPT_FSTR, "T", (char*)handle_T_option, "Specify a template file."},
         1514  +    {OPT_FSTR, "W", 0, "Ignored.  (Placeholder for '-W' compiler options.)"},
  1511   1515       {OPT_FLAG,0,0,0}
  1512   1516     };
  1513   1517     int i;
  1514   1518     int exitcode;
  1515   1519     struct lemon lem;
  1516   1520   
  1517   1521     OptInit(argv,options,stderr);
................................................................................
  1808   1812     v = argv[i][0]=='-' ? 1 : 0;
  1809   1813     if( op[j].label==0 ){
  1810   1814       if( err ){
  1811   1815         fprintf(err,"%sundefined option.\n",emsg);
  1812   1816         errline(i,1,err);
  1813   1817       }
  1814   1818       errcnt++;
         1819  +  }else if( op[j].arg==0 ){
         1820  +    /* Ignore this option */
  1815   1821     }else if( op[j].type==OPT_FLAG ){
  1816   1822       *((int*)op[j].arg) = v;
  1817   1823     }else if( op[j].type==OPT_FFLAG ){
  1818   1824       (*(void(*)(int))(op[j].arg))(v);
  1819   1825     }else if( op[j].type==OPT_FSTR ){
  1820   1826       (*(void(*)(char *))(op[j].arg))(&argv[i][2]);
  1821   1827     }else{
................................................................................
  1997   2003       switch( op[i].type ){
  1998   2004         case OPT_FLAG:
  1999   2005         case OPT_FFLAG:
  2000   2006           fprintf(errstream,"  -%-*s  %s\n",max,op[i].label,op[i].message);
  2001   2007           break;
  2002   2008         case OPT_INT:
  2003   2009         case OPT_FINT:
  2004         -        fprintf(errstream,"  %s=<integer>%*s  %s\n",op[i].label,
         2010  +        fprintf(errstream,"  -%s<integer>%*s  %s\n",op[i].label,
  2005   2011             (int)(max-lemonStrlen(op[i].label)-9),"",op[i].message);
  2006   2012           break;
  2007   2013         case OPT_DBL:
  2008   2014         case OPT_FDBL:
  2009         -        fprintf(errstream,"  %s=<real>%*s  %s\n",op[i].label,
         2015  +        fprintf(errstream,"  -%s<real>%*s  %s\n",op[i].label,
  2010   2016             (int)(max-lemonStrlen(op[i].label)-6),"",op[i].message);
  2011   2017           break;
  2012   2018         case OPT_STR:
  2013   2019         case OPT_FSTR:
  2014         -        fprintf(errstream,"  %s=<string>%*s  %s\n",op[i].label,
         2020  +        fprintf(errstream,"  -%s<string>%*s  %s\n",op[i].label,
  2015   2021             (int)(max-lemonStrlen(op[i].label)-8),"",op[i].message);
  2016   2022           break;
  2017   2023       }
  2018   2024     }
  2019   2025   }
  2020   2026   /*********************** From the file "parse.c" ****************************/
  2021   2027   /*