/ Check-in [57912327]
Login

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

Overview
Comment:Bring the apple-wal-readonly branch up to date with the latest changes in apple-osx, and especially the fix for disappearing WAL transactions.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | apple-wal-readonly
Files: files | file ages | folders
SHA1: 5791232778c825ec487a06c72b638dcb247cdd58
User & Date: drh 2011-05-19 02:34:30
Context
2011-05-19
02:34
Bring the apple-wal-readonly branch up to date with the latest changes in apple-osx, and especially the fix for disappearing WAL transactions. Leaf check-in: 57912327 user: drh tags: apple-wal-readonly
01:51
Pull all the latest trunk changes, and especially the fix for WAL cache spills causing transactions to disappear, into the apple-osx branch. check-in: 8d1a6bb0 user: drh tags: apple-osx
2011-05-12
15:32
Pull in the patches to support read-only WAL databases into a new branch off of the apple-osx branch. This also pulls in all the other pending 3.7.7 changes such as URI support. check-in: 97b98010 user: drh tags: apple-wal-readonly
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to Makefile.in.

   377    377     $(TOP)/src/test_superlock.c \
   378    378     $(TOP)/src/test_syscall.c \
   379    379     $(TOP)/src/test_stat.c \
   380    380     $(TOP)/src/test_tclvar.c \
   381    381     $(TOP)/src/test_thread.c \
   382    382     $(TOP)/src/test_vfs.c \
   383    383     $(TOP)/src/test_wholenumber.c \
   384         -  $(TOP)/src/test_wsd.c
          384  +  $(TOP)/src/test_wsd.c       \
          385  +  $(TOP)/ext/fts3/fts3_term.c 
   385    386   
   386    387   # Source code to the library files needed by the test fixture
   387    388   #
   388    389   TESTSRC2 = \
   389    390     $(TOP)/src/attach.c \
   390    391     $(TOP)/src/backup.c \
   391    392     $(TOP)/src/bitvec.c \
................................................................................
   419    420     $(TOP)/src/vdbemem.c \
   420    421     $(TOP)/src/vdbetrace.c \
   421    422     $(TOP)/src/where.c \
   422    423     parse.c \
   423    424     $(TOP)/ext/fts3/fts3.c \
   424    425     $(TOP)/ext/fts3/fts3_aux.c \
   425    426     $(TOP)/ext/fts3/fts3_expr.c \
          427  +  $(TOP)/ext/fts3/fts3_term.c \
   426    428     $(TOP)/ext/fts3/fts3_tokenizer.c \
   427    429     $(TOP)/ext/fts3/fts3_write.c \
   428    430     $(TOP)/ext/async/sqlite3async.c
   429    431   
   430    432   # Header files used by all library source files.
   431    433   #
   432    434   HDR = \
................................................................................
   837    839   	$(LTCOMPILE) -DSQLITE_CORE -c $(TOP)/ext/fts3/fts3_expr.c
   838    840   
   839    841   fts3_hash.lo:	$(TOP)/ext/fts3/fts3_hash.c $(HDR) $(EXTHDR)
   840    842   	$(LTCOMPILE) -DSQLITE_CORE -c $(TOP)/ext/fts3/fts3_hash.c
   841    843   
   842    844   fts3_icu.lo:	$(TOP)/ext/fts3/fts3_icu.c $(HDR) $(EXTHDR)
   843    845   	$(LTCOMPILE) -DSQLITE_CORE -c $(TOP)/ext/fts3/fts3_icu.c
          846  +
          847  +fts3_porter.lo:	$(TOP)/ext/fts3/fts3_porter.c $(HDR) $(EXTHDR)
          848  +	$(LTCOMPILE) -DSQLITE_CORE -c $(TOP)/ext/fts3/fts3_porter.c
   844    849   
   845    850   fts3_snippet.lo:	$(TOP)/ext/fts3/fts3_snippet.c $(HDR) $(EXTHDR)
   846    851   	$(LTCOMPILE) -DSQLITE_CORE -c $(TOP)/ext/fts3/fts3_snippet.c
   847    852   
   848         -fts3_porter.lo:	$(TOP)/ext/fts3/fts3_porter.c $(HDR) $(EXTHDR)
   849         -	$(LTCOMPILE) -DSQLITE_CORE -c $(TOP)/ext/fts3/fts3_porter.c
   850         -
   851    853   fts3_tokenizer.lo:	$(TOP)/ext/fts3/fts3_tokenizer.c $(HDR) $(EXTHDR)
   852    854   	$(LTCOMPILE) -DSQLITE_CORE -c $(TOP)/ext/fts3/fts3_tokenizer.c
   853    855   
   854    856   fts3_tokenizer1.lo:	$(TOP)/ext/fts3/fts3_tokenizer1.c $(HDR) $(EXTHDR)
   855    857   	$(LTCOMPILE) -DSQLITE_CORE -c $(TOP)/ext/fts3/fts3_tokenizer1.c
   856    858   
   857    859   fts3_write.lo:	$(TOP)/ext/fts3/fts3_write.c $(HDR) $(EXTHDR)

Changes to ext/fts3/fts3.c.

  1191   1191       }else{
  1192   1192         int rc = sqlite3_reset(pCsr->pStmt);
  1193   1193         if( rc==SQLITE_OK ){
  1194   1194           /* If no row was found and no error has occured, then the %_content
  1195   1195           ** table is missing a row that is present in the full-text index.
  1196   1196           ** The data structures are corrupt.
  1197   1197           */
  1198         -        rc = SQLITE_CORRUPT;
         1198  +        rc = SQLITE_CORRUPT_VTAB;
  1199   1199         }
  1200   1200         pCsr->isEof = 1;
  1201   1201         if( pContext ){
  1202   1202           sqlite3_result_error_code(pContext, rc);
  1203   1203         }
  1204   1204         return rc;
  1205   1205       }
................................................................................
  1251   1251     ** contents, or two zero bytes. Or, if the node is read from the %_segments
  1252   1252     ** table, then there are always 20 bytes of zeroed padding following the
  1253   1253     ** nNode bytes of content (see sqlite3Fts3ReadBlock() for details).
  1254   1254     */
  1255   1255     zCsr += sqlite3Fts3GetVarint(zCsr, &iChild);
  1256   1256     zCsr += sqlite3Fts3GetVarint(zCsr, &iChild);
  1257   1257     if( zCsr>zEnd ){
  1258         -    return SQLITE_CORRUPT;
         1258  +    return SQLITE_CORRUPT_VTAB;
  1259   1259     }
  1260   1260     
  1261   1261     while( zCsr<zEnd && (piFirst || piLast) ){
  1262   1262       int cmp;                      /* memcmp() result */
  1263   1263       int nSuffix;                  /* Size of term suffix */
  1264   1264       int nPrefix = 0;              /* Size of term prefix */
  1265   1265       int nBuffer;                  /* Total term size */
................................................................................
  1269   1269       if( !isFirstTerm ){
  1270   1270         zCsr += sqlite3Fts3GetVarint32(zCsr, &nPrefix);
  1271   1271       }
  1272   1272       isFirstTerm = 0;
  1273   1273       zCsr += sqlite3Fts3GetVarint32(zCsr, &nSuffix);
  1274   1274       
  1275   1275       if( nPrefix<0 || nSuffix<0 || &zCsr[nSuffix]>zEnd ){
  1276         -      rc = SQLITE_CORRUPT;
         1276  +      rc = SQLITE_CORRUPT_VTAB;
  1277   1277         goto finish_scan;
  1278   1278       }
  1279   1279       if( nPrefix+nSuffix>nAlloc ){
  1280   1280         char *zNew;
  1281   1281         nAlloc = (nPrefix+nSuffix) * 2;
  1282   1282         zNew = (char *)sqlite3_realloc(zBuffer, nAlloc);
  1283   1283         if( !zNew ){

Changes to ext/fts3/fts3Int.h.

   377    377   /* fts3_expr.c */
   378    378   int sqlite3Fts3ExprParse(sqlite3_tokenizer *, 
   379    379     char **, int, int, const char *, int, Fts3Expr **
   380    380   );
   381    381   void sqlite3Fts3ExprFree(Fts3Expr *);
   382    382   #ifdef SQLITE_TEST
   383    383   int sqlite3Fts3ExprInitTestInterface(sqlite3 *db);
          384  +int sqlite3Fts3InitTerm(sqlite3 *db);
   384    385   #endif
   385    386   
   386    387   /* fts3_aux.c */
   387    388   int sqlite3Fts3InitAux(sqlite3 *db);
   388    389   
   389    390   #endif /* _FTSINT_H */

Changes to ext/fts3/fts3_snippet.c.

   956    956       if( rc!=SQLITE_OK ) return rc;
   957    957     }
   958    958     pStmt = *ppStmt;
   959    959     assert( sqlite3_data_count(pStmt)==1 );
   960    960   
   961    961     a = sqlite3_column_blob(pStmt, 0);
   962    962     a += sqlite3Fts3GetVarint(a, &nDoc);
   963         -  if( nDoc==0 ) return SQLITE_CORRUPT;
          963  +  if( nDoc==0 ) return SQLITE_CORRUPT_VTAB;
   964    964     *pnDoc = (u32)nDoc;
   965    965   
   966    966     if( paLen ) *paLen = a;
   967    967     return SQLITE_OK;
   968    968   }
   969    969   
   970    970   /*
................................................................................
  1551   1551           if( rc==SQLITE_OK ){
  1552   1552             char aBuffer[64];
  1553   1553             sqlite3_snprintf(sizeof(aBuffer), aBuffer, 
  1554   1554                 "%d %d %d %d ", iCol, pTerm-sCtx.aTerm, iStart, iEnd-iStart
  1555   1555             );
  1556   1556             rc = fts3StringAppend(&res, aBuffer, -1);
  1557   1557           }else if( rc==SQLITE_DONE ){
  1558         -          rc = SQLITE_CORRUPT;
         1558  +          rc = SQLITE_CORRUPT_VTAB;
  1559   1559           }
  1560   1560         }
  1561   1561       }
  1562   1562       if( rc==SQLITE_DONE ){
  1563   1563         rc = SQLITE_OK;
  1564   1564       }
  1565   1565   

Changes to ext/fts3/fts3_write.c.

   287    287     if( rc==SQLITE_OK ){
   288    288       if( eStmt==SQL_SELECT_DOCSIZE ){
   289    289         sqlite3_bind_int64(pStmt, 1, iDocid);
   290    290       }
   291    291       rc = sqlite3_step(pStmt);
   292    292       if( rc!=SQLITE_ROW || sqlite3_column_type(pStmt, 0)!=SQLITE_BLOB ){
   293    293         rc = sqlite3_reset(pStmt);
   294         -      if( rc==SQLITE_OK ) rc = SQLITE_CORRUPT;
          294  +      if( rc==SQLITE_OK ) rc = SQLITE_CORRUPT_VTAB;
   295    295         pStmt = 0;
   296    296       }else{
   297    297         rc = SQLITE_OK;
   298    298       }
   299    299     }
   300    300   
   301    301     *ppStmt = pStmt;
................................................................................
   968    968     ** safe (no risk of overread) even if the node data is corrupted.  
   969    969     */
   970    970     pNext += sqlite3Fts3GetVarint32(pNext, &nPrefix);
   971    971     pNext += sqlite3Fts3GetVarint32(pNext, &nSuffix);
   972    972     if( nPrefix<0 || nSuffix<=0 
   973    973      || &pNext[nSuffix]>&pReader->aNode[pReader->nNode] 
   974    974     ){
   975         -    return SQLITE_CORRUPT;
          975  +    return SQLITE_CORRUPT_VTAB;
   976    976     }
   977    977   
   978    978     if( nPrefix+nSuffix>pReader->nTermAlloc ){
   979    979       int nNew = (nPrefix+nSuffix)*2;
   980    980       char *zNew = sqlite3_realloc(pReader->zTerm, nNew);
   981    981       if( !zNew ){
   982    982         return SQLITE_NOMEM;
................................................................................
   994    994     /* Check that the doclist does not appear to extend past the end of the
   995    995     ** b-tree node. And that the final byte of the doclist is 0x00. If either 
   996    996     ** of these statements is untrue, then the data structure is corrupt.
   997    997     */
   998    998     if( &pReader->aDoclist[pReader->nDoclist]>&pReader->aNode[pReader->nNode] 
   999    999      || pReader->aDoclist[pReader->nDoclist-1]
  1000   1000     ){
  1001         -    return SQLITE_CORRUPT;
         1001  +    return SQLITE_CORRUPT_VTAB;
  1002   1002     }
  1003   1003     return SQLITE_OK;
  1004   1004   }
  1005   1005   
  1006   1006   /*
  1007   1007   ** Set the SegReader to point to the first docid in the doclist associated
  1008   1008   ** with the current term.
................................................................................
  1119   1119         pEnd = &a[sqlite3_column_bytes(pStmt, 0)];
  1120   1120         a += sqlite3Fts3GetVarint(a, &nDoc);
  1121   1121         while( a<pEnd ){
  1122   1122           a += sqlite3Fts3GetVarint(a, &nByte);
  1123   1123         }
  1124   1124         if( nDoc==0 || nByte==0 ){
  1125   1125           sqlite3_reset(pStmt);
  1126         -        return SQLITE_CORRUPT;
         1126  +        return SQLITE_CORRUPT_VTAB;
  1127   1127         }
  1128   1128   
  1129   1129         pCsr->nRowAvg = (int)(((nByte / nDoc) + pgsz) / pgsz);
  1130   1130         assert( pCsr->nRowAvg>0 ); 
  1131   1131         rc = sqlite3_reset(pStmt);
  1132   1132         if( rc!=SQLITE_OK ) return rc;
  1133   1133       }
................................................................................
  2758   2758       iRemove = sqlite3_value_int64(apVal[0]);
  2759   2759     }
  2760   2760     
  2761   2761     /* If this is an INSERT or UPDATE operation, insert the new record. */
  2762   2762     if( nArg>1 && rc==SQLITE_OK ){
  2763   2763       if( bInsertDone==0 ){
  2764   2764         rc = fts3InsertData(p, apVal, pRowid);
  2765         -      if( rc==SQLITE_CONSTRAINT ) rc = SQLITE_CORRUPT;
         2765  +      if( rc==SQLITE_CONSTRAINT ) rc = SQLITE_CORRUPT_VTAB;
  2766   2766       }
  2767   2767       if( rc==SQLITE_OK && (!isRemove || *pRowid!=iRemove) ){
  2768   2768         rc = fts3PendingTermsDocid(p, *pRowid);
  2769   2769       }
  2770   2770       if( rc==SQLITE_OK ){
  2771   2771         rc = fts3InsertTerms(p, apVal, aSzIns);
  2772   2772       }

Changes to ext/rtree/rtree.c.

   514    514     ** the root node. A height of one means the children of the root node
   515    515     ** are the leaves, and so on. If the depth as specified on the root node
   516    516     ** is greater than RTREE_MAX_DEPTH, the r-tree structure must be corrupt.
   517    517     */
   518    518     if( pNode && iNode==1 ){
   519    519       pRtree->iDepth = readInt16(pNode->zData);
   520    520       if( pRtree->iDepth>RTREE_MAX_DEPTH ){
   521         -      rc = SQLITE_CORRUPT;
          521  +      rc = SQLITE_CORRUPT_VTAB;
   522    522       }
   523    523     }
   524    524   
   525    525     /* If no error has occurred so far, check if the "number of entries"
   526    526     ** field on the node is too large. If so, set the return code to 
   527         -  ** SQLITE_CORRUPT.
          527  +  ** SQLITE_CORRUPT_VTAB.
   528    528     */
   529    529     if( pNode && rc==SQLITE_OK ){
   530    530       if( NCELL(pNode)>((pRtree->iNodeSize-4)/pRtree->nBytesPerCell) ){
   531         -      rc = SQLITE_CORRUPT;
          531  +      rc = SQLITE_CORRUPT_VTAB;
   532    532       }
   533    533     }
   534    534   
   535    535     if( rc==SQLITE_OK ){
   536    536       if( pNode!=0 ){
   537    537         nodeHashInsert(pRtree, pNode);
   538    538       }else{
   539         -      rc = SQLITE_CORRUPT;
          539  +      rc = SQLITE_CORRUPT_VTAB;
   540    540       }
   541    541       *ppNode = pNode;
   542    542     }else{
   543    543       sqlite3_free(pNode);
   544    544       *ppNode = 0;
   545    545     }
   546    546   
................................................................................
  1059   1059     int nCell = NCELL(pNode);
  1060   1060     for(ii=0; ii<nCell; ii++){
  1061   1061       if( nodeGetRowid(pRtree, pNode, ii)==iRowid ){
  1062   1062         *piIndex = ii;
  1063   1063         return SQLITE_OK;
  1064   1064       }
  1065   1065     }
  1066         -  return SQLITE_CORRUPT;
         1066  +  return SQLITE_CORRUPT_VTAB;
  1067   1067   }
  1068   1068   
  1069   1069   /*
  1070   1070   ** Return the index of the cell containing a pointer to node pNode
  1071   1071   ** in its parent. If pNode is the root node, return -1.
  1072   1072   */
  1073   1073   static int nodeParentIndex(Rtree *pRtree, RtreeNode *pNode, int *piIndex){
................................................................................
  1654   1654     RtreeNode *p = pNode;
  1655   1655     while( p->pParent ){
  1656   1656       RtreeNode *pParent = p->pParent;
  1657   1657       RtreeCell cell;
  1658   1658       int iCell;
  1659   1659   
  1660   1660       if( nodeParentIndex(pRtree, p, &iCell) ){
  1661         -      return SQLITE_CORRUPT;
         1661  +      return SQLITE_CORRUPT_VTAB;
  1662   1662       }
  1663   1663   
  1664   1664       nodeGetCell(pRtree, pParent, iCell, &cell);
  1665   1665       if( !cellContains(pRtree, &cell, pCell) ){
  1666   1666         cellUnion(pRtree, &cell, pCell);
  1667   1667         nodeOverwriteCell(pRtree, pParent, &cell, iCell);
  1668   1668       }
................................................................................
  2326   2326         for(pTest=pLeaf; pTest && pTest->iNode!=iNode; pTest=pTest->pParent);
  2327   2327         if( !pTest ){
  2328   2328           rc2 = nodeAcquire(pRtree, iNode, 0, &pChild->pParent);
  2329   2329         }
  2330   2330       }
  2331   2331       rc = sqlite3_reset(pRtree->pReadParent);
  2332   2332       if( rc==SQLITE_OK ) rc = rc2;
  2333         -    if( rc==SQLITE_OK && !pChild->pParent ) rc = SQLITE_CORRUPT;
         2333  +    if( rc==SQLITE_OK && !pChild->pParent ) rc = SQLITE_CORRUPT_VTAB;
  2334   2334       pChild = pChild->pParent;
  2335   2335     }
  2336   2336     return rc;
  2337   2337   }
  2338   2338   
  2339   2339   static int deleteCell(Rtree *, RtreeNode *, int, int);
  2340   2340   

Changes to main.mk.

    50     50   
    51     51   # Object files for the SQLite library.
    52     52   #
    53     53   LIBOBJ+= alter.o analyze.o attach.o auth.o \
    54     54            backup.o bitvec.o btmutex.o btree.o build.o \
    55     55            callback.o complete.o ctime.o date.o delete.o expr.o fault.o fkey.o \
    56     56            fts3.o fts3_aux.o fts3_expr.o fts3_hash.o fts3_icu.o fts3_porter.o \
    57         -         fts3_snippet.o fts3_tokenizer.o fts3_tokenizer1.o fts3_write.o \
    58         -         func.o global.o hash.o \
           57  +         fts3_snippet.o fts3_tokenizer.o fts3_tokenizer1.o \
           58  +         fts3_write.o func.o global.o hash.o \
    59     59            icu.o insert.o journal.o legacy.o loadext.o \
    60     60            main.o malloc.o mem0.o mem1.o mem2.o mem3.o mem5.o \
    61     61            memjournal.o \
    62     62            mutex.o mutex_noop.o mutex_os2.o mutex_unix.o mutex_w32.o \
    63     63            notify.o opcodes.o os.o os_os2.o os_unix.o os_win.o \
    64     64            pager.o parse.o pcache.o pcache1.o pragma.o prepare.o printf.o \
    65     65            random.o resolve.o rowset.o rtree.o select.o status.o \

Changes to src/btree.c.

   784    784       return;
   785    785     }
   786    786     offset = PTRMAP_PTROFFSET(iPtrmap, key);
   787    787     if( offset<0 ){
   788    788       *pRC = SQLITE_CORRUPT_BKPT;
   789    789       goto ptrmap_exit;
   790    790     }
          791  +  assert( offset <= (int)pBt->usableSize-5 );
   791    792     pPtrmap = (u8 *)sqlite3PagerGetData(pDbPage);
   792    793   
   793    794     if( eType!=pPtrmap[offset] || get4byte(&pPtrmap[offset+1])!=parent ){
   794    795       TRACE(("PTRMAP_UPDATE: %d->(%d,%d)\n", key, eType, parent));
   795    796       *pRC= rc = sqlite3PagerWrite(pDbPage);
   796    797       if( rc==SQLITE_OK ){
   797    798         pPtrmap[offset] = eType;
................................................................................
   823    824     rc = sqlite3PagerGet(pBt->pPager, iPtrmap, &pDbPage);
   824    825     if( rc!=0 ){
   825    826       return rc;
   826    827     }
   827    828     pPtrmap = (u8 *)sqlite3PagerGetData(pDbPage);
   828    829   
   829    830     offset = PTRMAP_PTROFFSET(iPtrmap, key);
          831  +  if( offset<0 ){
          832  +    sqlite3PagerUnref(pDbPage);
          833  +    return SQLITE_CORRUPT_BKPT;
          834  +  }
          835  +  assert( offset <= (int)pBt->usableSize-5 );
   830    836     assert( pEType!=0 );
   831    837     *pEType = pPtrmap[offset];
   832    838     if( pPgno ) *pPgno = get4byte(&pPtrmap[offset+1]);
   833    839   
   834    840     sqlite3PagerUnref(pDbPage);
   835    841     if( *pEType<1 || *pEType>5 ) return SQLITE_CORRUPT_BKPT;
   836    842     return SQLITE_OK;

Changes to src/main.c.

  2943   2943       }
  2944   2944   
  2945   2945     }
  2946   2946     va_end(ap);
  2947   2947   #endif /* SQLITE_OMIT_BUILTIN_TEST */
  2948   2948     return rc;
  2949   2949   }
         2950  +
         2951  +/*
         2952  +** This is a utility routine, useful to VFS implementations, that checks
         2953  +** to see if a database file was a URI that contained a specific query 
         2954  +** parameter, and if so obtains the value of the query parameter.
         2955  +**
         2956  +** The zFilename argument is the filename pointer passed into the xOpen()
         2957  +** method of a VFS implementation.  The zParam argument is the name of the
         2958  +** query parameter we seek.  This routine returns the value of the zParam
         2959  +** parameter if it exists.  If the parameter does not exist, this routine
         2960  +** returns a NULL pointer.
         2961  +*/
         2962  +const char *sqlite3_uri_parameter(const char *zFilename, const char *zParam){
         2963  +  zFilename += sqlite3Strlen30(zFilename) + 1;
         2964  +  while( zFilename[0] ){
         2965  +    int x = strcmp(zFilename, zParam);
         2966  +    zFilename += sqlite3Strlen30(zFilename) + 1;
         2967  +    if( x==0 ) return zFilename;
         2968  +    zFilename += sqlite3Strlen30(zFilename) + 1;
         2969  +  }
         2970  +  return 0;
         2971  +}

