mdb-check and prindex programs

This commit is contained in:
brianb
2003-01-05 15:00:23 +00:00
parent 320f03c401
commit c6da2f1845
4 changed files with 259 additions and 0 deletions

51
doc/Makefile.am Normal file
View File

@@ -0,0 +1,51 @@
# Converting DocBook to HTML (several small files)
# http://www.freebsd.org/tutorials/docproj-primer/x3132.html#AEN3140
# version: $Id: Makefile.am,v 1.1 2003/01/05 15:00:23 brianb Exp $
SHELL = /bin/sh
TXT2MAN = $(srcdir)/txt2man
RELEASE = 0.5
PRODUCT = MDBTools
man_MANS = mdb-tables.1 mdb-ver.1 mdb-export.1 mdb-schema.1 mdb-sql.1
EXTRA_DIST = mdb-tables.txt mdb-ver.txt mdb-export.txt mdb-schema.txt mdb-sql.txt
#html:: userguide.tgz
#dist: userguide.tgz man
dist: man
# To make the userguide, export DOCBOOK_DSL TO point to docbook.dsl.
#userguide.tgz: $(srcdir)/userguide.sgml
# if test -n "${DOCBOOK_DSL}"; then \
# rm -rf html && \
# mkdir html && \
# cd html && pwd && \
# openjade -d ${DOCBOOK_DSL} -t sgml ../$(srcdir)/userguide.sgml; \
# test -f book1.htm && \
# ln -s book1.htm index.html && cd .. && \
# if ! [ -L userguide ]; then \
# ln -s html userguide; \
# fi; \
# tar zcf userguide.tgz userguide/* \
# ; fi
man: mdb-tables.1 mdb-ver.1 mdb-export.1 mdb-sql.1
mdb-tables.1: mdb-tables.txt
- $(TXT2MAN) -P $(PRODUCT) -t $(PRODUCT) -r $(RELEASE) $(srcdir)/$< > $@
mdb-ver.1: mdb-ver.txt
- $(TXT2MAN) -P $(PRODUCT) -t $(PRODUCT) -r $(RELEASE) $(srcdir)/$< > $@
mdb-export.1: mdb-export.txt
- $(TXT2MAN) -P $(PRODUCT) -t $(PRODUCT) -r $(RELEASE) $(srcdir)/$< > $@
mdb-schema.1: mdb-schema.txt
- $(TXT2MAN) -P $(PRODUCT) -t $(PRODUCT) -r $(RELEASE) $(srcdir)/$< > $@
mdb-sql.1: mdb-sql.txt
- $(TXT2MAN) -P $(PRODUCT) -t $(PRODUCT) -r $(RELEASE) $(srcdir)/$< > $@

View File

@@ -10,10 +10,12 @@ mdb-schema
mdb-sql
mdb-tables
mdb-ver
mdb-check
prcat
prdata
prdump
prkkd
prtable
prole
prindex
updrow

102
src/util/mdb-check.c Normal file
View File

@@ -0,0 +1,102 @@
/* MDB Tools - A library for reading MS Access database file
* Copyright (C) 2000 Brian Bruns
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* this utility dumps the schema for an existing database */
#include "mdbtools.h"
int
dbcc_page_usage(MdbTableDef *table)
{
}
int
dbcc_idx_page_usage(MdbTableDef *table)
{
}
int
dbcc_lost_pages(MdbTableDef *table)
{
}
main (int argc, char **argv)
{
int i, j, k;
MdbHandle *mdb;
MdbCatalogEntry *entry;
MdbTableDef *table;
MdbColumn *col;
char *tabname = NULL;
int opt;
if (argc < 2) {
fprintf (stderr, "Usage: %s <file> [-T <table>]\n",argv[0]);
exit (1);
}
while ((opt=getopt(argc, argv, "T:"))!=-1) {
switch (opt) {
case 'T':
tabname = (char *) malloc(strlen(optarg)+1);
strcpy(tabname, optarg);
break;
}
}
mdb_init();
/* open the database */
mdb = mdb_open (argv[optind]);
/* read the catalog */
mdb_read_catalog (mdb, MDB_TABLE);
/* loop over each entry in the catalog */
for (i=0; i < mdb->num_catalog; i++)
{
entry = g_ptr_array_index (mdb->catalog, i);
/* if it's a table */
if (entry->object_type == MDB_TABLE) {
/* skip the MSys tables */
if ((tabname && !strcmp(entry->object_name,tabname)) ||
(!tabname )) {
// && strncmp (entry->object_name, "MSys", 4))) {
table = mdb_read_table(entry);
/* get the columns */
mdb_read_columns(table);
fprintf(stdout,"Check 1: Checking data page usage map\n");
ret = dbcc_page_usage(table);
fprintf(stdout,"Check 1: %s\n", ret ? "Failed" : "Passed");
fprintf(stdout,"Check 2: Checking index page usage map\n");
fprintf(stdout,"Check 3: Checking for lost pages\n");
ret = dbcc_lost_pages(table);
//check_ret(table, ret);
}
}
mdb_free_handle (mdb);
mdb_exit();
exit(0);
}

104
src/util/prindex.c Normal file
View File

@@ -0,0 +1,104 @@
/* MDB Tools - A library for reading MS Access database file
* Copyright (C) 2000 Brian Bruns
*
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include "mdbtools.h"
main(int argc, char **argv)
{
int rows;
int i, j;
unsigned char buf[2048];
MdbHandle *mdb;
MdbCatalogEntry *entry;
MdbTableDef *table;
MdbIndex *idx;
GList *l;
int found = 0;
if (argc<4) {
fprintf(stderr,"Usage: %s <file> <table> <index>\n",argv[0]);
exit(1);
}
mdb_init();
mdb = mdb_open(argv[1]);
mdb_read_catalog(mdb, MDB_TABLE);
for (i=0;i<mdb->num_catalog;i++) {
entry = g_ptr_array_index(mdb->catalog,i);
if (entry->object_type == MDB_TABLE &&
!strcmp(entry->object_name,argv[2])) {
table = mdb_read_table(entry);
mdb_read_columns(table);
mdb_read_indices(table);
for (j=0;j<table->num_idxs;j++) {
idx = g_ptr_array_index (table->indices, j);
if (!strcmp(idx->name, argv[3])) {
walk_index(mdb, idx);
}
}
//mdb_table_dump(entry);
found++;
}
}
if (!found) {
fprintf(stderr,"No table named %s found.\n", argv[2]);
}
mdb_free_handle(mdb);
mdb_exit();
exit(0);
}
void
walk_index(MdbHandle *mdb, MdbIndex *idx)
{
int i, j, start, len;
unsigned char byte;
guint32 pg;
int row;
printf("name %s\n", idx->name);
printf("root page %ld\n", idx->first_pg);
mdb_read_pg(mdb, idx->first_pg);
start = 0xf8; /* start byte of the index entries */
len = -1;
for (i=0x16;i<0xf8;i++) {
byte = mdb->pg_buf[i];
//printf("%02x ",byte);
for (j=0;j<8;j++) {
len++;
if ((1 << j) & byte) {
// printf("start = %04x len = %d\n", start, len);
buffer_dump(mdb->pg_buf, start, start+len-1);
row = mdb->pg_buf[start+len-1];
pg = mdb_get_int24_msb(mdb, start+len-4);
printf("row = %d pg = %lu\n", row, pg);
start += len;
len = 0;
// printf("\nbit %d set\n", j);
}
}
}
}