/ Check-in [4f9d9562]
Login

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

Overview
Comment:Rename the '.repair' shell command to '.clone'.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 4f9d95624ae4e123f83c835b5940f64d4a47be0d
User & Date: mistachkin 2014-02-06 01:15:29
Context
2014-02-06
02:46
Add additional error messages and a progress spinner to the ".clone" command. check-in: dd0db3f0 user: drh tags: trunk
01:15
Rename the '.repair' shell command to '.clone'. check-in: 4f9d9562 user: mistachkin tags: trunk
00:49
Add the ".repair" command to the command-line shell. check-in: d1dfadea user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Show Whitespace Changes Patch

Changes to src/shell.c.

  1577   1577     ".open ?FILENAME?       Close existing database and reopen FILENAME\n"
  1578   1578     ".output FILENAME       Send output to FILENAME\n"
  1579   1579     ".output stdout         Send output to the screen\n"
  1580   1580     ".print STRING...       Print literal STRING\n"
  1581   1581     ".prompt MAIN CONTINUE  Replace the standard prompts\n"
  1582   1582     ".quit                  Exit this program\n"
  1583   1583     ".read FILENAME         Execute SQL in FILENAME\n"
  1584         -  ".repair NEWDB          Recover data into NEWDB from a corrupt database\n"
         1584  +  ".clone NEWDB           Clone data into NEWDB from the existing database\n"
  1585   1585     ".restore ?DB? FILE     Restore content of DB (default \"main\") from FILE\n"
  1586   1586     ".schema ?TABLE?        Show the CREATE statements\n"
  1587   1587     "                         If TABLE specified, only show tables matching\n"
  1588   1588     "                         LIKE pattern TABLE.\n"
  1589   1589     ".separator STRING      Change separator used by output mode and .import\n"
  1590   1590     ".show                  Show the current values for various settings\n"
  1591   1591     ".stats ON|OFF          Turn stats on or off\n"
................................................................................
  1896   1896     if( p->z ) p->z[p->n] = 0;
  1897   1897     return p->z;
  1898   1898   }
  1899   1899   
  1900   1900   /*
  1901   1901   ** Try to transfer data for table zTable
  1902   1902   */
  1903         -static void tryToRepairData(
         1903  +static void tryToCloneData(
  1904   1904     struct callback_data *p,
  1905   1905     sqlite3 *newDb,
  1906   1906     const char *zTable
  1907   1907   ){
  1908   1908     sqlite3_stmt *pQuery = 0; 
  1909   1909     sqlite3_stmt *pInsert = 0;
  1910   1910     char *zQuery = 0;
................................................................................
  1998   1998   }
  1999   1999   
  2000   2000   
  2001   2001   /*
  2002   2002   ** Try to transfer all rows of the schema that match zWhere.  For
  2003   2003   ** each row, invoke xForEach() on the object defined by that row.
  2004   2004   */
  2005         -static void tryToRepairSchema(
         2005  +static void tryToCloneSchema(
  2006   2006     struct callback_data *p,
  2007   2007     sqlite3 *newDb,
  2008   2008     const char *zWhere,
  2009   2009     void (*xForEach)(struct callback_data*,sqlite3*,const char*)
  2010   2010   ){
  2011   2011     sqlite3_stmt *pQuery = 0;
  2012   2012     char *zQuery = 0;
................................................................................
  2062   2062   }
  2063   2063   
  2064   2064   /*
  2065   2065   ** Open a new database file named "zNewDb".  Try to recover as much information
  2066   2066   ** as possible out of the main database (which might be corrupt) and write it
  2067   2067   ** into zNewDb.
  2068   2068   */
  2069         -static void tryToRepair(struct callback_data *p, const char *zNewDb){
         2069  +static void tryToClone(struct callback_data *p, const char *zNewDb){
  2070   2070     int rc;
  2071   2071     sqlite3 *newDb = 0;
  2072   2072     if( access(zNewDb,0)==0 ){
  2073   2073       fprintf(stderr, "File \"%s\" already exists.\n", zNewDb);
  2074   2074       return;
  2075   2075     }
  2076   2076     rc = sqlite3_open(zNewDb, &newDb);
  2077   2077     if( rc ){
  2078   2078       fprintf(stderr, "Cannot create output database: %s\n",
  2079   2079               sqlite3_errmsg(newDb));
  2080   2080     }else{
  2081   2081       sqlite3_exec(newDb, "BEGIN EXCLUSIVE;", 0, 0, 0);
  2082         -    tryToRepairSchema(p, newDb, "type='table'", tryToRepairData);
  2083         -    tryToRepairSchema(p, newDb, "type!='table'", 0);
         2082  +    tryToCloneSchema(p, newDb, "type='table'", tryToCloneData);
         2083  +    tryToCloneSchema(p, newDb, "type!='table'", 0);
  2084   2084       sqlite3_exec(newDb, "COMMIT;", 0, 0, 0);
  2085   2085     }
  2086   2086     sqlite3_close(newDb);
  2087   2087   }
  2088   2088   
  2089   2089   /*
  2090   2090   ** If an input line begins with "." then invoke this routine to
................................................................................
  2188   2188   
  2189   2189     /* The undocumented ".breakpoint" command causes a call to the no-op
  2190   2190     ** routine named test_breakpoint().
  2191   2191     */
  2192   2192     if( c=='b' && n>=3 && strncmp(azArg[0], "breakpoint", n)==0 ){
  2193   2193       test_breakpoint();
  2194   2194     }else
         2195  +
         2196  +  if( c=='c' && strncmp(azArg[0], "clone", n)==0 && nArg>1 && nArg<3 ){
         2197  +    tryToClone(p, azArg[1]);
         2198  +  }else
  2195   2199   
  2196   2200     if( c=='d' && n>1 && strncmp(azArg[0], "databases", n)==0 && nArg==1 ){
  2197   2201       struct callback_data data;
  2198   2202       char *zErrMsg = 0;
  2199   2203       open_db(p, 0);
  2200   2204       memcpy(&data, p, sizeof(data));
  2201   2205       data.showHeader = 1;
................................................................................
  2681   2685         rc = 1;
  2682   2686       }else{
  2683   2687         rc = process_input(p, alt);
  2684   2688         fclose(alt);
  2685   2689       }
  2686   2690     }else
  2687   2691   
  2688         -  if( c=='r' && strncmp(azArg[0], "repair", n)==0 && nArg>1 && nArg<3 ){
  2689         -    tryToRepair(p, azArg[1]);
  2690         -  }else
  2691         -
  2692   2692     if( c=='r' && n>=3 && strncmp(azArg[0], "restore", n)==0 && nArg>1 && nArg<4){
  2693   2693       const char *zSrcFile;
  2694   2694       const char *zDb;
  2695   2695       sqlite3 *pSrc;
  2696   2696       sqlite3_backup *pBackup;
  2697   2697       int nTimeout = 0;
  2698   2698