summaryrefslogtreecommitdiffstats
path: root/src/storage/flexible_ngram.h
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2011-05-05 11:13:34 +0800
committerPeng Wu <alexepico@gmail.com>2011-05-05 11:13:34 +0800
commit5f987095add7f63c7389fc5255c74fc408351c71 (patch)
treed9ceaf3db292e659756422883352074dd79af727 /src/storage/flexible_ngram.h
parentd91e11a3e0e3215db7b87eb902dc7e7f9974823f (diff)
downloadlibpinyin-5f987095add7f63c7389fc5255c74fc408351c71.tar.gz
libpinyin-5f987095add7f63c7389fc5255c74fc408351c71.tar.xz
libpinyin-5f987095add7f63c7389fc5255c74fc408351c71.zip
refine attach method in flexible n-gram
Diffstat (limited to 'src/storage/flexible_ngram.h')
-rw-r--r--src/storage/flexible_ngram.h16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/storage/flexible_ngram.h b/src/storage/flexible_ngram.h
index 6f3c778..e5a086b 100644
--- a/src/storage/flexible_ngram.h
+++ b/src/storage/flexible_ngram.h
@@ -275,18 +275,26 @@ public:
}
/* attach berkeley db on filesystem for training purpose. */
- bool attach(const char * dbfile){
+ bool attach(const char * dbfile, guint32 flags){
reset();
+ u_int32_t db_flags = 0;
+
+ if ( flags & ATTACH_READONLY )
+ db_flags |= DB_RDONLY;
+ if ( flags & ATTACH_READWRITE )
+ assert( !(flags & ATTACH_READONLY ) );
+
if ( !dbfile )
return false;
int ret = db_create(&m_db, NULL, 0);
if ( ret != 0 )
assert(false);
- ret = m_db->open(m_db, NULL, dbfile, NULL, DB_HASH, 0, 0644);
- if ( ret != 0 ) {
+ ret = m_db->open(m_db, NULL, dbfile, NULL, DB_HASH, db_flags, 0644);
+ if ( ret != 0 && (flags & ATTACH_CREATE) ) {
+ db_flags |= DB_CREATE;
/* Create database file here, and write the signature. */
- ret = m_db->open(m_db, NULL, dbfile, NULL, DB_HASH, DB_CREATE, 0644);
+ ret = m_db->open(m_db, NULL, dbfile, NULL, DB_HASH, db_flags, 0644);
if ( ret != 0 )
return false;