Commit 8bf12e1b authored by Bradley C. Kuszmaul's avatar Bradley C. Kuszmaul

db_dump_e.cpp test runs. Addresses #215. Fixes #216.

git-svn-id: file:///svn/tokudb@1321 c7de825b-a66e-492c-adef-691d508d4ae1
parent 9d70992a
......@@ -10,6 +10,7 @@ int Dbc::close (void) {
int Dbc::get(Dbt* key, Dbt *data, u_int32_t flags) {
DBC *dbc = this;
int ret = dbc->c_get(dbc, key, data, flags);
DbEnv *env = (DbEnv*)dbc->dbp->api_internal;
DB_ENV *dbenv_c=dbc->dbp->dbenv;
DbEnv *env = (DbEnv*)dbenv_c->api1_internal;
return env->maybe_throw_error(ret);
}
......@@ -27,3 +27,5 @@ check: $(TARGETS)
$(VGRIND) ./db_dump foo.db > foo.out
(echo " 61";echo " 62";echo " 63";echo " 64")>foo.expectout
diff foo.out foo.expectout
$(VGRIND) ./db_dump_e foo.db > foo.out
diff foo.out foo.expectout
/* Just like db_dump.cpp except use exceptions. */
#include <stdlib.h>
#include <assert.h>
#include <db_cxx.h>
void hexdump(Dbt *d) {
unsigned char *cp = (unsigned char *) d->get_data();
int n = d->get_size();
printf(" ");
for (int i=0; i<n; i++)
printf("%2.2x", cp[i]);
printf("\n");
}
int dbdump(char *dbfile, char *dbname) {
int r;
#if USE_ENV
DbEnv env(0);
r = env.open(".", DB_INIT_MPOOL + DB_CREATE + DB_PRIVATE, 0777); assert(r == 0);
Db db(&env, 0);
#else
Db db(0, 0);
#endif
try {
r = db.open(0, dbfile, dbname, DB_BTREE, 0, 0777);
assert(r==0);
} catch (DbException e) {
printf("Cannot open %s:%s due to error %d\n", dbfile, dbname, e.get_errno());
#if USE_ENV
r = env.close(0); assert(r == 0);
#endif
return 1;
}
Dbc *cursor;
r = db.cursor(0, &cursor, 0); assert(r == 0);
try {
for (;;) {
Dbt key; key.set_flags(DB_DBT_MALLOC);
Dbt val; val.set_flags(DB_DBT_MALLOC);
r = cursor->get(&key, &val, DB_NEXT);
assert(r==0);
// printf("%.*s\n", key.get_size(), (char *)key.get_data());
hexdump(&key);
free(key.get_data());
// printf("%.*s\n", val.get_size(), (char *)val.get_data());
hexdump(&val);
free(val.get_data());
}
} catch (DbException ) {
/* Nothing, that's just how we got out of the loop. */
}
r = cursor->close(); assert(r == 0);
r = db.close(0); assert(r == 0);
#if USE_ENV
r = env.close(0); assert(r == 0);
#endif
return 0;
}
int usage() {
printf("db_dump [-s DBNAME] DBFILE\n");
return 1;
}
int main(int argc, char *argv[]) {
int i;
char *dbname = 0;
for (i=1; i<argc; i++) {
char *arg = argv[i];
if (0 == strcmp(arg, "-h") || 0 == strcmp(arg, "--help"))
return usage();
if (0 == strcmp(arg, "-s")) {
i++;
if (i >= argc)
return usage();
dbname = argv[i];
continue;
}
break;
}
if (i >= argc)
return usage();
return dbdump(argv[i], dbname);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment