From e7743002a75d83e24de94f712fac0f0b61ab0ca3 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Fri, 30 Jan 2015 01:08:08 +0100 Subject: Open the database readonly in readonly mode. --- common/storage_lmdb.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'common') diff --git a/common/storage_lmdb.cpp b/common/storage_lmdb.cpp index 3f39192..a2a95c3 100644 --- a/common/storage_lmdb.cpp +++ b/common/storage_lmdb.cpp @@ -88,7 +88,7 @@ Storage::Private::Private(const QString &s, const QString &n, AccessMode m, bool // TODO: handle error std::cerr << "mdb_env_create: " << rc << " " << mdb_strerror(rc) << std::endl; } else { - if ((rc = mdb_env_open(env, fullPath.toStdString().data(), 0, 0664))) { + if ((rc = mdb_env_open(env, fullPath.toStdString().data(), mode == ReadOnly ? MDB_RDONLY : 0 , 0664))) { std::cerr << "mdb_env_open: " << rc << " " << mdb_strerror(rc) << std::endl; mdb_env_close(env); env = 0; @@ -157,12 +157,14 @@ bool Storage::startTransaction(AccessMode type) } if (d->firstOpen && requestedRead) { + //This is only required for named databases + //A write transaction is at least required the first time - mdb_txn_begin(d->env, nullptr, 0, &d->transaction); + // mdb_txn_begin(d->env, nullptr, 0, &d->transaction); //Open the database //With this we could open multiple named databases if we wanted to - mdb_dbi_open(d->transaction, nullptr, 0, &d->dbi); - mdb_txn_abort(d->transaction); + // mdb_dbi_open(d->transaction, nullptr, 0, &d->dbi); + // mdb_txn_abort(d->transaction); } int rc; -- cgit v1.2.3