Changes to src/os_unix.c.

  4022   4022       zShmFilename = pShmNode->zFilename = (char*)&pShmNode[1];
  4023   4023   #ifdef SQLITE_SHM_DIRECTORY
  4024   4024       sqlite3_snprintf(nShmFilename, zShmFilename, 
  4025   4025                        SQLITE_SHM_DIRECTORY "/sqlite-shm-%x-%x",
  4026   4026                        (u32)sStat.st_ino, (u32)sStat.st_dev);
  4027   4027   #else
  4028   4028       sqlite3_snprintf(nShmFilename, zShmFilename, "%s-shm", zBasePath);
         4029  +    sqlite3FileSuffix3(pDbFd->zPath, zShmFilename);
  4029   4030   #endif
  4030   4031       pShmNode->h = -1;
  4031   4032       pDbFd->pInode->pShmNode = pShmNode;
  4032   4033       pShmNode->pInode = pDbFd->pInode;
  4033   4034       pShmNode->mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST);
  4034   4035       if( pShmNode->mutex==0 ){
  4035   4036         rc = SQLITE_NOMEM;
................................................................................
  5074   5075   ** mask SQLITE_DEFAULT_FILE_PERMISSIONS.
  5075   5076   **
  5076   5077   ** Finally, if the file being opened is a WAL or regular journal file, then 
  5077   5078   ** this function queries the file-system for the permissions on the 
  5078   5079   ** corresponding database file and sets *pMode to this value. Whenever 
  5079   5080   ** possible, WAL and journal files are created using the same permissions 
  5080   5081   ** as the associated database file.
         5082  +**
         5083  +** If the SQLITE_ENABLE_8_3_NAMES option is enabled, then the
         5084  +** original filename is unavailable.  But 8_3_NAMES is only used for
         5085  +** FAT filesystems and permissions do not matter there, so just use
         5086  +** the default permissions.
  5081   5087   */
  5082   5088   static int findCreateFileMode(
  5083   5089     const char *zPath,              /* Path of file (possibly) being created */
  5084   5090     int flags,                      /* Flags passed as 4th argument to xOpen() */
  5085   5091     mode_t *pMode                   /* OUT: Permissions to open file with */
  5086   5092   ){
  5087   5093     int rc = SQLITE_OK;             /* Return Code */
         5094  +  *pMode = SQLITE_DEFAULT_FILE_PERMISSIONS;
  5088   5095     if( flags & (SQLITE_OPEN_WAL|SQLITE_OPEN_MAIN_JOURNAL) ){
  5089   5096       char zDb[MAX_PATHNAME+1];     /* Database file path */
  5090   5097       int nDb;                      /* Number of valid bytes in zDb */
  5091   5098       struct stat sStat;            /* Output of stat() on database file */
  5092   5099   
  5093   5100       /* zPath is a path to a WAL or journal file. The following block derives
  5094   5101       ** the path to the associated database file from zPath. This block handles
  5095   5102       ** the following naming conventions:
  5096   5103       **
  5097   5104       **   "<path to db>-journal"
  5098   5105       **   "<path to db>-wal"
  5099         -    **   "<path to db>-journal-NNNN"
  5100         -    **   "<path to db>-wal-NNNN"
         5106  +    **   "<path to db>-journalNN"
         5107  +    **   "<path to db>-walNN"
  5101   5108       **
  5102         -    ** where NNNN is a 4 digit decimal number. The NNNN naming schemes are 
         5109  +    ** where NN is a 4 digit decimal number. The NN naming schemes are 
  5103   5110       ** used by the test_multiplex.c module.
  5104   5111       */
  5105   5112       nDb = sqlite3Strlen30(zPath) - 1; 
  5106         -    while( nDb>0 && zPath[nDb]!='l' ) nDb--;
  5107         -    nDb -= ((flags & SQLITE_OPEN_WAL) ? 3 : 7);
         5113  +    while( nDb>0 && zPath[nDb]!='-' ) nDb--;
         5114  +    if( nDb==0 ) return SQLITE_OK;
  5108   5115       memcpy(zDb, zPath, nDb);
  5109   5116       zDb[nDb] = '\0';
  5110   5117   
  5111   5118       if( 0==stat(zDb, &sStat) ){
  5112   5119         *pMode = sStat.st_mode & 0777;
  5113   5120       }else{
  5114   5121         rc = SQLITE_IOERR_FSTAT;
  5115   5122       }
  5116   5123     }else if( flags & SQLITE_OPEN_DELETEONCLOSE ){
  5117   5124       *pMode = 0600;
  5118         -  }else{
  5119         -    *pMode = SQLITE_DEFAULT_FILE_PERMISSIONS;
  5120   5125     }
  5121   5126     return rc;
  5122   5127   }
  5123   5128   
  5124   5129   /*
  5125   5130   ** Open the file zPath.
  5126   5131   ** 

Changes to src/os_win.c.

  1566   1566     if( pNew==0 ){
  1567   1567       sqlite3_free(p);
  1568   1568       return SQLITE_NOMEM;
  1569   1569     }
  1570   1570     memset(pNew, 0, sizeof(*pNew));
  1571   1571     pNew->zFilename = (char*)&pNew[1];
  1572   1572     sqlite3_snprintf(nName+15, pNew->zFilename, "%s-shm", pDbFd->zPath);
         1573  +  sqlite3FileSuffix3(pDbFd->zPath, pNew->zFilename); 
  1573   1574   
  1574   1575     /* Look to see if there is an existing winShmNode that can be used.
  1575   1576     ** If no matching winShmNode currently exists, create a new one.
  1576   1577     */
  1577   1578     winShmEnterMutex();
  1578   1579     for(pShmNode = winShmNodeList; pShmNode; pShmNode=pShmNode->pNext){
  1579   1580       /* TBD need to come up with better match here.  Perhaps

Changes to src/pager.c.

  4403   4403     if( zPathname ){
  4404   4404       assert( nPathname>0 );
  4405   4405       pPager->zJournal =   (char*)(pPtr += nPathname + 1 + nUri);
  4406   4406       memcpy(pPager->zFilename, zPathname, nPathname);
  4407   4407       memcpy(&pPager->zFilename[nPathname+1], zUri, nUri);
  4408   4408       memcpy(pPager->zJournal, zPathname, nPathname);
  4409   4409       memcpy(&pPager->zJournal[nPathname], "-journal", 8);
         4410  +    sqlite3FileSuffix3(pPager->zFilename, pPager->zJournal);
  4410   4411   #ifndef SQLITE_OMIT_WAL
  4411   4412       pPager->zWal = &pPager->zJournal[nPathname+8+1];
  4412   4413       memcpy(pPager->zWal, zPathname, nPathname);
  4413   4414       memcpy(&pPager->zWal[nPathname], "-wal", 4);
         4415  +    sqlite3FileSuffix3(pPager->zFilename, pPager->zWal);
  4414   4416   #endif
  4415   4417       sqlite3_free(zPathname);
  4416   4418     }
  4417   4419     pPager->pVfs = pVfs;
  4418   4420     pPager->vfsFlags = vfsFlags;
  4419   4421     pPager->readOnlyShm = (flags & PAGER_READONLYSHM)!=0;
  4420   4422   
................................................................................
  5744   5746       ** function has already been called, it is mostly a no-op.  However, any
  5745   5747       ** backup in progress needs to be restarted.
  5746   5748       */
  5747   5749       sqlite3BackupRestart(pPager->pBackup);
  5748   5750     }else{
  5749   5751       if( pagerUseWal(pPager) ){
  5750   5752         PgHdr *pList = sqlite3PcacheDirtyList(pPager->pPCache);
         5753  +      PgHdr *pPageOne = 0;
         5754  +      if( pList==0 ){
         5755  +        /* Must have at least one page for the WAL commit flag.
         5756  +        ** Ticket [2d1a5c67dfc2363e44f29d9bbd57f] 2011-05-18 */
         5757  +        rc = sqlite3PagerGet(pPager, 1, &pPageOne);
         5758  +        pList = pPageOne;
         5759  +        pList->pDirty = 0;
         5760  +      }
         5761  +      assert( pList!=0 || rc!=SQLITE_OK );
  5751   5762         if( pList ){
  5752   5763           rc = pagerWalFrames(pPager, pList, pPager->dbSize, 1, 
  5753   5764               (pPager->fullSync ? pPager->syncFlags : 0)
  5754   5765           );
  5755   5766         }
         5767  +      sqlite3PagerUnref(pPageOne);
  5756   5768         if( rc==SQLITE_OK ){
  5757   5769           sqlite3PcacheCleanAll(pPager->pPCache);
  5758   5770         }
  5759   5771       }else{
  5760   5772         /* The following block updates the change-counter. Exactly how it
  5761   5773         ** does this depends on whether or not the atomic-update optimization
  5762   5774         ** was enabled at compile time, and if this transaction meets the 
................................................................................
  6606   6618   **
  6607   6619   ** Setting the size limit to -1 means no limit is enforced.
  6608   6620   ** An attempt to set a limit smaller than -1 is a no-op.
  6609   6621   */
  6610   6622   i64 sqlite3PagerJournalSizeLimit(Pager *pPager, i64 iLimit){
  6611   6623     if( iLimit>=-1 ){
  6612   6624       pPager->journalSizeLimit = iLimit;
         6625  +    sqlite3WalLimit(pPager->pWal, iLimit);
  6613   6626     }
  6614   6627     return pPager->journalSizeLimit;
  6615   6628   }
  6616   6629   
  6617   6630   /*
  6618   6631   ** Return a pointer to the pPager->pBackup variable. The backup module
  6619   6632   ** in backup.c maintains the content of this variable. This module
................................................................................
  6697   6710     }
  6698   6711   
  6699   6712     /* Open the connection to the log file. If this operation fails, 
  6700   6713     ** (e.g. due to malloc() failure), return an error code.
  6701   6714     */
  6702   6715     if( rc==SQLITE_OK ){
  6703   6716       rc = sqlite3WalOpen(pPager->pVfs, 
  6704         -        pPager->fd, pPager->zWal, pPager->exclusiveMode, &pPager->pWal
         6717  +        pPager->fd, pPager->zWal, pPager->exclusiveMode,
         6718  +        pPager->journalSizeLimit, &pPager->pWal
  6705   6719       );
  6706   6720     }
  6707   6721   
  6708   6722     return rc;
  6709   6723   }
  6710   6724   
  6711   6725   

Changes to src/pragma.c.

    45     45     }
    46     46     return 1;
    47     47   }
    48     48   
    49     49   /*
    50     50   ** Interpret the given string as a boolean value.
    51     51   */
    52         -static u8 getBoolean(const char *z){
           52  +u8 sqlite3GetBoolean(const char *z){
    53     53     return getSafetyLevel(z)&1;
    54     54   }
    55     55   
    56     56   /*
    57     57   ** Interpret the given string as a locking mode value.
    58     58   */
    59     59   static int getLockingMode(const char *z){
................................................................................
   216    216             int mask = p->mask;          /* Mask of bits to set or clear. */
   217    217             if( db->autoCommit==0 ){
   218    218               /* Foreign key support may not be enabled or disabled while not
   219    219               ** in auto-commit mode.  */
   220    220               mask &= ~(SQLITE_ForeignKeys);
   221    221             }
   222    222   
   223         -          if( getBoolean(zRight) ){
          223  +          if( sqlite3GetBoolean(zRight) ){
   224    224               db->flags |= mask;
   225    225             }else{
   226    226               db->flags &= ~mask;
   227    227             }
   228    228   
   229    229             /* Many of the flag-pragmas modify the code generated by the SQL 
   230    230             ** compiler (eg. count_changes). So add an opcode to expire all
................................................................................
   430    430     ** flag setting and reports thenew value.
   431    431     */
   432    432     if( sqlite3StrICmp(zLeft,"secure_delete")==0 ){
   433    433       Btree *pBt = pDb->pBt;
   434    434       sqlite3_int64 b = -1;
   435    435       assert( pBt!=0 );
   436    436       if( zRight ){
   437         -      b = getBoolean(zRight);
          437  +      b = sqlite3GetBoolean(zRight);
   438    438       }
   439    439       if( pId2->n==0 && b>=0 ){
   440    440         int ii;
   441    441         for(ii=0; ii<db->nDb; ii++){
   442    442           sqlite3BtreeSecureDelete(db->aDb[ii].pBt, b);
   443    443         }
   444    444       }
................................................................................
  1033   1033       }
  1034   1034     }else
  1035   1035   #endif /* !defined(SQLITE_OMIT_FOREIGN_KEY) */
  1036   1036   
  1037   1037   #ifndef NDEBUG
  1038   1038     if( sqlite3StrICmp(zLeft, "parser_trace")==0 ){
  1039   1039       if( zRight ){
  1040         -      if( getBoolean(zRight) ){
         1040  +      if( sqlite3GetBoolean(zRight) ){
  1041   1041           sqlite3ParserTrace(stderr, "parser: ");
  1042   1042         }else{
  1043   1043           sqlite3ParserTrace(0, 0);
  1044   1044         }
  1045   1045       }
  1046   1046     }else
  1047   1047   #endif
  1048   1048   
  1049   1049     /* Reinstall the LIKE and GLOB functions.  The variant of LIKE
  1050   1050     ** used will be case sensitive or not depending on the RHS.
  1051   1051     */
  1052   1052     if( sqlite3StrICmp(zLeft, "case_sensitive_like")==0 ){
  1053   1053       if( zRight ){
  1054         -      sqlite3RegisterLikeFunctions(db, getBoolean(zRight));
         1054  +      sqlite3RegisterLikeFunctions(db, sqlite3GetBoolean(zRight));
  1055   1055       }
  1056   1056     }else
  1057   1057   
  1058   1058   #ifndef SQLITE_INTEGRITY_CHECK_ERROR_MAX
  1059   1059   # define SQLITE_INTEGRITY_CHECK_ERROR_MAX 100
  1060   1060   #endif
  1061   1061   

Changes to src/shell.c.

  2645   2645   ** Initialize the state information in data
  2646   2646   */
  2647   2647   static void main_init(struct callback_data *data) {
  2648   2648     memset(data, 0, sizeof(*data));
  2649   2649     data->mode = MODE_List;
  2650   2650     memcpy(data->separator,"|", 2);
  2651   2651     data->showHeader = 0;
         2652  +  sqlite3_config(SQLITE_CONFIG_URI, 1);
  2652   2653     sqlite3_config(SQLITE_CONFIG_LOG, shellLog, data);
  2653   2654     sqlite3_snprintf(sizeof(mainPrompt), mainPrompt,"sqlite> ");
  2654   2655     sqlite3_snprintf(sizeof(continuePrompt), continuePrompt,"   ...> ");
  2655   2656     sqlite3_config(SQLITE_CONFIG_SINGLETHREAD);
  2656   2657   }
  2657   2658   
  2658   2659   int main(int argc, char **argv){
................................................................................
  2659   2660     char *zErrMsg = 0;
  2660   2661     struct callback_data data;
  2661   2662     const char *zInitFile = 0;
  2662   2663     char *zFirstCmd = 0;
  2663   2664     int i;
  2664   2665     int rc = 0;
  2665   2666   
         2667  +  if( strcmp(sqlite3_sourceid(),SQLITE_SOURCE_ID)!=0 ){
         2668  +    fprintf(stderr, "SQLite header and source version mismatch\n%s\n%s\n",
         2669  +            sqlite3_sourceid(), SQLITE_SOURCE_ID);
         2670  +    exit(1);
         2671  +  }
  2666   2672     Argv0 = argv[0];
  2667   2673     main_init(&data);
  2668   2674     stdin_is_interactive = isatty(0);
  2669   2675   
  2670   2676     /* Make sure we have a valid signal handler early, before anything
  2671   2677     ** else is done.
  2672   2678     */

Changes to src/sqlite.h.in.

   449    449   #define SQLITE_IOERR_SHMSIZE           (SQLITE_IOERR | (19<<8))
   450    450   #define SQLITE_IOERR_SHMLOCK           (SQLITE_IOERR | (20<<8))
   451    451   #define SQLITE_IOERR_SHMMAP            (SQLITE_IOERR | (21<<8))
   452    452   #define SQLITE_IOERR_SEEK              (SQLITE_IOERR | (22<<8))
   453    453   #define SQLITE_LOCKED_SHAREDCACHE      (SQLITE_LOCKED |  (1<<8))
   454    454   #define SQLITE_BUSY_RECOVERY           (SQLITE_BUSY   |  (1<<8))
   455    455   #define SQLITE_CANTOPEN_NOTEMPDIR      (SQLITE_CANTOPEN | (1<<8))
          456  +#define SQLITE_CORRUPT_VTAB            (SQLITE_CORRUPT | (1<<8))
   456    457   
   457    458   #define SQLITE_READONLY_RECOVERY       (SQLITE_READONLY | (1<<8))
   458    459   #define SQLITE_READONLY_CANTLOCK       (SQLITE_READONLY | (2<<8))
   459    460   
   460    461   /*
   461    462   ** CAPI3REF: Flags For File Open Operations
   462    463   **
   463    464   ** These bit values are intended for use in the
   464    465   ** 3rd parameter to the [sqlite3_open_v2()] interface and
   465         -** in the 4th parameter to the xOpen method of the
   466         -** [sqlite3_vfs] object.
          466  +** in the 4th parameter to the [sqlite3_vfs.xOpen] method.
   467    467   */
   468    468   #define SQLITE_OPEN_READONLY         0x00000001  /* Ok for sqlite3_open_v2() */
   469    469   #define SQLITE_OPEN_READWRITE        0x00000002  /* Ok for sqlite3_open_v2() */
   470    470   #define SQLITE_OPEN_CREATE           0x00000004  /* Ok for sqlite3_open_v2() */
   471    471   #define SQLITE_OPEN_DELETEONCLOSE    0x00000008  /* VFS only */
   472    472   #define SQLITE_OPEN_EXCLUSIVE        0x00000010  /* VFS only */
   473    473   #define SQLITE_OPEN_AUTOPROXY        0x00000020  /* VFS only */
          474  +#define SQLITE_OPEN_URI              0x00000040  /* Ok for sqlite3_open_v2() */
   474    475   #define SQLITE_OPEN_MAIN_DB          0x00000100  /* VFS only */
   475    476   #define SQLITE_OPEN_TEMP_DB          0x00000200  /* VFS only */
   476    477   #define SQLITE_OPEN_TRANSIENT_DB     0x00000400  /* VFS only */
   477    478   #define SQLITE_OPEN_MAIN_JOURNAL     0x00000800  /* VFS only */
   478    479   #define SQLITE_OPEN_TEMP_JOURNAL     0x00001000  /* VFS only */
   479    480   #define SQLITE_OPEN_SUBJOURNAL       0x00002000  /* VFS only */
   480    481   #define SQLITE_OPEN_MASTER_JOURNAL   0x00004000  /* VFS only */
   481    482   #define SQLITE_OPEN_NOMUTEX          0x00008000  /* Ok for sqlite3_open_v2() */
   482    483   #define SQLITE_OPEN_FULLMUTEX        0x00010000  /* Ok for sqlite3_open_v2() */
   483    484   #define SQLITE_OPEN_SHAREDCACHE      0x00020000  /* Ok for sqlite3_open_v2() */
   484    485   #define SQLITE_OPEN_PRIVATECACHE     0x00040000  /* Ok for sqlite3_open_v2() */
   485    486   #define SQLITE_OPEN_WAL              0x00080000  /* VFS only */
   486         -#define SQLITE_OPEN_URI              0x00100000  /* Ok for sqlite3_open_v2() */
   487    487   
   488    488   /* Reserved:                         0x00F00000 */
   489    489   
   490    490   /*
   491    491   ** CAPI3REF: Device Characteristics
   492    492   **
   493    493   ** The xDeviceCharacteristics method of the [sqlite3_io_methods]
................................................................................
   578    578   struct sqlite3_file {
   579    579     const struct sqlite3_io_methods *pMethods;  /* Methods for an open file */
   580    580   };
   581    581   
   582    582   /*
   583    583   ** CAPI3REF: OS Interface File Virtual Methods Object
   584    584   **
   585         -** Every file opened by the [sqlite3_vfs] xOpen method populates an
          585  +** Every file opened by the [sqlite3_vfs.xOpen] method populates an
   586    586   ** [sqlite3_file] object (or, more commonly, a subclass of the
   587    587   ** [sqlite3_file] object) with a pointer to an instance of this object.
   588    588   ** This object defines the methods used to perform various operations
   589    589   ** against the open file represented by the [sqlite3_file] object.
   590    590   **
   591         -** If the xOpen method sets the sqlite3_file.pMethods element 
          591  +** If the [sqlite3_vfs.xOpen] method sets the sqlite3_file.pMethods element 
   592    592   ** to a non-NULL pointer, then the sqlite3_io_methods.xClose method
   593         -** may be invoked even if the xOpen reported that it failed.  The
   594         -** only way to prevent a call to xClose following a failed xOpen
   595         -** is for the xOpen to set the sqlite3_file.pMethods element to NULL.
          593  +** may be invoked even if the [sqlite3_vfs.xOpen] reported that it failed.  The
          594  +** only way to prevent a call to xClose following a failed [sqlite3_vfs.xOpen]
          595  +** is for the [sqlite3_vfs.xOpen] to set the sqlite3_file.pMethods element
          596  +** to NULL.
   596    597   **
   597    598   ** The flags argument to xSync may be one of [SQLITE_SYNC_NORMAL] or
   598    599   ** [SQLITE_SYNC_FULL].  The first choice is the normal fsync().
   599    600   ** The second choice is a Mac OS X style fullsync.  The [SQLITE_SYNC_DATAONLY]
   600    601   ** flag may be ORed in to indicate that only the data of the file
   601    602   ** and not its inode needs to be synced.
   602    603   **
................................................................................
   812    813   ** or modify this field while holding a particular static mutex.
   813    814   ** The application should never modify anything within the sqlite3_vfs
   814    815   ** object once the object has been registered.
   815    816   **
   816    817   ** The zName field holds the name of the VFS module.  The name must
   817    818   ** be unique across all VFS modules.
   818    819   **
          820  +** [[sqlite3_vfs.xOpen]]
   819    821   ** ^SQLite guarantees that the zFilename parameter to xOpen
   820    822   ** is either a NULL pointer or string obtained
   821    823   ** from xFullPathname() with an optional suffix added.
   822    824   ** ^If a suffix is added to the zFilename parameter, it will
   823    825   ** consist of a single "-" character followed by no more than
   824    826   ** 10 alphanumeric and/or "-" characters.
   825    827   ** ^SQLite further guarantees that
................................................................................
   889    891   ** allocate the structure; it should just fill it in.  Note that
   890    892   ** the xOpen method must set the sqlite3_file.pMethods to either
   891    893   ** a valid [sqlite3_io_methods] object or to NULL.  xOpen must do
   892    894   ** this even if the open fails.  SQLite expects that the sqlite3_file.pMethods
   893    895   ** element will be valid after xOpen returns regardless of the success
   894    896   ** or failure of the xOpen call.
   895    897   **
          898  +** [[sqlite3_vfs.xAccess]]
   896    899   ** ^The flags argument to xAccess() may be [SQLITE_ACCESS_EXISTS]
   897    900   ** to test for the existence of a file, or [SQLITE_ACCESS_READWRITE] to
   898    901   ** test whether a file is readable and writable, or [SQLITE_ACCESS_READ]
   899    902   ** to test whether a file is at least readable.   The file can be a
   900    903   ** directory.
   901    904   **
   902    905   ** ^SQLite will always allocate at least mxPathname+1 bytes for the
................................................................................
  1135   1138   ** [sqlite3_initialize()] or after shutdown by [sqlite3_shutdown()].
  1136   1139   ** ^If sqlite3_config() is called after [sqlite3_initialize()] and before
  1137   1140   ** [sqlite3_shutdown()] then it will return SQLITE_MISUSE.
  1138   1141   ** Note, however, that ^sqlite3_config() can be called as part of the
  1139   1142   ** implementation of an application-defined [sqlite3_os_init()].
  1140   1143   **
  1141   1144   ** The first argument to sqlite3_config() is an integer
  1142         -** [SQLITE_CONFIG_SINGLETHREAD | configuration option] that determines
         1145  +** [configuration option] that determines
  1143   1146   ** what property of SQLite is to be configured.  Subsequent arguments
  1144         -** vary depending on the [SQLITE_CONFIG_SINGLETHREAD | configuration option]
         1147  +** vary depending on the [configuration option]
  1145   1148   ** in the first argument.
  1146   1149   **
  1147   1150   ** ^When a configuration option is set, sqlite3_config() returns [SQLITE_OK].
  1148   1151   ** ^If the option is unknown or SQLite is unable to set the option
  1149   1152   ** then this routine returns a non-zero [error code].
  1150   1153   */
  1151   1154   int sqlite3_config(int, ...);
................................................................................
  1247   1250     int (*xInit)(void*);           /* Initialize the memory allocator */
  1248   1251     void (*xShutdown)(void*);      /* Deinitialize the memory allocator */
  1249   1252     void *pAppData;                /* Argument to xInit() and xShutdown() */
  1250   1253   };
  1251   1254   
  1252   1255   /*
  1253   1256   ** CAPI3REF: Configuration Options
         1257  +** KEYWORDS: {configuration option}
  1254   1258   **
  1255   1259   ** These constants are the available integer configuration options that
  1256   1260   ** can be passed as the first argument to the [sqlite3_config()] interface.
  1257   1261   **
  1258   1262   ** New configuration options may be added in future releases of SQLite.
  1259   1263   ** Existing configuration options might be discontinued.  Applications
  1260   1264   ** should check the return code from [sqlite3_config()] to make sure that
  1261   1265   ** the call worked.  The [sqlite3_config()] interface will return a
  1262   1266   ** non-zero [error code] if a discontinued or unsupported configuration option
  1263   1267   ** is invoked.
  1264   1268   **
  1265   1269   ** <dl>
  1266         -** <dt>SQLITE_CONFIG_SINGLETHREAD</dt>
         1270  +** [[SQLITE_CONFIG_SINGLETHREAD]] <dt>SQLITE_CONFIG_SINGLETHREAD</dt>
  1267   1271   ** <dd>There are no arguments to this option.  ^This option sets the
  1268   1272   ** [threading mode] to Single-thread.  In other words, it disables
  1269   1273   ** all mutexing and puts SQLite into a mode where it can only be used
  1270   1274   ** by a single thread.   ^If SQLite is compiled with
  1271   1275   ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
  1272   1276   ** it is not possible to change the [threading mode] from its default
  1273   1277   ** value of Single-thread and so [sqlite3_config()] will return 
  1274   1278   ** [SQLITE_ERROR] if called with the SQLITE_CONFIG_SINGLETHREAD
  1275   1279   ** configuration option.</dd>
  1276   1280   **
  1277         -** <dt>SQLITE_CONFIG_MULTITHREAD</dt>
         1281  +** [[SQLITE_CONFIG_MULTITHREAD]] <dt>SQLITE_CONFIG_MULTITHREAD</dt>
  1278   1282   ** <dd>There are no arguments to this option.  ^This option sets the
  1279   1283   ** [threading mode] to Multi-thread.  In other words, it disables
  1280   1284   ** mutexing on [database connection] and [prepared statement] objects.
  1281   1285   ** The application is responsible for serializing access to
  1282   1286   ** [database connections] and [prepared statements].  But other mutexes
  1283   1287   ** are enabled so that SQLite will be safe to use in a multi-threaded
  1284   1288   ** environment as long as no two threads attempt to use the same
  1285   1289   ** [database connection] at the same time.  ^If SQLite is compiled with
  1286   1290   ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
  1287   1291   ** it is not possible to set the Multi-thread [threading mode] and
  1288   1292   ** [sqlite3_config()] will return [SQLITE_ERROR] if called with the
  1289   1293   ** SQLITE_CONFIG_MULTITHREAD configuration option.</dd>
  1290   1294   **
  1291         -** <dt>SQLITE_CONFIG_SERIALIZED</dt>
         1295  +** [[SQLITE_CONFIG_SERIALIZED]] <dt>SQLITE_CONFIG_SERIALIZED</dt>
  1292   1296   ** <dd>There are no arguments to this option.  ^This option sets the
  1293   1297   ** [threading mode] to Serialized. In other words, this option enables
  1294   1298   ** all mutexes including the recursive
  1295   1299   ** mutexes on [database connection] and [prepared statement] objects.
  1296   1300   ** In this mode (which is the default when SQLite is compiled with
  1297   1301   ** [SQLITE_THREADSAFE=1]) the SQLite library will itself serialize access
  1298   1302   ** to [database connections] and [prepared statements] so that the
................................................................................
  1300   1304   ** same [prepared statement] in different threads at the same time.
  1301   1305   ** ^If SQLite is compiled with
  1302   1306   ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
  1303   1307   ** it is not possible to set the Serialized [threading mode] and
  1304   1308   ** [sqlite3_config()] will return [SQLITE_ERROR] if called with the
  1305   1309   ** SQLITE_CONFIG_SERIALIZED configuration option.</dd>
  1306   1310   **
  1307         -** <dt>SQLITE_CONFIG_MALLOC</dt>
         1311  +** [[SQLITE_CONFIG_MALLOC]] <dt>SQLITE_CONFIG_MALLOC</dt>
  1308   1312   ** <dd> ^(This option takes a single argument which is a pointer to an
  1309   1313   ** instance of the [sqlite3_mem_methods] structure.  The argument specifies
  1310   1314   ** alternative low-level memory allocation routines to be used in place of
  1311   1315   ** the memory allocation routines built into SQLite.)^ ^SQLite makes
  1312   1316   ** its own private copy of the content of the [sqlite3_mem_methods] structure
  1313   1317   ** before the [sqlite3_config()] call returns.</dd>
  1314   1318   **
  1315         -** <dt>SQLITE_CONFIG_GETMALLOC</dt>
         1319  +** [[SQLITE_CONFIG_GETMALLOC]] <dt>SQLITE_CONFIG_GETMALLOC</dt>
  1316   1320   ** <dd> ^(This option takes a single argument which is a pointer to an
  1317   1321   ** instance of the [sqlite3_mem_methods] structure.  The [sqlite3_mem_methods]
  1318   1322   ** structure is filled with the currently defined memory allocation routines.)^
  1319   1323   ** This option can be used to overload the default memory allocation
  1320   1324   ** routines with a wrapper that simulations memory allocation failure or
  1321   1325   ** tracks memory usage, for example. </dd>
  1322   1326   **
  1323         -** <dt>SQLITE_CONFIG_MEMSTATUS</dt>
         1327  +** [[SQLITE_CONFIG_MEMSTATUS]] <dt>SQLITE_CONFIG_MEMSTATUS</dt>
  1324   1328   ** <dd> ^This option takes single argument of type int, interpreted as a 
  1325   1329   ** boolean, which enables or disables the collection of memory allocation 
  1326   1330   ** statistics. ^(When memory allocation statistics are disabled, the 
  1327   1331   ** following SQLite interfaces become non-operational:
  1328   1332   **   <ul>
  1329   1333   **   <li> [sqlite3_memory_used()]
  1330   1334   **   <li> [sqlite3_memory_highwater()]
................................................................................
  1332   1336   **   <li> [sqlite3_status()]
  1333   1337   **   </ul>)^
  1334   1338   ** ^Memory allocation statistics are enabled by default unless SQLite is
  1335   1339   ** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory
  1336   1340   ** allocation statistics are disabled by default.
  1337   1341   ** </dd>
  1338   1342   **
  1339         -** <dt>SQLITE_CONFIG_SCRATCH</dt>
         1343  +** [[SQLITE_CONFIG_SCRATCH]] <dt>SQLITE_CONFIG_SCRATCH</dt>
  1340   1344   ** <dd> ^This option specifies a static memory buffer that SQLite can use for
  1341   1345   ** scratch memory.  There are three arguments:  A pointer an 8-byte
  1342   1346   ** aligned memory buffer from which the scratch allocations will be
  1343   1347   ** drawn, the size of each scratch allocation (sz),
  1344   1348   ** and the maximum number of scratch allocations (N).  The sz
  1345   1349   ** argument must be a multiple of 16.
  1346   1350   ** The first argument must be a pointer to an 8-byte aligned buffer
................................................................................
  1348   1352   ** ^SQLite will use no more than two scratch buffers per thread.  So
  1349   1353   ** N should be set to twice the expected maximum number of threads.
  1350   1354   ** ^SQLite will never require a scratch buffer that is more than 6
  1351   1355   ** times the database page size. ^If SQLite needs needs additional
  1352   1356   ** scratch memory beyond what is provided by this configuration option, then 
  1353   1357   ** [sqlite3_malloc()] will be used to obtain the memory needed.</dd>
  1354   1358   **
  1355         -** <dt>SQLITE_CONFIG_PAGECACHE</dt>
         1359  +** [[SQLITE_CONFIG_PAGECACHE]] <dt>SQLITE_CONFIG_PAGECACHE</dt>
  1356   1360   ** <dd> ^This option specifies a static memory buffer that SQLite can use for
  1357   1361   ** the database page cache with the default page cache implemenation.  
  1358   1362   ** This configuration should not be used if an application-define page
  1359   1363   ** cache implementation is loaded using the SQLITE_CONFIG_PCACHE option.
  1360   1364   ** There are three arguments to this option: A pointer to 8-byte aligned
  1361   1365   ** memory, the size of each page buffer (sz), and the number of pages (N).
  1362   1366   ** The sz argument should be the size of the largest database page
................................................................................
  1369   1373   ** memory needs for the first N pages that it adds to cache.  ^If additional
  1370   1374   ** page cache memory is needed beyond what is provided by this option, then
  1371   1375   ** SQLite goes to [sqlite3_malloc()] for the additional storage space.
  1372   1376   ** The pointer in the first argument must
  1373   1377   ** be aligned to an 8-byte boundary or subsequent behavior of SQLite
  1374   1378   ** will be undefined.</dd>
  1375   1379   **
  1376         -** <dt>SQLITE_CONFIG_HEAP</dt>
         1380  +** [[SQLITE_CONFIG_HEAP]] <dt>SQLITE_CONFIG_HEAP</dt>
  1377   1381   ** <dd> ^This option specifies a static memory buffer that SQLite will use
  1378   1382   ** for all of its dynamic memory allocation needs beyond those provided
  1379   1383   ** for by [SQLITE_CONFIG_SCRATCH] and [SQLITE_CONFIG_PAGECACHE].
  1380   1384   ** There are three arguments: An 8-byte aligned pointer to the memory,
  1381   1385   ** the number of bytes in the memory buffer, and the minimum allocation size.
  1382   1386   ** ^If the first pointer (the memory pointer) is NULL, then SQLite reverts
  1383   1387   ** to using its default memory allocator (the system malloc() implementation),
................................................................................
  1386   1390   ** [SQLITE_ENABLE_MEMSYS5] are defined, then the alternative memory
  1387   1391   ** allocator is engaged to handle all of SQLites memory allocation needs.
  1388   1392   ** The first pointer (the memory pointer) must be aligned to an 8-byte
  1389   1393   ** boundary or subsequent behavior of SQLite will be undefined.
  1390   1394   ** The minimum allocation size is capped at 2^12. Reasonable values
  1391   1395   ** for the minimum allocation size are 2^5 through 2^8.</dd>
  1392   1396   **
  1393         -** <dt>SQLITE_CONFIG_MUTEX</dt>
         1397  +** [[SQLITE_CONFIG_MUTEX]] <dt>SQLITE_CONFIG_MUTEX</dt>
  1394   1398   ** <dd> ^(This option takes a single argument which is a pointer to an
  1395   1399   ** instance of the [sqlite3_mutex_methods] structure.  The argument specifies
  1396   1400   ** alternative low-level mutex routines to be used in place
  1397   1401   ** the mutex routines built into SQLite.)^  ^SQLite makes a copy of the
  1398   1402   ** content of the [sqlite3_mutex_methods] structure before the call to
  1399   1403   ** [sqlite3_config()] returns. ^If SQLite is compiled with
  1400   1404   ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
  1401   1405   ** the entire mutexing subsystem is omitted from the build and hence calls to
  1402   1406   ** [sqlite3_config()] with the SQLITE_CONFIG_MUTEX configuration option will
  1403   1407   ** return [SQLITE_ERROR].</dd>
  1404   1408   **
  1405         -** <dt>SQLITE_CONFIG_GETMUTEX</dt>
         1409  +** [[SQLITE_CONFIG_GETMUTEX]] <dt>SQLITE_CONFIG_GETMUTEX</dt>
  1406   1410   ** <dd> ^(This option takes a single argument which is a pointer to an
  1407   1411   ** instance of the [sqlite3_mutex_methods] structure.  The
  1408   1412   ** [sqlite3_mutex_methods]
  1409   1413   ** structure is filled with the currently defined mutex routines.)^
  1410   1414   ** This option can be used to overload the default mutex allocation
  1411   1415   ** routines with a wrapper used to track mutex usage for performance
  1412   1416   ** profiling or testing, for example.   ^If SQLite is compiled with
  1413   1417   ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
  1414   1418   ** the entire mutexing subsystem is omitted from the build and hence calls to
  1415   1419   ** [sqlite3_config()] with the SQLITE_CONFIG_GETMUTEX configuration option will
  1416   1420   ** return [SQLITE_ERROR].</dd>
  1417   1421   **
  1418         -** <dt>SQLITE_CONFIG_LOOKASIDE</dt>
         1422  +** [[SQLITE_CONFIG_LOOKASIDE]] <dt>SQLITE_CONFIG_LOOKASIDE</dt>
  1419   1423   ** <dd> ^(This option takes two arguments that determine the default
  1420   1424   ** memory allocation for the lookaside memory allocator on each
  1421   1425   ** [database connection].  The first argument is the
  1422   1426   ** size of each lookaside buffer slot and the second is the number of
  1423   1427   ** slots allocated to each database connection.)^  ^(This option sets the
  1424   1428   ** <i>default</i> lookaside size. The [SQLITE_DBCONFIG_LOOKASIDE]
  1425   1429   ** verb to [sqlite3_db_config()] can be used to change the lookaside
  1426   1430   ** configuration on individual connections.)^ </dd>
  1427   1431   **
  1428         -** <dt>SQLITE_CONFIG_PCACHE</dt>
         1432  +** [[SQLITE_CONFIG_PCACHE]] <dt>SQLITE_CONFIG_PCACHE</dt>
  1429   1433   ** <dd> ^(This option takes a single argument which is a pointer to
  1430   1434   ** an [sqlite3_pcache_methods] object.  This object specifies the interface
  1431   1435   ** to a custom page cache implementation.)^  ^SQLite makes a copy of the
  1432   1436   ** object and uses it for page cache memory allocations.</dd>
  1433   1437   **
  1434         -** <dt>SQLITE_CONFIG_GETPCACHE</dt>
         1438  +** [[SQLITE_CONFIG_GETPCACHE]] <dt>SQLITE_CONFIG_GETPCACHE</dt>
  1435   1439   ** <dd> ^(This option takes a single argument which is a pointer to an
  1436   1440   ** [sqlite3_pcache_methods] object.  SQLite copies of the current
  1437   1441   ** page cache implementation into that object.)^ </dd>
  1438   1442   **
  1439         -** <dt>SQLITE_CONFIG_LOG</dt>
         1443  +** [[SQLITE_CONFIG_LOG]] <dt>SQLITE_CONFIG_LOG</dt>
  1440   1444   ** <dd> ^The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a
  1441   1445   ** function with a call signature of void(*)(void*,int,const char*), 
  1442   1446   ** and a pointer to void. ^If the function pointer is not NULL, it is
  1443   1447   ** invoked by [sqlite3_log()] to process each logging event.  ^If the
  1444   1448   ** function pointer is NULL, the [sqlite3_log()] interface becomes a no-op.
  1445   1449   ** ^The void pointer that is the second argument to SQLITE_CONFIG_LOG is
  1446   1450   ** passed through as the first parameter to the application-defined logger
................................................................................
  1450   1454   ** [extended result code].  ^The third parameter passed to the logger is
  1451   1455   ** log message after formatting via [sqlite3_snprintf()].
  1452   1456   ** The SQLite logging interface is not reentrant; the logger function
  1453   1457   ** supplied by the application must not invoke any SQLite interface.
  1454   1458   ** In a multi-threaded application, the application-defined logger
  1455   1459   ** function must be threadsafe. </dd>
  1456   1460   **
  1457         -** <dt>SQLITE_CONFIG_URI
         1461  +** [[SQLITE_CONFIG_URI]] <dt>SQLITE_CONFIG_URI
  1458   1462   ** <dd> This option takes a single argument of type int. If non-zero, then
  1459   1463   ** URI handling is globally enabled. If the parameter is zero, then URI handling
  1460   1464   ** is globally disabled. If URI handling is globally enabled, all filenames
  1461   1465   ** passed to [sqlite3_open()], [sqlite3_open_v2()], [sqlite3_open16()] or
  1462   1466   ** specified as part of [ATTACH] commands are interpreted as URIs, regardless
  1463   1467   ** of whether or not the [SQLITE_OPEN_URI] flag is set when the database
  1464   1468   ** connection is opened. If it is globally disabled, filenames are
................................................................................
  1566   1570   ** as an undeclared column named ROWID, OID, or _ROWID_ as long as those
  1567   1571   ** names are not also used by explicitly declared columns. ^If
  1568   1572   ** the table has a column of type [INTEGER PRIMARY KEY] then that column
  1569   1573   ** is another alias for the rowid.
  1570   1574   **
  1571   1575   ** ^This routine returns the [rowid] of the most recent
  1572   1576   ** successful [INSERT] into the database from the [database connection]
  1573         -** in the first argument.  ^If no successful [INSERT]s
         1577  +** in the first argument.  ^As of SQLite version 3.7.7, this routines
         1578  +** records the last insert rowid of both ordinary tables and [virtual tables].
         1579  +** ^If no successful [INSERT]s
  1574   1580   ** have ever occurred on that database connection, zero is returned.
  1575   1581   **
  1576         -** ^(If an [INSERT] occurs within a trigger, then the [rowid] of the inserted
  1577         -** row is returned by this routine as long as the trigger is running.
  1578         -** But once the trigger terminates, the value returned by this routine
  1579         -** reverts to the last value inserted before the trigger fired.)^
         1582  +** ^(If an [INSERT] occurs within a trigger or within a [virtual table]
         1583  +** method, then this routine will return the [rowid] of the inserted
         1584  +** row as long as the trigger or virtual table method is running.
         1585  +** But once the trigger or virtual table method ends, the value returned 
         1586  +** by this routine reverts to what it was before the trigger or virtual
         1587  +** table method began.)^
  1580   1588   **
  1581   1589   ** ^An [INSERT] that fails due to a constraint violation is not a
  1582   1590   ** successful [INSERT] and does not change the value returned by this
  1583   1591   ** routine.  ^Thus INSERT OR FAIL, INSERT OR IGNORE, INSERT OR ROLLBACK,
  1584   1592   ** and INSERT OR ABORT make no changes to the return value of this
  1585   1593   ** routine when their insertion fails.  ^(When INSERT OR REPLACE
  1586   1594   ** encounters a constraint violation, it does not fail.  The
................................................................................
  2387   2395   **
  2388   2396   ** The sqlite3_open_v2() interface works like sqlite3_open()
  2389   2397   ** except that it accepts two additional parameters for additional control
  2390   2398   ** over the new database connection.  ^(The flags parameter to
  2391   2399   ** sqlite3_open_v2() can take one of
  2392   2400   ** the following three values, optionally combined with the 
  2393   2401   ** [SQLITE_OPEN_NOMUTEX], [SQLITE_OPEN_FULLMUTEX], [SQLITE_OPEN_SHAREDCACHE],
  2394         -** and/or [SQLITE_OPEN_PRIVATECACHE] flags:)^
         2402  +** [SQLITE_OPEN_PRIVATECACHE], and/or [SQLITE_OPEN_URI] flags:)^
  2395   2403   **
  2396   2404   ** <dl>
  2397   2405   ** ^(<dt>[SQLITE_OPEN_READONLY]</dt>
  2398   2406   ** <dd>The database is opened in read-only mode.  If the database does not
  2399   2407   ** already exist, an error is returned.</dd>)^
  2400   2408   **
  2401   2409   ** ^(<dt>[SQLITE_OPEN_READWRITE]</dt>
................................................................................
  2406   2414   ** ^(<dt>[SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]</dt>
  2407   2415   ** <dd>The database is opened for reading and writing, and is created if
  2408   2416   ** it does not already exist. This is the behavior that is always used for
  2409   2417   ** sqlite3_open() and sqlite3_open16().</dd>)^
  2410   2418   ** </dl>
  2411   2419   **
  2412   2420   ** If the 3rd parameter to sqlite3_open_v2() is not one of the
  2413         -** combinations shown above or one of the combinations shown above combined
  2414         -** with the [SQLITE_OPEN_NOMUTEX], [SQLITE_OPEN_FULLMUTEX],
  2415         -** [SQLITE_OPEN_SHAREDCACHE] and/or [SQLITE_OPEN_PRIVATECACHE] flags,
         2421  +** combinations shown above optionally combined with other
         2422  +** [SQLITE_OPEN_READONLY | SQLITE_OPEN_* bits]
  2416   2423   ** then the behavior is undefined.
  2417   2424   **
  2418   2425   ** ^If the [SQLITE_OPEN_NOMUTEX] flag is set, then the database connection
  2419   2426   ** opens in the multi-thread [threading mode] as long as the single-thread
  2420   2427   ** mode has not been set at compile-time or start-time.  ^If the
  2421   2428   ** [SQLITE_OPEN_FULLMUTEX] flag is set then the database connection opens
  2422   2429   ** in the serialized [threading mode] unless single-thread was
................................................................................
  2440   2447   ** a ":" character you should prefix the filename with a pathname such as
  2441   2448   ** "./" to avoid ambiguity.
  2442   2449   **
  2443   2450   ** ^If the filename is an empty string, then a private, temporary
  2444   2451   ** on-disk database will be created.  ^This private database will be
  2445   2452   ** automatically deleted as soon as the database connection is closed.
  2446   2453   **
  2447         -** ^If URI filename interpretation is enabled, and the filename argument
         2454  +** [[URI filenames in sqlite3_open()]] <h3>URI Filenames</h3>
         2455  +**
         2456  +** ^If [URI filename] interpretation is enabled, and the filename argument
  2448   2457   ** begins with "file:", then the filename is interpreted as a URI. ^URI
  2449   2458   ** filename interpretation is enabled if the [SQLITE_OPEN_URI] flag is
  2450   2459   ** is set in the fourth argument to sqlite3_open_v2(), or if it has
  2451   2460   ** been enabled globally using the [SQLITE_CONFIG_URI] option with the
  2452         -** [sqlite3_config()] method. 
         2461  +** [sqlite3_config()] method or by the [SQLITE_USE_URI] compile-time option.
         2462  +** As of SQLite version 3.7.7, URI filename interpretation is turned off
         2463  +** by default, but future releases of SQLite might enable URI filename
         2464  +** intepretation by default.  See "[URI filenames]" for additional
         2465  +** information.
  2453   2466   **
  2454         -** URI filenames are parsed according to RFC 1738. If the URI contains an
  2455         -** 'authority', then it must be either an empty string or the string 
         2467  +** URI filenames are parsed according to RFC 3986. ^If the URI contains an
         2468  +** authority, then it must be either an empty string or the string 
  2456   2469   ** "localhost". ^If the authority is not an empty string or "localhost", an 
  2457         -** error is returned to the caller. ^The 'fragment' component of a URI, if 
  2458         -** present, is always ignored.
         2470  +** error is returned to the caller. ^The fragment component of a URI, if 
         2471  +** present, is ignored.
  2459   2472   **
  2460         -** ^SQLite uses the 'path' component of the URI as the path to the database file
  2461         -** to open. ^If the path begins with a '/' character, then it is interpreted as
  2462         -** an absolute path. ^If it does not begin with a '/', it is interpreted as a 
  2463         -** relative path. ^On windows, the first component of an absolute path 
         2473  +** ^SQLite uses the path component of the URI as the name of the disk file
         2474  +** which contains the database. ^If the path begins with a '/' character, 
         2475  +** then it is interpreted as an absolute path. ^If the path does not begin 
         2476  +** with a '/' (meaning that the authority section is omitted from the URI)
         2477  +** then the path is interpreted as a relative path. 
         2478  +** ^On windows, the first component of an absolute path 
  2464   2479   ** is a drive specification (e.g. "C:").
  2465   2480   **
         2481  +** [[core URI query parameters]]
  2466   2482   ** The query component of a URI may contain parameters that are interpreted
  2467         -** either by SQLite itself, or by a [sqlite3_vfs | custom VFS implementation].
         2483  +** either by SQLite itself, or by a [VFS | custom VFS implementation].
  2468   2484   ** SQLite interprets the following four query parameters:
  2469   2485   **
  2470   2486   ** <ul>
  2471   2487   **   <li> <b>vfs</b>: ^The "vfs" parameter may be used to specify the name of
  2472   2488   **     a VFS object that provides the operating system interface that should
  2473   2489   **     be used to access the database file on disk. ^If this option is set to
  2474   2490   **     an empty string the default VFS object is used. ^Specifying an unknown
................................................................................
  2512   2528   **     database corruption, or return an SQLITE_READONLY error. Or if the
  2513   2529   **     most recent read-write connection shut down cleanly, it may not be
  2514   2530   **     possible to open the shared-memory in read-only mode at all, and SQLite
  2515   2531   **     will return SQLITE_CANTOPEN.
  2516   2532   ** </ul>
  2517   2533   **
  2518   2534   ** ^Specifying an unknown parameter in the query component of a URI is not an
  2519         -** error.
         2535  +** error.  Future versions of SQLite might understand additional query
         2536  +** parameters.  See "[query parameters with special meaning to SQLite]" for
         2537  +** additional information.
  2520   2538   **
  2521         -** URI filename examples:
         2539  +** [[URI filename examples]] <h3>URI filename examples</h3>
  2522   2540   **
  2523   2541   ** <table border="1" align=center cellpadding=5>
  2524   2542   ** <tr><th> URI filenames <th> Results
  2525   2543   ** <tr><td> file:data.db <td> 
  2526   2544   **          Open the file "data.db" in the current directory.
  2527   2545   ** <tr><td> file:/home/fred/data.db<br>
  2528   2546   **          file:///home/fred/data.db <br> 
................................................................................
  2571   2589   );
  2572   2590   int sqlite3_open_v2(
  2573   2591     const char *filename,   /* Database filename (UTF-8) */
  2574   2592     sqlite3 **ppDb,         /* OUT: SQLite db handle */
  2575   2593     int flags,              /* Flags */
  2576   2594     const char *zVfs        /* Name of VFS module to use */
  2577   2595   );
         2596  +
         2597  +/*
         2598  +** CAPI3REF: Obtain Values For URI Parameters
         2599  +**
         2600  +** This is a utility routine, useful to VFS implementations, that checks
         2601  +** to see if a database file was a URI that contained a specific query 
         2602  +** parameter, and if so obtains the value of the query parameter.
         2603  +**
         2604  +** The zFilename argument is the filename pointer passed into the xOpen()
         2605  +** method of a VFS implementation.  The zParam argument is the name of the
         2606  +** query parameter we seek.  This routine returns the value of the zParam
         2607  +** parameter if it exists.  If the parameter does not exist, this routine
         2608  +** returns a NULL pointer.
         2609  +**
         2610  +** If the zFilename argument to this function is not a pointer that SQLite
         2611  +** passed into the xOpen VFS method, then the behavior of this routine
         2612  +** is undefined and probably undesirable.
         2613  +*/
         2614  +const char *sqlite3_uri_parameter(const char *zFilename, const char *zParam);
         2615  +
  2578   2616   
  2579   2617   /*
  2580   2618   ** CAPI3REF: Error Codes And Messages
  2581   2619   **
  2582   2620   ** ^The sqlite3_errcode() interface returns the numeric [result code] or
  2583   2621   ** [extended result code] for the most recent failed sqlite3_* API call
  2584   2622   ** associated with a [database connection]. If a prior API call failed
................................................................................
  2687   2725   **
  2688   2726   ** These constants define various performance limits
  2689   2727   ** that can be lowered at run-time using [sqlite3_limit()].
  2690   2728   ** The synopsis of the meanings of the various limits is shown below.
  2691   2729   ** Additional information is available at [limits | Limits in SQLite].
  2692   2730   **
  2693   2731   ** <dl>
  2694         -** ^(<dt>SQLITE_LIMIT_LENGTH</dt>
         2732  +** [[SQLITE_LIMIT_LENGTH]] ^(<dt>SQLITE_LIMIT_LENGTH</dt>
  2695   2733   ** <dd>The maximum size of any string or BLOB or table row, in bytes.<dd>)^
  2696   2734   **
  2697         -** ^(<dt>SQLITE_LIMIT_SQL_LENGTH</dt>
         2735  +** [[SQLITE_LIMIT_SQL_LENGTH]] ^(<dt>SQLITE_LIMIT_SQL_LENGTH</dt>
  2698   2736   ** <dd>The maximum length of an SQL statement, in bytes.</dd>)^
  2699   2737   **
  2700         -** ^(<dt>SQLITE_LIMIT_COLUMN</dt>
         2738  +** [[SQLITE_LIMIT_COLUMN]] ^(<dt>SQLITE_LIMIT_COLUMN</dt>
  2701   2739   ** <dd>The maximum number of columns in a table definition or in the
  2702   2740   ** result set of a [SELECT] or the maximum number of columns in an index
  2703   2741   ** or in an ORDER BY or GROUP BY clause.</dd>)^
  2704   2742   **
  2705         -** ^(<dt>SQLITE_LIMIT_EXPR_DEPTH</dt>
         2743  +** [[SQLITE_LIMIT_EXPR_DEPTH]] ^(<dt>SQLITE_LIMIT_EXPR_DEPTH</dt>
  2706   2744   ** <dd>The maximum depth of the parse tree on any expression.</dd>)^
  2707   2745   **
  2708         -** ^(<dt>SQLITE_LIMIT_COMPOUND_SELECT</dt>
         2746  +** [[SQLITE_LIMIT_COMPOUND_SELECT]] ^(<dt>SQLITE_LIMIT_COMPOUND_SELECT</dt>
  2709   2747   ** <dd>The maximum number of terms in a compound SELECT statement.</dd>)^
  2710   2748   **
  2711         -** ^(<dt>SQLITE_LIMIT_VDBE_OP</dt>
         2749  +** [[SQLITE_LIMIT_VDBE_OP]] ^(<dt>SQLITE_LIMIT_VDBE_OP</dt>
  2712   2750   ** <dd>The maximum number of instructions in a virtual machine program
  2713   2751   ** used to implement an SQL statement.  This limit is not currently
  2714   2752   ** enforced, though that might be added in some future release of
  2715   2753   ** SQLite.</dd>)^
  2716   2754   **
  2717         -** ^(<dt>SQLITE_LIMIT_FUNCTION_ARG</dt>
         2755  +** [[SQLITE_LIMIT_FUNCTION_ARG]] ^(<dt>SQLITE_LIMIT_FUNCTION_ARG</dt>
  2718   2756   ** <dd>The maximum number of arguments on a function.</dd>)^
  2719   2757   **
  2720         -** ^(<dt>SQLITE_LIMIT_ATTACHED</dt>
         2758  +** [[SQLITE_LIMIT_ATTACHED]] ^(<dt>SQLITE_LIMIT_ATTACHED</dt>
  2721   2759   ** <dd>The maximum number of [ATTACH | attached databases].)^</dd>
  2722   2760   **
         2761  +** [[SQLITE_LIMIT_LIKE_PATTERN_LENGTH]]
  2723   2762   ** ^(<dt>SQLITE_LIMIT_LIKE_PATTERN_LENGTH</dt>
  2724   2763   ** <dd>The maximum length of the pattern argument to the [LIKE] or
  2725   2764   ** [GLOB] operators.</dd>)^
  2726   2765   **
         2766  +** [[SQLITE_LIMIT_VARIABLE_NUMBER]]
  2727   2767   ** ^(<dt>SQLITE_LIMIT_VARIABLE_NUMBER</dt>
  2728   2768   ** <dd>The maximum index number of any [parameter] in an SQL statement.)^
  2729   2769   **
  2730         -** ^(<dt>SQLITE_LIMIT_TRIGGER_DEPTH</dt>
         2770  +** [[SQLITE_LIMIT_TRIGGER_DEPTH]] ^(<dt>SQLITE_LIMIT_TRIGGER_DEPTH</dt>
  2731   2771   ** <dd>The maximum depth of recursion for triggers.</dd>)^
  2732   2772   ** </dl>
  2733   2773   */
  2734   2774   #define SQLITE_LIMIT_LENGTH                    0
  2735   2775   #define SQLITE_LIMIT_SQL_LENGTH                1
  2736   2776   #define SQLITE_LIMIT_COLUMN                    2
  2737   2777   #define SQLITE_LIMIT_EXPR_DEPTH                3
................................................................................
  5577   5617   /*
  5578   5618   ** CAPI3REF: SQLite Runtime Status
  5579   5619   **
  5580   5620   ** ^This interface is used to retrieve runtime status information
  5581   5621   ** about the performance of SQLite, and optionally to reset various
  5582   5622   ** highwater marks.  ^The first argument is an integer code for
  5583   5623   ** the specific parameter to measure.  ^(Recognized integer codes
  5584         -** are of the form [SQLITE_STATUS_MEMORY_USED | SQLITE_STATUS_...].)^
         5624  +** are of the form [status parameters | SQLITE_STATUS_...].)^
  5585   5625   ** ^The current value of the parameter is returned into *pCurrent.
  5586   5626   ** ^The highest recorded value is returned in *pHighwater.  ^If the
  5587   5627   ** resetFlag is true, then the highest record value is reset after
  5588   5628   ** *pHighwater is written.  ^(Some parameters do not record the highest
  5589   5629   ** value.  For those parameters
  5590   5630   ** nothing is written into *pHighwater and the resetFlag is ignored.)^
  5591   5631   ** ^(Other parameters record only the highwater mark and not the current
................................................................................
  5604   5644   ** See also: [sqlite3_db_status()]
  5605   5645   */
  5606   5646   int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag);
  5607   5647   
  5608   5648   
  5609   5649   /*
  5610   5650   ** CAPI3REF: Status Parameters
         5651  +** KEYWORDS: {status parameters}
  5611   5652   **
  5612   5653   ** These integer constants designate various run-time status parameters
  5613   5654   ** that can be returned by [sqlite3_status()].
  5614   5655   **
  5615   5656   ** <dl>
  5616         -** ^(<dt>SQLITE_STATUS_MEMORY_USED</dt>
         5657  +** [[SQLITE_STATUS_MEMORY_USED]] ^(<dt>SQLITE_STATUS_MEMORY_USED</dt>
  5617   5658   ** <dd>This parameter is the current amount of memory checked out
  5618   5659   ** using [sqlite3_malloc()], either directly or indirectly.  The
  5619   5660   ** figure includes calls made to [sqlite3_malloc()] by the application
  5620   5661   ** and internal memory usage by the SQLite library.  Scratch memory
  5621   5662   ** controlled by [SQLITE_CONFIG_SCRATCH] and auxiliary page-cache
  5622   5663   ** memory controlled by [SQLITE_CONFIG_PAGECACHE] is not included in
  5623   5664   ** this parameter.  The amount returned is the sum of the allocation
  5624   5665   ** sizes as reported by the xSize method in [sqlite3_mem_methods].</dd>)^
  5625   5666   **
  5626         -** ^(<dt>SQLITE_STATUS_MALLOC_SIZE</dt>
         5667  +** [[SQLITE_STATUS_MALLOC_SIZE]] ^(<dt>SQLITE_STATUS_MALLOC_SIZE</dt>
  5627   5668   ** <dd>This parameter records the largest memory allocation request
  5628   5669   ** handed to [sqlite3_malloc()] or [sqlite3_realloc()] (or their
  5629   5670   ** internal equivalents).  Only the value returned in the
  5630   5671   ** *pHighwater parameter to [sqlite3_status()] is of interest.  
  5631   5672   ** The value written into the *pCurrent parameter is undefined.</dd>)^
  5632   5673   **
  5633         -** ^(<dt>SQLITE_STATUS_MALLOC_COUNT</dt>
         5674  +** [[SQLITE_STATUS_MALLOC_COUNT]] ^(<dt>SQLITE_STATUS_MALLOC_COUNT</dt>
  5634   5675   ** <dd>This parameter records the number of separate memory allocations
  5635   5676   ** currently checked out.</dd>)^
  5636   5677   **
  5637         -** ^(<dt>SQLITE_STATUS_PAGECACHE_USED</dt>
         5678  +** [[SQLITE_STATUS_PAGECACHE_USED]] ^(<dt>SQLITE_STATUS_PAGECACHE_USED</dt>
  5638   5679   ** <dd>This parameter returns the number of pages used out of the
  5639   5680   ** [pagecache memory allocator] that was configured using 
  5640   5681   ** [SQLITE_CONFIG_PAGECACHE].  The
  5641   5682   ** value returned is in pages, not in bytes.</dd>)^
  5642   5683   **
         5684  +** [[SQLITE_STATUS_PAGECACHE_OVERFLOW]] 
  5643   5685   ** ^(<dt>SQLITE_STATUS_PAGECACHE_OVERFLOW</dt>
  5644   5686   ** <dd>This parameter returns the number of bytes of page cache
  5645   5687   ** allocation which could not be satisfied by the [SQLITE_CONFIG_PAGECACHE]
  5646   5688   ** buffer and where forced to overflow to [sqlite3_malloc()].  The
  5647   5689   ** returned value includes allocations that overflowed because they
  5648   5690   ** where too large (they were larger than the "sz" parameter to
  5649   5691   ** [SQLITE_CONFIG_PAGECACHE]) and allocations that overflowed because
  5650   5692   ** no space was left in the page cache.</dd>)^
  5651   5693   **
  5652         -** ^(<dt>SQLITE_STATUS_PAGECACHE_SIZE</dt>
         5694  +** [[SQLITE_STATUS_PAGECACHE_SIZE]] ^(<dt>SQLITE_STATUS_PAGECACHE_SIZE</dt>
  5653   5695   ** <dd>This parameter records the largest memory allocation request
  5654   5696   ** handed to [pagecache memory allocator].  Only the value returned in the
  5655   5697   ** *pHighwater parameter to [sqlite3_status()] is of interest.  
  5656   5698   ** The value written into the *pCurrent parameter is undefined.</dd>)^
  5657   5699   **
  5658         -** ^(<dt>SQLITE_STATUS_SCRATCH_USED</dt>
         5700  +** [[SQLITE_STATUS_SCRATCH_USED]] ^(<dt>SQLITE_STATUS_SCRATCH_USED</dt>
  5659   5701   ** <dd>This parameter returns the number of allocations used out of the
  5660   5702   ** [scratch memory allocator] configured using
  5661   5703   ** [SQLITE_CONFIG_SCRATCH].  The value returned is in allocations, not
  5662   5704   ** in bytes.  Since a single thread may only have one scratch allocation
  5663   5705   ** outstanding at time, this parameter also reports the number of threads
  5664   5706   ** using scratch memory at the same time.</dd>)^
  5665   5707   **
  5666         -** ^(<dt>SQLITE_STATUS_SCRATCH_OVERFLOW</dt>
         5708  +** [[SQLITE_STATUS_SCRATCH_OVERFLOW]] ^(<dt>SQLITE_STATUS_SCRATCH_OVERFLOW</dt>
  5667   5709   ** <dd>This parameter returns the number of bytes of scratch memory
  5668   5710   ** allocation which could not be satisfied by the [SQLITE_CONFIG_SCRATCH]
  5669   5711   ** buffer and where forced to overflow to [sqlite3_malloc()].  The values
  5670   5712   ** returned include overflows because the requested allocation was too
  5671   5713   ** larger (that is, because the requested allocation was larger than the
  5672   5714   ** "sz" parameter to [SQLITE_CONFIG_SCRATCH]) and because no scratch buffer
  5673   5715   ** slots were available.
  5674   5716   ** </dd>)^
  5675   5717   **
  5676         -** ^(<dt>SQLITE_STATUS_SCRATCH_SIZE</dt>
         5718  +** [[SQLITE_STATUS_SCRATCH_SIZE]] ^(<dt>SQLITE_STATUS_SCRATCH_SIZE</dt>
  5677   5719   ** <dd>This parameter records the largest memory allocation request
  5678   5720   ** handed to [scratch memory allocator].  Only the value returned in the
  5679   5721   ** *pHighwater parameter to [sqlite3_status()] is of interest.  
  5680   5722   ** The value written into the *pCurrent parameter is undefined.</dd>)^
  5681   5723   **
  5682         -** ^(<dt>SQLITE_STATUS_PARSER_STACK</dt>
         5724  +** [[SQLITE_STATUS_PARSER_STACK]] ^(<dt>SQLITE_STATUS_PARSER_STACK</dt>
  5683   5725   ** <dd>This parameter records the deepest parser stack.  It is only
  5684   5726   ** meaningful if SQLite is compiled with [YYTRACKMAXSTACKDEPTH].</dd>)^
  5685   5727   ** </dl>
  5686   5728   **
  5687   5729   ** New status parameters may be added from time to time.
  5688   5730   */
  5689   5731   #define SQLITE_STATUS_MEMORY_USED          0
