Files
mdbtools/src/util/mdb-prop.c

106 lines
2.4 KiB
C
Raw Normal View History

2003-05-02 22:20:44 +00:00
/* MDB Tools - A library for reading MS Access database file
2011-02-16 18:58:02 -05:00
* Copyright (C) 2000-2011 Brian Bruns and others
2003-05-02 22:20:44 +00:00
*
2011-08-28 19:53:29 -04:00
* 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.
2003-05-02 22:20:44 +00:00
*
2011-08-28 19:53:29 -04:00
* This program is distributed in the hope that it will be useful,
2003-05-02 22:20:44 +00:00
* but WITHOUT ANY WARRANTY; without even the implied warranty of
2011-08-28 19:53:29 -04:00
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
2003-05-02 22:20:44 +00:00
*
2011-08-28 19:53:29 -04:00
* 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.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
2003-05-02 22:20:44 +00:00
*/
#include "mdbtools.h"
2005-10-17 11:26:51 +00:00
void dump_kkd(MdbHandle *mdb, void *kkd, size_t len);
2003-05-02 22:20:44 +00:00
int
main(int argc, char **argv)
{
2005-03-16 12:50:21 +00:00
MdbHandle *mdb;
2003-05-02 22:20:44 +00:00
MdbTableDef *table;
gchar name[256];
gchar *propColName;
2005-10-17 11:26:51 +00:00
void *buf;
2005-03-16 12:50:21 +00:00
int col_num;
int found = 0;
2003-05-02 22:20:44 +00:00
if (argc < 3) {
fprintf(stderr,"Usage: %s <file> <object name> [<prop col>]\n",
2005-10-17 11:26:51 +00:00
argv[0]);
2005-03-16 12:50:21 +00:00
return 1;
2003-05-02 22:20:44 +00:00
}
if (argc < 4)
propColName = "LvProp";
else
propColName = argv[3];
2003-05-02 22:20:44 +00:00
mdb_init();
2005-10-17 11:26:51 +00:00
mdb = mdb_open(argv[1], MDB_NOFLAGS);
if (!mdb) {
2005-03-16 12:50:21 +00:00
mdb_exit();
return 1;
2003-05-02 22:20:44 +00:00
}
2005-10-17 11:26:51 +00:00
2005-03-16 12:50:21 +00:00
table = mdb_read_table_by_name(mdb, "MSysObjects", MDB_ANY);
2005-10-17 11:26:51 +00:00
if (!table) {
mdb_close(mdb);
mdb_exit();
return 1;
}
2003-05-02 22:20:44 +00:00
mdb_read_columns(table);
mdb_rewind_table(table);
mdb_bind_column_by_name(table, "Name", name, NULL);
2005-10-17 11:26:51 +00:00
buf = g_malloc(MDB_BIND_SIZE);
col_num = mdb_bind_column_by_name(table, propColName, buf, NULL);
2005-10-17 11:26:51 +00:00
if (col_num < 1) {
g_free(buf);
mdb_free_tabledef(table);
mdb_close(mdb);
mdb_exit();
2011-08-28 19:53:29 -04:00
printf("Column %s not found in MSysObjects!\n", argv[3]);
2005-10-17 11:26:51 +00:00
return 1;
}
2003-05-02 22:20:44 +00:00
while(mdb_fetch_row(table)) {
if (!strcmp(name, argv[2])) {
2005-03-16 12:50:21 +00:00
found = 1;
break;
}
}
if (found) {
2011-02-16 18:58:02 -05:00
MdbColumn *col = g_ptr_array_index(table->columns, col_num-1);
2011-02-16 18:57:40 -05:00
size_t size;
void *kkd = mdb_ole_read_full(mdb, col, &size);
dump_kkd(mdb, kkd, size);
free(kkd);
2003-05-02 22:20:44 +00:00
}
2005-10-17 11:26:51 +00:00
g_free(buf);
2004-06-24 04:22:40 +00:00
mdb_free_tabledef(table);
mdb_close(mdb);
2003-05-02 22:20:44 +00:00
mdb_exit();
2005-03-16 12:50:21 +00:00
return 0;
2003-05-02 22:20:44 +00:00
}
2005-10-17 11:26:51 +00:00
void dump_kkd(MdbHandle *mdb, void *kkd, size_t len)
2003-05-02 22:20:44 +00:00
{
2011-08-28 19:42:34 -04:00
GArray *aprops = mdb_kkd_to_props(mdb, kkd, len);
2011-02-16 18:58:02 -05:00
int i;
2011-08-28 19:42:34 -04:00
if (!aprops)
return;
2011-02-16 18:58:02 -05:00
for (i=0; i<aprops->len; ++i) {
MdbProperties *props = g_array_index(aprops, MdbProperties*, i);
mdb_dump_props(props, stdout, 1);
2003-05-02 22:20:44 +00:00
}
}