SQLite

Check-in [d14263a719]
Login

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

Overview
Comment:Enhance the pgidx of the showdb utility so that it provides better information even if the sqlite_master table is corrupt.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: d14263a719101d9c70054f2fc37e7788f73aab28
User & Date: drh 2013-02-19 18:45:11.538
Context
2013-02-19
20:25
Fix the showdb utility so that it displays the correct secondary usage of a page when reporting on an error of a page being used more than once. (check-in: 4507f0b3d4 user: drh tags: trunk)
18:45
Enhance the pgidx of the showdb utility so that it provides better information even if the sqlite_master table is corrupt. (check-in: d14263a719 user: drh tags: trunk)
18:34
Do not rollback the schema if a parsing error occurs while parsing the schema and writable_schema is set. (check-in: 680d3ab56b user: drh tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to tool/showdb.c.
615
616
617
618
619
620
621
622
623
624
625
626

627
628
629
630
631
632
633
  }
}

/*
** Try to figure out how every page in the database file is being used.
*/
static void page_usage_report(const char *zDbName){
  int i;
  int rc;
  sqlite3 *db;
  sqlite3_stmt *pStmt;
  unsigned char *a;


  /* Avoid the pathological case */
  if( mxPage<1 ){
    printf("empty database\n");
    return;
  }








|




>







615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
  }
}

/*
** Try to figure out how every page in the database file is being used.
*/
static void page_usage_report(const char *zDbName){
  int i, j;
  int rc;
  sqlite3 *db;
  sqlite3_stmt *pStmt;
  unsigned char *a;
  char zQuery[200];

  /* Avoid the pathological case */
  if( mxPage<1 ){
    printf("empty database\n");
    return;
  }

646
647
648
649
650
651
652


653
654

655
656
657
658
659
660
661
662
663
664


665
666
667
668
669
670
671
  memset(zPageUse, 0, sizeof(zPageUse[0])*(mxPage+1));

  /* Discover the usage of each page */
  a = getContent(0, 100);
  page_usage_freelist(decodeInt32(a+32));
  free(a);
  page_usage_btree(1, 0, 0, "sqlite_master");


  rc = sqlite3_prepare_v2(db,
           "SELECT type, name, rootpage FROM SQLITE_MASTER WHERE rootpage",

           -1, &pStmt, 0);
  if( rc==SQLITE_OK ){
    while( sqlite3_step(pStmt)==SQLITE_ROW ){
      int pgno = sqlite3_column_int(pStmt, 2);
      page_usage_btree(pgno, 0, 0, sqlite3_column_text(pStmt, 1));
    }
  }else{
    printf("ERROR: cannot query database: %s\n", sqlite3_errmsg(db));
  }
  sqlite3_finalize(pStmt);


  sqlite3_close(db);

  /* Print the report and free memory used */
  for(i=1; i<=mxPage; i++){
    printf("%5d: %s\n", i, zPageUse[i] ? zPageUse[i] : "???");
    sqlite3_free(zPageUse[i]);
  }







>
>
|
|
>
|
|
|
|
|
|
|
|
|
|
>
>







647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
  memset(zPageUse, 0, sizeof(zPageUse[0])*(mxPage+1));

  /* Discover the usage of each page */
  a = getContent(0, 100);
  page_usage_freelist(decodeInt32(a+32));
  free(a);
  page_usage_btree(1, 0, 0, "sqlite_master");
  sqlite3_exec(db, "PRAGMA writable_schema=ON", 0, 0, 0);
  for(j=0; j<2; j++){
    sqlite3_snprintf(sizeof(zQuery), zQuery,
             "SELECT type, name, rootpage FROM SQLITE_MASTER WHERE rootpage"
             " ORDER BY rowid %s", j?"DESC":"");
    rc = sqlite3_prepare_v2(db, zQuery, -1, &pStmt, 0);
    if( rc==SQLITE_OK ){
      while( sqlite3_step(pStmt)==SQLITE_ROW ){
        int pgno = sqlite3_column_int(pStmt, 2);
        page_usage_btree(pgno, 0, 0, sqlite3_column_text(pStmt, 1));
      }
    }else{
      printf("ERROR: cannot query database: %s\n", sqlite3_errmsg(db));
    }
    rc = sqlite3_finalize(pStmt);
    if( rc==SQLITE_OK ) break;
  }
  sqlite3_close(db);

  /* Print the report and free memory used */
  for(i=1; i<=mxPage; i++){
    printf("%5d: %s\n", i, zPageUse[i] ? zPageUse[i] : "???");
    sqlite3_free(zPageUse[i]);
  }