mirror of
https://github.com/mdbtools/mdbtools.git
synced 2025-09-19 10:37:54 +08:00
Preliminary row handling
This commit is contained in:
@@ -79,6 +79,7 @@ typedef struct {
|
|||||||
} MdbCatalogEntry;
|
} MdbCatalogEntry;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
MdbCatalogEntry *entry;
|
||||||
char name[MDB_MAX_OBJ_NAME+1];
|
char name[MDB_MAX_OBJ_NAME+1];
|
||||||
int num_cols;
|
int num_cols;
|
||||||
int num_rows;
|
int num_rows;
|
||||||
@@ -104,11 +105,20 @@ extern void mdb_free_handle(MdbHandle *mdb);
|
|||||||
extern void mdb_free_catalog(MdbHandle *mdb);
|
extern void mdb_free_catalog(MdbHandle *mdb);
|
||||||
extern MdbTableDef *mdb_alloc_tabledef(MdbCatalogEntry *entry);
|
extern MdbTableDef *mdb_alloc_tabledef(MdbCatalogEntry *entry);
|
||||||
|
|
||||||
|
/* file.c */
|
||||||
extern size_t mdb_read_pg(MdbHandle *mdb, unsigned long pg);
|
extern size_t mdb_read_pg(MdbHandle *mdb, unsigned long pg);
|
||||||
extern int mdb_get_int16(MdbHandle *mdb, int offset);
|
extern int mdb_get_int16(MdbHandle *mdb, int offset);
|
||||||
extern long mdb_get_int32(MdbHandle *mdb, int offset);
|
extern long mdb_get_int32(MdbHandle *mdb, int offset);
|
||||||
extern MdbHandle *mdb_open(char *filename);
|
extern MdbHandle *mdb_open(char *filename);
|
||||||
|
|
||||||
|
/* catalog.c */
|
||||||
extern void mdb_catalog_dump(MdbHandle *mdb, int obj_type);
|
extern void mdb_catalog_dump(MdbHandle *mdb, int obj_type);
|
||||||
extern int mdb_catalog_rows(MdbHandle *mdb);
|
extern int mdb_catalog_rows(MdbHandle *mdb);
|
||||||
extern MdbCatalogEntry *mdb_get_catalog_entry(MdbHandle *mdb, int rowid, MdbCatalogEntry *entry);
|
extern MdbCatalogEntry *mdb_get_catalog_entry(MdbHandle *mdb, int rowid, MdbCatalogEntry *entry);
|
||||||
|
|
||||||
|
/* table.c */
|
||||||
|
extern MdbTableDef *mdb_read_table(MdbCatalogEntry *entry);
|
||||||
|
|
||||||
|
/* data.c */
|
||||||
|
extern void mdb_data_dump(MdbTableDef *table);
|
||||||
#endif /* _mdbtools_h_ */
|
#endif /* _mdbtools_h_ */
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
CC = gcc
|
CC = gcc
|
||||||
|
|
||||||
INC = -I ../include `glib-config --cflags`
|
INC = -I ../include `glib-config --cflags`
|
||||||
OBJS = catalog.o mem.o file.o kkd.o table.o
|
OBJS = catalog.o mem.o file.o kkd.o table.o data.o
|
||||||
|
|
||||||
all: libmdb
|
all: libmdb
|
||||||
|
|
||||||
|
44
src/libmdb/data.c
Normal file
44
src/libmdb/data.c
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
/* 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"
|
||||||
|
|
||||||
|
|
||||||
|
void mdb_data_dump(MdbTableDef *table)
|
||||||
|
{
|
||||||
|
MdbColumn col;
|
||||||
|
MdbHandle *mdb = table->entry->mdb;
|
||||||
|
int i, pg_num;
|
||||||
|
int rows;
|
||||||
|
int row_start, row_end;
|
||||||
|
|
||||||
|
for (pg_num=1;pg_num<=table->num_pgs;pg_num++) {
|
||||||
|
mdb_read_pg(mdb,table->first_data_pg + pg_num);
|
||||||
|
rows = mdb_get_int16(mdb,8);
|
||||||
|
fprintf(stdout,"Rows on page %d: %d\n", pg_num, rows);
|
||||||
|
row_end=2047;
|
||||||
|
for (i=0;i<rows;i++) {
|
||||||
|
row_start = mdb_get_int16(mdb,10+i*2);
|
||||||
|
fprintf(stdout,"Row %d bytes %d to %d\n", i, row_start, row_end);
|
||||||
|
|
||||||
|
fprintf(stdout,"#cols: %-3d #varcols %-3d\n", mdb->pg_buf[row_start], mdb->pg_buf[row_end-1]);
|
||||||
|
row_end = row_start-1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -48,6 +48,7 @@ MdbTableDef *table;
|
|||||||
|
|
||||||
table = (MdbTableDef *) malloc(sizeof(MdbTableDef));
|
table = (MdbTableDef *) malloc(sizeof(MdbTableDef));
|
||||||
memset(table, '\0', sizeof(MdbTableDef));
|
memset(table, '\0', sizeof(MdbTableDef));
|
||||||
|
table->entry=entry;
|
||||||
strcpy(table->name, entry->object_name);
|
strcpy(table->name, entry->object_name);
|
||||||
|
|
||||||
return table;
|
return table;
|
||||||
|
@@ -77,8 +77,9 @@ int len, i;
|
|||||||
return table;
|
return table;
|
||||||
}
|
}
|
||||||
|
|
||||||
GArray *mdb_read_columns(MdbHandle *mdb, MdbTableDef *table)
|
GArray *mdb_read_columns(MdbTableDef *table)
|
||||||
{
|
{
|
||||||
|
MdbHandle *mdb = table->entry->mdb;
|
||||||
MdbColumn col;
|
MdbColumn col;
|
||||||
GArray *columns;
|
GArray *columns;
|
||||||
int len, i;
|
int len, i;
|
||||||
@@ -127,13 +128,13 @@ int i;
|
|||||||
fprintf(stdout,"number of datapages = %d\n",table->num_pgs);
|
fprintf(stdout,"number of datapages = %d\n",table->num_pgs);
|
||||||
fprintf(stdout,"first data page = %d\n",table->first_data_pg);
|
fprintf(stdout,"first data page = %d\n",table->first_data_pg);
|
||||||
|
|
||||||
mdb_read_columns(mdb, table);
|
mdb_read_columns(table);
|
||||||
for (i=0;i<table->num_cols;i++) {
|
for (i=0;i<table->num_cols;i++) {
|
||||||
col = g_array_index(table->columns,MdbColumn,i);
|
col = g_array_index(table->columns,MdbColumn,i);
|
||||||
|
|
||||||
fprintf(stdout,"column %2d %s\n",i,col.name);
|
fprintf(stdout,"column %d Name: %-20s Type: %s(%d)\n",
|
||||||
fprintf(stdout,"column type %s\n",
|
i, col.name,
|
||||||
mdb_get_coltype_string(col.col_type));
|
mdb_get_coltype_string(col.col_type),
|
||||||
fprintf(stdout,"column size %d\n",col.col_size);
|
col.col_size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -3,10 +3,11 @@ CC = gcc
|
|||||||
|
|
||||||
INC = -I ../include `glib-config --cflags`
|
INC = -I ../include `glib-config --cflags`
|
||||||
LIBS = -L ../libmdb -lmdb `glib-config --libs`
|
LIBS = -L ../libmdb -lmdb `glib-config --libs`
|
||||||
PROGS = prcat prkkd prtable
|
PROGS = prcat prkkd prtable prdata
|
||||||
PRCATOBJS = prcat.o
|
PRCATOBJS = prcat.o
|
||||||
PRKKDOBJS = prkkd.o
|
PRKKDOBJS = prkkd.o
|
||||||
PRTABLEOBJS = prtable.o
|
PRTABLEOBJS = prtable.o
|
||||||
|
PRDATAOBJS = prdata.o
|
||||||
|
|
||||||
all: $(PROGS)
|
all: $(PROGS)
|
||||||
|
|
||||||
@@ -19,6 +20,9 @@ prkkd: $(PRKKDOBJS)
|
|||||||
prtable: $(PRTABLEOBJS)
|
prtable: $(PRTABLEOBJS)
|
||||||
$(CC) -g -o $@ $(PRTABLEOBJS) $(LIBS)
|
$(CC) -g -o $@ $(PRTABLEOBJS) $(LIBS)
|
||||||
|
|
||||||
|
prdata: $(PRDATAOBJS)
|
||||||
|
$(CC) -g -o $@ $(PRDATAOBJS) $(LIBS)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f core *.o $(PROGS)
|
rm -f core *.o $(PROGS)
|
||||||
|
|
||||||
|
54
src/util/prdata.c
Normal file
54
src/util/prdata.c
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
/* 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;
|
||||||
|
unsigned char buf[2048];
|
||||||
|
MdbHandle *mdb;
|
||||||
|
MdbCatalogEntry entry;
|
||||||
|
MdbTableDef *table;
|
||||||
|
GList *l;
|
||||||
|
|
||||||
|
|
||||||
|
if (argc<2) {
|
||||||
|
fprintf(stderr,"Usage: prtable <file> <table>\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
mdb = mdb_open(argv[1]);
|
||||||
|
|
||||||
|
mdb_read_catalog(mdb, MDB_TABLE);
|
||||||
|
|
||||||
|
for (i=0;i<mdb->num_catalog;i++) {
|
||||||
|
entry = g_array_index(mdb->catalog,MdbCatalogEntry,i);
|
||||||
|
if (!strcmp(entry.object_name,argv[2])) {
|
||||||
|
table = mdb_read_table(&entry);
|
||||||
|
mdb_read_columns(table);
|
||||||
|
mdb_data_dump(table);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mdb_free_handle(mdb);
|
||||||
|
}
|
||||||
|
|
Reference in New Issue
Block a user