................................................................................
  5700   5742   /*
  5701   5743   ** CAPI3REF: Database Connection Status
  5702   5744   **
  5703   5745   ** ^This interface is used to retrieve runtime status information 
  5704   5746   ** about a single [database connection].  ^The first argument is the
  5705   5747   ** database connection object to be interrogated.  ^The second argument
  5706   5748   ** is an integer constant, taken from the set of
  5707         -** [SQLITE_DBSTATUS_LOOKASIDE_USED | SQLITE_DBSTATUS_*] macros, that
         5749  +** [SQLITE_DBSTATUS options], that
  5708   5750   ** determines the parameter to interrogate.  The set of 
  5709         -** [SQLITE_DBSTATUS_LOOKASIDE_USED | SQLITE_DBSTATUS_*] macros is likely
         5751  +** [SQLITE_DBSTATUS options] is likely
  5710   5752   ** to grow in future releases of SQLite.
  5711   5753   **
  5712   5754   ** ^The current value of the requested parameter is written into *pCur
  5713   5755   ** and the highest instantaneous value is written into *pHiwtr.  ^If
  5714   5756   ** the resetFlg is true, then the highest instantaneous value is
  5715   5757   ** reset back down to the current value.
  5716   5758   **
................................................................................
  5719   5761   **
  5720   5762   ** See also: [sqlite3_status()] and [sqlite3_stmt_status()].
  5721   5763   */
  5722   5764   int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg);
  5723   5765   
  5724   5766   /*
  5725   5767   ** CAPI3REF: Status Parameters for database connections
         5768  +** KEYWORDS: {SQLITE_DBSTATUS options}
  5726   5769   **
  5727   5770   ** These constants are the available integer "verbs" that can be passed as
  5728   5771   ** the second argument to the [sqlite3_db_status()] interface.
  5729   5772   **
  5730   5773   ** New verbs may be added in future releases of SQLite. Existing verbs
  5731   5774   ** might be discontinued. Applications should check the return code from
  5732   5775   ** [sqlite3_db_status()] to make sure that the call worked.
  5733   5776   ** The [sqlite3_db_status()] interface will return a non-zero error code
  5734   5777   ** if a discontinued or unsupported verb is invoked.
  5735   5778   **
  5736   5779   ** <dl>
  5737         -** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt>
         5780  +** [[SQLITE_DBSTATUS_LOOKASIDE_USED]] ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt>
  5738   5781   ** <dd>This parameter returns the number of lookaside memory slots currently
  5739   5782   ** checked out.</dd>)^
  5740   5783   **
  5741         -** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_HIT</dt>
         5784  +** [[SQLITE_DBSTATUS_LOOKASIDE_HIT]] ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_HIT</dt>
  5742   5785   ** <dd>This parameter returns the number malloc attempts that were 
  5743   5786   ** satisfied using lookaside memory. Only the high-water value is meaningful;
  5744   5787   ** the current value is always zero.)^
  5745   5788   **
         5789  +** [[SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE]]
  5746   5790   ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE</dt>
  5747   5791   ** <dd>This parameter returns the number malloc attempts that might have
  5748   5792   ** been satisfied using lookaside memory but failed due to the amount of
  5749   5793   ** memory requested being larger than the lookaside slot size.
  5750   5794   ** Only the high-water value is meaningful;
  5751   5795   ** the current value is always zero.)^
  5752   5796   **
         5797  +** [[SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL]]
  5753   5798   ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL</dt>
  5754   5799   ** <dd>This parameter returns the number malloc attempts that might have
  5755   5800   ** been satisfied using lookaside memory but failed due to all lookaside
  5756   5801   ** memory already being in use.
  5757   5802   ** Only the high-water value is meaningful;
  5758   5803   ** the current value is always zero.)^
  5759   5804   **
  5760         -** ^(<dt>SQLITE_DBSTATUS_CACHE_USED</dt>
         5805  +** [[SQLITE_DBSTATUS_CACHE_USED]] ^(<dt>SQLITE_DBSTATUS_CACHE_USED</dt>
  5761   5806   ** <dd>This parameter returns the approximate number of of bytes of heap
  5762   5807   ** memory used by all pager caches associated with the database connection.)^
  5763   5808   ** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0.
  5764   5809   **
  5765         -** ^(<dt>SQLITE_DBSTATUS_SCHEMA_USED</dt>
         5810  +** [[SQLITE_DBSTATUS_SCHEMA_USED]] ^(<dt>SQLITE_DBSTATUS_SCHEMA_USED</dt>
  5766   5811   ** <dd>This parameter returns the approximate number of of bytes of heap
  5767   5812   ** memory used to store the schema for all databases associated
  5768   5813   ** with the connection - main, temp, and any [ATTACH]-ed databases.)^ 
  5769   5814   ** ^The full amount of memory used by the schemas is reported, even if the
  5770   5815   ** schema memory is shared with other database connections due to
  5771   5816   ** [shared cache mode] being enabled.
  5772   5817   ** ^The highwater mark associated with SQLITE_DBSTATUS_SCHEMA_USED is always 0.
  5773   5818   **
  5774         -** ^(<dt>SQLITE_DBSTATUS_STMT_USED</dt>
         5819  +** [[SQLITE_DBSTATUS_STMT_USED]] ^(<dt>SQLITE_DBSTATUS_STMT_USED</dt>
  5775   5820   ** <dd>This parameter returns the approximate number of of bytes of heap
  5776   5821   ** and lookaside memory used by all prepared statements associated with
  5777   5822   ** the database connection.)^
  5778   5823   ** ^The highwater mark associated with SQLITE_DBSTATUS_STMT_USED is always 0.
  5779   5824   ** </dd>
  5780   5825   ** </dl>
  5781   5826   */
