2007-11-29 14:29:22 +00:00
|
|
|
/* -*- mode: C; c-basic-offset: 3 -*- */
|
2008-01-24 15:10:32 +00:00
|
|
|
#ident "Copyright (c) 2007, 2008 Tokutek Inc. All rights reserved."
|
2007-11-29 14:29:22 +00:00
|
|
|
|
2007-07-13 19:37:47 +00:00
|
|
|
#include <assert.h>
|
|
|
|
#include <stdio.h>
|
2007-10-11 18:01:43 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <getopt.h>
|
|
|
|
#include <db.h>
|
|
|
|
#include "tokudb_common.h"
|
2007-07-13 19:37:47 +00:00
|
|
|
|
2007-10-11 18:01:43 +00:00
|
|
|
typedef struct {
|
|
|
|
bool leadingspace;
|
|
|
|
bool plaintext;
|
|
|
|
bool header;
|
2007-10-17 01:24:30 +00:00
|
|
|
bool footer;
|
2007-10-11 18:01:43 +00:00
|
|
|
bool is_private;
|
|
|
|
char* progname;
|
|
|
|
char* homedir;
|
|
|
|
char* database;
|
|
|
|
char* subdatabase;
|
|
|
|
int exitcode;
|
2007-10-17 01:24:30 +00:00
|
|
|
int recover_flags;
|
2007-10-11 18:01:43 +00:00
|
|
|
DBTYPE dbtype;
|
2007-10-17 01:24:30 +00:00
|
|
|
DBTYPE opened_dbtype;
|
2007-10-11 18:01:43 +00:00
|
|
|
DB* db;
|
|
|
|
DB_ENV* dbenv;
|
|
|
|
} dump_globals;
|
|
|
|
|
|
|
|
dump_globals g;
|
|
|
|
#include "tokudb_common_funcs.h"
|
|
|
|
|
|
|
|
int usage ();
|
|
|
|
int create_init_env();
|
2007-10-17 01:24:30 +00:00
|
|
|
int dump_database ();
|
2007-10-11 18:01:43 +00:00
|
|
|
int open_database ();
|
2007-10-17 01:24:30 +00:00
|
|
|
int dump_pairs ();
|
|
|
|
int dump_footer ();
|
|
|
|
int dump_header ();
|
2007-10-11 18:01:43 +00:00
|
|
|
int close_database ();
|
|
|
|
|
|
|
|
int main(int argc, char *argv[]) {
|
|
|
|
int ch;
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
/* Set up the globals. */
|
|
|
|
memset(&g, 0, sizeof(g));
|
|
|
|
g.leadingspace = true;
|
2007-10-17 01:54:47 +00:00
|
|
|
//TODO: Uncomment when DB_UNKNOWN + db->get_type are implemented.
|
2007-12-11 19:34:21 +00:00
|
|
|
g.dbtype = DB_UNKNOWN;
|
|
|
|
//g.dbtype = DB_BTREE;
|
2007-10-11 18:01:43 +00:00
|
|
|
g.progname = argv[0];
|
|
|
|
g.header = true;
|
2007-10-17 01:24:30 +00:00
|
|
|
g.footer = true;
|
2007-10-11 18:01:43 +00:00
|
|
|
|
2007-10-17 01:24:30 +00:00
|
|
|
if (verify_library_version() != 0) goto error;
|
2007-10-11 18:01:43 +00:00
|
|
|
|
2007-12-10 21:15:21 +00:00
|
|
|
while ((ch = getopt(argc, argv, "d:f:h:klNP:ps:RrVT")) != EOF) {
|
2007-10-11 18:01:43 +00:00
|
|
|
switch (ch) {
|
2007-12-10 19:42:02 +00:00
|
|
|
case ('d'): {
|
|
|
|
ERRORX("-%c option not supported.\n", ch);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
case ('f'): {
|
|
|
|
if (freopen(optarg, "w", stdout) == NULL) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"%s: %s: reopen: %s\n",
|
|
|
|
g.progname, optarg, strerror(errno));
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ('h'): {
|
|
|
|
g.homedir = optarg;
|
|
|
|
break;
|
|
|
|
}
|
2007-10-17 01:24:30 +00:00
|
|
|
case ('k'): {
|
|
|
|
ERRORX("-%c option not supported.\n", ch);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
case ('l'): {
|
|
|
|
//TODO: Implement (Requires master database support)
|
2007-12-10 19:42:02 +00:00
|
|
|
ERRORX("-%c option not supported.\n", ch); //YET!
|
2007-10-17 01:24:30 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
case ('N'): {
|
|
|
|
ERRORX("-%c option not supported.\n", ch);
|
|
|
|
goto error;
|
2007-10-11 18:01:43 +00:00
|
|
|
}
|
2007-12-10 19:42:02 +00:00
|
|
|
case ('P'): {
|
|
|
|
/* Clear password. */
|
|
|
|
memset(optarg, 0, strlen(optarg));
|
|
|
|
ERRORX("-%c option not supported.\n", ch);
|
|
|
|
goto error;
|
2007-10-11 18:01:43 +00:00
|
|
|
}
|
2007-10-17 01:24:30 +00:00
|
|
|
case ('p'): {
|
|
|
|
g.plaintext = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ('R'): {
|
2007-10-17 01:54:47 +00:00
|
|
|
//TODO: Uncomment when DB_SALVAGE,DB_AGGRESSIVE are implemented.
|
|
|
|
/*g.recover_flags |= DB_SALVAGE | DB_AGGRESSIVE;*/
|
2007-10-17 01:24:30 +00:00
|
|
|
|
|
|
|
//TODO: Implement aggressive recovery (requires db->verify())
|
|
|
|
ERRORX("-%c option not supported.\n", ch);
|
2007-10-11 18:01:43 +00:00
|
|
|
goto error;
|
|
|
|
}
|
2007-10-17 01:24:30 +00:00
|
|
|
case ('r'): {
|
2007-10-17 01:54:47 +00:00
|
|
|
//TODO: Uncomment when DB_SALVAGE,DB_AGGRESSIVE are implemented.
|
|
|
|
/*g.recover_flags |= DB_SALVAGE;*/
|
2007-10-17 01:24:30 +00:00
|
|
|
|
|
|
|
//TODO: Implement recovery (requires db->verify())
|
|
|
|
ERRORX("-%c option not supported.\n", ch);
|
|
|
|
goto error;
|
|
|
|
}
|
2007-12-10 19:42:02 +00:00
|
|
|
case ('s'): {
|
|
|
|
g.subdatabase = optarg;
|
2008-01-27 19:36:15 +00:00
|
|
|
break;
|
2007-12-10 19:42:02 +00:00
|
|
|
}
|
2007-10-17 01:24:30 +00:00
|
|
|
case ('V'): {
|
|
|
|
printf("%s\n", db_version(NULL, NULL, NULL));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2007-12-10 19:42:02 +00:00
|
|
|
case ('T'): {
|
|
|
|
g.plaintext = true;
|
|
|
|
g.leadingspace = false;
|
|
|
|
g.header = false;
|
|
|
|
g.footer = false;
|
2007-10-11 18:01:43 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ('?'):
|
|
|
|
default: {
|
|
|
|
g.exitcode = usage();
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
2007-10-17 01:54:47 +00:00
|
|
|
|
|
|
|
//TODO: Uncomment when DB_SALVAGE,DB_AGGRESSIVE,DB_PRINTABLE,db->verify are implemented.
|
|
|
|
/*
|
2007-10-17 01:24:30 +00:00
|
|
|
if (g.plaintext) g.recover_flags |= DB_PRINTABLE;
|
|
|
|
|
|
|
|
if (g.subdatabase != NULL && IS_SET_ALL(g.recover_flags, DB_SALVAGE)) {
|
|
|
|
if (IS_SET_ALL(g.recover_flags, DB_AGGRESSIVE)) {
|
|
|
|
ERRORX("The -s and -R options may not both be specified.\n");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
ERRORX("The -s and -r options may not both be specified.\n");
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
}
|
2007-10-17 01:54:47 +00:00
|
|
|
*/
|
2007-10-11 18:01:43 +00:00
|
|
|
|
|
|
|
if (argc != 1) {
|
|
|
|
g.exitcode = usage();
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2007-12-10 20:51:27 +00:00
|
|
|
init_catch_signals();
|
|
|
|
|
2007-10-11 18:01:43 +00:00
|
|
|
g.database = argv[0];
|
2007-12-10 20:51:27 +00:00
|
|
|
if (caught_any_signals()) goto cleanup;
|
2007-10-11 18:01:43 +00:00
|
|
|
if (create_init_env() != 0) goto error;
|
2007-12-10 20:51:27 +00:00
|
|
|
if (caught_any_signals()) goto cleanup;
|
2007-10-11 18:01:43 +00:00
|
|
|
if (dump_database() != 0) goto error;
|
|
|
|
if (false) {
|
|
|
|
error:
|
|
|
|
g.exitcode = EXIT_FAILURE;
|
|
|
|
fprintf(stderr, "%s: Quitting out due to errors.\n", g.progname);
|
|
|
|
}
|
|
|
|
cleanup:
|
|
|
|
if (g.dbenv && (retval = g.dbenv->close(g.dbenv, 0)) != 0) {
|
|
|
|
g.exitcode = EXIT_FAILURE;
|
2007-10-17 01:24:30 +00:00
|
|
|
fprintf(stderr, "%s: %s: dbenv->close\n", g.progname, db_strerror(retval));
|
2007-10-11 18:01:43 +00:00
|
|
|
}
|
2008-01-27 19:36:15 +00:00
|
|
|
// if (g.subdatabase) free(g.subdatabase);
|
2007-12-10 21:32:38 +00:00
|
|
|
resend_signals();
|
2007-10-11 18:01:43 +00:00
|
|
|
|
|
|
|
return g.exitcode;
|
|
|
|
}
|
|
|
|
|
|
|
|
int dump_database()
|
|
|
|
{
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
/* Create a database handle. */
|
|
|
|
retval = db_create(&g.db, g.dbenv, 0);
|
|
|
|
if (retval != 0) {
|
2007-10-17 01:24:30 +00:00
|
|
|
ERROR(retval, "db_create");
|
2007-10-11 18:01:43 +00:00
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
TODO: If/when supporting encryption
|
|
|
|
if (g.password && (retval = db->set_flags(db, DB_ENCRYPT))) {
|
2007-10-17 01:24:30 +00:00
|
|
|
ERROR(ret, "DB->set_flags: DB_ENCRYPT");
|
2007-10-11 18:01:43 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
if (open_database() != 0) goto error;
|
2007-12-10 20:51:27 +00:00
|
|
|
if (caught_any_signals()) goto cleanup;
|
2007-10-17 01:24:30 +00:00
|
|
|
if (g.header && dump_header() != 0) goto error;
|
2007-12-10 20:51:27 +00:00
|
|
|
if (caught_any_signals()) goto cleanup;
|
2007-10-11 18:01:43 +00:00
|
|
|
if (dump_pairs() != 0) goto error;
|
2007-12-10 20:51:27 +00:00
|
|
|
if (caught_any_signals()) goto cleanup;
|
2007-10-17 01:24:30 +00:00
|
|
|
if (g.footer && dump_footer() != 0) goto error;
|
2007-10-11 18:01:43 +00:00
|
|
|
|
|
|
|
if (false) {
|
|
|
|
error:
|
|
|
|
g.exitcode = EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
cleanup:
|
|
|
|
|
|
|
|
if (close_database() != 0) g.exitcode = EXIT_FAILURE;
|
|
|
|
|
|
|
|
return g.exitcode;
|
|
|
|
}
|
|
|
|
|
|
|
|
int usage()
|
|
|
|
{
|
2007-10-17 01:24:30 +00:00
|
|
|
fprintf(stderr,
|
2007-12-10 19:44:29 +00:00
|
|
|
"usage: %s [-pVT] [-f output] [-h home] [-s database] db_file\n",
|
2007-10-17 01:24:30 +00:00
|
|
|
g.progname);
|
2007-10-11 18:01:43 +00:00
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
int create_init_env()
|
|
|
|
{
|
|
|
|
int retval;
|
|
|
|
DB_ENV* dbenv;
|
|
|
|
int flags;
|
|
|
|
//TODO: Experiments to determine right cache size for tokudb, or maybe command line argument.
|
|
|
|
int cache = 1 << 20; /* 1 megabyte */
|
|
|
|
|
|
|
|
retval = db_env_create(&dbenv, 0);
|
|
|
|
if (retval) {
|
|
|
|
fprintf(stderr, "%s: db_dbenv_create: %s\n", g.progname, db_strerror(retval));
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
///TODO: UNCOMMENT/IMPLEMENT dbenv->set_errfile(dbenv, stderr);
|
|
|
|
dbenv->set_errpfx(dbenv, g.progname);
|
|
|
|
/*
|
|
|
|
TODO: Anything for encryption?
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Open the dbenvironment. */
|
|
|
|
g.is_private = false;
|
|
|
|
//flags = DB_INIT_LOCK | DB_INIT_LOG | DB_INIT_MPOOL | DB_USE_ENVIRON;
|
|
|
|
flags = DB_INIT_LOCK | DB_INIT_LOG | DB_INIT_MPOOL; ///TODO: UNCOMMENT/IMPLEMENT | DB_USE_ENVIRON;
|
|
|
|
//TODO: Transactions.. SET_BITS(flags, DB_INIT_TXN);
|
|
|
|
|
|
|
|
/*
|
|
|
|
///TODO: UNCOMMENT/IMPLEMENT Notes: We require DB_PRIVATE
|
|
|
|
if (!dbenv->open(dbenv, g.homedir, flags, 0)) goto success;
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
///TODO: UNCOMMENT/IMPLEMENT
|
|
|
|
retval = dbenv->set_cachesize(dbenv, 0, cache, 1);
|
|
|
|
if (retval) {
|
2007-10-17 01:24:30 +00:00
|
|
|
ERROR(retval, "DB_ENV->set_cachesize");
|
2007-10-11 18:01:43 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
g.is_private = true;
|
2007-10-17 01:24:30 +00:00
|
|
|
//TODO: Do we want to support transactions even in single-process mode?
|
|
|
|
//Logging is not necessary.. this is read-only.
|
|
|
|
//However, do we need to use DB_INIT_LOG to join a logging environment?
|
2007-10-11 18:01:43 +00:00
|
|
|
REMOVE_BITS(flags, DB_INIT_LOCK | DB_INIT_LOG | DB_INIT_TXN);
|
|
|
|
SET_BITS(flags, DB_CREATE | DB_PRIVATE);
|
|
|
|
|
2007-12-10 19:31:47 +00:00
|
|
|
retval = dbenv->open(dbenv, g.homedir, flags, 0);
|
2007-10-11 18:01:43 +00:00
|
|
|
if (retval) {
|
2007-10-17 01:24:30 +00:00
|
|
|
ERROR(retval, "DB_ENV->open");
|
2007-10-11 18:01:43 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
success:
|
|
|
|
g.dbenv = dbenv;
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
|
|
|
|
error:
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
2007-10-17 01:24:30 +00:00
|
|
|
#define DUMP_FLAG(bit, dump) if (IS_SET_ALL(flags, bit)) printf(dump);
|
2007-10-11 18:01:43 +00:00
|
|
|
|
2007-10-17 01:24:30 +00:00
|
|
|
#define DUMP_IGNORED_FLAG(bit, dump)
|
2007-10-11 18:01:43 +00:00
|
|
|
|
|
|
|
|
2007-10-17 01:24:30 +00:00
|
|
|
int dump_header()
|
|
|
|
{
|
|
|
|
u_int32_t flags;
|
|
|
|
int retval;
|
|
|
|
DB* db = g.db;
|
|
|
|
|
|
|
|
assert(g.header);
|
|
|
|
printf("VERSION=3\n");
|
|
|
|
printf("format=%s\n", g.plaintext ? "print" : "bytevalue");
|
2007-10-17 01:54:47 +00:00
|
|
|
//TODO: Uncomment when DB_UNKNOWN + db->get_type are implemented.
|
|
|
|
/*assert(g.dbtype == DB_BTREE || (g.dbtype == DB_UNKNOWN && g.opened_dbtype == DB_BTREE));*/
|
2007-10-17 01:24:30 +00:00
|
|
|
printf("type=btree\n");
|
|
|
|
//TODO: Get page size from db. Currently tokudb does not support db->get_pagesize.
|
2007-12-10 20:51:27 +00:00
|
|
|
//Don't print this out //printf("db_pagesize=4096\n");
|
2007-10-17 01:24:30 +00:00
|
|
|
if (g.subdatabase) {
|
|
|
|
printf("subdatabase=");
|
|
|
|
outputplaintextstring(g.subdatabase);
|
|
|
|
printf("\n");
|
|
|
|
}
|
2007-10-17 01:54:47 +00:00
|
|
|
//TODO: Uncomment when db->get_flags is implemented
|
2007-10-17 01:24:30 +00:00
|
|
|
if ((retval = db->get_flags(db, &flags)) != 0) {
|
|
|
|
ERROR(retval, "DB->get_flags");
|
2007-10-11 18:01:43 +00:00
|
|
|
goto error;
|
|
|
|
}
|
2007-12-11 19:34:21 +00:00
|
|
|
DUMP_IGNORED_FLAG(DB_CHKSUM, "chksum=1\n");
|
|
|
|
DUMP_FLAG( DB_DUP, "duplicates=1\n");
|
|
|
|
DUMP_FLAG( DB_DUPSORT, "dupsort=1\n");
|
|
|
|
DUMP_IGNORED_FLAG(DB_RECNUM, "recnum=1\n");
|
2007-10-17 01:24:30 +00:00
|
|
|
printf("HEADER=END\n");
|
|
|
|
|
|
|
|
if (ferror(stdout)) goto error;
|
2007-10-11 18:01:43 +00:00
|
|
|
return EXIT_SUCCESS;
|
|
|
|
|
|
|
|
error:
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
2007-10-17 01:24:30 +00:00
|
|
|
int dump_footer()
|
2007-10-11 18:01:43 +00:00
|
|
|
{
|
2007-10-17 01:24:30 +00:00
|
|
|
printf("DATA=END\n");
|
|
|
|
if (ferror(stdout)) goto error;
|
2007-10-11 18:01:43 +00:00
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
error:
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
int open_database()
|
|
|
|
{
|
|
|
|
DB* db = g.db;
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
int open_flags = DB_RDONLY;
|
|
|
|
//TODO: Transaction auto commit stuff
|
|
|
|
//if (TXN_ON(dbenv)) SET_BITS(open_flags, DB_AUTO_COMMIT);
|
2007-10-17 01:24:30 +00:00
|
|
|
|
2007-10-11 18:01:43 +00:00
|
|
|
retval = db->open(db, NULL, g.database, g.subdatabase, g.dbtype, open_flags, 0666);
|
|
|
|
if (retval != 0) {
|
2007-10-17 01:24:30 +00:00
|
|
|
ERROR(retval, "DB->open: %s", g.database);
|
2007-10-11 18:01:43 +00:00
|
|
|
goto error;
|
|
|
|
}
|
2007-10-17 01:54:47 +00:00
|
|
|
//TODO: Uncomment when DB_UNKNOWN + db->get_type are implemented.
|
|
|
|
/*
|
2007-10-17 01:24:30 +00:00
|
|
|
retval = db->get_type(db, &g.opened_dbtype);
|
2007-10-11 18:01:43 +00:00
|
|
|
if (retval != 0) {
|
2007-10-17 01:24:30 +00:00
|
|
|
ERROR(retval, "DB->get_type");
|
2007-10-11 18:01:43 +00:00
|
|
|
goto error;
|
|
|
|
}
|
2007-10-17 01:24:30 +00:00
|
|
|
if (g.opened_dbtype != DB_BTREE) {
|
|
|
|
ERRORX("Unsupported db type %d\n", g.opened_dbtype);
|
2007-10-11 18:01:43 +00:00
|
|
|
goto error;
|
|
|
|
}
|
2007-10-17 01:24:30 +00:00
|
|
|
if (g.dbtype != DB_UNKNOWN && g.opened_dbtype != g.dbtype) {
|
|
|
|
ERRORX("DBTYPE %d does not match opened DBTYPE %d.\n", g.dbtype, g.opened_dbtype);
|
2007-10-11 18:01:43 +00:00
|
|
|
goto error;
|
2007-10-17 01:54:47 +00:00
|
|
|
}*/
|
2007-10-11 18:01:43 +00:00
|
|
|
return EXIT_SUCCESS;
|
|
|
|
error:
|
2007-10-17 01:24:30 +00:00
|
|
|
fprintf(stderr, "Quitting out due to errors.\n");
|
2007-10-11 18:01:43 +00:00
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
int dump_dbt(DBT* dbt)
|
|
|
|
{
|
|
|
|
char* str;
|
|
|
|
uint32_t index;
|
|
|
|
|
|
|
|
assert(dbt);
|
|
|
|
str = (char*)dbt->data;
|
|
|
|
if (g.leadingspace) printf(" ");
|
|
|
|
if (dbt->size > 0) {
|
|
|
|
assert(dbt->data);
|
|
|
|
for (index = 0; index < dbt->size; index++) {
|
|
|
|
outputbyte(str[index]);
|
|
|
|
if (ferror(stdout)) {
|
|
|
|
perror("stdout");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
if (false) {
|
|
|
|
error:
|
|
|
|
g.exitcode = EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
return g.exitcode;
|
|
|
|
}
|
|
|
|
|
|
|
|
int dump_pairs()
|
|
|
|
{
|
|
|
|
int retval;
|
|
|
|
size_t length;
|
|
|
|
DBT key;
|
|
|
|
DBT data;
|
|
|
|
int spacech;
|
2007-10-17 01:24:30 +00:00
|
|
|
DB* db = g.db;
|
2007-10-11 18:01:43 +00:00
|
|
|
DBC* dbc = NULL;
|
|
|
|
|
|
|
|
memset(&key, 0, sizeof(key));
|
|
|
|
memset(&data, 0, sizeof(data));
|
|
|
|
|
|
|
|
if ((retval = db->cursor(db, (DB_TXN*)NULL, &dbc, 0)) != 0) {
|
2007-10-17 01:24:30 +00:00
|
|
|
ERROR(retval, "DB->cursor");
|
2007-10-11 18:01:43 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
while ((retval = dbc->c_get(dbc, &key, &data, DB_NEXT)) == 0) {
|
2007-12-10 20:51:27 +00:00
|
|
|
if (caught_any_signals()) goto cleanup;
|
2007-10-11 18:01:43 +00:00
|
|
|
if (dump_dbt(&key) != 0) goto error;
|
|
|
|
if (dump_dbt(&data) != 0) goto error;
|
|
|
|
}
|
|
|
|
if (retval != DB_NOTFOUND) {
|
2007-10-17 01:24:30 +00:00
|
|
|
ERROR(retval, "DBC->c_get");
|
2007-10-11 18:01:43 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (false) {
|
|
|
|
error:
|
|
|
|
g.exitcode = EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
cleanup:
|
|
|
|
if (dbc && (retval = dbc->c_close(dbc)) != 0) {
|
2007-10-17 01:24:30 +00:00
|
|
|
ERROR(retval, "DBC->c_close");
|
2007-10-11 18:01:43 +00:00
|
|
|
g.exitcode = EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
success:
|
|
|
|
return g.exitcode;
|
|
|
|
}
|
|
|
|
|
|
|
|
int close_database()
|
|
|
|
{
|
|
|
|
DB* db = g.db;
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
assert(db);
|
|
|
|
if ((retval = db->close(db, 0)) != 0) {
|
2007-10-17 01:24:30 +00:00
|
|
|
ERROR(retval, "DB->close");
|
2007-10-11 18:01:43 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
error:
|
|
|
|
return EXIT_FAILURE;
|
2007-07-13 19:37:47 +00:00
|
|
|
}
|