From 17eca1b8defe9f890790b1c897407c471ac0562f Mon Sep 17 00:00:00 2001 From: Peng Wu Date: Thu, 3 Mar 2016 16:58:49 +0800 Subject: use copy_bdb function in ngram_bdb.cpp --- src/storage/ngram_bdb.cpp | 45 ++------------------------------------------- 1 file changed, 2 insertions(+), 43 deletions(-) diff --git a/src/storage/ngram_bdb.cpp b/src/storage/ngram_bdb.cpp index 1e2cbe1..65cd699 100644 --- a/src/storage/ngram_bdb.cpp +++ b/src/storage/ngram_bdb.cpp @@ -70,30 +70,9 @@ bool Bigram::load_db(const char * dbfile){ if ( ret != 0 ) return false; - DBC * cursorp = NULL; - DBT key, data; - - /* Get a cursor */ - tmp_db->cursor(tmp_db, NULL, &cursorp, 0); - - if (NULL == cursorp) + if ( !copy_bdb(tmp_db, m_db) ) 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) { - int ret = m_db->put(m_db, NULL, &key, &data, 0); - assert(ret == 0); - } - assert (ret == DB_NOTFOUND); - - /* Cursors must be closed */ - if ( cursorp != NULL ) - cursorp->c_close(cursorp); - if ( tmp_db != NULL ) tmp_db->close(tmp_db, 0); @@ -118,29 +97,9 @@ bool Bigram::save_db(const char * dbfile){ if ( ret != 0 ) return false; - DBC * cursorp = NULL; - DBT key, data; - /* Get a cursor */ - m_db->cursor(m_db, NULL, &cursorp, 0); - - if (NULL == cursorp) + if ( !copy_bdb(m_db, tmp_db) ) 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) { - int ret = tmp_db->put(tmp_db, NULL, &key, &data, 0); - assert(ret == 0); - } - assert (ret == DB_NOTFOUND); - - /* Cursors must be closed */ - if ( cursorp != NULL ) - cursorp->c_close(cursorp); - if ( tmp_db != NULL ) { tmp_db->sync(m_db, 0); tmp_db->close(tmp_db, 0); -- cgit