................................................................................
  5789   5834   #define SQLITE_DBSTATUS_MAX                  6   /* Largest defined DBSTATUS */
  5790   5835   
  5791   5836   
  5792   5837   /*
  5793   5838   ** CAPI3REF: Prepared Statement Status
  5794   5839   **
  5795   5840   ** ^(Each prepared statement maintains various
  5796         -** [SQLITE_STMTSTATUS_SORT | counters] that measure the number
         5841  +** [SQLITE_STMTSTATUS counters] that measure the number
  5797   5842   ** of times it has performed specific operations.)^  These counters can
  5798   5843   ** be used to monitor the performance characteristics of the prepared
  5799   5844   ** statements.  For example, if the number of table steps greatly exceeds
  5800   5845   ** the number of table searches or result rows, that would tend to indicate
  5801   5846   ** that the prepared statement is using a full table scan rather than
  5802   5847   ** an index.  
  5803   5848   **
  5804   5849   ** ^(This interface is used to retrieve and reset counter values from
  5805   5850   ** a [prepared statement].  The first argument is the prepared statement
  5806   5851   ** object to be interrogated.  The second argument
  5807         -** is an integer code for a specific [SQLITE_STMTSTATUS_SORT | counter]
         5852  +** is an integer code for a specific [SQLITE_STMTSTATUS counter]
  5808   5853   ** to be interrogated.)^
  5809   5854   ** ^The current value of the requested counter is returned.
  5810   5855   ** ^If the resetFlg is true, then the counter is reset to zero after this
  5811   5856   ** interface call returns.
  5812   5857   **
  5813   5858   ** See also: [sqlite3_status()] and [sqlite3_db_status()].
  5814   5859   */
  5815   5860   int sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg);
  5816   5861   
  5817   5862   /*
  5818   5863   ** CAPI3REF: Status Parameters for prepared statements
         5864  +** KEYWORDS: {SQLITE_STMTSTATUS counter} {SQLITE_STMTSTATUS counters}
  5819   5865   **
  5820   5866   ** These preprocessor macros define integer codes that name counter
  5821   5867   ** values associated with the [sqlite3_stmt_status()] interface.
  5822   5868   ** The meanings of the various counters are as follows:
  5823   5869   **
  5824   5870   ** <dl>
  5825         -** <dt>SQLITE_STMTSTATUS_FULLSCAN_STEP</dt>
         5871  +** [[SQLITE_STMTSTATUS_FULLSCAN_STEP]] <dt>SQLITE_STMTSTATUS_FULLSCAN_STEP</dt>
  5826   5872   ** <dd>^This is the number of times that SQLite has stepped forward in
  5827   5873   ** a table as part of a full table scan.  Large numbers for this counter
  5828   5874   ** may indicate opportunities for performance improvement through 
  5829   5875   ** careful use of indices.</dd>
  5830   5876   **
  5831         -** <dt>SQLITE_STMTSTATUS_SORT</dt>
         5877  +** [[SQLITE_STMTSTATUS_SORT]] <dt>SQLITE_STMTSTATUS_SORT</dt>
  5832   5878   ** <dd>^This is the number of sort operations that have occurred.
  5833   5879   ** A non-zero value in this counter may indicate an opportunity to
  5834   5880   ** improvement performance through careful use of indices.</dd>
  5835   5881   **
  5836         -** <dt>SQLITE_STMTSTATUS_AUTOINDEX</dt>
         5882  +** [[SQLITE_STMTSTATUS_AUTOINDEX]] <dt>SQLITE_STMTSTATUS_AUTOINDEX</dt>
  5837   5883   ** <dd>^This is the number of rows inserted into transient indices that
  5838   5884   ** were created automatically in order to help joins run faster.
  5839   5885   ** A non-zero value in this counter may indicate an opportunity to
  5840   5886   ** improvement performance by adding permanent indices that do not
  5841   5887   ** need to be reinitialized each time the statement is run.</dd>
  5842   5888   **
  5843   5889   ** </dl>
................................................................................
  5880   5926   ** The built-in page cache is recommended for most uses.
  5881   5927   **
  5882   5928   ** ^(The contents of the sqlite3_pcache_methods structure are copied to an
  5883   5929   ** internal buffer by SQLite within the call to [sqlite3_config].  Hence
  5884   5930   ** the application may discard the parameter after the call to
  5885   5931   ** [sqlite3_config()] returns.)^
  5886   5932   **
         5933  +** [[the xInit() page cache method]]
  5887   5934   ** ^(The xInit() method is called once for each effective 
  5888   5935   ** call to [sqlite3_initialize()])^
  5889   5936   ** (usually only once during the lifetime of the process). ^(The xInit()
  5890   5937   ** method is passed a copy of the sqlite3_pcache_methods.pArg value.)^
  5891   5938   ** The intent of the xInit() method is to set up global data structures 
  5892   5939   ** required by the custom page cache implementation. 
  5893   5940   ** ^(If the xInit() method is NULL, then the 
  5894   5941   ** built-in default page cache is used instead of the application defined
  5895   5942   ** page cache.)^
  5896   5943   **
         5944  +** [[the xShutdown() page cache method]]
  5897   5945   ** ^The xShutdown() method is called by [sqlite3_shutdown()].
  5898   5946   ** It can be used to clean up 
  5899   5947   ** any outstanding resources before process shutdown, if required.
  5900   5948   ** ^The xShutdown() method may be NULL.
  5901   5949   **
  5902   5950   ** ^SQLite automatically serializes calls to the xInit method,
  5903   5951   ** so the xInit method need not be threadsafe.  ^The
................................................................................
  5904   5952   ** xShutdown method is only called from [sqlite3_shutdown()] so it does
  5905   5953   ** not need to be threadsafe either.  All other methods must be threadsafe
  5906   5954   ** in multithreaded applications.
  5907   5955   **
  5908   5956   ** ^SQLite will never invoke xInit() more than once without an intervening
  5909   5957   ** call to xShutdown().
  5910   5958   **
         5959  +** [[the xCreate() page cache methods]]
  5911   5960   ** ^SQLite invokes the xCreate() method to construct a new cache instance.
  5912   5961   ** SQLite will typically create one cache instance for each open database file,
  5913   5962   ** though this is not guaranteed. ^The
  5914   5963   ** first parameter, szPage, is the size in bytes of the pages that must
  5915   5964   ** be allocated by the cache.  ^szPage will not be a power of two.  ^szPage
  5916   5965   ** will the page size of the database file that is to be cached plus an
  5917   5966   ** increment (here called "R") of less than 250.  SQLite will use the
................................................................................
  5928   5977   ** it is purely advisory.  ^On a cache where bPurgeable is false, SQLite will
  5929   5978   ** never invoke xUnpin() except to deliberately delete a page.
  5930   5979   ** ^In other words, calls to xUnpin() on a cache with bPurgeable set to
  5931   5980   ** false will always have the "discard" flag set to true.  
  5932   5981   ** ^Hence, a cache created with bPurgeable false will
  5933   5982   ** never contain any unpinned pages.
  5934   5983   **
         5984  +** [[the xCachesize() page cache method]]
  5935   5985   ** ^(The xCachesize() method may be called at any time by SQLite to set the
  5936   5986   ** suggested maximum cache-size (number of pages stored by) the cache
  5937   5987   ** instance passed as the first argument. This is the value configured using
  5938   5988   ** the SQLite "[PRAGMA cache_size]" command.)^  As with the bPurgeable
  5939   5989   ** parameter, the implementation is not required to do anything with this
  5940   5990   ** value; it is advisory only.
  5941   5991   **
         5992  +** [[the xPagecount() page cache methods]]
  5942   5993   ** The xPagecount() method must return the number of pages currently
  5943   5994   ** stored in the cache, both pinned and unpinned.
  5944   5995   ** 
         5996  +** [[the xFetch() page cache methods]]
  5945   5997   ** The xFetch() method locates a page in the cache and returns a pointer to 
  5946   5998   ** the page, or a NULL pointer.
  5947   5999   ** A "page", in this context, means a buffer of szPage bytes aligned at an
  5948   6000   ** 8-byte boundary. The page to be fetched is determined by the key. ^The
  5949   6001   ** mimimum key value is 1.  After it has been retrieved using xFetch, the page 
  5950   6002   ** is considered to be "pinned".
  5951   6003   **
................................................................................
  5966   6018   **
  5967   6019   ** ^(SQLite will normally invoke xFetch() with a createFlag of 0 or 1.  SQLite
  5968   6020   ** will only use a createFlag of 2 after a prior call with a createFlag of 1
  5969   6021   ** failed.)^  In between the to xFetch() calls, SQLite may
  5970   6022   ** attempt to unpin one or more cache pages by spilling the content of
  5971   6023   ** pinned pages to disk and synching the operating system disk cache.
  5972   6024   **
         6025  +** [[the xUnpin() page cache method]]
  5973   6026   ** ^xUnpin() is called by SQLite with a pointer to a currently pinned page
  5974   6027   ** as its second argument.  If the third parameter, discard, is non-zero,
  5975   6028   ** then the page must be evicted from the cache.
  5976   6029   ** ^If the discard parameter is
  5977   6030   ** zero, then the page may be discarded or retained at the discretion of
  5978   6031   ** page cache implementation. ^The page cache implementation
  5979   6032   ** may choose to evict unpinned pages at any time.
  5980   6033   **
  5981   6034   ** The cache must not perform any reference counting. A single 
  5982   6035   ** call to xUnpin() unpins the page regardless of the number of prior calls 
  5983   6036   ** to xFetch().
  5984   6037   **
         6038  +** [[the xRekey() page cache methods]]
  5985   6039   ** The xRekey() method is used to change the key value associated with the
  5986   6040   ** page passed as the second argument. If the cache
  5987   6041   ** previously contains an entry associated with newKey, it must be
  5988   6042   ** discarded. ^Any prior cache entry associated with newKey is guaranteed not
  5989   6043   ** to be pinned.
  5990   6044   **
  5991   6045   ** When SQLite calls the xTruncate() method, the cache must discard all
  5992   6046   ** existing cache entries with page numbers (keys) greater than or equal
  5993   6047   ** to the value of the iLimit parameter passed to xTruncate(). If any
  5994   6048   ** of these pages are pinned, they are implicitly unpinned, meaning that
  5995   6049   ** they can be safely discarded.
  5996   6050   **
         6051  +** [[the xDestroy() page cache method]]
  5997   6052   ** ^The xDestroy() method is used to delete a cache allocated by xCreate().
  5998   6053   ** All resources associated with the specified cache should be freed. ^After
  5999   6054   ** calling the xDestroy() method, SQLite considers the [sqlite3_pcache*]
  6000   6055   ** handle invalid, and will not use it with any other sqlite3_pcache_methods
  6001   6056   ** functions.
  6002   6057   */
  6003   6058   typedef struct sqlite3_pcache_methods sqlite3_pcache_methods;
