CMD_FIRST,
CMD_NEXT,
CMD_SYSTEM,
+ CMD_CHECK,
CMD_QUIT,
CMD_HELP
};
{"1", CMD_FIRST},
{"next", CMD_NEXT},
{"n", CMD_NEXT},
+ {"check", CMD_CHECK},
{"quit", CMD_QUIT},
{"q", CMD_QUIT},
{"!", CMD_SYSTEM},
" delete key : delete a record by key\n"
" list : print the database hash table and freelist\n"
" free : print the database freelist\n"
-" ! command : execute system command\n"
+" check : check the integrity of an opened database\n"
+" ! command : execute system command\n"
" 1 | first : print the first record\n"
" n | next : print the next record\n"
" q | quit : terminate\n"
print_rec(the_tdb, *pkey, dbuf, NULL);
}
+static int test_fn(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf, void *state)
+{
+ return 0;
+}
+
+static void check_db(TDB_CONTEXT *the_tdb)
+{
+ int tdbcount=-1;
+ if (the_tdb) {
+ tdbcount = tdb_traverse(the_tdb, test_fn, NULL);
+ } else {
+ printf("Error: No database opened!\n");
+ }
+
+ if (tdbcount<0) {
+ printf("Integrity check for the opened database failed.\n");
+ } else {
+ printf("Database integrity is OK and has %d records.\n", tdbcount);
+ }
+}
+
static int do_command(void)
{
COMMAND_TABLE *ctp = cmd_table;
if (bIterate)
next_record(tdb, &iterate_kbuf);
return 0;
+ case CMD_CHECK:
+ check_db(tdb);
+ return 0;
case CMD_HELP:
help();
return 0;