mirror of
https://github.com/mdbtools/mdbtools.git
synced 2025-04-05 20:31:00 +08:00
added (trivial) mdb-count utility
This commit is contained in:
parent
d6f5745d94
commit
b92f4cc882
2
AUTHORS
2
AUTHORS
@ -40,3 +40,5 @@ Tim Retout <tim@retout.co.uk>
|
|||||||
Nirgal Vourgère <jmb_deb@nirgal.com>
|
Nirgal Vourgère <jmb_deb@nirgal.com>
|
||||||
postgres fixes and adds, bug fixes
|
postgres fixes and adds, bug fixes
|
||||||
|
|
||||||
|
@kodonnell
|
||||||
|
added (trivial) mdb-count utility
|
||||||
|
2
README
2
README
@ -12,6 +12,8 @@ pieces are:
|
|||||||
mdb-export -- export table to CSV format.
|
mdb-export -- export table to CSV format.
|
||||||
mdb-tables -- a simple dump of table names to be used with shell
|
mdb-tables -- a simple dump of table names to be used with shell
|
||||||
scripts
|
scripts
|
||||||
|
mdb-count -- a simple count of number of rows in a table, to be
|
||||||
|
used in shell scripts and ETL pipelines
|
||||||
mdb-header -- generates a C header to be used in exporting mdb
|
mdb-header -- generates a C header to be used in exporting mdb
|
||||||
data to a C prog.
|
data to a C prog.
|
||||||
mdb-parsecsv -- generates a C program given a CSV file made with
|
mdb-parsecsv -- generates a C program given a CSV file made with
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
SUBDIRS = bash-completion
|
SUBDIRS = bash-completion
|
||||||
bin_PROGRAMS = mdb-export mdb-array mdb-schema mdb-tables mdb-parsecsv mdb-header mdb-sql mdb-ver mdb-prop
|
bin_PROGRAMS = mdb-export mdb-array mdb-schema mdb-tables mdb-parsecsv mdb-header mdb-sql mdb-ver mdb-prop mdb-count
|
||||||
noinst_PROGRAMS = mdb-import prtable prcat prdata prkkd prdump prole updrow prindex
|
noinst_PROGRAMS = mdb-import prtable prcat prdata prkkd prdump prole updrow prindex
|
||||||
LIBS = $(GLIB_LIBS) @LIBS@ @LEXLIB@
|
LIBS = $(GLIB_LIBS) @LIBS@ @LEXLIB@
|
||||||
DEFS = @DEFS@ -DLOCALEDIR=\"$(localedir)\"
|
DEFS = @DEFS@ -DLOCALEDIR=\"$(localedir)\"
|
||||||
|
55
src/util/mdb-count.c
Normal file
55
src/util/mdb-count.c
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
/* 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"
|
||||||
|
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
|
||||||
|
unsigned int i;
|
||||||
|
MdbHandle *mdb;
|
||||||
|
MdbCatalogEntry *entry;
|
||||||
|
MdbTableDef *table;
|
||||||
|
int found = 0;
|
||||||
|
|
||||||
|
if (argc < 3) {
|
||||||
|
fprintf(stderr, "Usage: %s <file> <table>\n", argv[0]);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// open db and try to read table:
|
||||||
|
mdb = mdb_open(argv[1], MDB_NOFLAGS);
|
||||||
|
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, argv[2])) {
|
||||||
|
table = mdb_read_table(entry);
|
||||||
|
fprintf(stdout, "%d\n", table->num_rows);
|
||||||
|
found = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check was found:
|
||||||
|
if (!found) {
|
||||||
|
fprintf(stderr, "No table named %s found.\n", argv[2]);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
mdb_close(mdb);
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user