-
Notifications
You must be signed in to change notification settings - Fork 0
/
prole.c
87 lines (71 loc) · 2.19 KB
/
prole.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/* MDB Tools - A library for reading MS Access database file
* Copyright (C) 2000 Brian Bruns
*
* 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.
*
* This program 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 General Public License for more details.
*
* 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.
*/
#include "mdbtools.h"
void dump_ole(MdbTableDef *table, char *colname, char *sargname);
int
main(int argc, char **argv)
{
MdbHandle *mdb;
MdbTableDef *table;
char *dot, *colname, *tabname;
char *sargname = NULL;
if (argc<2) {
fprintf(stderr,"Usage: %s <file> <table.column> [sargs]\n",argv[0]);
exit(1);
}
mdb = mdb_open(argv[1], MDB_NOFLAGS);
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;
table = mdb_read_table_by_name(mdb, tabname, MDB_TABLE);
if (table) {
mdb_read_columns(table);
dump_ole(table, colname, sargname);
mdb_free_tabledef(table);
}
mdb_close(mdb);
return 0;
}
void dump_ole(MdbTableDef *table, char *colname, char *sargname)
{
char ole_data[200000];
int len;
MdbSarg sarg;
char *sargcol, *sargop, *sargval;
mdb_bind_column_by_name(table, colname, ole_data, &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)) {
mdb_buffer_dump(ole_data, 0, len);
printf("---\n");
}
}