................................................................................
  6052   6107   **         the data between the two databases, and finally
  6053   6108   **     <li><b>sqlite3_backup_finish()</b> is called to release all resources 
  6054   6109   **         associated with the backup operation. 
  6055   6110   **   </ol>)^
  6056   6111   ** There should be exactly one call to sqlite3_backup_finish() for each
  6057   6112   ** successful call to sqlite3_backup_init().
  6058   6113   **
  6059         -** <b>sqlite3_backup_init()</b>
         6114  +** [[sqlite3_backup_init()]] <b>sqlite3_backup_init()</b>
  6060   6115   **
  6061   6116   ** ^The D and N arguments to sqlite3_backup_init(D,N,S,M) are the 
  6062   6117   ** [database connection] associated with the destination database 
  6063   6118   ** and the database name, respectively.
  6064   6119   ** ^The database name is "main" for the main database, "temp" for the
  6065   6120   ** temporary database, or the name specified after the AS keyword in
  6066   6121   ** an [ATTACH] statement for an attached database.
................................................................................
  6079   6134   ** [sqlite3_errmsg16()] functions.
  6080   6135   ** ^A successful call to sqlite3_backup_init() returns a pointer to an
  6081   6136   ** [sqlite3_backup] object.
  6082   6137   ** ^The [sqlite3_backup] object may be used with the sqlite3_backup_step() and
  6083   6138   ** sqlite3_backup_finish() functions to perform the specified backup 
  6084   6139   ** operation.
  6085   6140   **
  6086         -** <b>sqlite3_backup_step()</b>
         6141  +** [[sqlite3_backup_step()]] <b>sqlite3_backup_step()</b>
  6087   6142   **
  6088   6143   ** ^Function sqlite3_backup_step(B,N) will copy up to N pages between 
  6089   6144   ** the source and destination databases specified by [sqlite3_backup] object B.
  6090   6145   ** ^If N is negative, all remaining source pages are copied. 
  6091   6146   ** ^If sqlite3_backup_step(B,N) successfully copies N pages and there
  6092   6147   ** are still more pages to be copied, then the function returns [SQLITE_OK].
  6093   6148   ** ^If sqlite3_backup_step(B,N) successfully finishes copying all pages
