#include #include #include void print_help() { printf("Usage: bdbtokyotodb "); } bool convert(DB * bdb, kyotocabinet::BasicDB * kyotodb) { DBC * cursorp = NULL; DBT key, data; int ret; /* Get a cursor */ bdb->cursor(bdb, NULL, &cursorp, 0); if (NULL == cursorp) return false; /* Initialize our DBTs. */ memset(&key, 0, sizeof(DBT)); memset(&data, 0, sizeof(DBT)); /* Iterate over the database, retrieving each record in turn. */ while ((ret = cursorp->c_get(cursorp, &key, &data, DB_NEXT)) == 0) { assert(NULL != data.data); kyotodb->set((char *)key.data, key.size, (char *)data.data, data.size); } assert (ret == DB_NOTFOUND); /* Cursors must be closed */ if (cursorp != NULL) cursorp->c_close(cursorp); return true; } int main(int argc, char * argv[]) { if (argc != 3) { print_help(); exit(1); } const char * bdbfile = argv[1]; const char * kyotodbfile = argv[2]; DB * bdb = NULL; int ret = db_create(&bdb, NULL, 0); ret = bdb->open(bdb, NULL, bdbfile, NULL, DB_HASH, DB_RDONLY, 0644); kyotocabinet::BasicDB * kyotodb = new kyotocabinet::HashDB; kyotodb->open(kyotodbfile, kyotocabinet::BasicDB::OWRITER | kyotocabinet::BasicDB::OCREATE); convert(bdb, kyotodb); kyotodb->synchronize(); kyotodb->close(); delete kyotodb; bdb->sync(bdb, 0); bdb->close(bdb, 0); bdb = NULL; return 0; }