new mdb-array.c and changes to data.c (Karl)

database password stuff from (Carl)
multiple backend support (Carl and Brian)
This commit is contained in:
brianb
2000-04-02 17:08:30 +00:00
parent 418d57bc0c
commit c12b9ec987
20 changed files with 352 additions and 43 deletions

View File

@@ -20,7 +20,7 @@ LIBS =
INSTALL= @INSTALL@
INC = -I ../include `glib-config --cflags`
LIBS = -L ../libmdb -lmdb `glib-config --libs`
PROGS = prcat prkkd prtable prdata prdump mdb-schema mdb-export mdb-tables mdb-header mdb-parsecsv
PROGS = prcat prkkd prtable prdata prdump mdb-schema mdb-export mdb-tables mdb-header mdb-parsecsv mdb-array
PRCATOBJS = prcat.o
PRKKDOBJS = prkkd.o
PRTABLEOBJS = prtable.o
@@ -31,6 +31,7 @@ EXPORTOBJS = mdb-export.o
HEADEROBJS = header.o
TABLEOBJS = tables.o
CSVOBJS = parsecsv.o
ARROBJS = mdb-array.o
all: $(PROGS)
@@ -64,6 +65,9 @@ mdb-header: $(HEADEROBJS)
mdb-parsecsv: $(CSVOBJS)
$(CC) -g -o $@ $(CSVOBJS) $(LIBS)
mdb-array: $(ARROBJS)
$(CC) -g -o $@ $(ARROBJS) $(LIBS)
clean:
rm -f core *.o $(PROGS)

View File

@@ -20,7 +20,7 @@ LIBS = @LIBS@
INSTALL= @INSTALL@
INC = -I ../include `glib-config --cflags`
LIBS = -L ../libmdb -lmdb `glib-config --libs`
PROGS = prcat prkkd prtable prdata prdump mdb-schema mdb-export mdb-tables mdb-header mdb-parsecsv
PROGS = prcat prkkd prtable prdata prdump mdb-schema mdb-export mdb-tables mdb-header mdb-parsecsv mdb-array
PRCATOBJS = prcat.o
PRKKDOBJS = prkkd.o
PRTABLEOBJS = prtable.o
@@ -31,6 +31,7 @@ EXPORTOBJS = mdb-export.o
HEADEROBJS = header.o
TABLEOBJS = tables.o
CSVOBJS = parsecsv.o
ARROBJS = mdb-array.o
all: $(PROGS)
@@ -64,6 +65,9 @@ mdb-header: $(HEADEROBJS)
mdb-parsecsv: $(CSVOBJS)
$(CC) -g -o $@ $(CSVOBJS) $(LIBS)
mdb-array: $(ARROBJS)
$(CC) -g -o $@ $(ARROBJS) $(LIBS)
clean:
rm -f core *.o $(PROGS)

View File

@@ -45,10 +45,13 @@ FILE *cfile;
exit (1);
}
mdb_init();
/* open the database */
mdb = mdb_open (argv[1]);
if (!mdb) {
mdb_exit();
exit(1);
}
@@ -147,5 +150,6 @@ FILE *cfile;
fclose (cfile);
mdb_free_handle (mdb);
mdb_exit();
}

131
src/util/mdb-array.c Normal file
View File

@@ -0,0 +1,131 @@
/* 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.
*/
/* this is inherited from mdb-export.c, modified to make arrays similar to
those generated by parsecsv.c */
#include "mdbtools.h"
main (int argc, char **argv)
{
int rows;
int i, j;
unsigned char buf [2048];
MdbHandle *mdb;
MdbCatalogEntry entry;
MdbTableDef *table;
MdbColumn *col;
/* doesn't handle tables > 256 columns. Can that happen? */
char *bound_values [256];
char delimiter [] = ", ";
char quote_text = 1;
int count;
int started;
if (argc < 2)
{
fprintf (stderr, "Usage: %s <file> <table>\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_array_index (mdb->catalog, MdbCatalogEntry, i);
if (!strcmp (entry.object_name, argv [2]))
{
table = mdb_read_table (&entry);
mdb_read_columns (table);
mdb_rewind_table (table);
for (j = 0; j < table->num_cols; j++)
{
bound_values [j] = (char *) malloc (256);
bound_values [j] [0] = '\0';
mdb_bind_column (table, j + 1, bound_values [j]);
}
fprintf (stdout, "/******************************************************************/\n");
fprintf (stdout, "/* THIS IS AN AUTOMATICALLY GENERATED FILE. DO NOT EDIT IT!!!!!! */\n");
fprintf (stdout, "/******************************************************************/\n");
fprintf (stdout, "\n");
fprintf (stdout, "#include <stdio.h>\n");
fprintf (stdout, "#include \"types.h\"\n");
fprintf (stdout, "#include \"dump.h\"\n");
fprintf (stdout, "\n");
fprintf (stdout, "const %s %s_array [] = {\n", argv [2], argv [2]);
count = 0;
started = 0;
while (mdb_fetch_row (table))
{
if (started != 0)
{
fprintf (stdout, ",\n");
}
started = 1;
fprintf (stdout, "{\t\t\t\t/* %6d */\n\t", count);
for (j = 0; j < table->num_cols; j++)
{
fprintf (stdout, "\t");
col = g_ptr_array_index (table->columns, j);
if (quote_text &&
(col->col_type == MDB_TEXT ||
col->col_type == MDB_MEMO))
{
fprintf (stdout, "\"%s\"", bound_values [j]);
}
else
{
fprintf (stdout, "%s", bound_values [j]);
}
if (j != table->num_cols - 1)
{
fprintf (stdout, "%s\n", delimiter);
}
else
{
fprintf (stdout, "\n");
}
}
fprintf (stdout, "}");
count++;
}
for (j = 0; j < table->num_cols; j++)
{
free (bound_values [j]);
}
}
}
mdb_free_handle (mdb);
mdb_exit();
fprintf (stdout, "\n};\n");
fprintf (stdout, "\nconst int %s_array_length = %d;\n",
argv [2],
count);
}

View File

@@ -40,6 +40,8 @@ char quote_text = 1;
exit(1);
}
mdb_init();
mdb = mdb_open(argv[1]);
mdb_read_catalog(mdb, MDB_TABLE);
@@ -87,5 +89,6 @@ char quote_text = 1;
}
mdb_free_handle(mdb);
mdb_exit();
}

