System.Data.SQLite
Check-in [f9c2d67ad2]
Not logged in

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

Overview
Comment:Update SQLite core to latest, including the os_win.c fixes and the new SQLITE_FCNTL_PERSIST_WAL file control.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: f9c2d67ad20d4fd174a6d4d0b2880723be268bf3
User & Date: mistachkin 2011-07-29 20:35:34
Context
2011-08-09
06:01
Remove old VS designer installer. check-in: 6eff911e63 user: mistachkin tags: trunk
2011-07-29
20:35
Update SQLite core to latest, including the os_win.c fixes and the new SQLITE_FCNTL_PERSIST_WAL file control. check-in: f9c2d67ad2 user: mistachkin tags: trunk
2011-07-24
21:50
Sync up ProjectGuids for the static interop projects. check-in: 5c03dc1829 user: mistachkin tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to SQLite.Interop/src/core/sqlite3.c.

   648    648   **
   649    649   ** See also: [sqlite3_libversion()],
   650    650   ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
   651    651   ** [sqlite_version()] and [sqlite_source_id()].
   652    652   */
   653    653   #define SQLITE_VERSION        "3.7.8"
   654    654   #define SQLITE_VERSION_NUMBER 3007008
   655         -#define SQLITE_SOURCE_ID      "2011-07-22 21:25:57 a6b85c73406caa3bf0585341c8ebc9897a1884f4"
          655  +#define SQLITE_SOURCE_ID      "2011-07-28 20:48:38 1b56677bdfb102d070a2057a65ba424fec81131d"
   656    656   
   657    657   /*
   658    658   ** CAPI3REF: Run-Time Library Version Numbers
   659    659   ** KEYWORDS: sqlite3_version, sqlite3_sourceid
   660    660   **
   661    661   ** These interfaces provide the same information as the [SQLITE_VERSION],
   662    662   ** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros
................................................................................
  1296   1296   ** to be adjusted.  The values are changed for all database connections
  1297   1297   ** within the same process.  The argument is a pointer to an array of two
  1298   1298   ** integers where the first integer i the new retry count and the second
  1299   1299   ** integer is the delay.  If either integer is negative, then the setting
  1300   1300   ** is not changed but instead the prior value of that setting is written
  1301   1301   ** into the array entry, allowing the current retry settings to be
  1302   1302   ** interrogated.  The zDbName parameter is ignored.
         1303  +**
         1304  +** ^The [SQLITE_FCNTL_PERSIST_WAL] opcode is used to set or query the
         1305  +** persistent [WAL | Write AHead Log] setting.  By default, the auxiliary
         1306  +** write ahead log and shared memory files used for transaction control
         1307  +** are automatically deleted when the latest connection to the database
         1308  +** closes.  Setting persistent WAL mode causes those files to persist after
         1309  +** close.  Persisting the files is useful when other processes that do not
         1310  +** have write permission on the directory containing the database file want
         1311  +** to read the database file, as the WAL and shared memory files must exist
         1312  +** in order for the database to be readable.  The fourth parameter to
         1313  +** [sqlite3_file_control()] for this opcode should be a pointer to an integer.
         1314  +** That integer is 0 to disable persistent WAL mode or 1 to enable persistent
         1315  +** WAL mode.  If the integer is -1, then it is overwritten with the current
         1316  +** WAL persistence setting.
  1303   1317   ** 
  1304   1318   */
  1305   1319   #define SQLITE_FCNTL_LOCKSTATE        1
  1306   1320   #define SQLITE_GET_LOCKPROXYFILE      2
  1307   1321   #define SQLITE_SET_LOCKPROXYFILE      3
  1308   1322   #define SQLITE_LAST_ERRNO             4
  1309   1323   #define SQLITE_FCNTL_SIZE_HINT        5
  1310   1324   #define SQLITE_FCNTL_CHUNK_SIZE       6
  1311   1325   #define SQLITE_FCNTL_FILE_POINTER     7
  1312   1326   #define SQLITE_FCNTL_SYNC_OMITTED     8
  1313   1327   #define SQLITE_FCNTL_WIN32_AV_RETRY   9
         1328  +#define SQLITE_FCNTL_PERSIST_WAL     10
  1314   1329   
  1315   1330   /*
  1316   1331   ** CAPI3REF: Mutex Handle
  1317   1332   **
  1318   1333   ** The mutex module within SQLite defines [sqlite3_mutex] to be an
  1319   1334   ** abstract type for a mutex object.  The SQLite core never looks
  1320   1335   ** at the internal representation of an [sqlite3_mutex].  It only
................................................................................
 24541  24556     char aPadding[32];
 24542  24557   #endif
 24543  24558   };
 24544  24559   
 24545  24560   /*
 24546  24561   ** Allowed values for the unixFile.ctrlFlags bitmask:
 24547  24562   */
 24548         -#define UNIXFILE_EXCL   0x01     /* Connections from one process only */
 24549         -#define UNIXFILE_RDONLY 0x02     /* Connection is read only */
        24563  +#define UNIXFILE_EXCL        0x01     /* Connections from one process only */
        24564  +#define UNIXFILE_RDONLY      0x02     /* Connection is read only */
        24565  +#define UNIXFILE_PERSIST_WAL 0x04     /* Persistent WAL mode */
 24550  24566   
 24551  24567   /*
 24552  24568   ** Include code that is common to all os_*.c files
 24553  24569   */
 24554  24570   /************** Include os_common.h in the middle of os_unix.c ***************/
 24555  24571   /************** Begin file os_common.h ***************************************/
 24556  24572   /*
................................................................................
 27894  27910   ** file-control operation.
 27895  27911   **
 27896  27912   ** If the user has configured a chunk-size for this file, it could be
 27897  27913   ** that the file needs to be extended at this point. Otherwise, the
 27898  27914   ** SQLITE_FCNTL_SIZE_HINT operation is a no-op for Unix.
 27899  27915   */
 27900  27916   static int fcntlSizeHint(unixFile *pFile, i64 nByte){
 27901         -  if( pFile->szChunk ){
        27917  +  { /* preserve indentation of removed "if" */
 27902  27918       i64 nSize;                    /* Required file size */
        27919  +    i64 szChunk;                  /* Chunk size */
 27903  27920       struct stat buf;              /* Used to hold return values of fstat() */
 27904  27921      
 27905  27922       if( osFstat(pFile->h, &buf) ) return SQLITE_IOERR_FSTAT;
 27906  27923   
 27907         -    nSize = ((nByte+pFile->szChunk-1) / pFile->szChunk) * pFile->szChunk;
        27924  +    szChunk = pFile->szChunk;
        27925  +    if( szChunk==0 ){
        27926  +      nSize = nByte;
        27927  +    }else{
        27928  +      nSize = ((nByte+szChunk-1) / szChunk) * szChunk;
        27929  +    }
 27908  27930       if( nSize>(i64)buf.st_size ){
 27909  27931   
 27910  27932   #if defined(HAVE_POSIX_FALLOCATE) && HAVE_POSIX_FALLOCATE
 27911  27933         /* The code below is handling the return value of osFallocate() 
 27912  27934         ** correctly. posix_fallocate() is defined to "returns zero on success, 
 27913  27935         ** or an error number on  failure". See the manpage for details. */
 27914  27936         int err;
................................................................................
 27943  27965     return SQLITE_OK;
 27944  27966   }
 27945  27967   
 27946  27968   /*
 27947  27969   ** Information and control of an open file handle.
 27948  27970   */
 27949  27971   static int unixFileControl(sqlite3_file *id, int op, void *pArg){
        27972  +  unixFile *pFile = (unixFile*)id;
 27950  27973     switch( op ){
 27951  27974       case SQLITE_FCNTL_LOCKSTATE: {
 27952         -      *(int*)pArg = ((unixFile*)id)->eFileLock;
        27975  +      *(int*)pArg = pFile->eFileLock;
 27953  27976         return SQLITE_OK;
 27954  27977       }
 27955  27978       case SQLITE_LAST_ERRNO: {
 27956         -      *(int*)pArg = ((unixFile*)id)->lastErrno;
        27979  +      *(int*)pArg = pFile->lastErrno;
 27957  27980         return SQLITE_OK;
 27958  27981       }
 27959  27982       case SQLITE_FCNTL_CHUNK_SIZE: {
 27960         -      ((unixFile*)id)->szChunk = *(int *)pArg;
        27983  +      pFile->szChunk = *(int *)pArg;
 27961  27984         return SQLITE_OK;
 27962  27985       }
 27963  27986       case SQLITE_FCNTL_SIZE_HINT: {
 27964         -      return fcntlSizeHint((unixFile *)id, *(i64 *)pArg);
        27987  +      return fcntlSizeHint(pFile, *(i64 *)pArg);
        27988  +    }
        27989  +    case SQLITE_FCNTL_PERSIST_WAL: {
        27990  +      int bPersist = *(int*)pArg;
        27991  +      if( bPersist<0 ){
        27992  +        *(int*)pArg = (pFile->ctrlFlags & UNIXFILE_PERSIST_WAL)!=0;
        27993  +      }else if( bPersist==0 ){
        27994  +        pFile->ctrlFlags &= ~UNIXFILE_PERSIST_WAL;
        27995  +      }else{
        27996  +        pFile->ctrlFlags |= UNIXFILE_PERSIST_WAL;
        27997  +      }
        27998  +      return SQLITE_OK;
 27965  27999       }
 27966  28000   #ifndef NDEBUG
 27967  28001       /* The pager calls this method to signal that it has done
 27968  28002       ** a rollback and that the database is therefore unchanged and
 27969  28003       ** it hence it is OK for the transaction change counter to be
 27970  28004       ** unchanged.
 27971  28005       */
................................................................................
 29282  29316     ** almost certain that an open() call on the same path will also fail.
 29283  29317     ** For this reason, if an error occurs in the stat() call here, it is
 29284  29318     ** ignored and -1 is returned. The caller will try to open a new file
 29285  29319     ** descriptor on the same path, fail, and return an error to SQLite.
 29286  29320     **
 29287  29321     ** Even if a subsequent open() call does succeed, the consequences of
 29288  29322     ** not searching for a resusable file descriptor are not dire.  */
 29289         -  if( 0==stat(zPath, &sStat) ){
        29323  +  if( 0==osStat(zPath, &sStat) ){
 29290  29324       unixInodeInfo *pInode;
 29291  29325   
 29292  29326       unixEnterMutex();
 29293  29327       pInode = inodeList;
 29294  29328       while( pInode && (pInode->fileId.dev!=sStat.st_dev
 29295  29329                        || pInode->fileId.ino!=sStat.st_ino) ){
 29296  29330          pInode = pInode->pNext;
................................................................................
 29358  29392       */
 29359  29393       nDb = sqlite3Strlen30(zPath) - 1; 
 29360  29394       while( nDb>0 && zPath[nDb]!='-' ) nDb--;
 29361  29395       if( nDb==0 ) return SQLITE_OK;
 29362  29396       memcpy(zDb, zPath, nDb);
 29363  29397       zDb[nDb] = '\0';
 29364  29398   
 29365         -    if( 0==stat(zDb, &sStat) ){
        29399  +    if( 0==osStat(zDb, &sStat) ){
 29366  29400         *pMode = sStat.st_mode & 0777;
 29367  29401       }else{
 29368  29402         rc = SQLITE_IOERR_FSTAT;
 29369  29403       }
 29370  29404     }else if( flags & SQLITE_OPEN_DELETEONCLOSE ){
 29371  29405       *pMode = 0600;
 29372  29406     }
................................................................................
 29703  29737   
 29704  29738       default:
 29705  29739         assert(!"Invalid flags argument");
 29706  29740     }
 29707  29741     *pResOut = (osAccess(zPath, amode)==0);
 29708  29742     if( flags==SQLITE_ACCESS_EXISTS && *pResOut ){
 29709  29743       struct stat buf;
 29710         -    if( 0==stat(zPath, &buf) && buf.st_size==0 ){
        29744  +    if( 0==osStat(zPath, &buf) && buf.st_size==0 ){
 29711  29745         *pResOut = 0;
 29712  29746       }
 29713  29747     }
 29714  29748     return SQLITE_OK;
 29715  29749   }
 29716  29750   
 29717  29751   
................................................................................
 31559  31593   ** portability layer.
 31560  31594   */
 31561  31595   typedef struct winFile winFile;
 31562  31596   struct winFile {
 31563  31597     const sqlite3_io_methods *pMethod; /*** Must be first ***/
 31564  31598     sqlite3_vfs *pVfs;      /* The VFS used to open this file */
 31565  31599     HANDLE h;               /* Handle for accessing the file */
 31566         -  unsigned char locktype; /* Type of lock currently held on this file */
        31600  +  u8 locktype;            /* Type of lock currently held on this file */
 31567  31601     short sharedLockByte;   /* Randomly chosen byte used as a shared lock */
        31602  +  u8 bPersistWal;         /* True to persist WAL files */
 31568  31603     DWORD lastErrno;        /* The Windows errno from the last I/O error */
 31569  31604     DWORD sectorSize;       /* Sector size of the device file is on */
 31570  31605     winShm *pShm;           /* Instance of shared memory on this file */
 31571  31606     const char *zPath;      /* Full pathname of this file */
 31572  31607     int szChunk;            /* Chunk size configured by FCNTL_CHUNK_SIZE */
 31573  31608   #if SQLITE_OS_WINCE
 31574  31609     WCHAR *zDeleteOnClose;  /* Name of file to delete when closing */
................................................................................
 32791  32826     return rc;
 32792  32827   }
 32793  32828   
 32794  32829   /*
 32795  32830   ** Control and query of the open file handle.
 32796  32831   */
 32797  32832   static int winFileControl(sqlite3_file *id, int op, void *pArg){
        32833  +  winFile *pFile = (winFile*)id;
 32798  32834     switch( op ){
 32799  32835       case SQLITE_FCNTL_LOCKSTATE: {
 32800         -      *(int*)pArg = ((winFile*)id)->locktype;
        32836  +      *(int*)pArg = pFile->locktype;
 32801  32837         return SQLITE_OK;
 32802  32838       }
 32803  32839       case SQLITE_LAST_ERRNO: {
 32804         -      *(int*)pArg = (int)((winFile*)id)->lastErrno;
        32840  +      *(int*)pArg = (int)pFile->lastErrno;
 32805  32841         return SQLITE_OK;
 32806  32842       }
 32807  32843       case SQLITE_FCNTL_CHUNK_SIZE: {
 32808         -      ((winFile*)id)->szChunk = *(int *)pArg;
        32844  +      pFile->szChunk = *(int *)pArg;
 32809  32845         return SQLITE_OK;
 32810  32846       }
 32811  32847       case SQLITE_FCNTL_SIZE_HINT: {
 32812  32848         sqlite3_int64 sz = *(sqlite3_int64*)pArg;
 32813  32849         SimulateIOErrorBenign(1);
 32814  32850         winTruncate(id, sz);
 32815  32851         SimulateIOErrorBenign(0);
 32816  32852         return SQLITE_OK;
        32853  +    }
        32854  +    case SQLITE_FCNTL_PERSIST_WAL: {
        32855  +      int bPersist = *(int*)pArg;
        32856  +      if( bPersist<0 ){
        32857  +        *(int*)pArg = pFile->bPersistWal;
        32858  +      }else{
        32859  +        pFile->bPersistWal = bPersist!=0;
        32860  +      }
        32861  +      return SQLITE_OK;
 32817  32862       }
 32818  32863       case SQLITE_FCNTL_SYNC_OMITTED: {
 32819  32864         return SQLITE_OK;
 32820  32865       }
 32821  32866       case SQLITE_FCNTL_WIN32_AV_RETRY: {
 32822  32867         int *a = (int*)pArg;
 32823  32868         if( a[0]>0 ){
................................................................................
 33911  33956     if( zConverted==0 ){
 33912  33957       return SQLITE_NOMEM;
 33913  33958     }
 33914  33959     if( isNT() ){
 33915  33960       int cnt = 0;
 33916  33961       WIN32_FILE_ATTRIBUTE_DATA sAttrData;
 33917  33962       memset(&sAttrData, 0, sizeof(sAttrData));
 33918         -    while( (rc = GetFileAttributesExW((WCHAR*)zConverted,
        33963  +    while( !(rc = GetFileAttributesExW((WCHAR*)zConverted,
 33919  33964                                GetFileExInfoStandard, 
 33920         -                             &sAttrData)) && rc==0 && retryIoerr(&cnt) ){}
        33965  +                             &sAttrData)) && retryIoerr(&cnt) ){}
 33921  33966       if( rc ){
 33922  33967         /* For an SQLITE_ACCESS_EXISTS query, treat a zero-length file
 33923  33968         ** as if it does not exist.
 33924  33969         */
 33925  33970         if(    flags==SQLITE_ACCESS_EXISTS
 33926  33971             && sAttrData.nFileSizeHigh==0 
 33927  33972             && sAttrData.nFileSizeLow==0 ){
 33928  33973           attr = INVALID_FILE_ATTRIBUTES;
 33929  33974         }else{
 33930  33975           attr = sAttrData.dwFileAttributes;
 33931  33976         }
 33932  33977       }else{
        33978  +      logIoerr(cnt);
 33933  33979         if( GetLastError()!=ERROR_FILE_NOT_FOUND ){
 33934  33980           winLogError(SQLITE_IOERR_ACCESS, "winAccess", zFilename);
 33935  33981           free(zConverted);
 33936  33982           return SQLITE_IOERR_ACCESS;
 33937  33983         }else{
 33938  33984           attr = INVALID_FILE_ATTRIBUTES;
 33939  33985         }
................................................................................
 33950  33996     free(zConverted);
 33951  33997     switch( flags ){
 33952  33998       case SQLITE_ACCESS_READ:
 33953  33999       case SQLITE_ACCESS_EXISTS:
 33954  34000         rc = attr!=INVALID_FILE_ATTRIBUTES;
 33955  34001         break;
 33956  34002       case SQLITE_ACCESS_READWRITE:
 33957         -      rc = (attr & FILE_ATTRIBUTE_READONLY)==0;
        34003  +      rc = attr!=INVALID_FILE_ATTRIBUTES &&
        34004  +             (attr & FILE_ATTRIBUTE_READONLY)==0;
 33958  34005         break;
 33959  34006       default:
 33960  34007         assert(!"Invalid flags argument");
 33961  34008     }
 33962  34009     *pResOut = rc;
 33963  34010     return SQLITE_OK;
 33964  34011   }
................................................................................
 45534  45581       ** the database. In this case checkpoint the database and unlink both
 45535  45582       ** the wal and wal-index files.
 45536  45583       **
 45537  45584       ** The EXCLUSIVE lock is not released before returning.
 45538  45585       */
 45539  45586       rc = sqlite3OsLock(pWal->pDbFd, SQLITE_LOCK_EXCLUSIVE);
 45540  45587       if( rc==SQLITE_OK ){
        45588  +      int bPersistWal = -1;
 45541  45589         if( pWal->exclusiveMode==WAL_NORMAL_MODE ){
 45542  45590           pWal->exclusiveMode = WAL_EXCLUSIVE_MODE;
 45543  45591         }
 45544  45592         rc = sqlite3WalCheckpoint(
 45545  45593             pWal, SQLITE_CHECKPOINT_PASSIVE, 0, 0, sync_flags, nBuf, zBuf, 0, 0
 45546  45594         );
 45547         -      if( rc==SQLITE_OK ){
        45595  +      sqlite3OsFileControl(pWal->pDbFd, SQLITE_FCNTL_PERSIST_WAL, &bPersistWal);
        45596  +      if( rc==SQLITE_OK && bPersistWal!=1 ){
 45548  45597           isDelete = 1;
 45549  45598         }
 45550  45599       }
 45551  45600   
 45552  45601       walIndexClose(pWal, isDelete);
 45553  45602       sqlite3OsClose(pWal->pWalFd);
 45554  45603       if( isDelete ){

Changes to SQLite.Interop/src/core/sqlite3.h.

   105    105   **
   106    106   ** See also: [sqlite3_libversion()],
   107    107   ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
   108    108   ** [sqlite_version()] and [sqlite_source_id()].
   109    109   */
   110    110   #define SQLITE_VERSION        "3.7.8"
   111    111   #define SQLITE_VERSION_NUMBER 3007008
   112         -#define SQLITE_SOURCE_ID      "2011-07-22 21:25:57 a6b85c73406caa3bf0585341c8ebc9897a1884f4"
          112  +#define SQLITE_SOURCE_ID      "2011-07-28 20:48:38 1b56677bdfb102d070a2057a65ba424fec81131d"
   113    113   
   114    114   /*
   115    115   ** CAPI3REF: Run-Time Library Version Numbers
   116    116   ** KEYWORDS: sqlite3_version, sqlite3_sourceid
   117    117   **
   118    118   ** These interfaces provide the same information as the [SQLITE_VERSION],
   119    119   ** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros
................................................................................
   753    753   ** to be adjusted.  The values are changed for all database connections
   754    754   ** within the same process.  The argument is a pointer to an array of two
   755    755   ** integers where the first integer i the new retry count and the second
   756    756   ** integer is the delay.  If either integer is negative, then the setting
   757    757   ** is not changed but instead the prior value of that setting is written
   758    758   ** into the array entry, allowing the current retry settings to be
   759    759   ** interrogated.  The zDbName parameter is ignored.
          760  +**
          761  +** ^The [SQLITE_FCNTL_PERSIST_WAL] opcode is used to set or query the
          762  +** persistent [WAL | Write AHead Log] setting.  By default, the auxiliary
          763  +** write ahead log and shared memory files used for transaction control
          764  +** are automatically deleted when the latest connection to the database
          765  +** closes.  Setting persistent WAL mode causes those files to persist after
          766  +** close.  Persisting the files is useful when other processes that do not
          767  +** have write permission on the directory containing the database file want
          768  +** to read the database file, as the WAL and shared memory files must exist
          769  +** in order for the database to be readable.  The fourth parameter to
          770  +** [sqlite3_file_control()] for this opcode should be a pointer to an integer.
          771  +** That integer is 0 to disable persistent WAL mode or 1 to enable persistent
          772  +** WAL mode.  If the integer is -1, then it is overwritten with the current
          773  +** WAL persistence setting.
   760    774   ** 
   761    775   */
   762    776   #define SQLITE_FCNTL_LOCKSTATE        1
   763    777   #define SQLITE_GET_LOCKPROXYFILE      2
   764    778   #define SQLITE_SET_LOCKPROXYFILE      3
   765    779   #define SQLITE_LAST_ERRNO             4
   766    780   #define SQLITE_FCNTL_SIZE_HINT        5
   767    781   #define SQLITE_FCNTL_CHUNK_SIZE       6
   768    782   #define SQLITE_FCNTL_FILE_POINTER     7
   769    783   #define SQLITE_FCNTL_SYNC_OMITTED     8
   770    784   #define SQLITE_FCNTL_WIN32_AV_RETRY   9
          785  +#define SQLITE_FCNTL_PERSIST_WAL     10
   771    786   
   772    787   /*
   773    788   ** CAPI3REF: Mutex Handle
   774    789   **
   775    790   ** The mutex module within SQLite defines [sqlite3_mutex] to be an
   776    791   ** abstract type for a mutex object.  The SQLite core never looks
   777    792   ** at the internal representation of an [sqlite3_mutex].  It only