From c6da2f1845597b84df521409afa762df37b252d5 Mon Sep 17 00:00:00 2001 From: brianb Date: Sun, 5 Jan 2003 15:00:23 +0000 Subject: [PATCH] mdb-check and prindex programs --- doc/Makefile.am | 51 +++++++++++++++++++++ src/util/.cvsignore | 2 + src/util/mdb-check.c | 102 ++++++++++++++++++++++++++++++++++++++++++ src/util/prindex.c | 104 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 259 insertions(+) create mode 100644 doc/Makefile.am create mode 100644 src/util/mdb-check.c create mode 100644 src/util/prindex.c diff --git a/doc/Makefile.am b/doc/Makefile.am new file mode 100644 index 0000000..2a33eda --- /dev/null +++ b/doc/Makefile.am @@ -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)/$< > $@ + + diff --git a/src/util/.cvsignore b/src/util/.cvsignore index f705f3b..b5b8984 100644 --- a/src/util/.cvsignore +++ b/src/util/.cvsignore @@ -10,10 +10,12 @@ mdb-schema mdb-sql mdb-tables mdb-ver +mdb-check prcat prdata prdump prkkd prtable prole +prindex updrow diff --git a/src/util/mdb-check.c b/src/util/mdb-check.c new file mode 100644 index 0000000..beb8e7b --- /dev/null +++ b/src/util/mdb-check.c @@ -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 [-T ]\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); +} + diff --git a/src/util/prindex.c b/src/util/prindex.c new file mode 100644 index 0000000..088f533 --- /dev/null +++ b/src/util/prindex.c @@ -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
\n",argv[0]); + exit(1); + } + + mdb_init(); + mdb = mdb_open(argv[1]); + + mdb_read_catalog(mdb, MDB_TABLE); + + for (i=0;inum_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;jnum_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); + } + } + } +}