From 639fc60c100204c87b93112516cf3b3117cfff0d Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Fri, 5 Dec 2014 01:02:51 +0100 Subject: Return false on error during read. --- store/database.cpp | 14 ++++++++------ store/database.h | 4 ++-- store/test/storagetest.cpp | 6 ++++-- 3 files changed, 14 insertions(+), 10 deletions(-) (limited to 'store') diff --git a/store/database.cpp b/store/database.cpp index 0c4fd18..c4dfbd6 100644 --- a/store/database.cpp +++ b/store/database.cpp @@ -187,9 +187,9 @@ bool Database::write(const std::string &sKey, const std::string &sValue) return !rc; } -void Database::read(const std::string &sKey, const std::function &resultHandler) +bool Database::read(const std::string &sKey, const std::function &resultHandler) { - read(sKey, + return read(sKey, [&](void *ptr, int size) { const std::string resultValue(static_cast(ptr), size); resultHandler(resultValue); @@ -197,10 +197,10 @@ void Database::read(const std::string &sKey, const std::function &resultHandler) +bool Database::read(const std::string &sKey, const std::function &resultHandler) { if (!d->env) { - return; + return false; } int rc; @@ -215,14 +215,14 @@ void Database::read(const std::string &sKey, const std::functiontransaction, d->dbi, &cursor); if (rc) { std::cerr << "mdb_cursor_get: " << rc << " " << mdb_strerror(rc) << std::endl; - return; + return false; } if (sKey.empty()) { @@ -246,6 +246,7 @@ void Database::read(const std::string &sKey, const std::function &); - void read(const std::string &sKey, const std::function &); + bool read(const std::string &sKey, const std::function &); + bool read(const std::string &sKey, const std::function &); qint64 diskUsage() const; void removeFromDisk() const; diff --git a/store/test/storagetest.cpp b/store/test/storagetest.cpp index 1b105af..dba4f6c 100644 --- a/store/test/storagetest.cpp +++ b/store/test/storagetest.cpp @@ -37,12 +37,14 @@ private: { bool error = false; const auto reference = keyPrefix + std::to_string(i); - db.read(keyPrefix + std::to_string(i), [&error, &reference](const std::string &value) { + if(!db.read(keyPrefix + std::to_string(i), [&error, &reference](const std::string &value) { if (value != reference) { qDebug() << "Mismatch while reading"; error = true; } - }); + })) { + return false; + } return !error; } -- cgit v1.2.3