/ Check-in [9a0078a5]
Login

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

Overview
Comment:Add the -vacuum switch to the "rbu" demonstration program.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | rbu-vacuum
Files: files | file ages | folders
SHA1: 9a0078a538c7e73a009960347b8953c5af99fefd
User & Date: dan 2016-04-18 09:17:05
Context
2016-04-18
18:18
Fix some zipvfs related problems in RBU vacuum. check-in: d76f4aaa user: dan tags: rbu-vacuum
09:17
Add the -vacuum switch to the "rbu" demonstration program. check-in: 9a0078a5 user: dan tags: rbu-vacuum
2016-04-16
19:02
Changes so that rbu vacuum works with zipvfs databases. check-in: bae7f875 user: dan tags: rbu-vacuum
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to ext/rbu/rbu.c.

    20     20   #include <string.h>
    21     21   
    22     22   /*
    23     23   ** Print a usage message and exit.
    24     24   */
    25     25   void usage(const char *zArgv0){
    26     26     fprintf(stderr, 
    27         -"Usage: %s [-step NSTEP] TARGET-DB RBU-DB\n"
           27  +"Usage: %s ?OPTIONS? TARGET-DB RBU-DB\n"
           28  +"\n"
           29  +"Where options are:\n"
           30  +"\n"
           31  +"    -step NSTEP\n"
           32  +"    -vacuum\n"
           33  +"\n"
           34  +"  If the -vacuum switch is not present, argument RBU-DB must be an RBU\n"
           35  +"  database containing an update suitable for target database TARGET-DB.\n"
           36  +"  Or, if -vacuum is specified, then TARGET-DB is a database to vacuum using\n"
           37  +"  RBU, and RBU-DB is used as the state database for the vacuum (refer to\n"
           38  +"  API documentation for details).\n"
    28     39   "\n"
    29         -"  Argument RBU-DB must be an RBU database containing an update suitable for\n"
    30         -"  target database TARGET-DB. If NSTEP is set to less than or equal to zero\n"
    31         -"  (the default value), this program attempts to apply the entire update to\n"
    32         -"  the target database.\n"
           40  +"  If NSTEP is set to less than or equal to zero (the default value), this \n"
           41  +"  program attempts to perform the entire update or vacuum operation before\n"
           42  +"  exiting\n"
    33     43   "\n"
    34     44   "  If NSTEP is greater than zero, then a maximum of NSTEP calls are made\n"
    35     45   "  to sqlite3rbu_step(). If the RBU update has not been completely applied\n"
    36     46   "  after the NSTEP'th call is made, the state is saved in the database RBU-DB\n"
    37     47   "  and the program exits. Subsequent invocations of this (or any other RBU)\n"
    38     48   "  application will use this state to resume applying the RBU update to the\n"
    39     49   "  target db.\n"
................................................................................
    65     75     int i;
    66     76     const char *zTarget;            /* Target database to apply RBU to */
    67     77     const char *zRbu;               /* Database containing RBU */
    68     78     char zBuf[200];                 /* Buffer for printf() */
    69     79     char *zErrmsg;                  /* Error message, if any */
    70     80     sqlite3rbu *pRbu;               /* RBU handle */
    71     81     int nStep = 0;                  /* Maximum number of step() calls */
           82  +  int bVacuum = 0;
    72     83     int rc;
    73     84     sqlite3_int64 nProgress = 0;
           85  +  int nArg = argc-2;
    74     86   
    75         -  /* Process command line arguments. Following this block local variables 
    76         -  ** zTarget, zRbu and nStep are all set. */
    77         -  if( argc==5 ){
    78         -    size_t nArg1 = strlen(argv[1]);
    79         -    if( nArg1>5 || nArg1<2 || memcmp("-step", argv[1], nArg1) ) usage(argv[0]);
    80         -    nStep = atoi(argv[2]);
    81         -  }else if( argc!=3 ){
    82         -    usage(argv[0]);
           87  +  if( argc<3 ) usage(argv[0]);
           88  +  for(i=1; i<nArg; i++){
           89  +    const char *zArg = argv[i];
           90  +    int nArg = strlen(zArg);
           91  +    if( nArg>1 && nArg<=8 && 0==memcmp(zArg, "-vacuum", nArg) ){
           92  +      bVacuum = 1;
           93  +    }else if( nArg>1 && nArg<=5 && 0==memcmp(zArg, "-step", nArg) && i<nArg-1 ){
           94  +      i++;
           95  +      nStep = atoi(argv[i]);
           96  +    }else{
           97  +      usage(argv[0]);
           98  +    }
    83     99     }
          100  +
    84    101     zTarget = argv[argc-2];
    85    102     zRbu = argv[argc-1];
    86    103   
    87    104     report_default_vfs();
    88    105   
    89         -  /* Open an RBU handle. If nStep is less than or equal to zero, call
          106  +  /* Open an RBU handle. A vacuum handle if -vacuum was specified, or a
          107  +  ** regular RBU update handle otherwise.  */
          108  +  if( bVacuum ){
          109  +    pRbu = sqlite3rbu_vacuum(zTarget, zRbu);
          110  +  }else{
          111  +    pRbu = sqlite3rbu_open(zTarget, zRbu, 0);
          112  +  }
          113  +  report_rbu_vfs(pRbu);
          114  +
          115  +  /* If nStep is less than or equal to zero, call
    90    116     ** sqlite3rbu_step() until either the RBU has been completely applied
    91    117     ** or an error occurs. Or, if nStep is greater than zero, call
    92    118     ** sqlite3rbu_step() a maximum of nStep times.  */
    93         -  pRbu = sqlite3rbu_open(zTarget, zRbu, 0);
    94         -  report_rbu_vfs(pRbu);
    95    119     for(i=0; (nStep<=0 || i<nStep) && sqlite3rbu_step(pRbu)==SQLITE_OK; i++);
    96    120     nProgress = sqlite3rbu_progress(pRbu);
    97    121     rc = sqlite3rbu_close(pRbu, &zErrmsg);
    98    122   
    99    123     /* Let the user know what happened. */
   100    124     switch( rc ){
   101    125       case SQLITE_OK: