/ Check-in [d7381eff]
Login

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

Overview
Comment:Merge 3.12.0 changes.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | begin-concurrent
Files: files | file ages | folders
SHA1: d7381efff47c0a2f307478f196d03df7534f19e3
User & Date: drh 2016-03-29 10:36:07
Wiki:begin-concurrent
Context
2016-04-20
12:16
Merge all recent enhancements from trunk. check-in: 1f709fbf user: drh tags: begin-concurrent
2016-03-29
10:36
Merge 3.12.0 changes. check-in: d7381eff user: drh tags: begin-concurrent
10:14
Version 3.12.0 check-in: e9bb4cf4 user: drh tags: trunk, release, version-3.12.0
2016-03-21
15:54
Merge all recent changes from trunk. check-in: 8ee7d346 user: drh tags: begin-concurrent
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to ext/fts5/fts5Int.h.

    43     43   ** Constants for the largest and smallest possible 64-bit signed integers.
    44     44   */
    45     45   # define LARGEST_INT64  (0xffffffff|(((i64)0x7fffffff)<<32))
    46     46   # define SMALLEST_INT64 (((i64)-1) - LARGEST_INT64)
    47     47   
    48     48   #endif
    49     49   
           50  +/* Truncate very long tokens to this many bytes. Hard limit is 
           51  +** (65536-1-1-4-9)==65521 bytes. The limiting factor is the 16-bit offset
           52  +** field that occurs at the start of each leaf page (see fts5_index.c). */
           53  +#define FTS5_MAX_TOKEN_SIZE 32768
    50     54   
    51     55   /*
    52     56   ** Maximum number of prefix indexes on single FTS5 table. This must be
    53     57   ** less than 32. If it is set to anything large than that, an #error
    54     58   ** directive in fts5_index.c will cause the build to fail.
    55     59   */
    56     60   #define FTS5_MAX_PREFIX_INDEXES 31

