/ Check-in [87d76047d6]
Login

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

Overview
Comment:Improve the ".recover" command in the shell tool so that it is not confused by auto-vacuum databases. And so that it can recover tables for which one or more of the column names are SQL keywords.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 87d76047d6a3df31bc9b7c0cffa7b758236c124f87263a520850b019cbbc4c6e
User & Date: dan 2019-07-24 08:15:09
Context
2019-07-24
19:20
Improve the ".recover" command's handling of corrupt database schemas. check-in: becaaa4d29 user: dan tags: trunk
08:15
Improve the ".recover" command in the shell tool so that it is not confused by auto-vacuum databases. And so that it can recover tables for which one or more of the column names are SQL keywords. check-in: 87d76047d6 user: dan tags: trunk
2019-07-23
13:26
Avoid redefining types u32 and u16 when fossildelta.c is compiled as part of the amalgamation. check-in: d8e88248e3 user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/shell.c.in.

  6393   6393         if( bIntkey ){
  6394   6394           pTab->azlCol[0] = shellMPrintf(&rc, "%Q", zPk);
  6395   6395         }else{
  6396   6396           pTab->azlCol[0] = shellMPrintf(&rc, "");
  6397   6397         }
  6398   6398         i = 1;
  6399   6399         shellPreparePrintf(dbtmp, &rc, &pStmt, 
  6400         -          "SELECT %Q || group_concat(name, ', ') "
         6400  +          "SELECT %Q || group_concat(quote(name), ', ') "
  6401   6401             "  FILTER (WHERE cid!=%d) OVER (ORDER BY %s cid) "
  6402   6402             "FROM pragma_table_info(%Q)", 
  6403   6403             bIntkey ? ", " : "", pTab->iPk, 
  6404   6404             bIntkey ? "" : "(CASE WHEN pk=0 THEN 1000000 ELSE pk END), ",
  6405   6405             zName
  6406   6406         );
  6407   6407         while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pStmt) ){
................................................................................
  6614   6614         "    UNION ALL"
  6615   6615         "  SELECT data, n-1, shell_int32(data, 2+n) "
  6616   6616         "      FROM freelist WHERE n>=0"
  6617   6617         ")"
  6618   6618         "REPLACE INTO recovery.freelist SELECT freepgno FROM freelist;"
  6619   6619       );
  6620   6620     }
         6621  +
         6622  +  /* If this is an auto-vacuum database, add all pointer-map pages to
         6623  +  ** the freelist table. Do this regardless of whether or not 
         6624  +  ** --freelist-corrupt was specified.  */
         6625  +  shellExec(pState->db, &rc, 
         6626  +    "WITH ptrmap(pgno) AS ("
         6627  +    "  SELECT 2 WHERE shell_int32("
         6628  +    "    (SELECT data FROM sqlite_dbpage WHERE pgno=1), 13"
         6629  +    "  )"
         6630  +    "    UNION ALL "
         6631  +    "  SELECT pgno+1+(SELECT page_size FROM pragma_page_size)/5 AS pp "
         6632  +    "  FROM ptrmap WHERE pp<=(SELECT page_count FROM pragma_page_count)"
         6633  +    ")"
         6634  +    "REPLACE INTO recovery.freelist SELECT pgno FROM ptrmap"
         6635  +  );
  6621   6636   
  6622   6637     shellExec(pState->db, &rc, 
  6623   6638       "CREATE TABLE recovery.dbptr("
  6624   6639       "      pgno, child, PRIMARY KEY(child, pgno)"
  6625   6640       ") WITHOUT ROWID;"
  6626   6641       "INSERT OR IGNORE INTO recovery.dbptr(pgno, child) "
  6627   6642       "    SELECT * FROM sqlite_dbptr"