This commit is contained in:
bert hubert 2018-12-07 14:16:21 +01:00
parent 8665a8bf08
commit 9eafb01508
3 changed files with 13 additions and 13 deletions

View File

@ -1,7 +1,8 @@
#LIBS=-Llmdb-0.9.21/libraries/liblmdb/
#INCLUDES=-Ilmdb-0.9.21/libraries/liblmdb/
#LIBS=lmdb-0.9.21/libraries/liblmdb/liblmdb.a
#INCLUDES=-Ilmdb-0.9.21/libraries/liblmdb/liblmdb
LIBS=-llmdb
CXXFLAGS:=-std=gnu++11 -Wall -O2 -MMD -MP -ggdb -pthread $(INCLUDES)
CFLAGS:= -Wall -O2 -MMD -MP -ggdb
@ -17,5 +18,4 @@ clean:
lmdb-test: lmdb-test.o lmdb-safe.o
g++ -std=gnu++11 $^ -o $@ -pthread $(LIBS) -llmdb
g++ -std=gnu++11 $^ -o $@ -pthread $(LIBS)

View File

@ -169,13 +169,12 @@ public:
}
MDBROCursor getCursor(const MDBDbi&);
~MDBROTransaction()
{
if(d_txn) {
d_parent->d_transactionOut=false;
mdb_txn_abort(d_txn);
mdb_txn_commit(d_txn); // this appears to work better than abort for r/o database opening
}
}
@ -201,7 +200,7 @@ public:
{
int rc= mdb_cursor_open(d_parent->d_txn, dbi, &d_cursor);
if(rc) {
throw std::runtime_error("Error creating cursor: "+std::string(mdb_strerror(rc)));
throw std::runtime_error("Error creating RO cursor: "+std::string(mdb_strerror(rc)));
}
}
MDBROCursor(MDBROCursor&& rhs)
@ -360,7 +359,7 @@ public:
{
int rc= mdb_cursor_open(d_parent->d_txn, dbi, &d_cursor);
if(rc) {
throw std::runtime_error("Error creating cursor: "+std::string(mdb_strerror(rc)));
throw std::runtime_error("Error creating RW cursor: "+std::string(mdb_strerror(rc)));
}
d_parent->reportCursor(this);
}

View File

@ -6,10 +6,11 @@
static void closeTest()
{
MDBEnv env("./database", 0, 0600);
MDBDbi dbi = env.openDB("ahu", MDB_CREATE);
MDBDbi main = env.openDB(0, MDB_CREATE);
MDBDbi hyc = env.openDB("hyc", MDB_CREATE);
MDBEnv env("./database", MDB_RDONLY, 0600);
int c= MDB_CREATE;
MDBDbi dbi = env.openDB("ahu", c);
MDBDbi main = env.openDB(0, c);
MDBDbi hyc = env.openDB("hyc2", c);
auto txn = env.getROTransaction();
auto cursor = txn.getCursor(dbi);