................................................................................
  6136   6191   ** external process or via a database connection other than the one being
  6137   6192   ** used by the backup operation, then the backup will be automatically
  6138   6193   ** restarted by the next call to sqlite3_backup_step(). ^If the source 
  6139   6194   ** database is modified by the using the same database connection as is used
  6140   6195   ** by the backup operation, then the backup database is automatically
  6141   6196   ** updated at the same time.
  6142   6197   **
  6143         -** <b>sqlite3_backup_finish()</b>
         6198  +** [[sqlite3_backup_finish()]] <b>sqlite3_backup_finish()</b>
  6144   6199   **
  6145   6200   ** When sqlite3_backup_step() has returned [SQLITE_DONE], or when the 
  6146   6201   ** application wishes to abandon the backup operation, the application
  6147   6202   ** should destroy the [sqlite3_backup] by passing it to sqlite3_backup_finish().
  6148   6203   ** ^The sqlite3_backup_finish() interfaces releases all
  6149   6204   ** resources associated with the [sqlite3_backup] object. 
  6150   6205   ** ^If sqlite3_backup_step() has not yet returned [SQLITE_DONE], then any
................................................................................
  6159   6214   ** sqlite3_backup_step() call on the same [sqlite3_backup] object, then
  6160   6215   ** sqlite3_backup_finish() returns the corresponding [error code].
  6161   6216   **
  6162   6217   ** ^A return of [SQLITE_BUSY] or [SQLITE_LOCKED] from sqlite3_backup_step()
  6163   6218   ** is not a permanent error and does not affect the return value of
  6164   6219   ** sqlite3_backup_finish().
  6165   6220   **
  6166         -** <b>sqlite3_backup_remaining(), sqlite3_backup_pagecount()</b>
         6221  +** [[sqlite3_backup__remaining()]] [[sqlite3_backup_pagecount()]]
         6222  +** <b>sqlite3_backup_remaining() and sqlite3_backup_pagecount()</b>
  6167   6223   **
  6168   6224   ** ^Each call to sqlite3_backup_step() sets two values inside
  6169   6225   ** the [sqlite3_backup] object: the number of pages still to be backed
  6170   6226   ** up and the total number of pages in the source database file.
  6171   6227   ** The sqlite3_backup_remaining() and sqlite3_backup_pagecount() interfaces
  6172   6228   ** retrieve these two values, respectively.
  6173   6229   **
................................................................................
  6540   6596   /*
  6541   6597   ** CAPI3REF: Checkpoint operation parameters
  6542   6598   **
  6543   6599   ** These constants can be used as the 3rd parameter to
  6544   6600   ** [sqlite3_wal_checkpoint_v2()].  See the [sqlite3_wal_checkpoint_v2()]
  6545   6601   ** documentation for additional information about the meaning and use of
  6546   6602   ** each of these values.
  6547         -**
  6548         -** <dt>SQLITE_CONFIG_GETMUTEX</dt>
  6549         -** <dd> ^(This option takes a single argument which is a pointer to an
  6550   6603   */
  6551   6604   #define SQLITE_CHECKPOINT_PASSIVE 0
  6552   6605   #define SQLITE_CHECKPOINT_FULL    1
  6553   6606   #define SQLITE_CHECKPOINT_RESTART 2
  6554   6607   
  6555   6608   /*
  6556   6609   ** CAPI3REF: Virtual Table Interface Configuration

Changes to src/sqliteInt.h.

  2937   2937   int sqlite3CheckCollSeq(Parse *, CollSeq *);
  2938   2938   int sqlite3CheckObjectName(Parse *, const char *);
  2939   2939   void sqlite3VdbeSetChanges(sqlite3 *, int);
  2940   2940   int sqlite3AddInt64(i64*,i64);
  2941   2941   int sqlite3SubInt64(i64*,i64);
  2942   2942   int sqlite3MulInt64(i64*,i64);
  2943   2943   int sqlite3AbsInt32(int);
         2944  +#ifdef SQLITE_ENABLE_8_3_NAMES
         2945  +void sqlite3FileSuffix3(const char*, char*);
         2946  +#else
         2947  +# define sqlite3FileSuffix3(X,Y)
         2948  +#endif
         2949  +u8 sqlite3GetBoolean(const char *z);
  2944   2950   
  2945   2951   const void *sqlite3ValueText(sqlite3_value*, u8);
  2946   2952   int sqlite3ValueBytes(sqlite3_value*, u8);
  2947   2953   void sqlite3ValueSetStr(sqlite3_value*, int, const void *,u8, 
  2948   2954                           void(*)(void*));
  2949   2955   void sqlite3ValueFree(sqlite3_value*);
  2950   2956   sqlite3_value *sqlite3ValueNew(sqlite3 *);

Changes to src/test1.c.

   159    159       case SQLITE_IOERR_DELETE:        zName = "SQLITE_IOERR_DELETE";      break;
   160    160       case SQLITE_IOERR_BLOCKED:       zName = "SQLITE_IOERR_BLOCKED";     break;
   161    161       case SQLITE_IOERR_NOMEM:         zName = "SQLITE_IOERR_NOMEM";       break;
   162    162       case SQLITE_IOERR_ACCESS:        zName = "SQLITE_IOERR_ACCESS";      break;
   163    163       case SQLITE_IOERR_CHECKRESERVEDLOCK:
   164    164                                  zName = "SQLITE_IOERR_CHECKRESERVEDLOCK"; break;
   165    165       case SQLITE_IOERR_LOCK:          zName = "SQLITE_IOERR_LOCK";        break;
   166         -
   167    166       case SQLITE_READONLY_RECOVERY:   zName = "SQLITE_READONLY_RECOVERY"; break;
   168    167       case SQLITE_READONLY_CANTLOCK:   zName = "SQLITE_READONLY_CANTLOCK"; break;
          168  +    case SQLITE_CORRUPT_VTAB:        zName = "SQLITE_CORRUPT_VTAB";      break;
   169    169       default:                         zName = "SQLITE_Unknown";           break;
   170    170     }
   171    171     return zName;
   172    172   }
   173    173   #define t1ErrorName sqlite3TestErrorName
   174    174   
   175    175   /*

Changes to src/test_config.c.

    68     68   #endif
    69     69   
    70     70   #if 1 /* def SQLITE_MEMDEBUG */
    71     71     Tcl_SetVar2(interp, "sqlite_options", "memdebug", "1", TCL_GLOBAL_ONLY);
    72     72   #else
    73     73     Tcl_SetVar2(interp, "sqlite_options", "memdebug", "0", TCL_GLOBAL_ONLY);
    74     74   #endif
           75  +
           76  +#ifdef SQLITE_ENABLE_8_3_NAMES
           77  +  Tcl_SetVar2(interp, "sqlite_options", "8_3_names", "1", TCL_GLOBAL_ONLY);
           78  +#else
           79  +  Tcl_SetVar2(interp, "sqlite_options", "8_3_names", "0", TCL_GLOBAL_ONLY);
           80  +#endif
    75     81   
    76     82   #ifdef SQLITE_ENABLE_MEMSYS3
    77     83     Tcl_SetVar2(interp, "sqlite_options", "mem3", "1", TCL_GLOBAL_ONLY);
    78     84   #else
    79     85     Tcl_SetVar2(interp, "sqlite_options", "mem3", "0", TCL_GLOBAL_ONLY);
    80     86   #endif
    81     87   

