/ Check-in [20133e9c]
Login

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

Overview
Comment:Merge fix [f80c3f922a] with experimental changes.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | experimental
Files: files | file ages | folders
SHA1: 20133e9ca98f5e6c42051ed3d65e4eb71d5366a5
User & Date: dan 2010-06-17 06:19:53
Context
2010-06-17
10:52
Merge trunk updates with experimental branch. Also add tests to journal2.test. check-in: 9f6ea1de user: dan tags: experimental
06:19
Merge fix [f80c3f922a] with experimental changes. check-in: 20133e9c user: dan tags: experimental
02:13
Bug fix: Only trust the database size number at offset 28 if the change counter at offset 24 matches the version number counter at offset 92. This prevents corruption in the case of two applications writing to the database where one is an older version of SQLite and the other is a newer version. check-in: f80c3f92 user: drh tags: trunk
2010-06-16
19:04
Experimental change: On systems where it is not possible to unlink a file while one or more processes has it open (i.e. not unix), avoid closing the journal file each time the database is unlocked and reopening it at the start of each transaction. check-in: bede8c8a user: dan tags: experimental
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/btree.c.

  2246   2246     /* Do some checking to help insure the file we opened really is
  2247   2247     ** a valid database file. 
  2248   2248     */
  2249   2249     nPage = nPageHeader = get4byte(28+(u8*)pPage1->aData);
  2250   2250     if( (rc = sqlite3PagerPagecount(pBt->pPager, &nPageFile))!=SQLITE_OK ){;
  2251   2251       goto page1_init_failed;
  2252   2252     }
  2253         -  if( nPage==0 ){
         2253  +  if( nPage==0 || memcmp(24+(u8*)pPage1->aData, 92+(u8*)pPage1->aData,4)!=0 ){
  2254   2254       nPage = nPageFile;
  2255   2255     }
  2256   2256     if( nPage>0 ){
  2257   2257       int pageSize;
  2258   2258       int usableSize;
  2259   2259       u8 *page1 = pPage1->aData;
  2260   2260       rc = SQLITE_NOTADB;

Changes to src/pager.c.

  2237   2237     }
  2238   2238   
  2239   2239     if( pgno==1 ){
  2240   2240       if( rc ){
  2241   2241         /* If the read is unsuccessful, set the dbFileVers[] to something
  2242   2242         ** that will never be a valid file version.  dbFileVers[] is a copy
  2243   2243         ** of bytes 24..39 of the database.  Bytes 28..31 should always be
  2244         -      ** zero.  Bytes 32..35 and 35..39 should be page numbers which are
  2245         -      ** never 0xffffffff.  So filling pPager->dbFileVers[] with all 0xff
  2246         -      ** bytes should suffice.
         2244  +      ** zero or the size of the database in page. Bytes 32..35 and 35..39
         2245  +      ** should be page numbers which are never 0xffffffff.  So filling
         2246  +      ** pPager->dbFileVers[] with all 0xff bytes should suffice.
  2247   2247         **
  2248   2248         ** For an encrypted database, the situation is more complex:  bytes
  2249   2249         ** 24..39 of the database are white noise.  But the probability of
  2250   2250         ** white noising equaling 16 bytes of 0xff is vanishingly small so
  2251   2251         ** we should still be ok.
  2252   2252         */
  2253   2253         memset(pPager->dbFileVers, 0xff, sizeof(pPager->dbFileVers));
................................................................................
  5007   5007   
  5008   5008       if( rc==SQLITE_OK ){
  5009   5009         /* Increment the value just read and write it back to byte 24. */
  5010   5010         change_counter = sqlite3Get4byte((u8*)pPager->dbFileVers);
  5011   5011         change_counter++;
  5012   5012         put32bits(((char*)pPgHdr->pData)+24, change_counter);
  5013   5013   
  5014         -      /* Also store the SQLite version number in bytes 96..99 */
         5014  +      /* Also store the SQLite version number in bytes 96..99 and in
         5015  +      ** bytes 92..95 store the change counter for which the version number
         5016  +      ** is valid. */
         5017  +      put32bits(((char*)pPgHdr->pData)+92, change_counter);
  5015   5018         put32bits(((char*)pPgHdr->pData)+96, SQLITE_VERSION_NUMBER);
  5016   5019   
  5017   5020         /* If running in direct mode, write the contents of page 1 to the file. */
  5018   5021         if( DIRECT_MODE ){
  5019   5022           const void *zBuf = pPgHdr->pData;
  5020   5023           assert( pPager->dbFileSize>0 );
  5021   5024           rc = sqlite3OsWrite(pPager->fd, zBuf, pPager->pageSize, 0);

Changes to tool/showdb.c.

   165    165     print_decode_line(aData, 64, 4, "Incremental-vacuum mode");
   166    166     print_decode_line(aData, 68, 4, "meta[7]");
   167    167     print_decode_line(aData, 72, 4, "meta[8]");
   168    168     print_decode_line(aData, 76, 4, "meta[9]");
   169    169     print_decode_line(aData, 80, 4, "meta[10]");
   170    170     print_decode_line(aData, 84, 4, "meta[11]");
   171    171     print_decode_line(aData, 88, 4, "meta[12]");
   172         -  print_decode_line(aData, 92, 4, "meta[13]");
          172  +  print_decode_line(aData, 92, 4, "Change counter for version number");
   173    173     print_decode_line(aData, 96, 4, "SQLite version number");
   174    174   }
   175    175   
   176    176   /*
   177    177   ** Create a description for a single cell.
   178    178   */
   179    179   static int describeCell(unsigned char cType, unsigned char *a, char **pzDesc){