summaryrefslogtreecommitdiffstats
path: root/common/storage_lmdb.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'common/storage_lmdb.cpp')
-rw-r--r--common/storage_lmdb.cpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/common/storage_lmdb.cpp b/common/storage_lmdb.cpp
index 2bffcd7..0070888 100644
--- a/common/storage_lmdb.cpp
+++ b/common/storage_lmdb.cpp
@@ -286,6 +286,50 @@ void Storage::scan(const char *keyData, uint keySize,
286 } 286 }
287 */ 287 */
288} 288}
289void Storage::readAll(const std::function<bool(void *key, int keySize, void *data, int dataSize)> &resultHandler,
290 const std::function<void(const Storage::Error &error)> &errorHandler)
291{
292 int rc;
293 MDB_val key;
294 MDB_val data;
295 MDB_cursor *cursor = 0;
296
297 const bool implicitTransaction = !d->transaction;
298 if (implicitTransaction) {
299 // TODO: if this fails, still try the write below?
300 if (!startTransaction(ReadOnly)) {
301 Error error(d->name.toStdString(), -2, "Could not start transaction");
302 errorHandler(error);
303 return;
304 }
305 }
306
307 rc = mdb_cursor_open(d->transaction, d->dbi, &cursor);
308 if (rc) {
309 Error error(d->name.toStdString(), rc, mdb_strerror(rc));
310 errorHandler(error);
311 return;
312 }
313
314 rc = mdb_cursor_get(cursor, &key, &data, MDB_FIRST);
315 while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) {
316 if (!resultHandler(key.mv_data, key.mv_size, data.mv_data, data.mv_size)) {
317 break;
318 }
319 }
320
321 //We never find the last value
322 if (rc == MDB_NOTFOUND) {
323 rc = 0;
324 }
325
326 mdb_cursor_close(cursor);
327
328 if (rc) {
329 Error error(d->name.toStdString(), rc, mdb_strerror(rc));
330 errorHandler(error);
331 }
332}
289 333
290qint64 Storage::diskUsage() const 334qint64 Storage::diskUsage() const
291{ 335{