Changes to ext/fts5/fts5_expr.c.

  1489   1489     TokenCtx *pCtx = (TokenCtx*)pContext;
  1490   1490     Fts5ExprPhrase *pPhrase = pCtx->pPhrase;
  1491   1491   
  1492   1492     UNUSED_PARAM2(iUnused1, iUnused2);
  1493   1493   
  1494   1494     /* If an error has already occurred, this is a no-op */
  1495   1495     if( pCtx->rc!=SQLITE_OK ) return pCtx->rc;
         1496  +  if( nToken>FTS5_MAX_TOKEN_SIZE ) nToken = FTS5_MAX_TOKEN_SIZE;
  1496   1497   
  1497   1498     if( pPhrase && pPhrase->nTerm>0 && (tflags & FTS5_TOKEN_COLOCATED) ){
  1498   1499       Fts5ExprTerm *pSyn;
  1499   1500       int nByte = sizeof(Fts5ExprTerm) + sizeof(Fts5Buffer) + nToken+1;
  1500   1501       pSyn = (Fts5ExprTerm*)sqlite3_malloc(nByte);
  1501   1502       if( pSyn==0 ){
  1502   1503         rc = SQLITE_NOMEM;
................................................................................
  2491   2492   ){
  2492   2493     Fts5ExprCtx *p = (Fts5ExprCtx*)pCtx;
  2493   2494     Fts5Expr *pExpr = p->pExpr;
  2494   2495     int i;
  2495   2496   
  2496   2497     UNUSED_PARAM2(iUnused1, iUnused2);
  2497   2498   
         2499  +  if( nToken>FTS5_MAX_TOKEN_SIZE ) nToken = FTS5_MAX_TOKEN_SIZE;
  2498   2500     if( (tflags & FTS5_TOKEN_COLOCATED)==0 ) p->iOff++;
  2499   2501     for(i=0; i<pExpr->nPhrase; i++){
  2500   2502       Fts5ExprTerm *pTerm;
  2501   2503       if( p->aPopulator[i].bOk==0 ) continue;
  2502   2504       for(pTerm=&pExpr->apExprPhrase[i]->aTerm[0]; pTerm; pTerm=pTerm->pSynonym){
  2503   2505         int nTerm = (int)strlen(pTerm->zTerm);
  2504   2506         if( (nTerm==nToken || (nTerm<nToken && pTerm->bPrefix))

Changes to ext/fts5/fts5_index.c.

  1023   1023     if( p->pStruct==0 ){
  1024   1024       p->iStructVersion = fts5IndexDataVersion(p);
  1025   1025       if( p->rc==SQLITE_OK ){
  1026   1026         p->pStruct = fts5StructureReadUncached(p);
  1027   1027       }
  1028   1028     }
  1029   1029   
  1030         -#ifdef SQLITE_DEBUG
         1030  +#if 0
  1031   1031     else{
  1032   1032       Fts5Structure *pTest = fts5StructureReadUncached(p);
  1033   1033       if( pTest ){
  1034   1034         int i, j;
  1035   1035         assert_nc( p->pStruct->nSegment==pTest->nSegment );
  1036   1036         assert_nc( p->pStruct->nLevel==pTest->nLevel );
  1037   1037         for(i=0; i<pTest->nLevel; i++){
................................................................................
  2316   2316       pIter->iEndofDoclist = iTermOff + nExtra;
  2317   2317     }
  2318   2318     pIter->iPgidxOff = iPgidx;
  2319   2319   
  2320   2320     fts5SegIterLoadRowid(p, pIter);
  2321   2321     fts5SegIterLoadNPos(p, pIter);
  2322   2322   }
         2323  +
         2324  +static sqlite3_stmt *fts5IdxSelectStmt(Fts5Index *p){
         2325  +  if( p->pIdxSelect==0 ){
         2326  +    Fts5Config *pConfig = p->pConfig;
         2327  +    fts5IndexPrepareStmt(p, &p->pIdxSelect, sqlite3_mprintf(
         2328  +          "SELECT pgno FROM '%q'.'%q_idx' WHERE "
         2329  +          "segid=? AND term<=? ORDER BY term DESC LIMIT 1",
         2330  +          pConfig->zDb, pConfig->zName
         2331  +    ));
         2332  +  }
         2333  +  return p->pIdxSelect;
         2334  +}
  2323   2335   
  2324   2336   /*
  2325   2337   ** Initialize the object pIter to point to term pTerm/nTerm within segment
  2326   2338   ** pSeg. If there is no such term in the index, the iterator is set to EOF.
  2327   2339   **
  2328   2340   ** If an error occurs, Fts5Index.rc is set to an appropriate error code. If 
  2329   2341   ** an error has already occurred when this function is called, it is a no-op.
................................................................................
  2334   2346     int flags,                      /* Mask of FTS5INDEX_XXX flags */
  2335   2347     Fts5StructureSegment *pSeg,     /* Description of segment */
  2336   2348     Fts5SegIter *pIter              /* Object to populate */
  2337   2349   ){
  2338   2350     int iPg = 1;
  2339   2351     int bGe = (flags & FTS5INDEX_QUERY_SCAN);
  2340   2352     int bDlidx = 0;                 /* True if there is a doclist-index */
         2353  +  sqlite3_stmt *pIdxSelect = 0;
  2341   2354   
  2342   2355     assert( bGe==0 || (flags & FTS5INDEX_QUERY_DESC)==0 );
  2343   2356     assert( pTerm && nTerm );
  2344   2357     memset(pIter, 0, sizeof(*pIter));
  2345   2358     pIter->pSeg = pSeg;
  2346   2359   
  2347   2360     /* This block sets stack variable iPg to the leaf page number that may
  2348   2361     ** contain term (pTerm/nTerm), if it is present in the segment. */
  2349         -  if( p->pIdxSelect==0 ){
  2350         -    Fts5Config *pConfig = p->pConfig;
  2351         -    fts5IndexPrepareStmt(p, &p->pIdxSelect, sqlite3_mprintf(
  2352         -          "SELECT pgno FROM '%q'.'%q_idx' WHERE "
  2353         -          "segid=? AND term<=? ORDER BY term DESC LIMIT 1",
  2354         -          pConfig->zDb, pConfig->zName
  2355         -    ));
  2356         -  }
         2362  +  pIdxSelect = fts5IdxSelectStmt(p);
  2357   2363     if( p->rc ) return;
  2358         -  sqlite3_bind_int(p->pIdxSelect, 1, pSeg->iSegid);
  2359         -  sqlite3_bind_blob(p->pIdxSelect, 2, pTerm, nTerm, SQLITE_STATIC);
  2360         -  if( SQLITE_ROW==sqlite3_step(p->pIdxSelect) ){
  2361         -    i64 val = sqlite3_column_int(p->pIdxSelect, 0);
         2364  +  sqlite3_bind_int(pIdxSelect, 1, pSeg->iSegid);
         2365  +  sqlite3_bind_blob(pIdxSelect, 2, pTerm, nTerm, SQLITE_STATIC);
         2366  +  if( SQLITE_ROW==sqlite3_step(pIdxSelect) ){
         2367  +    i64 val = sqlite3_column_int(pIdxSelect, 0);
  2362   2368       iPg = (int)(val>>1);
  2363   2369       bDlidx = (val & 0x0001);
  2364   2370     }
  2365         -  p->rc = sqlite3_reset(p->pIdxSelect);
         2371  +  p->rc = sqlite3_reset(pIdxSelect);
  2366   2372   
  2367   2373     if( iPg<pSeg->pgnoFirst ){
  2368   2374       iPg = pSeg->pgnoFirst;
  2369   2375       bDlidx = 0;
  2370   2376     }
  2371   2377   
  2372   2378     pIter->iLeafPgno = iPg - 1;
................................................................................
  3548   3554   #ifdef SQLITE_DEBUG
  3549   3555         for(iLvl=0; iLvl<pStruct->nLevel; iLvl++){
  3550   3556           for(iSeg=0; iSeg<pStruct->aLevel[iLvl].nSeg; iSeg++){
  3551   3557             assert( iSegid!=pStruct->aLevel[iLvl].aSeg[iSeg].iSegid );
  3552   3558           }
  3553   3559         }
  3554   3560         assert( iSegid>0 && iSegid<=FTS5_MAX_SEGMENT );
         3561  +
         3562  +      {
         3563  +        sqlite3_stmt *pIdxSelect = fts5IdxSelectStmt(p);
         3564  +        if( p->rc==SQLITE_OK ){
         3565  +          u8 aBlob[2] = {0xff, 0xff};
         3566  +          sqlite3_bind_int(pIdxSelect, 1, iSegid);
         3567  +          sqlite3_bind_blob(pIdxSelect, 2, aBlob, 2, SQLITE_STATIC);
         3568  +          assert( sqlite3_step(pIdxSelect)!=SQLITE_ROW );
         3569  +          p->rc = sqlite3_reset(pIdxSelect);
         3570  +        }
         3571  +      }
  3555   3572   #endif
  3556   3573       }
  3557   3574     }
  3558   3575   
  3559   3576     return iSegid;
  3560   3577   }
  3561   3578   
................................................................................
  3793   3810     }
  3794   3811   }
  3795   3812   
  3796   3813   static void fts5WriteFlushLeaf(Fts5Index *p, Fts5SegWriter *pWriter){
  3797   3814     static const u8 zero[] = { 0x00, 0x00, 0x00, 0x00 };
  3798   3815     Fts5PageWriter *pPage = &pWriter->writer;
  3799   3816     i64 iRowid;
         3817  +
         3818  +static int nCall = 0;
         3819  +nCall++;
  3800   3820   
  3801   3821     assert( (pPage->pgidx.n==0)==(pWriter->bFirstTermInPage) );
  3802   3822   
  3803   3823     /* Set the szLeaf header field. */
  3804   3824     assert( 0==fts5GetU16(&pPage->buf.p[2]) );
  3805   3825     fts5PutU16(&pPage->buf.p[2], (u16)pPage->buf.n);
  3806   3826   
................................................................................
  4599   4619     }
  4600   4620   
  4601   4621     nByte += (pStruct->nLevel+1) * sizeof(Fts5StructureLevel);
  4602   4622     pNew = (Fts5Structure*)sqlite3Fts5MallocZero(&p->rc, nByte);
  4603   4623   
  4604   4624     if( pNew ){
  4605   4625       Fts5StructureLevel *pLvl;
  4606         -    int nByte = nSeg * sizeof(Fts5StructureSegment);
         4626  +    nByte = nSeg * sizeof(Fts5StructureSegment);
  4607   4627       pNew->nLevel = pStruct->nLevel+1;
  4608   4628       pNew->nRef = 1;
  4609   4629       pNew->nWriteCounter = pStruct->nWriteCounter;
  4610   4630       pLvl = &pNew->aLevel[pStruct->nLevel];
  4611   4631       pLvl->aSeg = (Fts5StructureSegment*)sqlite3Fts5MallocZero(&p->rc, nByte);
  4612   4632       if( pLvl->aSeg ){
  4613   4633         int iLvl, iSeg;

Changes to ext/fts5/fts5_storage.c.

   365    365     int nToken,                     /* Size of token in bytes */
   366    366     int iUnused1,                   /* Start offset of token */
   367    367     int iUnused2                    /* End offset of token */
   368    368   ){
   369    369     Fts5InsertCtx *pCtx = (Fts5InsertCtx*)pContext;
   370    370     Fts5Index *pIdx = pCtx->pStorage->pIndex;
   371    371     UNUSED_PARAM2(iUnused1, iUnused2);
          372  +  if( nToken>FTS5_MAX_TOKEN_SIZE ) nToken = FTS5_MAX_TOKEN_SIZE;
   372    373     if( (tflags & FTS5_TOKEN_COLOCATED)==0 || pCtx->szCol==0 ){
   373    374       pCtx->szCol++;
   374    375     }
   375    376     return sqlite3Fts5IndexWrite(pIdx, pCtx->iCol, pCtx->szCol-1, pToken, nToken);
   376    377   }
   377    378   
   378    379   /*
................................................................................
   811    812     int bPresent;
   812    813     int ii;
   813    814     int rc = SQLITE_OK;
   814    815     int iPos;
   815    816     int iCol;
   816    817   
   817    818     UNUSED_PARAM2(iUnused1, iUnused2);
          819  +  if( nToken>FTS5_MAX_TOKEN_SIZE ) nToken = FTS5_MAX_TOKEN_SIZE;
   818    820   
   819    821     if( (tflags & FTS5_TOKEN_COLOCATED)==0 || pCtx->szCol==0 ){
   820    822       pCtx->szCol++;
   821    823     }
   822    824   
   823    825     switch( pCtx->pConfig->eDetail ){
   824    826       case FTS5_DETAIL_FULL:

Changes to ext/fts5/test/fts5aa.test.

   428    428     set fd [db incrblob main n1_data block 10]
   429    429     fconfigure $fd -encoding binary -translation binary
   430    430     puts -nonewline $fd "\x44\x45"
   431    431     close $fd
   432    432   }
   433    433   db func funk funk
   434    434   
          435  +# This test case corrupts the structure record within the first invocation
          436  +# of function funk(). Which used to cause the bm25() function to throw an
          437  +# exception. But since bm25() can now used the cached structure record,
          438  +# it never sees the corruption introduced by funk() and so the following 
          439  +# statement no longer fails.
          440  +#
   435    441   do_catchsql_test 16.2 {
   436    442     SELECT funk(), bm25(n1), funk() FROM n1 WHERE n1 MATCH 'a+b+c+d'
   437         -} {1 {SQL logic error or missing database}}
          443  +} {0 {{} -1e-06 {}}}
          444  +# {1 {SQL logic error or missing database}}
   438    445   
   439    446   #-------------------------------------------------------------------------
   440    447   #
   441    448   reset_db
   442    449   do_execsql_test 17.1 {
   443    450     CREATE VIRTUAL TABLE b2 USING fts5(x, detail=%DETAIL%);
   444    451     INSERT INTO b2 VALUES('a');

Added ext/fts5/test/fts5determin.test.

            1  +# 2016 March 21
            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  +# This file implements regression tests for SQLite library.  The
           12  +# focus of this script is testing the FTS5 module.
           13  +#
           14  +# Specifically, that the fts5 module is deterministic. At one point, when
           15  +# segment ids were allocated using sqlite3_randomness(), this was not the
           16  +# case.
           17  +#
           18  +
           19  +source [file join [file dirname [info script]] fts5_common.tcl]
           20  +set testprefix fts5aa
           21  +return_if_no_fts5 
           22  +
           23  +proc do_determin_test {tn} {
           24  +  uplevel [list
           25  +    do_execsql_test $tn {
           26  +      SELECT (SELECT md5sum(id, block) FROM t1_data)==
           27  +             (SELECT md5sum(id, block) FROM t2_data),
           28  +             (SELECT md5sum(id, block) FROM t1_data)==
           29  +             (SELECT md5sum(id, block) FROM t3_data)
           30  +    } {1 1}
           31  +  ]
           32  +}
           33  +
           34  +foreach_detail_mode $::testprefix {
           35  +  do_execsql_test 1.0 {
           36  +    CREATE VIRTUAL TABLE t1 USING fts5(a, b, prefix="1 2", detail=%DETAIL%);
           37  +    CREATE VIRTUAL TABLE t2 USING fts5(a, b, prefix="1 2", detail=%DETAIL%);
           38  +    CREATE VIRTUAL TABLE t3 USING fts5(a, b, prefix="1 2", detail=%DETAIL%);
           39  +  }
           40  +
           41  +  do_test 1.1 {
           42  +    foreach t {t1 t2 t3} {
           43  +      execsql [string map [list TBL $t] {
           44  +        INSERT INTO TBL VALUES('a b c', 'd e f');
           45  +        INSERT INTO TBL VALUES('c1 c2 c3', 'c1 c2 c3');
           46  +        INSERT INTO TBL VALUES('xyzxyzxyz', 'xyzxyzxyz');
           47  +      }]
           48  +    }
           49  +  } {}
           50  +
           51  +  do_determin_test 1.2
           52  +
           53  +  do_test 1.3 {
           54  +    foreach t {t1 t2 t3} {
           55  +      execsql [string map [list TBL $t] {
           56  +        INSERT INTO TBL(TBL) VALUES('optimize');
           57  +      }]
           58  +    }
           59  +  } {}
           60  +
           61  +  do_determin_test 1.4
           62  +}
           63  +
           64  +
           65  +finish_test
           66  +
           67  +

Changes to ext/fts5/test/fts5fault4.test.

    82     82   }
    83     83   
    84     84   set ::res [db eval {SELECT rowid, x1 FROM x1 WHERE x1 MATCH '*reads'}]
    85     85   
    86     86   do_faultsim_test 4 -faults oom-* -body {
    87     87     db eval {SELECT rowid, x, x1 FROM x1 WHERE x1 MATCH '*reads'}
    88     88   } -test {
    89         -  faultsim_test_result {0 {0 {} 4}}
           89  +  faultsim_test_result {0 {0 {} 3}}
    90     90   }
    91     91   
    92     92   #-------------------------------------------------------------------------
    93     93   # An OOM within a query that uses a custom rank function.
    94     94   #
    95     95   reset_db
    96     96   do_execsql_test 5.0 {

Changes to ext/fts5/test/fts5simple.test.

   336    336   }
   337    337   do_test 14.2 { 
   338    338     fts5_level_segs ttt 
   339    339   } {1}
   340    340   
   341    341   #-------------------------------------------------------------------------
   342    342   db func rnddoc fts5_rnddoc
   343         -do_execsql_test 4.0 {
          343  +do_execsql_test 14.3 {
   344    344     CREATE VIRTUAL TABLE x1 USING fts5(x);
   345    345     INSERT INTO x1(x1, rank) VALUES('pgsz', 32);
   346    346   
   347    347     WITH ii(i) AS ( SELECT 1 UNION ALL SELECT i+1 FROM ii WHERE i<10 )
   348    348     INSERT INTO x1 SELECT rnddoc(5) FROM ii;
   349    349   }
   350    350   
   351         -do_execsql_test 4.1 {
          351  +do_execsql_test 14.4 {
   352    352     SELECT rowid, x, x1 FROM x1 WHERE x1 MATCH '*reads'
   353         -} {0 {} 4}
          353  +} {0 {} 3}
   354    354   
   355    355   #-------------------------------------------------------------------------
   356    356   reset_db
   357    357   do_execsql_test 15.0 {
   358    358     CREATE VIRTUAL TABLE x2 USING fts5(x, prefix=1);
   359    359     INSERT INTO x2 VALUES('ab');
   360    360   }
................................................................................
   443    443     execsql { INSERT INTO x1(x1) VALUES('optimize'); }
   444    444     execsql { DELETE FROM x1 WHERE rowid = 4; }
   445    445   } {}
   446    446   do_execsql_test 20.2 {
   447    447     INSERT INTO x1(x1) VALUES('optimize');
   448    448     INSERT INTO x1(x1) VALUES('integrity-check');
   449    449   } {}
          450  +
          451  +#-------------------------------------------------------------------------
          452  +reset_db
          453  +set doc "a b [string repeat x 100000]"
          454  +do_execsql_test 21.0 {
          455  +  CREATE VIRTUAL TABLE x1 USING fts5(x);
          456  +  INSERT INTO x1(rowid, x) VALUES(11111, $doc);
          457  +  INSERT INTO x1(rowid, x) VALUES(11112, $doc);
          458  +}
          459  +do_execsql_test 21.1 {
          460  +  INSERT INTO x1(x1) VALUES('integrity-check');
          461  +}
          462  +do_execsql_test 21.2 {
          463  +  SELECT rowid FROM x1($doc);
          464  +} {11111 11112}
          465  +do_execsql_test 21.3 {
          466  +  DELETE FROM x1 WHERE rowid=11111;
          467  +  INSERT INTO x1(x1) VALUES('integrity-check');
          468  +  SELECT rowid FROM x1($doc);
          469  +} {11112}
   450    470   
   451    471   finish_test

Changes to src/btree.c.

  2559   2559     */
  2560   2560     if( p->sharable ){
  2561   2561       int i;
  2562   2562       Btree *pSib;
  2563   2563       for(i=0; i<db->nDb; i++){
  2564   2564         if( (pSib = db->aDb[i].pBt)!=0 && pSib->sharable ){
  2565   2565           while( pSib->pPrev ){ pSib = pSib->pPrev; }
  2566         -        if( p->pBt<pSib->pBt ){
         2566  +        if( (uptr)p->pBt<(uptr)pSib->pBt ){
  2567   2567             p->pNext = pSib;
  2568   2568             p->pPrev = 0;
  2569   2569             pSib->pPrev = p;
  2570   2570           }else{
  2571         -          while( pSib->pNext && pSib->pNext->pBt<p->pBt ){
         2571  +          while( pSib->pNext && (uptr)pSib->pNext->pBt<(uptr)p->pBt ){
  2572   2572               pSib = pSib->pNext;
  2573   2573             }
  2574   2574             p->pNext = pSib->pNext;
  2575   2575             p->pPrev = pSib;
  2576   2576             if( p->pNext ){
  2577   2577               p->pNext->pPrev = p;
  2578   2578             }
................................................................................
  4864   4864     getCellInfo(pCur);
  4865   4865     aPayload = pCur->info.pPayload;
  4866   4866   #ifdef SQLITE_DIRECT_OVERFLOW_READ
  4867   4867     bEnd = offset+amt==pCur->info.nPayload;
  4868   4868   #endif
  4869   4869     assert( offset+amt <= pCur->info.nPayload );
  4870   4870   
  4871         -  if( &aPayload[pCur->info.nLocal] > &pPage->aData[pBt->usableSize] ){
  4872         -    /* Trying to read or write past the end of the data is an error */
         4871  +  assert( aPayload > pPage->aData );
         4872  +  if( (uptr)(aPayload - pPage->aData) > (pBt->usableSize - pCur->info.nLocal) ){
         4873  +    /* Trying to read or write past the end of the data is an error.  The
         4874  +    ** conditional above is really:
         4875  +    **    &aPayload[pCur->info.nLocal] > &pPage->aData[pBt->usableSize]
         4876  +    ** but is recast into its current form to avoid integer overflow problems
         4877  +    */
  4873   4878       return SQLITE_CORRUPT_BKPT;
  4874   4879     }
  4875   4880   
  4876   4881     /* Check if data must be read/written to/from the btree page itself. */
  4877   4882     if( offset<pCur->info.nLocal ){
  4878   4883       int a = amt;
  4879   4884       if( a+offset>pCur->info.nLocal ){

Changes to src/build.c.

  1052   1052     }
  1053   1053   #endif
  1054   1054     z = sqlite3DbMallocRaw(db, pName->n + pType->n + 2);
  1055   1055     if( z==0 ) return;
  1056   1056     memcpy(z, pName->z, pName->n);
  1057   1057     z[pName->n] = 0;
  1058   1058     sqlite3Dequote(z);
  1059         -  zType = z + sqlite3Strlen30(z) + 1;
  1060         -  memcpy(zType, pType->z, pType->n);
  1061         -  zType[pType->n] = 0;
  1062   1059     for(i=0; i<p->nCol; i++){
  1063   1060       if( sqlite3_stricmp(z, p->aCol[i].zName)==0 ){
  1064   1061         sqlite3ErrorMsg(pParse, "duplicate column name: %s", z);
  1065   1062         sqlite3DbFree(db, z);
  1066   1063         return;
  1067   1064       }
  1068   1065     }
................................................................................
  1082   1079    
  1083   1080     if( pType->n==0 ){
  1084   1081       /* If there is no type specified, columns have the default affinity
  1085   1082       ** 'BLOB'. */
  1086   1083       pCol->affinity = SQLITE_AFF_BLOB;
  1087   1084       pCol->szEst = 1;
  1088   1085     }else{
         1086  +    zType = z + sqlite3Strlen30(z) + 1;
         1087  +    memcpy(zType, pType->z, pType->n);
         1088  +    zType[pType->n] = 0;
  1089   1089       pCol->affinity = sqlite3AffinityType(zType, &pCol->szEst);
         1090  +    pCol->colFlags |= COLFLAG_HASTYPE;
  1090   1091     }
  1091   1092     p->nCol++;
  1092   1093     pParse->constraintName.n = 0;
  1093   1094   }
  1094   1095   
  1095   1096   /*
  1096   1097   ** This routine is called by the parser while in the middle of
................................................................................
  1278   1279     Parse *pParse,    /* Parsing context */
  1279   1280     ExprList *pList,  /* List of field names to be indexed */
  1280   1281     int onError,      /* What to do with a uniqueness conflict */
  1281   1282     int autoInc,      /* True if the AUTOINCREMENT keyword is present */
  1282   1283     int sortOrder     /* SQLITE_SO_ASC or SQLITE_SO_DESC */
  1283   1284   ){
  1284   1285     Table *pTab = pParse->pNewTable;
  1285         -  const char *zName = 0;
         1286  +  Column *pCol = 0;
  1286   1287     int iCol = -1, i;
  1287   1288     int nTerm;
  1288   1289     if( pTab==0 || IN_DECLARE_VTAB ) goto primary_key_exit;
  1289   1290     if( pTab->tabFlags & TF_HasPrimaryKey ){
  1290   1291       sqlite3ErrorMsg(pParse, 
  1291   1292         "table \"%s\" has more than one primary key", pTab->zName);
  1292   1293       goto primary_key_exit;
  1293   1294     }
  1294   1295     pTab->tabFlags |= TF_HasPrimaryKey;
  1295   1296     if( pList==0 ){
  1296   1297       iCol = pTab->nCol - 1;
  1297         -    pTab->aCol[iCol].colFlags |= COLFLAG_PRIMKEY;
  1298         -    zName = pTab->aCol[iCol].zName;
         1298  +    pCol = &pTab->aCol[iCol];
         1299  +    pCol->colFlags |= COLFLAG_PRIMKEY;
  1299   1300       nTerm = 1;
  1300   1301     }else{
  1301   1302       nTerm = pList->nExpr;
  1302   1303       for(i=0; i<nTerm; i++){
  1303   1304         Expr *pCExpr = sqlite3ExprSkipCollate(pList->a[i].pExpr);
  1304   1305         assert( pCExpr!=0 );
  1305   1306         sqlite3StringToId(pCExpr);
  1306   1307         if( pCExpr->op==TK_ID ){
  1307   1308           const char *zCName = pCExpr->u.zToken;
  1308   1309           for(iCol=0; iCol<pTab->nCol; iCol++){
  1309   1310             if( sqlite3StrICmp(zCName, pTab->aCol[iCol].zName)==0 ){
  1310         -            pTab->aCol[iCol].colFlags |= COLFLAG_PRIMKEY;
  1311         -            zName = pTab->aCol[iCol].zName;
         1311  +            pCol = &pTab->aCol[iCol];
         1312  +            pCol->colFlags |= COLFLAG_PRIMKEY;
  1312   1313               break;
  1313   1314             }
  1314   1315           }
  1315   1316         }
  1316   1317       }
  1317   1318     }
  1318   1319     if( nTerm==1
  1319         -   && zName
  1320         -   && sqlite3StrICmp(sqlite3StrNext(zName), "INTEGER")==0
         1320  +   && pCol
         1321  +   && sqlite3StrICmp(sqlite3ColumnType(pCol,""), "INTEGER")==0
  1321   1322      && sortOrder!=SQLITE_SO_DESC
  1322   1323     ){
  1323   1324       pTab->iPKey = iCol;
  1324   1325       pTab->keyConf = (u8)onError;
  1325   1326       assert( autoInc==0 || autoInc==1 );
  1326   1327       pTab->tabFlags |= autoInc*TF_Autoincrement;
  1327   1328       if( pList ) pParse->iPkSortOrder = pList->a[0].sortOrder;

Changes to src/main.c.

  3339   3339     **     1. The specified column name was rowid", "oid" or "_rowid_" 
  3340   3340     **        and there is no explicitly declared IPK column. 
  3341   3341     **
  3342   3342     **     2. The table is not a view and the column name identified an 
  3343   3343     **        explicitly declared column. Copy meta information from *pCol.
  3344   3344     */ 
  3345   3345     if( pCol ){
  3346         -    zDataType = sqlite3StrNext(pCol->zName);
  3347         -    if( zDataType[0]==0 ) zDataType = 0;
         3346  +    zDataType = sqlite3ColumnType(pCol,0);
  3348   3347       zCollSeq = pCol->zColl;
  3349   3348       notnull = pCol->notNull!=0;
  3350   3349       primarykey  = (pCol->colFlags & COLFLAG_PRIMKEY)!=0;
  3351   3350       autoinc = pTab->iPKey==iCol && (pTab->tabFlags & TF_Autoincrement)!=0;
  3352   3351     }else{
  3353   3352       zDataType = "INTEGER";
  3354   3353       primarykey = 1;

Changes to src/memjournal.c.

   399    399   }
   400    400   
   401    401   /* 
   402    402   ** Return the number of bytes required to store a JournalFile that uses vfs
   403    403   ** pVfs to create the underlying on-disk files.
   404    404   */
   405    405   int sqlite3JournalSize(sqlite3_vfs *pVfs){
   406         -  return MAX(pVfs->szOsFile, sizeof(MemJournal));
          406  +  return MAX(pVfs->szOsFile, (int)sizeof(MemJournal));
   407    407   }

Changes to src/os_unix.c.

  1362   1362     if( pFile->ctrlFlags & UNIXFILE_NOLOCK ) return;
  1363   1363   
  1364   1364     rc = osFstat(pFile->h, &buf);
  1365   1365     if( rc!=0 ){
  1366   1366       sqlite3_log(SQLITE_WARNING, "cannot fstat db file %s", pFile->zPath);
  1367   1367       return;
  1368   1368     }
  1369         -  if( buf.st_nlink==0 && (pFile->ctrlFlags & UNIXFILE_DELETE)==0 ){
         1369  +  if( buf.st_nlink==0 ){
  1370   1370       sqlite3_log(SQLITE_WARNING, "file unlinked while open: %s", pFile->zPath);
  1371   1371       return;
  1372   1372     }
  1373   1373     if( buf.st_nlink>1 ){
  1374   1374       sqlite3_log(SQLITE_WARNING, "multiple links to file: %s", pFile->zPath);
  1375   1375       return;
  1376   1376     }

Changes to src/os_win.c.

   340    340    *          data will almost certainly result in an immediate access violation.
   341    341    ******************************************************************************
   342    342    */
   343    343   #ifndef SQLITE_WIN32_HEAP_CREATE
   344    344   #  define SQLITE_WIN32_HEAP_CREATE    (TRUE)
   345    345   #endif
   346    346   
          347  +/*
          348  + * This is cache size used in the calculation of the initial size of the
          349  + * Win32-specific heap.  It cannot be negative.
          350  + */
          351  +#ifndef SQLITE_WIN32_CACHE_SIZE
          352  +#  if SQLITE_DEFAULT_CACHE_SIZE>=0
          353  +#    define SQLITE_WIN32_CACHE_SIZE (SQLITE_DEFAULT_CACHE_SIZE)
          354  +#  else
          355  +#    define SQLITE_WIN32_CACHE_SIZE (-(SQLITE_DEFAULT_CACHE_SIZE))
          356  +#  endif
          357  +#endif
          358  +
   347    359   /*
   348    360    * The initial size of the Win32-specific heap.  This value may be zero.
   349    361    */
   350    362   #ifndef SQLITE_WIN32_HEAP_INIT_SIZE
   351         -#  define SQLITE_WIN32_HEAP_INIT_SIZE ((SQLITE_DEFAULT_CACHE_SIZE) * \
          363  +#  define SQLITE_WIN32_HEAP_INIT_SIZE ((SQLITE_WIN32_CACHE_SIZE) * \
   352    364                                          (SQLITE_DEFAULT_PAGE_SIZE) + 4194304)
   353    365   #endif
   354    366   
   355    367   /*
   356    368    * The maximum size of the Win32-specific heap.  This value may be zero.
   357    369    */
   358    370   #ifndef SQLITE_WIN32_HEAP_MAX_SIZE
................................................................................
  5420   5432     UNUSED_PARAMETER(pVfs);
  5421   5433     memset(zBuf, 0, nBuf);
  5422   5434     return nBuf;
  5423   5435   #else
  5424   5436     EntropyGatherer e;
  5425   5437     UNUSED_PARAMETER(pVfs);
  5426   5438     memset(zBuf, 0, nBuf);
  5427         -#if defined(_MSC_VER) && _MSC_VER>=1400
  5428         -  rand_s((int*)zBuf); /* rand_s() is not available with MinGW */
         5439  +#if defined(_MSC_VER) && _MSC_VER>=1400 && !SQLITE_OS_WINCE
         5440  +  rand_s((unsigned int*)zBuf); /* rand_s() is not available with MinGW */
  5429   5441   #endif /* defined(_MSC_VER) && _MSC_VER>=1400 */
  5430   5442     e.a = (unsigned char*)zBuf;
  5431   5443     e.na = nBuf;
  5432   5444     e.nXor = 0;
  5433   5445     e.i = 0;
  5434   5446     {
  5435   5447       SYSTEMTIME x;

Changes to src/pragma.c.

  1062   1062         Column *pCol;
  1063   1063         Index *pPk = sqlite3PrimaryKeyIndex(pTab);
  1064   1064         pParse->nMem = 6;
  1065   1065         sqlite3CodeVerifySchema(pParse, iDb);
  1066   1066         setAllColumnNames(v, 6, azCol); assert( 6==ArraySize(azCol) );
  1067   1067         sqlite3ViewGetColumnNames(pParse, pTab);
  1068   1068         for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){
  1069         -        const char *zName;
  1070   1069           if( IsHiddenColumn(pCol) ){
  1071   1070             nHidden++;
  1072   1071             continue;
  1073   1072           }
  1074   1073           if( (pCol->colFlags & COLFLAG_PRIMKEY)==0 ){
  1075   1074             k = 0;
  1076   1075           }else if( pPk==0 ){
  1077   1076             k = 1;
  1078   1077           }else{
  1079   1078             for(k=1; k<=pTab->nCol && pPk->aiColumn[k-1]!=i; k++){}
  1080   1079           }
  1081   1080           assert( pCol->pDflt==0 || pCol->pDflt->op==TK_SPAN );
  1082         -        zName = pCol->zName;
  1083   1081           sqlite3VdbeMultiLoad(v, 1, "issisi",
  1084   1082                  i-nHidden,
  1085         -               zName,
  1086         -               sqlite3StrNext(zName),
         1083  +               pCol->zName,
         1084  +               sqlite3ColumnType(pCol,""),
  1087   1085                  pCol->notNull ? 1 : 0,
  1088   1086                  pCol->pDflt ? pCol->pDflt->u.zToken : 0,
  1089   1087                  k);
  1090   1088           sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 6);
  1091   1089         }
  1092   1090       }
  1093   1091     }

Changes to src/select.c.

  1426   1426           assert( iCol==-1 || (iCol>=0 && iCol<pTab->nCol) );
  1427   1427   #ifdef SQLITE_ENABLE_COLUMN_METADATA
  1428   1428           if( iCol<0 ){
  1429   1429             zType = "INTEGER";
  1430   1430             zOrigCol = "rowid";
  1431   1431           }else{
  1432   1432             zOrigCol = pTab->aCol[iCol].zName;
  1433         -          zType = sqlite3StrNext(zOrigCol);
         1433  +          zType = sqlite3ColumnType(&pTab->aCol[iCol],0);
  1434   1434             estWidth = pTab->aCol[iCol].szEst;
  1435   1435           }
  1436   1436           zOrigTab = pTab->zName;
  1437   1437           if( pNC->pParse ){
  1438   1438             int iDb = sqlite3SchemaToIndex(pNC->pParse->db, pTab->pSchema);
  1439   1439             zOrigDb = pNC->pParse->db->aDb[iDb].zName;
  1440   1440           }
  1441   1441   #else
  1442   1442           if( iCol<0 ){
  1443   1443             zType = "INTEGER";
  1444   1444           }else{
  1445         -          zType = sqlite3StrNext(pTab->aCol[iCol].zName);
         1445  +          zType = sqlite3ColumnType(&pTab->aCol[iCol],0);
  1446   1446             estWidth = pTab->aCol[iCol].szEst;
  1447   1447           }
  1448   1448   #endif
  1449   1449         }
  1450   1450         break;
  1451   1451       }
  1452   1452   #ifndef SQLITE_OMIT_SUBQUERY

Changes to src/sqliteInt.h.

   177    177   # define SQLITE_INT_TO_PTR(X)  ((void*)(intptr_t)(X))
   178    178   # define SQLITE_PTR_TO_INT(X)  ((int)(intptr_t)(X))
   179    179   #else                          /* Generates a warning - but it always works */
   180    180   # define SQLITE_INT_TO_PTR(X)  ((void*)(X))
   181    181   # define SQLITE_PTR_TO_INT(X)  ((int)(X))
   182    182   #endif
   183    183   
   184         -/*
   185         -** The SQLITE_WITHIN(P,S,E) macro checks to see if pointer P points to
   186         -** something between S (inclusive) and E (exclusive).
   187         -**
   188         -** In other words, S is a buffer and E is a pointer to the first byte after
   189         -** the end of buffer S.  This macro returns true if P points to something
   190         -** contained within the buffer S.
   191         -*/
   192         -#if defined(HAVE_STDINT_H)
   193         -# define SQLITE_WITHIN(P,S,E) \
   194         -    ((uintptr_t)(P)>=(uintptr_t)(S) && (uintptr_t)(P)<(uintptr_t)(E))
   195         -#else
   196         -# define SQLITE_WITHIN(P,S,E) ((P)>=(S) && (P)<(E))
   197         -#endif
   198         -
   199    184   /*
   200    185   ** A macro to hint to the compiler that a function should not be
   201    186   ** inlined.
   202    187   */
   203    188   #if defined(__GNUC__)
   204    189   #  define SQLITE_NOINLINE  __attribute__((noinline))
   205    190   #elif defined(_MSC_VER) && _MSC_VER>=1310
................................................................................
   579    564   #ifndef offsetof
   580    565   #define offsetof(STRUCTURE,FIELD) ((int)((char*)&((STRUCTURE*)0)->FIELD))
   581    566   #endif
   582    567   
   583    568   /*
   584    569   ** Macros to compute minimum and maximum of two numbers.
   585    570   */
   586         -#define MIN(A,B) ((A)<(B)?(A):(B))
   587         -#define MAX(A,B) ((A)>(B)?(A):(B))
          571  +#ifndef MIN
          572  +# define MIN(A,B) ((A)<(B)?(A):(B))
          573  +#endif
          574  +#ifndef MAX
          575  +# define MAX(A,B) ((A)>(B)?(A):(B))
          576  +#endif
   588    577   
   589    578   /*
   590    579   ** Swap two objects of type TYPE.
   591    580   */
   592    581   #define SWAP(TYPE,A,B) {TYPE t=A; A=B; B=t;}
   593    582   
   594    583   /*
................................................................................
   708    697   # elif defined(i386)     || defined(__i386__)   || defined(_M_IX86) ||    \
   709    698          defined(_M_ARM)   || defined(__arm__)    || defined(__x86)
   710    699   #   define SQLITE_PTRSIZE 4
   711    700   # else
   712    701   #   define SQLITE_PTRSIZE 8
   713    702   # endif
   714    703   #endif
          704  +
          705  +/* The uptr type is an unsigned integer large enough to hold a pointer
          706  +*/
          707  +#if defined(HAVE_STDINT_H)
          708  +  typedef uintptr_t uptr;
          709  +#elif SQLITE_PTRSIZE==4
          710  +  typedef u32 uptr;
          711  +#else
          712  +  typedef u64 uptr;
          713  +#endif
          714  +
          715  +/*
          716  +** The SQLITE_WITHIN(P,S,E) macro checks to see if pointer P points to
          717  +** something between S (inclusive) and E (exclusive).
          718  +**
          719  +** In other words, S is a buffer and E is a pointer to the first byte after
          720  +** the end of buffer S.  This macro returns true if P points to something
          721  +** contained within the buffer S.
          722  +*/
          723  +#define SQLITE_WITHIN(P,S,E) (((uptr)(P)>=(uptr)(S))&&((uptr)(P)<(uptr)(E)))
          724  +
   715    725   
   716    726   /*
   717    727   ** Macros to determine whether the machine is big or little endian,
   718    728   ** and whether or not that determination is run-time or compile-time.
   719    729   **
   720    730   ** For best performance, an attempt is made to guess at the byte-order
   721    731   ** using C-preprocessor macros.  If that is unsuccessful, or if
................................................................................
  1591   1601     u8 colFlags;     /* Boolean properties.  See COLFLAG_ defines below */
  1592   1602   };
  1593   1603   
  1594   1604   /* Allowed values for Column.colFlags:
  1595   1605   */
  1596   1606   #define COLFLAG_PRIMKEY  0x0001    /* Column is part of the primary key */
  1597   1607   #define COLFLAG_HIDDEN   0x0002    /* A hidden column in a virtual table */
         1608  +#define COLFLAG_HASTYPE  0x0004    /* Type name follows column name */
  1598   1609   
  1599   1610   /*
  1600   1611   ** A "Collating Sequence" is defined by an instance of the following
  1601   1612   ** structure. Conceptually, a collating sequence consists of a name and
  1602   1613   ** a comparison routine that defines the order of that sequence.
  1603   1614   **
  1604   1615   ** If CollSeq.xCmp is NULL, it means that the
................................................................................
  3294   3305   #endif
  3295   3306   
  3296   3307   /*
  3297   3308   ** Internal function prototypes
  3298   3309   */
  3299   3310   int sqlite3StrICmp(const char*,const char*);
  3300   3311   int sqlite3Strlen30(const char*);
  3301         -const char *sqlite3StrNext(const char*);
         3312  +char *sqlite3ColumnType(Column*,char*);
  3302   3313   #define sqlite3StrNICmp sqlite3_strnicmp
  3303   3314   
  3304   3315   int sqlite3MallocInit(void);
  3305   3316   void sqlite3MallocEnd(void);
  3306   3317   void *sqlite3Malloc(u64);
  3307   3318   void *sqlite3MallocZero(u64);
  3308   3319   void *sqlite3DbMallocZero(sqlite3*, u64);

Changes to src/sqliteLimit.h.

    97     97   # define SQLITE_MAX_FUNCTION_ARG 127
    98     98   #endif
    99     99   
   100    100   /*
   101    101   ** The suggested maximum number of in-memory pages to use for
   102    102   ** the main database table and for temporary tables.
   103    103   **
   104         -** IMPLEMENTATION-OF: R-31093-59126 The default suggested cache size
   105         -** is 2000*1024 bytes.
          104  +** IMPLEMENTATION-OF: R-30185-15359 The default suggested cache size is -2000,
          105  +** which means the cache size is limited to 2048000 bytes of memory.
   106    106   ** IMPLEMENTATION-OF: R-48205-43578 The default suggested cache size can be
   107    107   ** altered using the SQLITE_DEFAULT_CACHE_SIZE compile-time options.
   108    108   */
   109    109   #ifndef SQLITE_DEFAULT_CACHE_SIZE
   110    110   # define SQLITE_DEFAULT_CACHE_SIZE  -2000
   111    111   #endif
   112    112   

Changes to src/test_multiplex.c.

   713    713   static int multiplexSleep(sqlite3_vfs *a, int b){
   714    714     return gMultiplex.pOrigVfs->xSleep(gMultiplex.pOrigVfs, b);
   715    715   }
   716    716   static int multiplexCurrentTime(sqlite3_vfs *a, double *b){
   717    717     return gMultiplex.pOrigVfs->xCurrentTime(gMultiplex.pOrigVfs, b);
   718    718   }
   719    719   static int multiplexGetLastError(sqlite3_vfs *a, int b, char *c){
   720         -  return gMultiplex.pOrigVfs->xGetLastError(gMultiplex.pOrigVfs, b, c);
          720  +  if( gMultiplex.pOrigVfs->xGetLastError ){
          721  +    return gMultiplex.pOrigVfs->xGetLastError(gMultiplex.pOrigVfs, b, c);
          722  +  }else{
          723  +    return 0;
          724  +  }
   721    725   }
   722    726   static int multiplexCurrentTimeInt64(sqlite3_vfs *a, sqlite3_int64 *b){
   723    727     return gMultiplex.pOrigVfs->xCurrentTimeInt64(gMultiplex.pOrigVfs, b);
   724    728   }
   725    729   
   726    730   /************************ I/O Method Wrappers *******************************/
   727    731   

Changes to src/util.c.

   106    106   */
   107    107   int sqlite3Strlen30(const char *z){
   108    108     if( z==0 ) return 0;
   109    109     return 0x3fffffff & (int)strlen(z);
   110    110   }
   111    111   
   112    112   /*
   113         -** The string z[] is followed immediately by another string.  Return
   114         -** a poiner to that other string.
          113  +** Return the declared type of a column.  Or return zDflt if the column 
          114  +** has no declared type.
          115  +**
          116  +** The column type is an extra string stored after the zero-terminator on
          117  +** the column name if and only if the COLFLAG_HASTYPE flag is set.
   115    118   */
   116         -const char *sqlite3StrNext(const char *z){
   117         -  return z + strlen(z) + 1;
          119  +char *sqlite3ColumnType(Column *pCol, char *zDflt){
          120  +  if( (pCol->colFlags & COLFLAG_HASTYPE)==0 ) return zDflt;
          121  +  return pCol->zName + strlen(pCol->zName) + 1;
   118    122   }
   119    123   
   120    124   /*
   121    125   ** Helper function for sqlite3Error() - called rarely.  Broken out into
   122    126   ** a separate routine to avoid unnecessary register saves on entry to
   123    127   ** sqlite3Error().
   124    128   */

Changes to src/vdbe.c.

  2520   2520             offset64 += sqlite3VdbeSerialTypeLen(t);
  2521   2521           }
  2522   2522           pC->aType[i++] = t;
  2523   2523           aOffset[i] = (u32)(offset64 & 0xffffffff);
  2524   2524         }while( i<=p2 && zHdr<zEndHdr );
  2525   2525         pC->nHdrParsed = i;
  2526   2526         pC->iHdrOffset = (u32)(zHdr - zData);
  2527         -      if( pC->aRow==0 ) sqlite3VdbeMemRelease(&sMem);
  2528   2527     
  2529   2528         /* The record is corrupt if any of the following are true:
  2530   2529         ** (1) the bytes of the header extend past the declared header size
  2531   2530         ** (2) the entire header was used but not all data was used
  2532   2531         ** (3) the end of the data extends beyond the end of the record.
  2533   2532         */
  2534   2533         if( (zHdr>=zEndHdr && (zHdr>zEndHdr || offset64!=pC->payloadSize))
  2535   2534          || (offset64 > pC->payloadSize)
  2536   2535         ){
         2536  +        if( pC->aRow==0 ) sqlite3VdbeMemRelease(&sMem);
  2537   2537           rc = SQLITE_CORRUPT_BKPT;
  2538   2538           goto abort_due_to_error;
  2539   2539         }
         2540  +      if( pC->aRow==0 ) sqlite3VdbeMemRelease(&sMem);
         2541  +
  2540   2542       }else{
  2541   2543         t = 0;
  2542   2544       }
  2543   2545   
  2544   2546       /* If after trying to extract new entries from the header, nHdrParsed is
  2545   2547       ** still not up to p2, that means that the record has fewer than p2
  2546   2548       ** columns.  So the result will be either the default value or a NULL.

Changes to src/vtab.c.

   560    560         ** columns of the table to see if any of them contain the token "hidden".
   561    561         ** If so, set the Column COLFLAG_HIDDEN flag and remove the token from
   562    562         ** the type string.  */
   563    563         pVTable->pNext = pTab->pVTable;
   564    564         pTab->pVTable = pVTable;
   565    565   
   566    566         for(iCol=0; iCol<pTab->nCol; iCol++){
   567         -        char *zType = (char*)sqlite3StrNext(pTab->aCol[iCol].zName);
          567  +        char *zType = sqlite3ColumnType(&pTab->aCol[iCol], "");
   568    568           int nType;
   569    569           int i = 0;
   570         -        if( !zType[0] ){
   571         -          pTab->tabFlags |= oooHidden;
   572         -          continue;
   573         -        }
   574    570           nType = sqlite3Strlen30(zType);
   575         -        if( sqlite3StrNICmp("hidden", zType, 6)||(zType[6] && zType[6]!=' ') ){
   576         -          for(i=0; i<nType; i++){
   577         -            if( (0==sqlite3StrNICmp(" hidden", &zType[i], 7))
   578         -             && (zType[i+7]=='\0' || zType[i+7]==' ')
   579         -            ){
   580         -              i++;
   581         -              break;
   582         -            }
          571  +        for(i=0; i<nType; i++){
          572  +          if( 0==sqlite3StrNICmp("hidden", &zType[i], 6)
          573  +           && (i==0 || zType[i-1]==' ')
          574  +           && (zType[i+6]=='\0' || zType[i+6]==' ')
          575  +          ){
          576  +            break;
   583    577             }
   584    578           }
   585    579           if( i<nType ){
   586    580             int j;
   587    581             int nDel = 6 + (zType[i+6] ? 1 : 0);
   588    582             for(j=i; (j+nDel)<=nType; j++){
   589    583               zType[j] = zType[j+nDel];

Changes to test/capi3.test.

   925    925   } 1
   926    926   do_test capi3-11.10 {
   927    927     sqlite3_step $STMT
   928    928   } {SQLITE_ROW}
   929    929   do_test capi3-11.11 {
   930    930     sqlite3_step $STMT
   931    931   } {SQLITE_DONE}
   932         -ifcapable api_armor {
          932  +ifcapable !autoreset {
   933    933     do_test capi3-11.12armor {
   934    934       sqlite3_step $STMT
   935    935       sqlite3_step $STMT
   936    936     } {SQLITE_MISUSE}
   937    937   } else {
   938    938     do_test capi3-11.12 {
   939    939       sqlite3_step $STMT

Changes to test/capi3c.test.

   864    864   } 1
   865    865   do_test capi3c-11.10 {
   866    866     sqlite3_step $STMT
   867    867   } {SQLITE_ROW}
   868    868   do_test capi3c-11.11 {
   869    869     sqlite3_step $STMT
   870    870   } {SQLITE_DONE}
   871         -ifcapable api_armor {
          871  +ifcapable !autoreset {
   872    872     do_test capi3c-11.12armor {
   873    873       sqlite3_step $STMT
   874    874       sqlite3_step $STMT
   875    875     } {SQLITE_MISUSE}
   876    876   } else {
   877    877     do_test capi3c-11.12 {
   878    878       sqlite3_step $STMT

Changes to test/fuzzcheck.c.

   185    185   }
   186    186   #endif
   187    187   
   188    188   /*
   189    189   ** Reallocate memory.  Show and error and quit if unable.
   190    190   */
   191    191   static void *safe_realloc(void *pOld, int szNew){
   192         -  void *pNew = realloc(pOld, szNew);
          192  +  void *pNew = realloc(pOld, szNew<=0 ? 1 : szNew);
   193    193     if( pNew==0 ) fatalError("unable to realloc for %d bytes", szNew);
   194    194     return pNew;
   195    195   }
   196    196   
   197    197   /*
   198    198   ** Initialize the virtual file system.
   199    199   */

Changes to test/memsubsys1.test.

   253    253     expr {$pg_used<24}
   254    254   } 1
   255    255   do_test memsubsys1-7.4 {
   256    256     set pg_ovfl [lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_OVERFLOW 0] 2]
   257    257   } 0
   258    258   do_test memsubsys1-7.5 {
   259    259     set maxreq [lindex [sqlite3_status SQLITE_STATUS_MALLOC_SIZE 0] 2]
   260         -  expr {$maxreq<4100 + 4200*[nonzero_reserved_bytes]}
          260  +  expr {$maxreq<(4100 + 8200*[nonzero_reserved_bytes])}
   261    261   } 1
   262    262   do_test memsubsys1-7.6 {
   263    263     set s_used [lindex [sqlite3_status SQLITE_STATUS_SCRATCH_USED 0] 2]
   264    264   } 1
   265    265   do_test memsubsys1-7.7 {
   266    266     set s_ovfl [lindex [sqlite3_status SQLITE_STATUS_SCRATCH_OVERFLOW 0] 2]
   267    267   } 0

Changes to test/nolock.test.

   179    179          xAccess $::tvfs_calls(xAccess)
   180    180   } {xLock 0 xUnlock 0 xCheckReservedLock 0 xAccess 0}
   181    181   
   182    182   db2 close
   183    183   db close
   184    184   tvfs delete
   185    185   
   186         -# 2016-03-11:  Make sure all works when transitioning to WAL mode under nolock.
   187         -#
   188         -do_test nolock-4.1 {
   189         -  forcedelete test.db
   190         -  sqlite3 db file:test.db?nolock=1 -uri 1
   191         -  db eval {
   192         -     PRAGMA journal_mode=WAL;
   193         -     CREATE TABLE t1(x);
   194         -     INSERT INTO t1 VALUES('youngling');
   195         -     SELECT * FROM t1;
   196         -  }
   197         -} {delete youngling}
   198         -db close
   199         -
   200         -do_test nolock-4.2 {
   201         -  forcedelete test.db
   202         -  sqlite3 db test.db
   203         -  db eval {
   204         -    PRAGMA journal_mode=WAL;
   205         -    CREATE TABLE t1(x);
   206         -    INSERT INTO t1 VALUES('catbird');
   207         -    SELECT * FROM t1;
   208         -  }
   209         -} {wal catbird}
   210         -do_test nolock-4.3 {
          186  +if {[permutation]!="inmemory_journal"} {
          187  +  # 2016-03-11:  Make sure all works when transitioning to WAL mode
          188  +  # under nolock.
          189  +  #
          190  +  do_test nolock-4.1 {
          191  +    forcedelete test.db
          192  +    sqlite3 db file:test.db?nolock=1 -uri 1
          193  +    db eval {
          194  +       PRAGMA journal_mode=WAL;
          195  +       CREATE TABLE t1(x);
          196  +       INSERT INTO t1 VALUES('youngling');
          197  +       SELECT * FROM t1;
          198  +    }
          199  +  } {delete youngling}
   211    200     db close
   212         -  sqlite3 db file:test.db?nolock=1 -uri 1
   213         -  set rc [catch {db eval {SELECT * FROM t1}} msg]
   214         -  lappend rc $msg
   215         -} {1 {unable to open database file}}
          201  +  
          202  +  do_test nolock-4.2 {
          203  +    forcedelete test.db
          204  +    sqlite3 db test.db
          205  +    db eval {
          206  +      PRAGMA journal_mode=WAL;
          207  +      CREATE TABLE t1(x);
          208  +      INSERT INTO t1 VALUES('catbird');
          209  +      SELECT * FROM t1;
          210  +    }
          211  +  } {wal catbird}
          212  +  do_test nolock-4.3 {
          213  +    db close
          214  +    sqlite3 db file:test.db?nolock=1 -uri 1
          215  +    set rc [catch {db eval {SELECT * FROM t1}} msg]
          216  +    lappend rc $msg
          217  +  } {1 {unable to open database file}}
          218  +}
   216    219   
   217    220   finish_test

Changes to test/shell1.test.

    41     41     set res [catchcmd "test.db -bad" ""]
    42     42     set rc [lindex $res 0]
    43     43     list $rc \
    44     44          [regexp {Error: unknown option: -bad} $res]
    45     45   } {1 1}
    46     46   # error on extra options
    47     47   do_test shell1-1.1.2 {
    48         -  catchcmd "test.db \"select 3\" \"select 4\"" ""
           48  +  catchcmd "test.db \"select+3\" \"select+4\"" ""
    49     49   } {0 {3
    50     50   4}}
    51     51   # error on extra options
    52     52   do_test shell1-1.1.3 {
    53     53     catchcmd "test.db FOO test.db BAD" ".quit"
    54     54   } {1 {Error: near "FOO": syntax error}}
    55     55   
................................................................................
   272    272     # too many arguments
   273    273     catchcmd "test.db" ".bail OFF BAD"
   274    274   } {1 {Usage: .bail on|off}}
   275    275   
   276    276   # .databases             List names and files of attached databases
   277    277   do_test shell1-3.3.1 {
   278    278     catchcmd "-csv test.db" ".databases"
   279         -} "/0 +.*main +[string map {/ .} [string range [get_pwd] 0 10]].*/"
          279  +} "/0.+main.+[string map {/ ".{1,2}"} [string range [get_pwd] 0 10]].*/"
   280    280   do_test shell1-3.3.2 {
   281    281     # extra arguments ignored
   282    282     catchcmd "test.db" ".databases BAD"
   283         -} "/0 +.*main +[string map {/ .} [string range [get_pwd] 0 10]].*/"
          283  +} "/0.+main.+[string map {/ ".{1,2}"} [string range [get_pwd] 0 10]].*/"
   284    284   
   285    285   # .dump ?TABLE? ...      Dump the database in an SQL text format
   286    286   #                          If TABLE specified, only dump tables matching
   287    287   #                          LIKE pattern TABLE.
   288    288   do_test shell1-3.4.1 {
   289    289     set res [catchcmd "test.db" ".dump"]
   290    290     list [regexp {BEGIN TRANSACTION;} $res] \

Changes to test/shell2.test.

    39     39     set fexist [file exist foo.db]
    40     40     list $rc $fexist
    41     41   } {{0 {}} 1}
    42     42   
    43     43   # Shell silently ignores extra parameters.
    44     44   # Ticket [f5cb008a65].
    45     45   do_test shell2-1.2.1 {
    46         -  set rc [catch { eval exec $CLI \":memory:\" \"select 3\" \"select 4\" } msg]
           46  +  set rc [catch { eval exec $CLI \":memory:\" \"select+3\" \"select+4\" } msg]
    47     47     list $rc $msg
    48     48   } {0 {3
    49     49   4}}
    50     50   
    51     51   # Test a problem reported on the mailing list. The shell was at one point
    52     52   # returning the generic SQLITE_ERROR message ("SQL error or missing database")
    53     53   # instead of the "too many levels..." message in the test below.

Changes to test/shell3.test.

    21     21   #
    22     22   set testdir [file dirname $argv0]
    23     23   source $testdir/tester.tcl
    24     24   set CLI [test_find_cli]
    25     25   db close
    26     26   forcedelete test.db test.db-journal test.db-wal
    27     27   sqlite3 db test.db
           28  +
           29  +# There are inconsistencies in command-line argument quoting on Windows.
           30  +# In particular, individual applications are responsible for command-line
           31  +# parsing in Windows, not the shell.  Depending on whether the sqlite3.exe
           32  +# program is compiled with MinGW or MSVC, the command-line parsing is
           33  +# different.  This causes problems for the tests below.  To avoid
           34  +# issues, these tests are disabled for windows.
           35  +#
           36  +if {$::tcl_platform(platform)=="windows"} {
           37  +  finish_test
           38  +  return
           39  +}
    28     40   
    29     41   #----------------------------------------------------------------------------
    30     42   #   shell3-1.*: Basic tests for running SQL statments from command line.
    31     43   #
    32     44   
    33     45   # Run SQL statement from command line
    34     46   do_test shell3-1.1 {

Changes to test/snapshot.test.

    12     12   # of this file is the sqlite3_snapshot_xxx() APIs.
    13     13   #
    14     14   
    15     15   set testdir [file dirname $argv0]
    16     16   source $testdir/tester.tcl
    17     17   ifcapable !snapshot {finish_test; return}
    18     18   set testprefix snapshot
           19  +
           20  +# This test does not work with the inmemory_journal permutation. The reason
           21  +# is that each connection opened as part of this permutation executes
           22  +# "PRAGMA journal_mode=memory", which fails if the database is in wal mode
           23  +# and there are one or more existing connections.
           24  +if {[permutation]=="inmemory_journal"} {
           25  +  finish_test
           26  +  return
           27  +}
    19     28   
    20     29   #-------------------------------------------------------------------------
    21     30   # Check some error conditions in snapshot_get(). It is an error if:
    22     31   #
    23     32   #  1) snapshot_get() is called on a non-WAL database, or
    24     33   #  2) there is an open write transaction on the database.
    25     34   #

Changes to test/snapshot_fault.test.

   142    142       BEGIN;
   143    143     }
   144    144   } -body {
   145    145     if { [catch { sqlite3_snapshot_open db main $::snapshot } msg] } {
   146    146       error $msg
   147    147     }
   148    148   } -test {
   149         -  faultsim_test_result {0 {}} {1 SQLITE_IOERR} \
          149  +  faultsim_test_result {0 {}} {1 SQLITE_IOERR} {1 SQLITE_NOMEM} \
   150    150                                 {1 SQLITE_IOERR_NOMEM} {1 SQLITE_IOERR_READ}
   151    151     if {$testrc==0} {
   152    152       set res [db eval { 
   153    153         SELECT a FROM t1;
   154    154         PRAGMA integrity_check;
   155    155       }]
   156    156       if {$res != "1 2 3 ok"} { error "res is $res" }