View File

@@ -35,10 +35,13 @@ MdbHandle *mdb;
exit(1);
}
mdb_init();
mdb = mdb_open(argv[1]);
mdb_dump_catalog(mdb,(argc > 2) ? atoi(argv[2]) : MDB_TABLE);
mdb_free_handle(mdb);
mdb_exit();
}

View File

@@ -36,6 +36,7 @@ GList *l;
exit(1);
}
mdb_init();
mdb = mdb_open(argv[1]);
mdb_read_catalog(mdb, MDB_TABLE);
@@ -50,5 +51,6 @@ GList *l;
}
mdb_free_handle(mdb);
mdb_exit();
}

View File

@@ -37,6 +37,7 @@ int page, start, stop;
exit(1);
}
mdb_init();
mdb = mdb_open(argv[1]);
mdb_read_catalog(mdb, MDB_TABLE);
@@ -51,5 +52,6 @@ int page, start, stop;
}
mdb_free_handle(mdb);
mdb_exit();
}

View File

@@ -32,6 +32,7 @@ MdbCatalogEntry entry;
exit(1);
}
mdb_init();
mdb = mdb_open(argv[1]);
mdb_read_pg(mdb, MDB_CATALOG_PG);
@@ -46,5 +47,6 @@ MdbCatalogEntry entry;
}
mdb_free_handle(mdb);
mdb_exit();
}

View File

@@ -30,11 +30,12 @@ MdbCatalogEntry entry;
GList *l;
if (argc<2) {
if (argc<3) {
fprintf(stderr,"Usage: %s <file> <table>\n",argv[0]);
exit(1);
}
mdb_init();
mdb = mdb_open(argv[1]);
mdb_read_catalog(mdb, MDB_TABLE);
@@ -47,5 +48,6 @@ GList *l;
}
mdb_free_handle(mdb);
mdb_exit();
}

View File

@@ -29,13 +29,22 @@ MdbTableDef *table;
MdbColumn *col;
if (argc < 2) {
fprintf (stderr, "Usage: %s <file>\n",argv[0]);
fprintf (stderr, "Usage: %s <file> [<backend>]\n",argv[0]);
exit (1);
}
mdb_init();
/* open the database */
mdb = mdb_open (argv[1]);
if (argc>2) {
if (!mdb_set_default_backend(mdb, argv[2])) {
fprintf(stderr,"Invalid backend type\n");
mdb_exit();
exit(1);
}
}
/* read the catalog */
@@ -78,7 +87,7 @@ MdbColumn *col;
col = g_ptr_array_index (table->columns, k);
fprintf (stdout, "\t%s\t\t\t%s", col->name,
mdb_get_coltype_string (col->col_type));
mdb_get_coltype_string (mdb->default_backend, col->col_type));
if (col->col_size != 0)
fprintf (stdout, " (%d)", col->col_size);
@@ -98,5 +107,6 @@ MdbColumn *col;
}
mdb_free_handle (mdb);
mdb_exit();
}

View File

@@ -33,6 +33,9 @@ MdbColumn *col;
exit (1);
}
/* initialize the library */
mdb_init();
/* open the database */
mdb = mdb_open (argv[1]);
@@ -68,5 +71,6 @@ MdbColumn *col;
fprintf (stdout, "\n");
mdb_free_handle (mdb);
mdb_exit();
}