/ Check-in [d2efd3c1]
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:Additional error reporting. Open the source database read/write so that it can delete the WAL file when done.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | scrub-backup
Files: files | file ages | folders
SHA1: d2efd3c176f0eba2d78105f0bb3161db38bd4bab
User & Date: drh 2016-05-05 23:59:22
Context
2016-05-17
17:11
Merge the latest changes from trunk. check-in: 5021dfe1 user: drh tags: scrub-backup
2016-05-05
23:59
Additional error reporting. Open the source database read/write so that it can delete the WAL file when done. check-in: d2efd3c1 user: drh tags: scrub-backup
23:39
Working when run against sqlite.fossil. check-in: b0bd9dd6 user: drh tags: scrub-backup
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to ext/misc/scrub.c.

   153    153   
   154    154   /* Open the source database file */
   155    155   static void scrubBackupOpenSrc(ScrubState *p){
   156    156     sqlite3_stmt *pStmt;
   157    157     int rc;
   158    158     /* Open the source database file */
   159    159     p->rcErr = sqlite3_open_v2(p->zSrcFile, &p->dbSrc,
   160         -                 SQLITE_OPEN_READONLY |
          160  +                 SQLITE_OPEN_READWRITE |
   161    161                    SQLITE_OPEN_URI | SQLITE_OPEN_PRIVATECACHE, 0);
   162    162     if( p->rcErr ){
   163    163       scrubBackupErr(p, "cannot open source database: %s",
   164    164                         sqlite3_errmsg(p->dbSrc));
   165    165       return;
   166    166     }
   167    167     p->rcErr = sqlite3_exec(p->dbSrc, "BEGIN", 0, 0, 0);
................................................................................
   534    534     }
   535    535     sqlite3_finalize(pStmt);
   536    536   
   537    537   scrub_abort:    
   538    538     /* Close the destination database without closing the transaction. If we
   539    539     ** commit, page zero will be overwritten. */
   540    540     sqlite3_close(s.dbDest);
          541  +
          542  +  /* But do close out the read-transaction on the source database */
          543  +  sqlite3_exec(s.dbSrc, "COMMIT;", 0, 0, 0);
   541    544     sqlite3_close(s.dbSrc);
   542    545     sqlite3_free(s.page1);
   543    546     if( pzErr ){
   544    547       *pzErr = s.zErr;
   545    548     }else{
   546    549       sqlite3_free(s.zErr);
   547    550     }
   548    551     return s.rcErr;
   549    552   }   
   550    553   
   551    554   #ifdef SCRUB_STANDALONE
          555  +/* Error and warning log */
          556  +static void errorLogCallback(void *pNotUsed, int iErr, const char *zMsg){
          557  +  const char *zType;
          558  +  switch( iErr&0xff ){
          559  +    case SQLITE_WARNING: zType = "WARNING";  break;
          560  +    case SQLITE_NOTICE:  zType = "NOTICE";   break;
          561  +    default:             zType = "ERROR";    break;
          562  +  }
          563  +  fprintf(stderr, "%s: %s\n", zType, zMsg);
          564  +}
          565  +
   552    566   /* The main() routine when this utility is run as a stand-alone program */
   553    567   int main(int argc, char **argv){
   554    568     char *zErr = 0;
   555    569     int rc;
   556    570     if( argc!=3 ){
   557    571       fprintf(stderr,"Usage: %s SOURCE DESTINATION\n", argv[0]);
   558    572       exit(1);
   559    573     }
          574  +  sqlite3_config(SQLITE_CONFIG_LOG, errorLogCallback, 0);
   560    575     rc = sqlite3_scrub_backup(argv[1], argv[2], &zErr);
   561    576     if( rc==SQLITE_NOMEM ){
   562    577       fprintf(stderr, "%s: out of memory\n", argv[0]);
   563    578       exit(1);
   564    579     }
   565    580     if( zErr ){
   566    581       fprintf(stderr, "%s: %s\n", argv[0], zErr);
   567    582       sqlite3_free(zErr);
   568    583       exit(1);
   569    584     }
   570    585     return 0;
   571    586   }
   572    587   #endif