change catalogentry to GPtrArray, documentation fixes, add ifdef wrapper to mdbsql.h

This commit is contained in:
brianb 2002-03-27 13:00:00 +00:00
parent 16ecc4fe4d
commit 9b8285d937
24 changed files with 111 additions and 112 deletions

View File

@ -6,6 +6,7 @@ Basic Installation
This will build some useful utilities: This will build some useful utilities:
mdb-ver -- prints the version (JET 3 or 4) of an mdb file
mdb-dump -- simple hex dump utility that I've been using to look at mdb files mdb-dump -- simple hex dump utility that I've been using to look at mdb files
mdb-schema -- prints DDL for the specified table mdb-schema -- prints DDL for the specified table
mdb-export -- export table to CSV format mdb-export -- export table to CSV format

6
README
View File

@ -1,8 +1,6 @@
This is mdbtools version 0.3 This is mdbtools version 0.4
This software is beta so don't expect too much unless you know C and This software is still beta so don't expect too much.
probably a little something about databases and reverse engineering file
formats, you're welcome to try it out but don't expect miracles.
For the rest of you, read the HACKING file for a description of where the code For the rest of you, read the HACKING file for a description of where the code
stands and what has been gleened of the file format. stands and what has been gleened of the file format.

10
TODO
View File

@ -2,17 +2,11 @@ Things to Do
------------ ------------
. Complete the list of datatypes . Complete the list of datatypes
. Figure out how to properly determine fixed or variable length columns
. Figure out what happens for varchar columns starting at > 256
. Modify mdb-schema utility support different backend databases
. Modify mdb-export to handle different delimiters/options
. Get automake working
. Check out text file unixODBC driver to see if it can be adapted to use
libmdb (it already has a SQL parser).
. Straighten out which functions in libmdb are meant to be used and which . Straighten out which functions in libmdb are meant to be used and which
ones should be static. ones should be static.
. Create an API reference for libmdb (maybe some man pages). . Create an API reference for libmdb (maybe some man pages).
. Sargs need to support all datatypes . Sargs need to support all datatypes
. Need a way to express logical relationships between sargs (tree) . Need a way to express logical relationships between sargs (tree)
. Add support for index scanning when using sargs . Add support for index scanning when using sargs
. Convert code to use MSysObjects table for reading catalog. . Use allocation maps to read tables, should be more efficient
. Figure out why we get unresolved symbols when ODBC driver load by DM

View File

