summaryrefslogtreecommitdiffstats
path: root/src/storage/phrase_large_table3_bdb.cpp
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2016-03-03 17:02:18 +0800
committerPeng Wu <alexepico@gmail.com>2016-03-03 17:02:18 +0800
commit21892aaad6e37ab6134c2bd9270605270964c893 (patch)
tree11762a35723f4616c8fabad8c6b89eb0ae6fbc6e /src/storage/phrase_large_table3_bdb.cpp
parent17eca1b8defe9f890790b1c897407c471ac0562f (diff)
downloadlibpinyin-21892aaad6e37ab6134c2bd9270605270964c893.tar.gz
libpinyin-21892aaad6e37ab6134c2bd9270605270964c893.tar.xz
libpinyin-21892aaad6e37ab6134c2bd9270605270964c893.zip
use copy_bdb function in phrase_large_table3_bdb.cpp
Diffstat (limited to 'src/storage/phrase_large_table3_bdb.cpp')
-rw-r--r--src/storage/phrase_large_table3_bdb.cpp49
1 files changed, 4 insertions, 45 deletions
diff --git a/src/storage/phrase_large_table3_bdb.cpp b/src/storage/phrase_large_table3_bdb.cpp
index 00276d1..28d2428 100644
--- a/src/storage/phrase_large_table3_bdb.cpp
+++ b/src/storage/phrase_large_table3_bdb.cpp
@@ -99,31 +99,10 @@ bool PhraseLargeTable3::load_db(const char * filename) {
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 )
+ if (tmp_db != NULL)
tmp_db->close(tmp_db, 0);
m_entry = new PhraseTableEntry;
@@ -149,30 +128,10 @@ bool PhraseLargeTable3::store_db(const char * new_filename) {
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 ) {
+ if (tmp_db != NULL) {
tmp_db->sync(m_db, 0);
tmp_db->close(tmp_db, 0);
}