/ Check-in [ddb71cd9]
Login

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

Overview
Comment:Fix the backup API so that a backup from an empty database to a non-empty database works. Ticket [0bf974bdf9]. The only changes are in assert() statements.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: ddb71cd9ed395804a13dc136bb7688a7627c798f
User & Date: drh 2009-11-06 04:13:18
References
2009-11-06
04:15 Fixed ticket [0bf974bd]: backup api asserts with zero length source file plus 5 other changes artifact: daf649bb user: drh
Context
2009-11-06
17:20
Improved shell "dot" command argument handling. Ticket [f12a9eeedc]. check-in: 9fb69919 user: shaneh tags: trunk
04:13
Fix the backup API so that a backup from an empty database to a non-empty database works. Ticket [0bf974bdf9]. The only changes are in assert() statements. check-in: ddb71cd9 user: drh tags: trunk
03:33
Merged accidental fork. check-in: d410cd4e user: shaneh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/os_unix.c.

  3109   3109     assert( id );
  3110   3110     SimulateIOError( return SQLITE_IOERR_TRUNCATE );
  3111   3111     rc = ftruncate(((unixFile*)id)->h, (off_t)nByte);
  3112   3112     if( rc ){
  3113   3113       ((unixFile*)id)->lastErrno = errno;
  3114   3114       return SQLITE_IOERR_TRUNCATE;
  3115   3115     }else{
         3116  +#ifndef NDEBUG
         3117  +    /* If we are doing a normal write to a database file (as opposed to
         3118  +    ** doing a hot-journal rollback or a write to some file other than a
         3119  +    ** normal database file) and we truncate the file to zero length,
         3120  +    ** that effectively updates the change counter.  This might happen
         3121  +    ** when restoring a database using the backup API from a zero-length
         3122  +    ** source.
         3123  +    */
         3124  +    if( ((unixFile*)id)->inNormalWrite && nByte==0 ){
         3125  +      ((unixFile*)id)->transCntrChng = 1;
         3126  +    }
         3127  +#endif
         3128  +
  3116   3129       return SQLITE_OK;
  3117   3130     }
  3118   3131   }
  3119   3132   
  3120   3133   /*
  3121   3134   ** Determine the current size of a file in bytes
  3122   3135   */

Changes to src/pager.c.

  4442   4442     assert( isDirectMode==0 );
  4443   4443     UNUSED_PARAMETER(isDirectMode);
  4444   4444   #else
  4445   4445   # define DIRECT_MODE isDirectMode
  4446   4446   #endif
  4447   4447   
  4448   4448     assert( pPager->state>=PAGER_RESERVED );
  4449         -  if( !pPager->changeCountDone && ALWAYS(pPager->dbSize>0) ){
         4449  +  if( !pPager->changeCountDone && pPager->dbSize>0 ){
  4450   4450       PgHdr *pPgHdr;                /* Reference to page 1 */
  4451   4451       u32 change_counter;           /* Initial value of change-counter field */
  4452   4452   
  4453   4453       assert( !pPager->tempFile && isOpen(pPager->fd) );
  4454   4454   
  4455   4455       /* Open page 1 of the file for writing. */
  4456   4456       rc = sqlite3PagerGet(pPager, 1, &pPgHdr);