@ -3,6 +3,9 @@
#include <glib.h> #include <glib.h>
#include <mdbtools.h> #include <mdbtools.h>
#ifndef _mdbsql_h_
#define _mdbsql_h_
typedef struct { typedef struct {
MdbHandle *mdb; MdbHandle *mdb;
int all_columns; int all_columns;
@ -55,3 +58,5 @@ void mdb_sql_exit(MdbSQL *sql);
void mdb_sql_reset(MdbSQL *sql); void mdb_sql_reset(MdbSQL *sql);
void mdb_sql_listtables(MdbSQL *sql); void mdb_sql_listtables(MdbSQL *sql);
void mdb_sql_select(MdbSQL *sql); void mdb_sql_select(MdbSQL *sql);
#endif

View File

@ -103,7 +103,7 @@ typedef struct {
unsigned char pg_buf[MDB_PGSIZE]; unsigned char pg_buf[MDB_PGSIZE];
unsigned char alt_pg_buf[MDB_PGSIZE]; unsigned char alt_pg_buf[MDB_PGSIZE];
int num_catalog; int num_catalog;
GArray *catalog; GPtrArray *catalog;
int pg_size; int pg_size;
guint32 jet_version; guint32 jet_version;
guint32 db_key; guint32 db_key;

View File

@ -77,10 +77,10 @@ READLINE_LIBS = -lncurses -lreadline
SQL = SQL =
VERSION = 0.3 VERSION = 0.3
YACC = bison -y YACC = bison -y
#SUBDIRS = libmdb sql util extras SUBDIRS = libmdb sql util extras
SUBDIRS = libmdb util extras #SUBDIRS = libmdb util extras
#DEFDIR = $(prefix)
DEFDIR = $(prefix) DEFDIR = $(prefix)
#DEFDIR = $(prefix)
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
CONFIG_CLEAN_FILES = CONFIG_CLEAN_FILES =
DIST_COMMON = Makefile.am Makefile.in DIST_COMMON = Makefile.am Makefile.in

View File

@ -95,7 +95,7 @@ mdb_dump_OBJECTS = mdb-dump.o mdbsupport.o
mdb_dump_LDADD = $(LDADD) mdb_dump_LDADD = $(LDADD)
mdb_dump_DEPENDENCIES = ../libmdb/libmdb.la mdb_dump_DEPENDENCIES = ../libmdb/libmdb.la
mdb_dump_LDFLAGS = mdb_dump_LDFLAGS =
CFLAGS = -g -O2 CFLAGS = -g -O2 -DSQL
COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
CCLD = $(CC) CCLD = $(CC)

View File

@ -94,7 +94,7 @@ libmdb_la_LDFLAGS =
libmdb_la_LIBADD = libmdb_la_LIBADD =
libmdb_la_OBJECTS = catalog.lo mem.lo file.lo kkd.lo table.lo data.lo \ libmdb_la_OBJECTS = catalog.lo mem.lo file.lo kkd.lo table.lo data.lo \
dump.lo backend.lo money.lo sargs.lo index.lo like.lo dump.lo backend.lo money.lo sargs.lo index.lo like.lo
CFLAGS = -g -O2 CFLAGS = -g -O2 -DSQL
COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
CCLD = $(CC) CCLD = $(CC)

View File

@ -102,7 +102,7 @@ char *mdb_postgres_types[] =
char *bound_values[MDB_MAX_COLS]; char *bound_values[MDB_MAX_COLS];
char *relationships[4]; char *relationships[4];
MdbColumn *col; MdbColumn *col;
MdbCatalogEntry entry; MdbCatalogEntry *entry;
MdbTableDef *table; MdbTableDef *table;
int did_first; int did_first;
@ -168,11 +168,11 @@ static char text[255];
/* loop over each entry in the catalog */ /* loop over each entry in the catalog */
for (i=0; i < mdb->num_catalog; i++) { for (i=0; i < mdb->num_catalog; i++) {
entry = g_array_index (mdb->catalog, MdbCatalogEntry, i); entry = g_ptr_array_index (mdb->catalog, i);
if ((entry.object_type == MDB_TABLE) && if ((entry->object_type == MDB_TABLE) &&
(strncmp (entry.object_name, "MSysRelationships", 17) == 0)) (strncmp (entry->object_name, "MSysRelationships", 17) == 0))
{ {
table = mdb_read_table (&entry); table = mdb_read_table (entry);
if ( table->num_rows > 0 ) { if ( table->num_rows > 0 ) {
mdb_read_columns(table); mdb_read_columns(table);
mdb_rewind_table(table); mdb_rewind_table(table);

View File

@ -44,17 +44,16 @@ static char *type_name[] = {"Form",
/* new method */ /* new method */
#if 1 #if 1
GArray *mdb_read_catalog (MdbHandle *mdb, int objtype) GPtrArray *mdb_read_catalog (MdbHandle *mdb, int objtype)
{ {
int i, j, k; int i, j, k;
MdbCatalogEntry entry, msysobj; MdbCatalogEntry entry, msysobj, *data;
MdbTableDef *table; MdbTableDef *table;
MdbColumn *col; MdbColumn *col;
char parentid[256]; char parentid[256];
char objname[256]; char objname[256];
char tobjtype[256]; char tobjtype[256];
int type; int type;
gpointer data;
mdb_free_catalog(mdb); mdb_free_catalog(mdb);
mdb_alloc_catalog(mdb); mdb_alloc_catalog(mdb);
@ -89,8 +88,8 @@ gpointer data;
entry.object_type = type; entry.object_type = type;
entry.table_pg = atol(parentid) & 0x00FFFFFF; entry.table_pg = atol(parentid) & 0x00FFFFFF;
mdb->num_catalog++; mdb->num_catalog++;
//data = g_memdup(&entry,sizeof(MdbCatalogEntry)); data = g_memdup(&entry,sizeof(MdbCatalogEntry));
mdb->catalog = g_array_append_val(mdb->catalog, entry); g_ptr_array_add(mdb->catalog, data);
} }
} }
//mdb_dump_catalog(mdb, MDB_TABLE); //mdb_dump_catalog(mdb, MDB_TABLE);
@ -217,18 +216,18 @@ int next_pg, next_pg_off;
void mdb_dump_catalog(MdbHandle *mdb, int obj_type) void mdb_dump_catalog(MdbHandle *mdb, int obj_type)
{ {
int rows, i; int rows, i;
MdbCatalogEntry entry; MdbCatalogEntry *entry;
mdb_read_catalog(mdb, obj_type); mdb_read_catalog(mdb, obj_type);
for (i=0;i<mdb->num_catalog;i++) { for (i=0;i<mdb->num_catalog;i++) {
entry = g_array_index(mdb->catalog,MdbCatalogEntry,i); entry = g_ptr_array_index(mdb->catalog,i);
if (obj_type==-1 || entry.object_type==obj_type) { if (obj_type==-1 || entry->object_type==obj_type) {
fprintf(stdout,"Type: %-10s Name: %-18s T pg: %04x KKD pg: %04x row: %2d\n", fprintf(stdout,"Type: %-10s Name: %-18s T pg: %04x KKD pg: %04x row: %2d\n",
mdb_get_objtype_string(entry.object_type), mdb_get_objtype_string(entry->object_type),
entry.object_name, entry->object_name,
entry.table_pg, entry->table_pg,
entry.kkd_pg, entry->kkd_pg,
entry.kkd_rowid); entry->kkd_rowid);
} }
} }
return; return;

View File

@ -52,13 +52,15 @@ void mdb_free_handle(MdbHandle *mdb)
} }
void mdb_alloc_catalog(MdbHandle *mdb) void mdb_alloc_catalog(MdbHandle *mdb)
{ {
mdb->catalog = g_array_new(FALSE,FALSE,sizeof(MdbCatalogEntry)); mdb->catalog = g_ptr_array_new();
} }
void mdb_free_catalog(MdbHandle *mdb) void mdb_free_catalog(MdbHandle *mdb)
{ {
GList *l; GList *l;
MdbCatalogEntry entry; MdbCatalogEntry entry;
//g_ptr_array_free(mdb->catalog, FALSE);
mdb->catalog = NULL;
} }
MdbTableDef *mdb_alloc_tabledef(MdbCatalogEntry *entry) MdbTableDef *mdb_alloc_tabledef(MdbCatalogEntry *entry)
{ {

View File

@ -116,7 +116,7 @@ unittest_OBJECTS = unittest.o
unittest_DEPENDENCIES = libmdbodbc.la ../libmdb/libmdb.la \ unittest_DEPENDENCIES = libmdbodbc.la ../libmdb/libmdb.la \
../sql/libmdbsql.la ../sql/libmdbsql.la
unittest_LDFLAGS = unittest_LDFLAGS =
CFLAGS = -g -O2 CFLAGS = -g -O2 -DSQL
COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
CCLD = $(CC) CCLD = $(CC)

View File

@ -1,7 +1,7 @@
# Generated automatically from Makefile.in by configure. # Generated automatically from Makefile.in by configure.
# Makefile.in generated automatically by automake 1.4 from Makefile.am # Makefile.in generated automatically by automake 1.4-p5 from Makefile.am
# Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc. # Copyright (C) 1994, 1995-8, 1999, 2001 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation # This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it, # gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved. # with or without modifications, as long as this notice is preserved.
@ -96,7 +96,7 @@ libmdbsql_la_LIBADD =
libmdbsql_la_OBJECTS = mdbsql.lo parser.lo lexer.lo libmdbsql_la_OBJECTS = mdbsql.lo parser.lo lexer.lo
LEX_OUTPUT_ROOT = lex.yy LEX_OUTPUT_ROOT = lex.yy
LEXLIB = -lfl LEXLIB = -lfl
CFLAGS = -g -O2 CFLAGS = -g -O2 -DSQL
COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
CCLD = $(CC) CCLD = $(CC)

View File

@ -1,6 +1,6 @@
# Makefile.in generated automatically by automake 1.4 from Makefile.am # Makefile.in generated automatically by automake 1.4-p5 from Makefile.am
# Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc. # Copyright (C) 1994, 1995-8, 1999, 2001 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation # This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it, # gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved. # with or without modifications, as long as this notice is preserved.

View File

@ -286,7 +286,7 @@ int vlen;
void mdb_sql_listtables(MdbSQL *sql) void mdb_sql_listtables(MdbSQL *sql)
{ {
int i; int i;
MdbCatalogEntry entry; MdbCatalogEntry *entry;
MdbHandle *mdb = sql->mdb; MdbHandle *mdb = sql->mdb;
if (!mdb) { if (!mdb) {
@ -304,11 +304,11 @@ MdbHandle *mdb = sql->mdb;
fprintf(stdout,"\n"); fprintf(stdout,"\n");
/* loop over each entry in the catalog */ /* loop over each entry in the catalog */
for (i=0; i < mdb->num_catalog; i++) { for (i=0; i < mdb->num_catalog; i++) {
entry = g_array_index (mdb->catalog, MdbCatalogEntry, i); entry = g_ptr_array_index (mdb->catalog, i);
/* if it's a table */ /* if it's a table */
if (entry.object_type == MDB_TABLE) { if (entry->object_type == MDB_TABLE) {
if (strncmp (entry.object_name, "MSys", 4)) { if (strncmp (entry->object_name, "MSys", 4)) {
print_value (entry.object_name,30,1); print_value (entry->object_name,30,1);
fprintf(stdout,"\n"); fprintf(stdout,"\n");
} }
} }
@ -320,7 +320,7 @@ void mdb_sql_describe_table(MdbSQL *sql)
{ {
MdbTableDef *table = NULL; MdbTableDef *table = NULL;
MdbSQLTable *sql_tab; MdbSQLTable *sql_tab;
MdbCatalogEntry entry; MdbCatalogEntry *entry;
MdbHandle *mdb = sql->mdb; MdbHandle *mdb = sql->mdb;
MdbColumn *col; MdbColumn *col;
int i; int i;
@ -336,10 +336,10 @@ char colsize[11];
mdb_read_catalog(mdb, MDB_TABLE); mdb_read_catalog(mdb, MDB_TABLE);
for (i=0;i<mdb->num_catalog;i++) { for (i=0;i<mdb->num_catalog;i++) {
entry = g_array_index(mdb->catalog,MdbCatalogEntry,i); entry = g_ptr_array_index(mdb->catalog,i);
if (entry.object_type == MDB_TABLE && if (entry->object_type == MDB_TABLE &&
!strcasecmp(entry.object_name,sql_tab->name)) { !strcasecmp(entry->object_name,sql_tab->name)) {
table = mdb_read_table(&entry); table = mdb_read_table(entry);
break; break;
} }
} }
@ -385,7 +385,7 @@ char colsize[11];
void mdb_sql_select(MdbSQL *sql) void mdb_sql_select(MdbSQL *sql)
{ {
int i,j; int i,j;
MdbCatalogEntry entry; MdbCatalogEntry *entry;
MdbHandle *mdb = sql->mdb; MdbHandle *mdb = sql->mdb;
MdbTableDef *table = NULL; MdbTableDef *table = NULL;
MdbSQLTable *sql_tab; MdbSQLTable *sql_tab;
@ -404,10 +404,10 @@ int found = 0;
mdb_read_catalog(mdb, MDB_TABLE); mdb_read_catalog(mdb, MDB_TABLE);
for (i=0;i<mdb->num_catalog;i++) { for (i=0;i<mdb->num_catalog;i++) {
entry = g_array_index(mdb->catalog,MdbCatalogEntry,i); entry = g_ptr_array_index(mdb->catalog,i);
if (entry.object_type == MDB_TABLE && if (entry->object_type == MDB_TABLE &&
!strcasecmp(entry.object_name,sql_tab->name)) { !strcasecmp(entry->object_name,sql_tab->name)) {
table = mdb_read_table(&entry); table = mdb_read_table(entry);
break; break;
} }
} }

View File

@ -82,7 +82,7 @@ bin_PROGRAMS = mdb-export mdb-array mdb-schema mdb-tables mdb-parsecsv mdb-heade
LIBS = `glib-config --libs` $(READLINE_LIBS) -lfl LIBS = `glib-config --libs` $(READLINE_LIBS) -lfl
INCLUDES = -I$(top_srcdir)/include `glib-config --cflags` INCLUDES = -I$(top_srcdir)/include `glib-config --cflags`
LDADD = ../libmdb/libmdb.la LDADD = ../libmdb/libmdb.la
#mdb_sql_LDADD = #../libmdb/libmdb.la ../sql/libmdbsql.la mdb_sql_LDADD = ../libmdb/libmdb.la ../sql/libmdbsql.la
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
CONFIG_CLEAN_FILES = CONFIG_CLEAN_FILES =
PROGRAMS = $(bin_PROGRAMS) PROGRAMS = $(bin_PROGRAMS)
@ -123,8 +123,8 @@ mdb_header_DEPENDENCIES = ../libmdb/libmdb.la
mdb_header_LDFLAGS = mdb_header_LDFLAGS =
mdb_sql_SOURCES = mdb-sql.c mdb_sql_SOURCES = mdb-sql.c
mdb_sql_OBJECTS = mdb-sql.o mdb_sql_OBJECTS = mdb-sql.o
#mdb_sql_DEPENDENCIES = ../libmdb/libmdb.la \ mdb_sql_DEPENDENCIES = ../libmdb/libmdb.la \
#../sql/libmdbsql.la ../sql/libmdbsql.la
mdb_sql_LDFLAGS = mdb_sql_LDFLAGS =
mdb_ver_SOURCES = mdb-ver.c mdb_ver_SOURCES = mdb-ver.c
mdb_ver_OBJECTS = mdb-ver.o mdb_ver_OBJECTS = mdb-ver.o
@ -156,7 +156,7 @@ prdump_OBJECTS = prdump.o
prdump_LDADD = $(LDADD) prdump_LDADD = $(LDADD)
prdump_DEPENDENCIES = ../libmdb/libmdb.la prdump_DEPENDENCIES = ../libmdb/libmdb.la
prdump_LDFLAGS = prdump_LDFLAGS =
CFLAGS = -g -O2 CFLAGS = -g -O2 -DSQL
COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
CCLD = $(CC) CCLD = $(CC)

View File

@ -28,7 +28,7 @@ main (int argc, char **argv)
int rows; int rows;
int i, j; int i, j;
MdbHandle *mdb; MdbHandle *mdb;
MdbCatalogEntry entry; MdbCatalogEntry *entry;
MdbTableDef *table; MdbTableDef *table;
MdbColumn *col; MdbColumn *col;
/* doesn't handle tables > 256 columns. Can that happen? */ /* doesn't handle tables > 256 columns. Can that happen? */
@ -51,11 +51,11 @@ int started;
for (i = 0; i < mdb->num_catalog; i++) for (i = 0; i < mdb->num_catalog; i++)
{ {
entry = g_array_index (mdb->catalog, MdbCatalogEntry, i); entry = g_ptr_array_index (mdb->catalog, i);
if (entry.object_type == MDB_TABLE && if (entry->object_type == MDB_TABLE &&
!strcmp (entry.object_name, argv [2])) !strcmp (entry->object_name, argv [2]))
{ {
table = mdb_read_table (&entry); table = mdb_read_table (entry);
mdb_read_columns (table); mdb_read_columns (table);
mdb_rewind_table (table); mdb_rewind_table (table);

View File

@ -26,7 +26,7 @@ int rows;
int i, j; int i, j;
unsigned char buf[2048]; unsigned char buf[2048];
MdbHandle *mdb; MdbHandle *mdb;
MdbCatalogEntry entry; MdbCatalogEntry *entry;
MdbTableDef *table; MdbTableDef *table;
MdbColumn *col; MdbColumn *col;
/* doesn't handle tables > 256 columns. Can that happen? */ /* doesn't handle tables > 256 columns. Can that happen? */
@ -75,10 +75,10 @@ int opt;
mdb_read_catalog(mdb, MDB_TABLE); mdb_read_catalog(mdb, MDB_TABLE);
for (i=0;i<mdb->num_catalog;i++) { for (i=0;i<mdb->num_catalog;i++) {
entry = g_array_index(mdb->catalog,MdbCatalogEntry,i); entry = g_ptr_array_index(mdb->catalog,i);
if (entry.object_type == MDB_TABLE && if (entry->object_type == MDB_TABLE &&
!strcmp(entry.object_name,argv[argc-1])) { !strcmp(entry->object_name,argv[argc-1])) {
table = mdb_read_table(&entry); table = mdb_read_table(entry);
mdb_read_columns(table); mdb_read_columns(table);
mdb_rewind_table(table); mdb_rewind_table(table);

View File

@ -33,7 +33,7 @@ main (int argc, char **argv)
{ {
int i, j, k; int i, j, k;
MdbHandle *mdb; MdbHandle *mdb;
MdbCatalogEntry entry; MdbCatalogEntry *entry;
MdbTableDef *table; MdbTableDef *table;
MdbColumn *col; MdbColumn *col;
FILE *typesfile; FILE *typesfile;
@ -74,30 +74,30 @@ FILE *cfile;
for (i=0; i < mdb->num_catalog; i++) for (i=0; i < mdb->num_catalog; i++)
{ {
entry = g_array_index (mdb->catalog, MdbCatalogEntry, i); entry = g_ptr_array_index (mdb->catalog, i);
/* if it's a table */ /* if it's a table */
if (entry.object_type == MDB_TABLE) if (entry->object_type == MDB_TABLE)
{ {
/* skip the MSys tables */ /* skip the MSys tables */
if (strncmp (entry.object_name, "MSys", 4)) if (strncmp (entry->object_name, "MSys", 4))
{ {
/* make sure it's a table (may be redundant) */ /* make sure it's a table (may be redundant) */
if (!strcmp (mdb_get_objtype_string (entry.object_type), "Table")) if (!strcmp (mdb_get_objtype_string (entry->object_type), "Table"))
{ {
fprintf (typesfile, "typedef struct _%s\n", entry.object_name); fprintf (typesfile, "typedef struct _%s\n", entry->object_name);
fprintf (typesfile, "{\n"); fprintf (typesfile, "{\n");
fprintf (headerfile, "void dump_%s (%s x);\n", fprintf (headerfile, "void dump_%s (%s x);\n",
entry.object_name, entry.object_name); entry->object_name, entry->object_name);
fprintf (cfile, "void dump_%s (%s x)\n{\n", fprintf (cfile, "void dump_%s (%s x)\n{\n",
entry.object_name, entry.object_name); entry->object_name, entry->object_name);
fprintf (cfile, "\tfprintf (stdout, \"**************** %s ****************\\n\");\n", entry.object_name); fprintf (cfile, "\tfprintf (stdout, \"**************** %s ****************\\n\");\n", entry->object_name);
table = mdb_read_table (&entry); table = mdb_read_table (entry);
/* get the columns */ /* get the columns */
mdb_read_columns (table); mdb_read_columns (table);
@ -138,7 +138,7 @@ FILE *cfile;
fprintf (cfile, ");\n"); fprintf (cfile, ");\n");
} }
fprintf (typesfile, "\n} %s ;\n", entry.object_name); fprintf (typesfile, "\n} %s ;\n", entry->object_name);
fprintf (typesfile, "\n"); fprintf (typesfile, "\n");
fprintf (cfile, "}\n\n"); fprintf (cfile, "}\n\n");
} }

View File

@ -24,7 +24,7 @@ main (int argc, char **argv)
{ {
int i, j, k; int i, j, k;
MdbHandle *mdb; MdbHandle *mdb;
MdbCatalogEntry entry; MdbCatalogEntry *entry;
MdbTableDef *table; MdbTableDef *table;
MdbColumn *col; MdbColumn *col;
char *the_relation; char *the_relation;
@ -55,28 +55,28 @@ char *the_relation;
for (i=0; i < mdb->num_catalog; i++) for (i=0; i < mdb->num_catalog; i++)
{ {
entry = g_array_index (mdb->catalog, MdbCatalogEntry, i); entry = g_ptr_array_index (mdb->catalog, i);
/* if it's a table */ /* if it's a table */
if (entry.object_type == MDB_TABLE) if (entry->object_type == MDB_TABLE)
{ {
/* skip the MSys tables */ /* skip the MSys tables */
if (strncmp (entry.object_name, "MSys", 4)) if (strncmp (entry->object_name, "MSys", 4))
{ {
/* make sure it's a table (may be redundant) */ /* make sure it's a table (may be redundant) */
if (!strcmp (mdb_get_objtype_string (entry.object_type), "Table")) if (!strcmp (mdb_get_objtype_string (entry->object_type), "Table"))
{ {
/* drop the table if it exists */ /* drop the table if it exists */
fprintf (stdout, "DROP TABLE %s;\n", entry.object_name); fprintf (stdout, "DROP TABLE %s;\n", entry->object_name);
/* create the table */ /* create the table */
fprintf (stdout, "CREATE TABLE %s\n", entry.object_name); fprintf (stdout, "CREATE TABLE %s\n", entry->object_name);
fprintf (stdout, " (\n"); fprintf (stdout, " (\n");
table = mdb_read_table (&entry); table = mdb_read_table (entry);
/* get the columns */ /* get the columns */
mdb_read_columns (table); mdb_read_columns (table);

View File

@ -24,7 +24,7 @@ main (int argc, char **argv)
{ {
int i, j, k; int i, j, k;
MdbHandle *mdb; MdbHandle *mdb;
MdbCatalogEntry entry; MdbCatalogEntry *entry;
MdbTableDef *table; MdbTableDef *table;
MdbColumn *col; MdbColumn *col;
@ -48,22 +48,22 @@ MdbColumn *col;
for (i=0; i < mdb->num_catalog; i++) for (i=0; i < mdb->num_catalog; i++)
{ {
entry = g_array_index (mdb->catalog, MdbCatalogEntry, i); entry = g_ptr_array_index (mdb->catalog, i);
/* if it's a table */ /* if it's a table */
if (entry.object_type == MDB_TABLE) if (entry->object_type == MDB_TABLE)
{ {
/* skip the MSys tables */ /* skip the MSys tables */
if (strncmp (entry.object_name, "MSys", 4)) if (strncmp (entry->object_name, "MSys", 4))
{ {
/* make sure it's a table (may be redundant) */ /* make sure it's a table (may be redundant) */
if (!strcmp (mdb_get_objtype_string (entry.object_type), "Table")) if (!strcmp (mdb_get_objtype_string (entry->object_type), "Table"))
{ {
/* drop the table if it exists */ /* drop the table if it exists */
fprintf (stdout, "%s ", entry.object_name); fprintf (stdout, "%s ", entry->object_name);
} }
} }
} }

View File

@ -26,7 +26,7 @@ int rows;
int i; int i;
unsigned char buf[2048]; unsigned char buf[2048];
MdbHandle *mdb; MdbHandle *mdb;
MdbCatalogEntry entry; MdbCatalogEntry *entry;
MdbTableDef *table; MdbTableDef *table;
GList *l; GList *l;
@ -42,10 +42,10 @@ GList *l;
mdb_read_catalog(mdb, MDB_TABLE); mdb_read_catalog(mdb, MDB_TABLE);
for (i=0;i<mdb->num_catalog;i++) { for (i=0;i<mdb->num_catalog;i++) {
entry = g_array_index(mdb->catalog,MdbCatalogEntry,i); entry = g_ptr_array_index(mdb->catalog,i);
if (entry.object_type == MDB_TABLE && if (entry->object_type == MDB_TABLE &&
!strcmp(entry.object_name,argv[2])) { !strcmp(entry->object_name,argv[2])) {
table = mdb_read_table(&entry); table = mdb_read_table(entry);
mdb_read_columns(table); mdb_read_columns(table);
mdb_data_dump(table); mdb_data_dump(table);
} }

View File

@ -26,7 +26,7 @@ int rows;
int i; int i;
unsigned char buf[2048]; unsigned char buf[2048];
MdbHandle *mdb; MdbHandle *mdb;
MdbCatalogEntry entry; MdbCatalogEntry *entry;
GList *l; GList *l;
@ -41,10 +41,10 @@ GList *l;
mdb_read_catalog(mdb, MDB_TABLE); mdb_read_catalog(mdb, MDB_TABLE);
for (i=0;i<mdb->num_catalog;i++) { for (i=0;i<mdb->num_catalog;i++) {
entry = g_array_index(mdb->catalog,MdbCatalogEntry,i); entry = g_ptr_array_index(mdb->catalog,i);
if (entry.object_type == MDB_TABLE && if (entry->object_type == MDB_TABLE &&
!strcmp(entry.object_name,argv[2])) { !strcmp(entry->object_name,argv[2])) {
mdb_table_dump(&entry); mdb_table_dump(entry);
} }
} }

View File

@ -32,7 +32,7 @@ int rows;
int i; int i;
unsigned char buf[2048]; unsigned char buf[2048];
MdbHandle *mdb; MdbHandle *mdb;
MdbCatalogEntry entry; MdbCatalogEntry *entry;
MdbTableDef *table; MdbTableDef *table;
mdb_init(); mdb_init();
@ -44,10 +44,10 @@ MdbTableDef *table;
mdb_read_catalog(mdb, MDB_TABLE); mdb_read_catalog(mdb, MDB_TABLE);
for (i=0;i<mdb->num_catalog;i++) { for (i=0;i<mdb->num_catalog;i++) {
entry = g_array_index(mdb->catalog,MdbCatalogEntry,i); entry = g_ptr_array_index(mdb->catalog,i);
if (entry.object_type == MDB_TABLE && if (entry->object_type == MDB_TABLE &&
!strcmp(entry.object_name,TABLE_NAME)) { !strcmp(entry->object_name,TABLE_NAME)) {
table = mdb_read_table(&entry); table = mdb_read_table(entry);
print_table(table); print_table(table);
} }
} }