port of gmdb to gnome2. lots o other stuff

This commit is contained in:
brianb
2002-12-27 15:09:02 +00:00
parent fcd99f54e0
commit 16735470a7
56 changed files with 6630 additions and 241 deletions

View File

@@ -1,6 +1,6 @@
bin_PROGRAMS = mdb-export mdb-array mdb-schema mdb-tables mdb-parsecsv mdb-header mdb-sql mdb-ver prtable prcat prdata prkkd prdump
LIBS = `glib-config --libs` $(READLINE_LIBS) @LEXLIB@
INCLUDES = -I$(top_srcdir)/include `glib-config --cflags`
bin_PROGRAMS = mdb-export mdb-array mdb-schema mdb-tables mdb-parsecsv mdb-header mdb-sql mdb-ver prtable prcat prdata prkkd prdump prole updrow
LIBS = $(GLIB_LIBS) $(READLINE_LIBS) @LEXLIB@
INCLUDES = -I$(top_srcdir)/include $(GLIB_CFLAGS)
LDADD = ../libmdb/libmdb.la
if SQL
mdb_sql_LDADD = ../libmdb/libmdb.la ../sql/libmdbsql.la

View File

@@ -28,19 +28,34 @@ MdbCatalogEntry *entry;
MdbTableDef *table;
MdbColumn *col;
char *the_relation;
char *tabname = NULL;
int opt;
if (argc < 2) {
fprintf (stderr, "Usage: %s <file> [<backend>]\n",argv[0]);
exit (1);
}
if (argc < 2) {
fprintf (stderr, "Usage: %s [-S] [-1 | -d<delimiter>] <file>\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[1]);
if (argc>2) {
if (!mdb_set_default_backend(mdb, argv[2])) {
mdb = mdb_open (argv[optind]);
if (argc - optind >2) {
if (!mdb_set_default_backend(mdb, argv[optind + 1])) {
fprintf(stderr,"Invalid backend type\n");
mdb_exit();
exit(1);
@@ -62,7 +77,8 @@ char *the_relation;
if (entry->object_type == MDB_TABLE)
{
/* skip the MSys tables */
if (strncmp (entry->object_name, "MSys", 4))
if ((tabname && !strcmp(entry->object_name,tabname)) ||
(!tabname && strncmp (entry->object_name, "MSys", 4)))
{
/* make sure it's a table (may be redundant) */

View File

@@ -29,15 +29,18 @@ MdbTableDef *table;
MdbColumn *col;
char *delimiter = NULL;
int line_break=0;
int skip_sys=1;
int opt;
if (argc < 2) {
fprintf (stderr, "Usage: %s [-1 | -d<delimiter>] <file>\n",argv[0]);
fprintf (stderr, "Usage: %s [-S] [-1 | -d<delimiter>] <file>\n",argv[0]);
exit (1);
}
while ((opt=getopt(argc, argv, "1d:"))!=-1) {
while ((opt=getopt(argc, argv, "S1d:"))!=-1) {
switch (opt) {
case 'S':
skip_sys = 0;
case '1':
line_break = 1;
break;
@@ -65,7 +68,7 @@ int opt;
/* if it's a table */
if (entry->object_type == MDB_TABLE) {
/* skip the MSys tables */
if (strncmp (entry->object_name, "MSys", 4)) {
if (!skip_sys || strncmp (entry->object_name, "MSys", 4)) {
if (line_break)
fprintf (stdout, "%s\n", entry->object_name);
else if (delimiter)

111
src/util/prole.c Normal file
View File

@@ -0,0 +1,111 @@
/* 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 dump_ole(MdbTableDef *table, char *colname, char *sargname);
main(int argc, char **argv)
{
int rows;
int i;
unsigned char buf[2048];
MdbHandle *mdb;
MdbCatalogEntry *entry;
MdbTableDef *table;
GList *l;
char *dot, *colname, *tabname;
char *sargname = NULL;
if (argc<2) {
fprintf(stderr,"Usage: %s <file> <table.column> [sargs]\n",argv[0]);
exit(1);
}
mdb_init();
mdb = mdb_open(argv[1]);
dot = strchr(argv[2],'.');
if (argc>3) sargname = argv[3];
if (!dot) {
fprintf(stderr,"Usage: %s <file> <table.column> [sarg]\n",argv[0]);
exit(1);
}
tabname = argv[2];
*dot='\0';
colname = ++dot;
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,tabname)) {
table = mdb_read_table(entry);
mdb_read_columns(table);
dump_ole(table, colname, sargname);
}
}
mdb_free_handle(mdb);
mdb_exit();
exit(0);
}
void dump_ole(MdbTableDef *table, char *colname, char *sargname)
{
int i, found = 0;
char ole_data[12000];
int len;
MdbColumn *col;
MdbSarg sarg;
char *sargcol, *sargop, *sargval;
for (i=0;i<=table->num_cols;i++) {
col=g_ptr_array_index(table->columns,i);
printf("%d colname %s\n", i, col->name);
if (col && !strcmp(col->name,colname)) {
found = i+1;
}
}
printf("column %d\n",found);
mdb_bind_column(table, found, ole_data);
mdb_bind_len(table, found, &len);
if (sargname) {
sargcol = strtok(sargname," ");
sargop = strtok(NULL," ");
sargval = strtok(NULL," ");
printf("col %s op %s val %s\n",sargcol,sargop,sargval);
sarg.op = MDB_EQUAL; /* only support = for now, sorry */
strcpy(sarg.value.s, sargval);
mdb_add_sarg_by_name(table, sargcol, &sarg);
}
mdb_rewind_table(table);
while (mdb_fetch_row(table)) {
buffer_dump(ole_data, 0, len);
printf("---\n");
}
}

115
src/util/updrow.c Normal file
View File

@@ -0,0 +1,115 @@
/* 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;
char *dot, *colname, *tabname;
char *colop, *colval;
char *sargname = NULL;
char *updstr = NULL;
unsigned char data[255];
int len;
if (argc<4) {
fprintf(stderr,"Usage: %s <file> <table> <sargs> <updstr>\n",argv[0]);
exit(1);
}
mdb_init();
mdb = mdb_open(argv[1]);
tabname = argv[2];
sargname = argv[3];
updstr = strdup(argv[4]);
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,tabname)) {
table = mdb_read_table(entry);
mdb_read_columns(table);
mdb_read_indices(table);
printf("updstr %s\n",updstr);
colname = strtok(updstr,"=");
colval = strtok(NULL,"=");
bind_column(table, colname, data, &len);
read_to_row(table, sargname);
mdb_update_row(table);
printf("current value of %s is %s, changing to %s\n", colname, data, colval);
}
}
mdb_free_handle(mdb);
mdb_exit();
exit(0);
}
int bind_column(MdbTableDef *table, char *colname, unsigned char *data, int *len)
{
int i, found = 0;
MdbColumn *col;
for (i=0;i<table->num_cols;i++) {
col=g_ptr_array_index(table->columns,i);
printf("%d colname %s\n", i, col->name);
if (col && !strcmp(col->name,colname)) {
found = i+1;
}
}
printf("column %d\n",found);
mdb_bind_column(table, found, data);
mdb_bind_len(table, found, len);
}
void read_to_row(MdbTableDef *table, char *sargname)
{
MdbSarg sarg;
char *sargcol, *sargop, *sargval;
if (sargname) {
sargcol = strtok(sargname," ");
sargop = strtok(NULL," ");
sargval = strtok(NULL," ");
printf("col %s op %s val %s\n",sargcol,sargop,sargval);
sarg.op = MDB_EQUAL; /* only support = for now, sorry */
sarg.value.i = atoi(sargval);
mdb_add_sarg_by_name(table, sargcol, &sarg);
}
mdb_rewind_table(table);
while (mdb_fetch_row(table)) {
printf("row found at page %d row %d\n",
table->cur_phys_pg, table->cur_row);
return;
}
}