/ Check-in [9c59f5af]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

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

Overview
Comment:Back out the new device capability. The determination of whether or not a file has moved is now done strictly using a file-control.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | detect-moved-db
Files: files | file ages | folders
SHA1: 9c59f5af7ac4908583fab85d37241f200c40f02d
User & Date: drh 2013-12-07 16:45:05
Context
2013-12-07
16:56
At the start of each journaled write transaction, check to see if the database file has been moved, and if it has refuse to start the transaction, returning an SQLITE_READONLY_DBMOVED error code. Writing to a moved or renamed database is still allowed when journal_mode is OFF or MEMORY. check-in: 369a23e0 user: drh tags: trunk
16:45
Back out the new device capability. The determination of whether or not a file has moved is now done strictly using a file-control. Closed-Leaf check-in: 9c59f5af user: drh tags: detect-moved-db
12:29
Actually look at i-node numbers to determine whether or not the database file has moved. check-in: 2b1884dc user: drh tags: detect-moved-db
Changes
Hide Diffs Side-by-Side Diffs Show Whitespace Changes Patch

Changes to src/os_win.c.

  3188   3188   
  3189   3189   /*
  3190   3190   ** Return a vector of device characteristics.
  3191   3191   */
  3192   3192   static int winDeviceCharacteristics(sqlite3_file *id){
  3193   3193     winFile *p = (winFile*)id;
  3194   3194     return SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN |
  3195         -         SQLITE_IOCAP_UNMOVABLE_WHEN_OPEN |
  3196   3195            ((p->ctrlFlags & WINFILE_PSOW)?SQLITE_IOCAP_POWERSAFE_OVERWRITE:0);
  3197   3196   }
  3198   3197   
  3199   3198   /* 
  3200   3199   ** Windows will only let you create file view mappings
  3201   3200   ** on allocation size granularity boundaries.
  3202   3201   ** During sqlite3_os_init() we do a GetSystemInfo()

Changes to src/pager.c.

  4799   4799   
  4800   4800   /* Verify that the database file has not be deleted or renamed out from
  4801   4801   ** under the pager.  Return SQLITE_OK if the database is still were it ought
  4802   4802   ** to be on disk.  Return non-zero (SQLITE_READONLY_DBMOVED or some other error
  4803   4803   ** code from sqlite3OsAccess()) if the database has gone missing.
  4804   4804   */
  4805   4805   static int databaseIsUnmoved(Pager *pPager){
  4806         -  const int fixedFlags = SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN |
  4807         -                         SQLITE_IOCAP_UNMOVABLE_WHEN_OPEN;
  4808         -  int dc;
  4809   4806     int bHasMoved = 0;
  4810   4807     int rc;
  4811   4808   
  4812   4809     if( pPager->tempFile ) return SQLITE_OK;
  4813   4810     if( pPager->dbSize==0 ) return SQLITE_OK;
  4814   4811     assert( pPager->zFilename && pPager->zFilename[0] );
  4815         -  dc = sqlite3OsDeviceCharacteristics(pPager->fd);
  4816         -  if( (dc&fixedFlags)==fixedFlags ) return SQLITE_OK;
  4817   4812     rc = sqlite3OsFileControl(pPager->fd, SQLITE_FCNTL_HAS_MOVED, &bHasMoved);
  4818         -  if( rc==SQLITE_OK && bHasMoved ) rc = SQLITE_READONLY_DBMOVED;
         4813  +  if( rc==SQLITE_NOTFOUND ){
         4814  +    /* If the HAS_MOVED file-control is unimplemented, assume that the file
         4815  +    ** has not been moved.  That is the historical behavior of SQLite: prior to
         4816  +    ** version 3.8.3, it never checked */
         4817  +    rc = SQLITE_OK;
         4818  +  }else if( rc==SQLITE_OK && bHasMoved ){
         4819  +    rc = SQLITE_READONLY_DBMOVED;
         4820  +  }
  4819   4821     return rc;
  4820   4822   }
  4821   4823   
  4822   4824   
  4823   4825   /*
  4824   4826   ** This function is called after transitioning from PAGER_UNLOCK to
  4825   4827   ** PAGER_SHARED state. It tests if there is a hot journal present in

Changes to src/sqlite.h.in.

   551    551   ** way around.  The SQLITE_IOCAP_SEQUENTIAL property means that
   552    552   ** information is written to disk in the same order as calls
   553    553   ** to xWrite().  The SQLITE_IOCAP_POWERSAFE_OVERWRITE property means that
   554    554   ** after reboot following a crash or power loss, the only bytes in a
   555    555   ** file that were written at the application level might have changed
   556    556   ** and that adjacent bytes, even bytes within the same sector are
   557    557   ** guaranteed to be unchanged.  The SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN
   558         -** and SQLITE_IOCAP_UNMOVABLE_WHEN_OPEN flags indicate that a file 
   559         -** cannot be deleted or renamed when open, respectively.
          558  +** flag indicate that a file cannot be deleted when open.
   560    559   */
   561    560   #define SQLITE_IOCAP_ATOMIC                 0x00000001
   562    561   #define SQLITE_IOCAP_ATOMIC512              0x00000002
   563    562   #define SQLITE_IOCAP_ATOMIC1K               0x00000004
   564    563   #define SQLITE_IOCAP_ATOMIC2K               0x00000008
   565    564   #define SQLITE_IOCAP_ATOMIC4K               0x00000010
   566    565   #define SQLITE_IOCAP_ATOMIC8K               0x00000020
................................................................................
   567    566   #define SQLITE_IOCAP_ATOMIC16K              0x00000040
   568    567   #define SQLITE_IOCAP_ATOMIC32K              0x00000080
   569    568   #define SQLITE_IOCAP_ATOMIC64K              0x00000100
   570    569   #define SQLITE_IOCAP_SAFE_APPEND            0x00000200
   571    570   #define SQLITE_IOCAP_SEQUENTIAL             0x00000400
   572    571   #define SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN  0x00000800
   573    572   #define SQLITE_IOCAP_POWERSAFE_OVERWRITE    0x00001000
   574         -#define SQLITE_IOCAP_UNMOVABLE_WHEN_OPEN    0x00002000
   575    573   
   576    574   /*
   577    575   ** CAPI3REF: File Locking Levels
   578    576   **
   579    577   ** SQLite uses one of these integer values as the second
   580    578   ** argument to calls it makes to the xLock() and xUnlock() methods
   581    579   ** of an [sqlite3_io_methods] object.