diff options
Diffstat (limited to 'common/storage_lmdb.cpp')
-rw-r--r-- | common/storage_lmdb.cpp | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/common/storage_lmdb.cpp b/common/storage_lmdb.cpp index 6c25448..18a5aa6 100644 --- a/common/storage_lmdb.cpp +++ b/common/storage_lmdb.cpp | |||
@@ -180,9 +180,9 @@ bool Storage::write(const std::string &sKey, const std::string &sValue) | |||
180 | return !rc; | 180 | return !rc; |
181 | } | 181 | } |
182 | 182 | ||
183 | void Storage::read(const std::string &sKey, const std::function<void(const std::string &value)> &resultHandler) | 183 | bool Storage::read(const std::string &sKey, const std::function<void(const std::string &value)> &resultHandler) |
184 | { | 184 | { |
185 | read(sKey, | 185 | return read(sKey, |
186 | [&](void *ptr, int size) { | 186 | [&](void *ptr, int size) { |
187 | const std::string resultValue(static_cast<char*>(ptr), size); | 187 | const std::string resultValue(static_cast<char*>(ptr), size); |
188 | resultHandler(resultValue); | 188 | resultHandler(resultValue); |
@@ -190,10 +190,10 @@ void Storage::read(const std::string &sKey, const std::function<void(const std:: | |||
190 | // std::cout << "key: " << resultKey << " data: " << resultValue << std::endl; | 190 | // std::cout << "key: " << resultKey << " data: " << resultValue << std::endl; |
191 | } | 191 | } |
192 | 192 | ||
193 | void Storage::read(const std::string &sKey, const std::function<void(void *ptr, int size)> &resultHandler) | 193 | bool Storage::read(const std::string &sKey, const std::function<void(void *ptr, int size)> &resultHandler) |
194 | { | 194 | { |
195 | if (!d->env) { | 195 | if (!d->env) { |
196 | return; | 196 | return false; |
197 | } | 197 | } |
198 | 198 | ||
199 | int rc; | 199 | int rc; |
@@ -208,14 +208,14 @@ void Storage::read(const std::string &sKey, const std::function<void(void *ptr, | |||
208 | if (implicitTransaction) { | 208 | if (implicitTransaction) { |
209 | // TODO: if this fails, still try the write below? | 209 | // TODO: if this fails, still try the write below? |
210 | if (!startTransaction(ReadOnly)) { | 210 | if (!startTransaction(ReadOnly)) { |
211 | return; | 211 | return false; |
212 | } | 212 | } |
213 | } | 213 | } |
214 | 214 | ||
215 | rc = mdb_cursor_open(d->transaction, d->dbi, &cursor); | 215 | rc = mdb_cursor_open(d->transaction, d->dbi, &cursor); |
216 | if (rc) { | 216 | if (rc) { |
217 | std::cerr << "mdb_cursor_get: " << rc << " " << mdb_strerror(rc) << std::endl; | 217 | std::cerr << "mdb_cursor_get: " << rc << " " << mdb_strerror(rc) << std::endl; |
218 | return; | 218 | return false; |
219 | } | 219 | } |
220 | 220 | ||
221 | if (sKey.empty()) { | 221 | if (sKey.empty()) { |
@@ -237,18 +237,20 @@ void Storage::read(const std::string &sKey, const std::function<void(void *ptr, | |||
237 | } | 237 | } |
238 | } | 238 | } |
239 | 239 | ||
240 | mdb_cursor_close(cursor); | ||
241 | |||
240 | if (rc) { | 242 | if (rc) { |
241 | std::cerr << "mdb_cursor_get: " << rc << " " << mdb_strerror(rc) << std::endl; | 243 | std::cerr << "mdb_cursor_get: " << rc << " " << mdb_strerror(rc) << std::endl; |
244 | return false | ||
242 | } | 245 | } |
243 | 246 | ||
244 | mdb_cursor_close(cursor); | ||
245 | |||
246 | /** | 247 | /** |
247 | we don't abort the transaction since we need it for reading the values | 248 | we don't abort the transaction since we need it for reading the values |
248 | if (implicitTransaction) { | 249 | if (implicitTransaction) { |
249 | abortTransaction(); | 250 | abortTransaction(); |
250 | } | 251 | } |
251 | */ | 252 | */ |
253 | return true; | ||
252 | } | 254 | } |
253 | 255 | ||
254 | qint64 Storage::diskUsage() const | 256 | qint64 Storage::diskUsage() const |