Changes to src/test_multiplex.c.

   181    181   ** Compute a string length that is limited to what can be stored in
   182    182   ** lower 30 bits of a 32-bit signed integer.
   183    183   **
   184    184   ** The value returned will never be negative.  Nor will it ever be greater
   185    185   ** than the actual length of the string.  For very long strings (greater
   186    186   ** than 1GiB) the value returned might be less than the true string length.
   187    187   */
   188         -int multiplexStrlen30(const char *z){
          188  +static int multiplexStrlen30(const char *z){
   189    189     const char *z2 = z;
   190    190     if( z==0 ) return 0;
   191    191     while( *z2 ){ z2++; }
   192    192     return 0x3fffffff & (int)(z2 - z);
   193    193   }
          194  +
          195  +/*
          196  +** Create a temporary file name in zBuf.  zBuf must be big enough to
          197  +** hold at pOrigVfs->mxPathname characters.  This function departs
          198  +** from the traditional temporary name generation in the os_win
          199  +** and os_unix VFS in several ways, but is necessary so that 
          200  +** the file name is known for temporary files (like those used 
          201  +** during vacuum.)
          202  +**
          203  +** N.B. This routine assumes your underlying VFS is ok with using
          204  +** "/" as a directory seperator.  This is the default for UNIXs
          205  +** and is allowed (even mixed) for most versions of Windows.
          206  +*/
          207  +static int multiplexGetTempname(sqlite3_vfs *pOrigVfs, int nBuf, char *zBuf){
          208  +  static char zChars[] =
          209  +    "abcdefghijklmnopqrstuvwxyz"
          210  +    "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
          211  +    "0123456789";
          212  +  int i,j;
          213  +  int attempts = 0;
          214  +  int exists = 0;
          215  +  int rc = SQLITE_ERROR;
          216  +
          217  +  /* Check that the output buffer is large enough for 
          218  +  ** pVfs->mxPathname characters.
          219  +  */
          220  +  if( pOrigVfs->mxPathname <= nBuf ){
          221  +    char *zTmp = sqlite3_malloc(pOrigVfs->mxPathname);
          222  +    if( zTmp==0 ) return SQLITE_NOMEM;
          223  +
          224  +    /* sqlite3_temp_directory should always be less than
          225  +    ** pVfs->mxPathname characters.
          226  +    */
          227  +    sqlite3_snprintf(pOrigVfs->mxPathname,
          228  +                     zTmp,
          229  +                     "%s/",
          230  +                     sqlite3_temp_directory ? sqlite3_temp_directory : ".");
          231  +    rc = pOrigVfs->xFullPathname(pOrigVfs, zTmp, nBuf, zBuf);
          232  +    sqlite3_free(zTmp);
          233  +    if( rc ) return rc;
          234  +
          235  +    /* Check that the output buffer is large enough for the temporary file 
          236  +    ** name.
          237  +    */
          238  +    j = multiplexStrlen30(zBuf);
          239  +    if( (j + 8 + 1 + 3 + 1) <= nBuf ){
          240  +      /* Make 3 attempts to generate a unique name. */
          241  +      do {
          242  +        attempts++;
          243  +        sqlite3_randomness(8, &zBuf[j]);
          244  +        for(i=0; i<8; i++){
          245  +          zBuf[j+i] = (char)zChars[ ((unsigned char)zBuf[j+i])%(sizeof(zChars)-1) ];
          246  +        }
          247  +        memcpy(&zBuf[j+i], ".tmp", 5);
          248  +        rc = pOrigVfs->xAccess(pOrigVfs, zBuf, SQLITE_ACCESS_EXISTS, &exists);
          249  +      } while ( (rc==SQLITE_OK) && exists && (attempts<3) );
          250  +      if( rc==SQLITE_OK && exists ){
          251  +        rc = SQLITE_ERROR;
          252  +      }
          253  +    }
          254  +  }
          255  +
          256  +  return rc;
          257  +}
   194    258   
   195    259   /* Translate an sqlite3_file* that is really a multiplexGroup* into
   196    260   ** the sqlite3_file* for the underlying original VFS.
   197    261   */
   198    262   static sqlite3_file *multiplexSubOpen(multiplexConn *pConn, int iChunk, int *rc, int *pOutFlags){
   199    263     multiplexGroup *pGroup = pConn->pGroup;
   200    264     sqlite3_vfs *pOrigVfs = gMultiplex.pOrigVfs;        /* Real VFS */
................................................................................
   291    355   static int multiplexOpen(
   292    356     sqlite3_vfs *pVfs,         /* The multiplex VFS */
   293    357     const char *zName,         /* Name of file to be opened */
   294    358     sqlite3_file *pConn,       /* Fill in this file descriptor */
   295    359     int flags,                 /* Flags to control the opening */
   296    360     int *pOutFlags             /* Flags showing results of opening */
   297    361   ){
   298         -  int rc;                                        /* Result code */
          362  +  int rc = SQLITE_OK;                            /* Result code */
   299    363     multiplexConn *pMultiplexOpen;                 /* The new multiplex file descriptor */
   300    364     multiplexGroup *pGroup;                        /* Corresponding multiplexGroup object */
   301    365     sqlite3_file *pSubOpen;                        /* Real file descriptor */
   302    366     sqlite3_vfs *pOrigVfs = gMultiplex.pOrigVfs;   /* Real VFS */
   303         -  int nName = multiplexStrlen30(zName);
          367  +  int nName;
   304    368     int i;
   305    369     int sz;
   306    370   
   307    371     UNUSED_PARAMETER(pVfs);
   308    372   
   309    373     /* We need to create a group structure and manage
   310    374     ** access to this group of files.
   311    375     */
   312    376     multiplexEnter();
   313    377     pMultiplexOpen = (multiplexConn*)pConn;
   314         -  /* allocate space for group */
   315         -  sz = sizeof(multiplexGroup)                                /* multiplexGroup */
   316         -     + (sizeof(sqlite3_file *)*SQLITE_MULTIPLEX_MAX_CHUNKS)  /* pReal[] */
   317         -     + (pOrigVfs->szOsFile*SQLITE_MULTIPLEX_MAX_CHUNKS)      /* *pReal */
   318         -     + SQLITE_MULTIPLEX_MAX_CHUNKS                           /* bOpen[] */
   319         -     + nName + 1;                                            /* zName */
          378  +
          379  +  /* If the second argument to this function is NULL, generate a 
          380  +  ** temporary file name to use.  This will be handled by the
          381  +  ** original xOpen method.  We just need to allocate space for
          382  +  ** it.
          383  +  */
          384  +  if( !zName ){
          385  +    rc = multiplexGetTempname(pOrigVfs, pOrigVfs->mxPathname, gMultiplex.zName);
          386  +    zName = gMultiplex.zName;
          387  +  }
          388  +
          389  +  if( rc==SQLITE_OK ){
          390  +    /* allocate space for group */
          391  +    nName = multiplexStrlen30(zName);
          392  +    sz = sizeof(multiplexGroup)                                /* multiplexGroup */
          393  +       + (sizeof(sqlite3_file *)*SQLITE_MULTIPLEX_MAX_CHUNKS)  /* pReal[] */
          394  +       + (pOrigVfs->szOsFile*SQLITE_MULTIPLEX_MAX_CHUNKS)      /* *pReal */
          395  +       + SQLITE_MULTIPLEX_MAX_CHUNKS                           /* bOpen[] */
          396  +       + nName + 1;                                            /* zName */
   320    397   #ifndef SQLITE_MULTIPLEX_EXT_OVWR
   321         -  sz += SQLITE_MULTIPLEX_EXT_SZ;
   322         -  assert(nName+SQLITE_MULTIPLEX_EXT_SZ < pOrigVfs->mxPathname);
          398  +    sz += SQLITE_MULTIPLEX_EXT_SZ;
          399  +    assert(nName+SQLITE_MULTIPLEX_EXT_SZ < pOrigVfs->mxPathname);
   323    400   #else
   324         -  assert(nName >= SQLITE_MULTIPLEX_EXT_SZ);
   325         -  assert(nName < pOrigVfs->mxPathname);
          401  +    assert(nName >= SQLITE_MULTIPLEX_EXT_SZ);
          402  +    assert(nName < pOrigVfs->mxPathname);
   326    403   #endif
   327         -  pGroup = sqlite3_malloc( sz );
   328         -  if( pGroup==0 ){
   329         -    rc=SQLITE_NOMEM;
   330         -  }else{
          404  +    pGroup = sqlite3_malloc( sz );
          405  +    if( pGroup==0 ){
          406  +      rc=SQLITE_NOMEM;
          407  +    }
          408  +  }
          409  +
          410  +  if( rc==SQLITE_OK ){
   331    411       /* assign pointers to extra space allocated */
   332    412       char *p = (char *)&pGroup[1];
   333    413       pMultiplexOpen->pGroup = pGroup;
   334    414       memset(pGroup, 0, sz);
   335    415       pGroup->bEnabled = -1;
   336    416       pGroup->nChunkSize = SQLITE_MULTIPLEX_CHUNK_SIZE;
   337    417       pGroup->nMaxChunks = SQLITE_MULTIPLEX_MAX_CHUNKS;
................................................................................
   407    487           sqlite3_snprintf(SQLITE_MULTIPLEX_EXT_SZ+1, 
   408    488               gMultiplex.zName+nName, 
   409    489               SQLITE_MULTIPLEX_EXT_FMT, i);
   410    490   #endif
   411    491       }
   412    492       rc2 = pOrigVfs->xAccess(pOrigVfs, gMultiplex.zName, 
   413    493           SQLITE_ACCESS_EXISTS, &exists);
   414         -    if( rc2==SQLITE_OK && exists){
          494  +    if( rc2==SQLITE_OK && exists ){
   415    495         /* if it exists, delete it */
   416    496         rc2 = pOrigVfs->xDelete(pOrigVfs, gMultiplex.zName, syncDir);
   417    497         if( rc2!=SQLITE_OK ) rc = rc2;
   418    498       }else{
   419    499         /* stop at first "gap" */
   420    500         break;
   421    501       }

Changes to src/util.c.

  1142   1142   ** if the integer has a value of -2147483648, return +2147483647
  1143   1143   */
  1144   1144   int sqlite3AbsInt32(int x){
  1145   1145     if( x>=0 ) return x;
  1146   1146     if( x==(int)0x80000000 ) return 0x7fffffff;
  1147   1147     return -x;
  1148   1148   }
         1149  +
         1150  +#ifdef SQLITE_ENABLE_8_3_NAMES
         1151  +/*
         1152  +** If SQLITE_ENABLE_8_3_NAME is set at compile-time and if the database
         1153  +** filename in zBaseFilename is a URI with the "8_3_names=1" parameter and
         1154  +** if filename in z[] has a suffix (a.k.a. "extension") that is longer than
         1155  +** three characters, then shorten the suffix on z[] to be the last three
         1156  +** characters of the original suffix.
         1157  +**
         1158  +** Examples:
         1159  +**
         1160  +**     test.db-journal    =>   test.nal
         1161  +**     test.db-wal        =>   test.wal
         1162  +**     test.db-shm        =>   test.shm
         1163  +*/
         1164  +void sqlite3FileSuffix3(const char *zBaseFilename, char *z){
         1165  +  const char *zOk;
         1166  +  zOk = sqlite3_uri_parameter(zBaseFilename, "8_3_names");
         1167  +  if( zOk && sqlite3GetBoolean(zOk) ){
         1168  +    int i, sz;
         1169  +    sz = sqlite3Strlen30(z);
         1170  +    for(i=sz-1; i>0 && z[i]!='/' && z[i]!='.'; i--){}
         1171  +    if( z[i]=='.' && ALWAYS(sz>i+4) ) memcpy(&z[i+1], &z[sz-3], 4);
         1172  +  }
         1173  +}
         1174  +#endif

Changes to src/vdbe.c.

   560    560     Mem *aMem = p->aMem;       /* Copy of p->aMem */
   561    561     Mem *pIn1 = 0;             /* 1st input operand */
   562    562     Mem *pIn2 = 0;             /* 2nd input operand */
   563    563     Mem *pIn3 = 0;             /* 3rd input operand */
   564    564     Mem *pOut = 0;             /* Output operand */
   565    565     int iCompare = 0;          /* Result of last OP_Compare operation */
   566    566     int *aPermute = 0;         /* Permutation of columns for OP_Compare */
          567  +  i64 lastRowid = db->lastRowid;  /* Saved value of the last insert ROWID */
   567    568   #ifdef VDBE_PROFILE
   568    569     u64 start;                 /* CPU clock count at start of opcode */
   569    570     int origPc;                /* Program counter at start of opcode */
   570    571   #endif
   571    572     /*** INSERT STACK UNION HERE ***/
   572    573   
   573    574     assert( p->magic==VDBE_MAGIC_RUN );  /* sqlite3_step() verifies this */
................................................................................
   829    830     if( pOp->p1==SQLITE_OK && p->pFrame ){
   830    831       /* Halt the sub-program. Return control to the parent frame. */
   831    832       VdbeFrame *pFrame = p->pFrame;
   832    833       p->pFrame = pFrame->pParent;
   833    834       p->nFrame--;
   834    835       sqlite3VdbeSetChanges(db, p->nChange);
   835    836       pc = sqlite3VdbeFrameRestore(pFrame);
          837  +    lastRowid = db->lastRowid;
   836    838       if( pOp->p2==OE_Ignore ){
   837    839         /* Instruction pc is the OP_Program that invoked the sub-program 
   838    840         ** currently being halted. If the p2 instruction of this OP_Halt
   839    841         ** instruction is set to OE_Ignore, then the sub-program is throwing
   840    842         ** an IGNORE exception. In this case jump to the address specified
   841    843         ** as the p2 of the calling OP_Program.  */
   842    844         pc = p->aOp[pc].p2-1;
................................................................................
  1389   1391     ctx.isError = 0;
  1390   1392     if( ctx.pFunc->flags & SQLITE_FUNC_NEEDCOLL ){
  1391   1393       assert( pOp>aOp );
  1392   1394       assert( pOp[-1].p4type==P4_COLLSEQ );
  1393   1395       assert( pOp[-1].opcode==OP_CollSeq );
  1394   1396       ctx.pColl = pOp[-1].p4.pColl;
  1395   1397     }
         1398  +  db->lastRowid = lastRowid;
  1396   1399     (*ctx.pFunc->xFunc)(&ctx, n, apVal); /* IMP: R-24505-23230 */
         1400  +  lastRowid = db->lastRowid;
  1397   1401     if( db->mallocFailed ){
  1398   1402       /* Even though a malloc() has failed, the implementation of the
  1399   1403       ** user function may have called an sqlite3_result_XXX() function
  1400   1404       ** to return a value. The following call releases any resources
  1401   1405       ** associated with such a value.
  1402   1406       */
  1403   1407       sqlite3VdbeMemRelease(&ctx.s);
................................................................................
  3805   3809         /* IMPLEMENTATION-OF: R-07677-41881 If the largest ROWID is equal to the
  3806   3810         ** largest possible integer (9223372036854775807) then the database
  3807   3811         ** engine starts picking positive candidate ROWIDs at random until
  3808   3812         ** it finds one that is not previously used. */
  3809   3813         assert( pOp->p3==0 );  /* We cannot be in random rowid mode if this is
  3810   3814                                ** an AUTOINCREMENT table. */
  3811   3815         /* on the first attempt, simply do one more than previous */
  3812         -      v = db->lastRowid;
         3816  +      v = lastRowid;
  3813   3817         v &= (MAX_ROWID>>1); /* ensure doesn't go negative */
  3814   3818         v++; /* ensure non-zero */
  3815   3819         cnt = 0;
  3816   3820         while(   ((rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, 0, (u64)v,
  3817   3821                                                    0, &res))==SQLITE_OK)
  3818   3822               && (res==0)
  3819   3823               && (++cnt<100)){
................................................................................
  3915   3919       iKey = pKey->u.i;
  3916   3920     }else{
  3917   3921       assert( pOp->opcode==OP_InsertInt );
  3918   3922       iKey = pOp->p3;
  3919   3923     }
  3920   3924   
  3921   3925     if( pOp->p5 & OPFLAG_NCHANGE ) p->nChange++;
  3922         -  if( pOp->p5 & OPFLAG_LASTROWID ) db->lastRowid = iKey;
         3926  +  if( pOp->p5 & OPFLAG_LASTROWID ) db->lastRowid = lastRowid = iKey;
  3923   3927     if( pData->flags & MEM_Null ){
  3924   3928       pData->z = 0;
  3925   3929       pData->n = 0;
  3926   3930     }else{
  3927   3931       assert( pData->flags & (MEM_Blob|MEM_Str) );
  3928   3932     }
  3929   3933     seekResult = ((pOp->p5 & OPFLAG_USESEEKRESULT) ? pC->seekResult : 0);
................................................................................
  5003   5007       assert( pProgram->nMem+pProgram->nCsr==pFrame->nChildMem );
  5004   5008       assert( pProgram->nCsr==pFrame->nChildCsr );
  5005   5009       assert( pc==pFrame->pc );
  5006   5010     }
  5007   5011   
  5008   5012     p->nFrame++;
  5009   5013     pFrame->pParent = p->pFrame;
  5010         -  pFrame->lastRowid = db->lastRowid;
         5014  +  pFrame->lastRowid = lastRowid;
  5011   5015     pFrame->nChange = p->nChange;
  5012   5016     p->nChange = 0;
  5013   5017     p->pFrame = pFrame;
  5014   5018     p->aMem = aMem = &VdbeFrameMem(pFrame)[-1];
  5015   5019     p->nMem = pFrame->nChildMem;
  5016   5020     p->nCursor = (u16)pFrame->nChildCsr;
  5017   5021     p->apCsr = (VdbeCursor **)&aMem[p->nMem+1];
................................................................................
  5810   5814       }
  5811   5815       db->vtabOnConflict = pOp->p5;
  5812   5816       rc = pModule->xUpdate(pVtab, nArg, apArg, &rowid);
  5813   5817       db->vtabOnConflict = vtabOnConflict;
  5814   5818       importVtabErrMsg(p, pVtab);
  5815   5819       if( rc==SQLITE_OK && pOp->p1 ){
  5816   5820         assert( nArg>1 && apArg[0] && (apArg[0]->flags&MEM_Null) );
  5817         -      db->lastRowid = rowid;
         5821  +      db->lastRowid = lastRowid = rowid;
  5818   5822       }
  5819   5823       if( rc==SQLITE_CONSTRAINT && pOp->p4.pVtab->bConstraint ){
  5820   5824         if( pOp->p5==OE_Ignore ){
  5821   5825           rc = SQLITE_OK;
  5822   5826         }else{
  5823   5827           p->errorAction = ((pOp->p5==OE_Replace) ? OE_Abort : pOp->p5);
  5824   5828         }
................................................................................
  5968   5972       sqlite3ResetInternalSchema(db, resetSchemaOnFault-1);
  5969   5973     }
  5970   5974   
  5971   5975     /* This is the only way out of this procedure.  We have to
  5972   5976     ** release the mutexes on btrees that were acquired at the
  5973   5977     ** top. */
  5974   5978   vdbe_return:
         5979  +  db->lastRowid = lastRowid;
  5975   5980     sqlite3VdbeLeave(p);
  5976   5981     return rc;
  5977   5982   
  5978   5983     /* Jump to here if a string or blob larger than SQLITE_MAX_LENGTH
  5979   5984     ** is encountered.
  5980   5985     */
  5981   5986   too_big:

Changes to src/vdbeaux.c.

  1795   1795         u32 iRandom;
  1796   1796         sqlite3DbFree(db, zMaster);
  1797   1797         sqlite3_randomness(sizeof(iRandom), &iRandom);
  1798   1798         zMaster = sqlite3MPrintf(db, "%s-mj%08X", zMainFile, iRandom&0x7fffffff);
  1799   1799         if( !zMaster ){
  1800   1800           return SQLITE_NOMEM;
  1801   1801         }
         1802  +      sqlite3FileSuffix3(zMainFile, zMaster);
  1802   1803         rc = sqlite3OsAccess(pVfs, zMaster, SQLITE_ACCESS_EXISTS, &res);
  1803   1804       }while( rc==SQLITE_OK && res );
  1804   1805       if( rc==SQLITE_OK ){
  1805   1806         /* Open the master journal. */
  1806   1807         rc = sqlite3OsOpenMalloc(pVfs, zMaster, &pMaster, 
  1807   1808             SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|
  1808   1809             SQLITE_OPEN_EXCLUSIVE|SQLITE_OPEN_MASTER_JOURNAL, 0

Changes to src/wal.c.

   416    416   ** appropriate.
   417    417   */
   418    418   struct Wal {
   419    419     sqlite3_vfs *pVfs;         /* The VFS used to create pDbFd */
   420    420     sqlite3_file *pDbFd;       /* File handle for the database file */
   421    421     sqlite3_file *pWalFd;      /* File handle for WAL file */
   422    422     u32 iCallback;             /* Value to pass to log callback (or 0) */
          423  +  i64 mxWalSize;             /* Truncate WAL to this size upon reset */
   423    424     int nWiData;               /* Size of array apWiData */
   424    425     volatile u32 **apWiData;   /* Pointer to wal-index content in memory */
   425    426     u32 szPage;                /* Database page size */
   426    427     i16 readLock;              /* Which read lock is being held.  -1 for none */
   427    428     u8 exclusiveMode;          /* Non-zero if connection is in exclusive mode */
   428    429     u8 writeLock;              /* True if in a write transaction */
   429    430     u8 ckptLock;               /* True if holding a checkpoint lock */
................................................................................
  1254   1255   ** an SQLite error code is returned and *ppWal is left unmodified.
  1255   1256   */
  1256   1257   int sqlite3WalOpen(
  1257   1258     sqlite3_vfs *pVfs,              /* vfs module to open wal and wal-index */
  1258   1259     sqlite3_file *pDbFd,            /* The open database file */
  1259   1260     const char *zWalName,           /* Name of the WAL file */
  1260   1261     int bNoShm,                     /* True to run in heap-memory mode */
         1262  +  i64 mxWalSize,                  /* Truncate WAL to this size on reset */
  1261   1263     Wal **ppWal                     /* OUT: Allocated Wal handle */
  1262   1264   ){
  1263   1265     int rc;                         /* Return Code */
  1264   1266     Wal *pRet;                      /* Object to allocate and return */
  1265   1267     int flags;                      /* Flags passed to OsOpen() */
  1266   1268   
  1267   1269     assert( zWalName && zWalName[0] );
................................................................................
  1286   1288       return SQLITE_NOMEM;
  1287   1289     }
  1288   1290   
  1289   1291     pRet->pVfs = pVfs;
  1290   1292     pRet->pWalFd = (sqlite3_file *)&pRet[1];
  1291   1293     pRet->pDbFd = pDbFd;
  1292   1294     pRet->readLock = -1;
         1295  +  pRet->mxWalSize = mxWalSize;
  1293   1296     pRet->zWalName = zWalName;
  1294   1297     pRet->exclusiveMode = (bNoShm ? WAL_HEAPMEMORY_MODE: WAL_NORMAL_MODE);
  1295   1298   
  1296   1299     /* Open file handle on the write-ahead log file. */
  1297   1300     flags = (SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|SQLITE_OPEN_WAL);
  1298   1301     rc = sqlite3OsOpen(pVfs, zWalName, pRet->pWalFd, flags, &flags);
  1299   1302     if( rc==SQLITE_OK && flags&SQLITE_OPEN_READONLY ){
................................................................................
  1306   1309       sqlite3_free(pRet);
  1307   1310     }else{
  1308   1311       *ppWal = pRet;
  1309   1312       WALTRACE(("WAL%d: opened\n", pRet));
  1310   1313     }
  1311   1314     return rc;
  1312   1315   }
         1316  +
         1317  +/*
         1318  +** Change the size to which the WAL file is trucated on each reset.
         1319  +*/
         1320  +void sqlite3WalLimit(Wal *pWal, i64 iLimit){
         1321  +  if( pWal ) pWal->mxWalSize = iLimit;
         1322  +}
  1313   1323   
  1314   1324   /*
  1315   1325   ** Find the smallest page number out of all pages held in the WAL that
  1316   1326   ** has not been returned by any prior invocation of this method on the
  1317   1327   ** same WalIterator object.   Write into *piFrame the frame index where
  1318   1328   ** that page was last written into the WAL.  Write into *piPage the page
  1319   1329   ** number.
................................................................................
  2557   2567           ** In theory it would be Ok to update the cache of the header only
  2558   2568           ** at this point. But updating the actual wal-index header is also
  2559   2569           ** safe and means there is no special case for sqlite3WalUndo()
  2560   2570           ** to handle if this transaction is rolled back.
  2561   2571           */
  2562   2572           int i;                    /* Loop counter */
  2563   2573           u32 *aSalt = pWal->hdr.aSalt;       /* Big-endian salt values */
         2574  +
         2575  +        /* Limit the size of WAL file if the journal_size_limit PRAGMA is
         2576  +        ** set to a non-negative value.  Log errors encountered
         2577  +        ** during the truncation attempt. */
         2578  +        if( pWal->mxWalSize>=0 ){
         2579  +          i64 sz;
         2580  +          int rx;
         2581  +          rx = sqlite3OsFileSize(pWal->pWalFd, &sz);
         2582  +          if( rx==SQLITE_OK && (sz > pWal->mxWalSize) ){
         2583  +            rx = sqlite3OsTruncate(pWal->pWalFd, pWal->mxWalSize);
         2584  +          }
         2585  +          if( rx ){
         2586  +            sqlite3_log(rx, "cannot limit WAL size: %s", pWal->zWalName);
         2587  +          }
         2588  +        }
         2589  +
  2564   2590           pWal->nCkpt++;
  2565   2591           pWal->hdr.mxFrame = 0;
  2566   2592           sqlite3Put4byte((u8*)&aSalt[0], 1 + sqlite3Get4byte((u8*)&aSalt[0]));
  2567   2593           aSalt[1] = salt1;
  2568   2594           walIndexWriteHdr(pWal);
  2569   2595           pInfo->nBackfill = 0;
  2570   2596           for(i=1; i<WAL_NREADER; i++) pInfo->aReadMark[i] = READMARK_NOT_USED;

Changes to src/wal.h.

    17     17   #ifndef _WAL_H_
    18     18   #define _WAL_H_
    19     19   
    20     20   #include "sqliteInt.h"
    21     21   
    22     22   #ifdef SQLITE_OMIT_WAL
    23     23   # define sqlite3WalOpen(x,y,z)                   0
           24  +# define sqlite3WalLimit(x,y)
    24     25   # define sqlite3WalClose(w,x,y,z)                0
    25     26   # define sqlite3WalBeginReadTransaction(x,y,z)   0
    26     27   # define sqlite3WalEndReadTransaction(z)
    27     28   # define sqlite3WalRead(v,w,x,y,z)               0
    28     29   # define sqlite3WalDbsize(y)                     0
    29     30   # define sqlite3WalBeginWriteTransaction(y)      0
    30     31   # define sqlite3WalEndWriteTransaction(x)        0
................................................................................
    42     43   
    43     44   /* Connection to a write-ahead log (WAL) file. 
    44     45   ** There is one object of this type for each pager. 
    45     46   */
    46     47   typedef struct Wal Wal;
    47     48   
    48     49   /* Open and close a connection to a write-ahead log. */
    49         -int sqlite3WalOpen(sqlite3_vfs*, sqlite3_file*, const char *zName, int, Wal**);
           50  +int sqlite3WalOpen(sqlite3_vfs*, sqlite3_file*, const char *, int, i64, Wal**);
    50     51   int sqlite3WalClose(Wal *pWal, int sync_flags, int, u8 *);
           52  +
           53  +/* Set the limiting size of a WAL file. */
           54  +void sqlite3WalLimit(Wal*, i64);
    51     55   
    52     56   /* Used by readers to open (lock) and close (unlock) a snapshot.  A 
    53     57   ** snapshot is like a read-transaction.  It is the state of the database
    54     58   ** at an instant in time.  sqlite3WalOpenSnapshot gets a read lock and
    55     59   ** preserves the current state even if the other threads or processes
    56     60   ** write to or checkpoint the WAL.  sqlite3WalCloseSnapshot() closes the
    57     61   ** transaction and releases the lock.

Added test/8_3_names.test.

            1  +# 2011 May 17
            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  +# Test cases for the SQLITE_ENABLE_8_3_NAMES feature that forces all
           13  +# filename extensions to be limited to 3 characters.  Some embedded
           14  +# systems need this to work around microsoft FAT patents, but this
           15  +# feature should be disabled on most deployments.
           16  +#
           17  +
           18  +set testdir [file dirname $argv0]
           19  +source $testdir/tester.tcl
           20  +ifcapable !8_3_names {
           21  +  finish_test
           22  +  return
           23  +}
           24  +
           25  +db close
           26  +sqlite3_shutdown
           27  +sqlite3_config_uri 1
           28  +
           29  +do_test 8_3_names-1.0 {
           30  +  forcedelete test.db test.nal test.db-journal
           31  +  sqlite3 db test.db
           32  +  db eval {
           33  +    PRAGMA cache_size=10;
           34  +    CREATE TABLE t1(x);
           35  +    INSERT INTO t1 VALUES(randomblob(20000));
           36  +    BEGIN;
           37  +    DELETE FROM t1;
           38  +    INSERT INTO t1 VALUES(randomblob(15000));
           39  +  }
           40  +  file exists test.db-journal
           41  +} 1
           42  +do_test 8_3_names-1.1 {
           43  +  file exists test.nal
           44  +} 0
           45  +do_test 8_3_names-1.2 {
           46  +  db eval {
           47  +    ROLLBACK;
           48  +    SELECT length(x) FROM t1
           49  +  }
           50  +} 20000
           51  +
           52  +db close
           53  +do_test 8_3_names-2.0 {
           54  +  forcedelete test.db test.nal test.db-journal
           55  +  sqlite3 db file:./test.db?8_3_names=1
           56  +  db eval {
           57  +    PRAGMA cache_size=10;
           58  +    CREATE TABLE t1(x);
           59  +    INSERT INTO t1 VALUES(randomblob(20000));
           60  +    BEGIN;
           61  +    DELETE FROM t1;
           62  +    INSERT INTO t1 VALUES(randomblob(15000));
           63  +  }
           64  +  file exists test.db-journal
           65  +} 0
           66  +do_test 8_3_names-2.1 {
           67  +  file exists test.nal
           68  +} 1
           69  +forcedelete test2.db test2.nal test2.db-journal
           70  +file copy test.db test2.db
           71  +file copy test.nal test2.nal
           72  +do_test 8_3_names-2.2 {
           73  +  db eval {
           74  +    COMMIT;
           75  +    SELECT length(x) FROM t1
           76  +  }
           77  +} 15000
           78  +do_test 8_3_names-2.3 {
           79  +  sqlite3 db2 file:./test2.db?8_3_names=1
           80  +  db2 eval {
           81  +    PRAGMA integrity_check;
           82  +    SELECT length(x) FROM t1;
           83  +  }
           84  +} {ok 20000}
           85  +
           86  +db close
           87  +do_test 8_3_names-3.0 {
           88  +  forcedelete test.db test.nal test.db-journal
           89  +  sqlite3 db file:./test.db?8_3_names=0
           90  +  db eval {
           91  +    PRAGMA cache_size=10;
           92  +    CREATE TABLE t1(x);
           93  +    INSERT INTO t1 VALUES(randomblob(20000));
           94  +    BEGIN;
           95  +    DELETE FROM t1;
           96  +    INSERT INTO t1 VALUES(randomblob(15000));
           97  +  }
           98  +  file exists test.db-journal
           99  +} 1
          100  +do_test 8_3_names-3.1 {
          101  +  file exists test.nal
          102  +} 0
          103  +forcedelete test2.db test2.nal test2.db-journal
          104  +file copy test.db test2.db
          105  +file copy test.db-journal test2.db-journal
          106  +do_test 8_3_names-3.2 {
          107  +  db eval {
          108  +    COMMIT;
          109  +    SELECT length(x) FROM t1
          110  +  }
          111  +} 15000
          112  +do_test 8_3_names-3.3 {
          113  +  sqlite3 db2 file:./test2.db?8_3_names=0
          114  +  db2 eval {
          115  +    PRAGMA integrity_check;
          116  +    SELECT length(x) FROM t1;
          117  +  }
          118  +} {ok 20000}
          119  +
          120  +##########################################################################
          121  +# Master journals.
          122  +#
          123  +db close
          124  +forcedelete test.db test2.db
          125  +do_test 8_3_names-4.0 {
          126  +  sqlite3 db file:./test.db?8_3_names=1
          127  +  db eval {
          128  +    CREATE TABLE t1(x);
          129  +    INSERT INTO t1 VALUES(1);
          130  +    ATTACH 'file:./test2.db?8_3_names=1' AS db2;
          131  +    CREATE TABLE db2.t2(y);
          132  +    INSERT INTO t2 VALUES(2);
          133  +    BEGIN;
          134  +      INSERT INTO t1 VALUES(3);
          135  +      INSERT INTO t2 VALUES(4);
          136  +    COMMIT;
          137  +    SELECT * FROM t1, t2 ORDER BY x, y
          138  +  }
          139  +} {1 2 1 4 3 2 3 4}
          140  +    
          141  +
          142  +##########################################################################
          143  +# WAL mode.
          144  +#
          145  +ifcapable !wal {
          146  +  finish_test
          147  +  return
          148  +}
          149  +db close
          150  +forcedelete test.db
          151  +do_test 8_3_names-5.0 {
          152  +  sqlite3 db file:./test.db?8_3_names=1
          153  +  register_wholenumber_module db
          154  +  db eval {
          155  +    PRAGMA journal_mode=WAL;
          156  +    CREATE TABLE t1(x);
          157  +    CREATE VIRTUAL TABLE nums USING wholenumber;
          158  +    INSERT INTO t1 SELECT value FROM nums WHERE value BETWEEN 1 AND 1000;
          159  +    BEGIN;
          160  +    UPDATE t1 SET x=x*2;
          161  +  }
          162  +  sqlite3 db2 file:./test.db?8_3_names=1
          163  +  register_wholenumber_module db2
          164  +  db2 eval {
          165  +    BEGIN;
          166  +    SELECT sum(x) FROM t1;
          167  +  }
          168  +} {500500}
          169  +
          170  +do_test 8_3_names-5.1 {
          171  +  file exists test.db-wal
          172  +} 0
          173  +do_test 8_3_names-5.2 {
          174  +  file exists test.wal
          175  +} 1
          176  +do_test 8_3_names-5.3 {
          177  +  file exists test.db-shm
          178  +} 0
          179  +do_test 8_3_names-5.4 {
          180  +  file exists test.shm
          181  +} 1
          182  +
          183  +
          184  +do_test 8_3_names-5.5 {
          185  +  db eval {
          186  +    COMMIT;
          187  +    SELECT sum(x) FROM t1;
          188  +  }
          189  +} {1001000}
          190  +do_test 8_3_names-5.6 {
          191  +  db2 eval {
          192  +    SELECT sum(x) FROM t1;
          193  +  }
          194  +} {500500}
          195  +
          196  +
          197  +finish_test

Changes to test/fts3corrupt.test.

    36     36     foreach w {a b c d e f g h i j k l m n o} {
    37     37       execsql { INSERT INTO t1 VALUES($w) }
    38     38     }
    39     39   } {}
    40     40   do_catchsql_test 1.3 {
    41     41     INSERT INTO t1 VALUES('world');
    42     42   } {1 {database disk image is malformed}}
           43  +do_test 1.3.1 { sqlite3_extended_errcode db } SQLITE_CORRUPT_VTAB
    43     44   do_execsql_test 1.4 { 
    44     45     DROP TABLE t1;
    45     46   } 
    46     47   
    47     48   # This block of tests checks that corruption is correctly detected if the
    48     49   # length field of a term on a leaf node indicates that the term extends past
    49     50   # the end of the node on which it resides. There are two cases:
................................................................................
    65     66     set blob [db one {SELECT root from t1_segdir}]
    66     67     set blob [binary format a*a* "\x00\x7F" [string range $blob 2 end]]
    67     68     execsql { UPDATE t1_segdir SET root = $blob }
    68     69   } {}
    69     70   do_catchsql_test 2.2 {
    70     71     SELECT rowid FROM t1 WHERE t1 MATCH 'hello'
    71     72   } {1 {database disk image is malformed}}
           73  +do_test 2.2.1 { sqlite3_extended_errcode db } SQLITE_CORRUPT_VTAB
    72     74   
    73     75   do_execsql_test 3.0 {
    74     76     DROP TABLE t1;
    75     77     CREATE VIRTUAL TABLE t1 USING fts3;
    76     78     BEGIN;
    77     79       INSERT INTO t1 VALUES('hello');
    78     80       INSERT INTO t1 VALUES('world');
................................................................................
    82     84     set blob [db one {SELECT quote(root) from t1_segdir}]
    83     85     set blob [binary format a11a*a* $blob "\x7F" [string range $blob 12 end]]
    84     86     execsql { UPDATE t1_segdir SET root = $blob }
    85     87   } {}
    86     88   do_catchsql_test 3.2 {
    87     89     SELECT rowid FROM t1 WHERE t1 MATCH 'world'
    88     90   } {1 {database disk image is malformed}}
           91  +do_test 3.2.1 { sqlite3_extended_errcode db } SQLITE_CORRUPT_VTAB
    89     92   
    90     93   
    91     94   do_execsql_test 4.0 {
    92     95     DROP TABLE t1;
    93     96     CREATE VIRTUAL TABLE t1 USING fts3;
    94     97     INSERT INTO t1(t1) VALUES('nodesize=24');
    95     98   }
................................................................................
   107    110     execsql COMMIT
   108    111   } {}
   109    112   
   110    113   do_catchsql_test 4.2 {
   111    114     UPDATE t1_segdir SET root = X'FFFFFFFFFFFFFFFF';
   112    115     SELECT rowid FROM t1 WHERE t1 MATCH 'world';
   113    116   } {1 {database disk image is malformed}}
          117  +do_test 4.2.1 { sqlite3_extended_errcode db } SQLITE_CORRUPT_VTAB
   114    118   
   115    119   set    blob [binary format cca*cca*cca*cca*cca*cca*cca*cca*cca*cca*a* \
   116    120     22 120 [string repeat a 120]  \
   117    121     22 120 [string repeat b 120]  \
   118    122     22 120 [string repeat c 120]  \
   119    123     22 120 [string repeat d 120]  \
   120    124     22 120 [string repeat e 120]  \
................................................................................
   126    130     "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"
   127    131   ]
   128    132   
   129    133   do_catchsql_test 4.3 {
   130    134     UPDATE t1_segdir SET root = $blob;
   131    135     SELECT rowid FROM t1 WHERE t1 MATCH 'world';
   132    136   } {1 {database disk image is malformed}}
          137  +do_test 4.3.1 { sqlite3_extended_errcode db } SQLITE_CORRUPT_VTAB
   133    138   
   134    139   # Test a special kind of corruption, where the %_stat table contains
   135    140   # an invalid entry. At one point this could lead to a division-by-zero
   136    141   # error in fts4.
   137    142   #
   138    143   do_execsql_test 5.0 {
   139    144     DROP TABLE t1;
................................................................................
   148    153     execsql { INSERT INTO t1 VALUES('four') }
   149    154     execsql COMMIT
   150    155   } {}
   151    156   do_catchsql_test 5.2 {
   152    157     UPDATE t1_stat SET value = X'0000';
   153    158     SELECT matchinfo(t1, 'nxa') FROM t1 WHERE t1 MATCH 't*';
   154    159   } {1 {database disk image is malformed}}
          160  +do_test 5.2.1 { sqlite3_extended_errcode db } SQLITE_CORRUPT_VTAB
   155    161   do_catchsql_test 5.3 {
   156    162     UPDATE t1_stat SET value = NULL;
   157    163     SELECT matchinfo(t1, 'nxa') FROM t1 WHERE t1 MATCH 't*';
   158    164   } {1 {database disk image is malformed}}
          165  +do_test 5.3.1 { sqlite3_extended_errcode db } SQLITE_CORRUPT_VTAB
   159    166   
   160    167   
   161    168   finish_test
   162    169   

Changes to test/multiplex.test.

   562    562         }
   563    563       } {1 {disk I/O error}}
   564    564       do_test multiplex-5.6.4.$jmode {
   565    565         db close
   566    566       } {}
   567    567     }
   568    568   }
          569  +
          570  +#-------------------------------------------------------------------------
          571  +# Test that you can vacuum a multiplex'ed DB.  
          572  +
          573  +ifcapable vacuum {
          574  +
          575  +do_test multiplex-6.0.0 {
          576  +  multiplex_delete test.db
          577  +  sqlite3_multiplex_initialize "" 1
          578  +  sqlite3 db test.db
          579  +  multiplex_set db main 4096 16
          580  +} {SQLITE_OK}
          581  +
          582  +do_test multiplex-6.1.0 {
          583  +  execsql {
          584  +    PRAGMA page_size=1024;
          585  +    PRAGMA journal_mode=DELETE;
          586  +    PRAGMA auto_vacuum=OFF;
          587  +  }
          588  +  execsql {
          589  +    CREATE TABLE t1(a, b);
          590  +    INSERT INTO t1 VALUES(1, randomblob($g_chunk_size));
          591  +    INSERT INTO t1 VALUES(2, randomblob($g_chunk_size));
          592  +  }
          593  +} {}
          594  +do_test multiplex-6.2.1 { file size [multiplex_name test.db 0] } [list $g_chunk_size]
          595  +do_test multiplex-6.2.2 { file size [multiplex_name test.db 1] } [list $g_chunk_size]
          596  +
          597  +do_test multiplex-6.3.0 {
          598  +  execsql { VACUUM }
          599  +} {}
          600  +
          601  +do_test multiplex-6.99 {
          602  +  db close
          603  +  multiplex_delete test.db
          604  +  sqlite3_multiplex_shutdown
          605  +} {SQLITE_OK}
          606  +
          607  +}
          608  +
   569    609   
   570    610   catch { sqlite3_multiplex_shutdown }
   571    611   finish_test

Added test/tkt-2d1a5c67d.test.

            1  +# 2011 May 19
            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. Specifically,
           12  +# it tests that ticket [2d1a5c67dfc2363e44f29d9bbd57f7331851390a] has
           13  +# been resolved.
           14  +#
           15  +# 
           16  +#
           17  +
           18  +set testdir [file dirname $argv0]
           19  +source $testdir/tester.tcl
           20  +
           21  +ifcapable !wal {finish_test; return}
           22  +
           23  +for {set ii 1} {$ii<=10} {incr ii} {
           24  +  do_test tkt-2d1a5c67d.1.$ii {
           25  +    db close
           26  +    forcedelete test.db test.db-wal
           27  +    sqlite3 db test.db
           28  +    db eval "PRAGMA cache_size=$::ii"
           29  +    db eval {
           30  +      PRAGMA journal_mode=WAL;
           31  +      CREATE TABLE t1(a,b);
           32  +      CREATE INDEX t1b ON t1(b);
           33  +      CREATE TABLE t2(x,y UNIQUE);
           34  +      INSERT INTO t2 VALUES(3,4);
           35  +      BEGIN;
           36  +      INSERT INTO t1(a,b) VALUES(1,2);
           37  +      SELECT 'A', * FROM t2 WHERE y=4;
           38  +      SELECT 'B', * FROM t1;
           39  +      COMMIT;
           40  +      SELECT 'C', * FROM t1;
           41  +    }
           42  +  } {wal A 3 4 B 1 2 C 1 2}
           43  +}
           44  +
           45  +db close
           46  +forcedelete test.db test.db-wal
           47  +sqlite3 db test.db
           48  +register_wholenumber_module db
           49  +db eval {
           50  +  PRAGMA journal_mode=WAL;
           51  +  CREATE TABLE t1(a,b);
           52  +  CREATE INDEX t1b ON t1(b);
           53  +  CREATE TABLE t2(x,y);
           54  +  CREATE VIRTUAL TABLE nums USING wholenumber;
           55  +  INSERT INTO t2 SELECT value, randomblob(1000) FROM nums
           56  +                 WHERE value BETWEEN 1 AND 1000;
           57  +}
           58  +
           59  +for {set ii 1} {$ii<=10} {incr ii} {
           60  +  do_test tkt-2d1a5c67d.2.$ii {
           61  +    db eval "PRAGMA cache_size=$::ii"
           62  +    db eval {
           63  +      DELETE FROM t1;
           64  +      BEGIN;
           65  +      INSERT INTO t1(a,b) VALUES(1,2);
           66  +      SELECT sum(length(y)) FROM t2;
           67  +      COMMIT;
           68  +      SELECT * FROM t1;
           69  +    }
           70  +  } {1000000 1 2}
           71  +}
           72  +
           73  +finish_test

Added test/wal7.test.

            1  +# 2011 May 16
            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 file is testing the PRAGMA journal_size_limit when
           13  +# in WAL mode.
           14  +#
           15  +
           16  +set testdir [file dirname $argv0]
           17  +source $testdir/tester.tcl
           18  +ifcapable !wal {finish_test ; return }
           19  +
           20  +# Case 1:  No size limit.  Journal can get large.
           21  +#
           22  +do_test wal7-1.0 {
           23  +  db close
           24  +  forcedelete test.db
           25  +  sqlite3 db test.db
           26  +  db eval {
           27  +    PRAGMA page_size=1024;
           28  +    PRAGMA journal_mode=WAL;
           29  +    PRAGMA wal_autocheckpoint=50;  -- 50 pages
           30  +    CREATE TABLE t1(x, y UNIQUE);
           31  +    INSERT INTO t1 VALUES(1,2);
           32  +    INSERT INTO t1 VALUES(zeroblob(200000),4);
           33  +    CREATE TABLE t2(z);
           34  +    DELETE FROM t1;
           35  +    INSERT INTO t2 SELECT x FROM t1;
           36  +  }
           37  +  expr {[file size test.db-wal]>50*1100}
           38  +} 1
           39  +do_test wal7-1.1 {
           40  +  db eval {PRAGMA wal_checkpoint}
           41  +  expr {[file size test.db-wal]>50*1100}
           42  +} 1
           43  +do_test wal7-1.2 {
           44  +  db eval {INSERT INTO t2 VALUES('hi');}
           45  +  expr {[file size test.db-wal]>50*1100}
           46  +} 1
           47  +
           48  +# Case 2:  Size limit at half the autocheckpoint size.
           49  +#
           50  +do_test wal7-2.0 {
           51  +  db close
           52  +  forcedelete test.db
           53  +  sqlite3 db test.db
           54  +  db eval {
           55  +    PRAGMA page_size=1024;
           56  +    PRAGMA journal_mode=WAL;
           57  +    PRAGMA wal_autocheckpoint=50;  -- 50 pages
           58  +    PRAGMA journal_size_limit=25000;
           59  +    CREATE TABLE t1(x, y UNIQUE);
           60  +    INSERT INTO t1 VALUES(1,2);
           61  +    INSERT INTO t1 VALUES(zeroblob(200000),4);
           62  +    CREATE TABLE t2(z);
           63  +    DELETE FROM t1;
           64  +    INSERT INTO t2 SELECT x FROM t1;
           65  +  }
           66  +  file size test.db-wal
           67  +} 25000
           68  +
           69  +
           70  +# Case 3:  Size limit of zero.
           71  +#
           72  +do_test wal7-3.0 {
           73  +  db close
           74  +  forcedelete test.db
           75  +  sqlite3 db test.db
           76  +  db eval {
           77  +    PRAGMA page_size=1024;
           78  +    PRAGMA journal_mode=WAL;
           79  +    PRAGMA wal_autocheckpoint=50;  -- 50 pages
           80  +    PRAGMA journal_size_limit=0;
           81  +    CREATE TABLE t1(x, y UNIQUE);
           82  +    INSERT INTO t1 VALUES(1,2);
           83  +    INSERT INTO t1 VALUES(zeroblob(200000),4);
           84  +    CREATE TABLE t2(z);
           85  +    DELETE FROM t1;
           86  +    INSERT INTO t2 SELECT x FROM t1;
           87  +  }
           88  +  set sz [file size test.db-wal]
           89  +  expr {$sz>0 && $sz<10000}
           90  +} 1
           91  +
           92  +
           93  +# Case 4:  Size limit set before going WAL
           94  +#
           95  +do_test wal7-4.0 {
           96  +  db close
           97  +  forcedelete test.db
           98  +  sqlite3 db test.db
           99  +  db eval {
          100  +    PRAGMA page_size=1024;
          101  +    PRAGMA journal_size_limit=25000;
          102  +    PRAGMA journal_mode=WAL;
          103  +    PRAGMA wal_autocheckpoint=50;  -- 50 pages
          104  +    CREATE TABLE t1(x, y UNIQUE);
          105  +    INSERT INTO t1 VALUES(1,2);
          106  +    INSERT INTO t1 VALUES(zeroblob(200000),4);
          107  +    CREATE TABLE t2(z);
          108  +    DELETE FROM t1;
          109  +    INSERT INTO t2 SELECT x FROM t1;
          110  +  }
          111  +  set sz [file size test.db-wal]
          112  +} 25000
          113  +
          114  +
          115  +
          116  +
          117  +
          118  +finish_test