diff options
Diffstat (limited to 'store/database.cpp')
-rw-r--r-- | store/database.cpp | 14 |
1 files changed, 8 insertions, 6 deletions
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) | |||
187 | return !rc; | 187 | return !rc; |
188 | } | 188 | } |
189 | 189 | ||
190 | void Database::read(const std::string &sKey, const std::function<void(const std::string &value)> &resultHandler) | 190 | bool Database::read(const std::string &sKey, const std::function<void(const std::string &value)> &resultHandler) |
191 | { | 191 | { |
192 | read(sKey, | 192 | return read(sKey, |
193 | [&](void *ptr, int size) { | 193 | [&](void *ptr, int size) { |
194 | const std::string resultValue(static_cast<char*>(ptr), size); | 194 | const std::string resultValue(static_cast<char*>(ptr), size); |
195 | resultHandler(resultValue); | 195 | resultHandler(resultValue); |
@@ -197,10 +197,10 @@ void Database::read(const std::string &sKey, const std::function<void(const std: | |||
197 | // std::cout << "key: " << resultKey << " data: " << resultValue << std::endl; | 197 | // std::cout << "key: " << resultKey << " data: " << resultValue << std::endl; |
198 | } | 198 | } |
199 | 199 | ||
200 | void Database::read(const std::string &sKey, const std::function<void(void *ptr, int size)> &resultHandler) | 200 | bool Database::read(const std::string &sKey, const std::function<void(void *ptr, int size)> &resultHandler) |
201 | { | 201 | { |
202 | if (!d->env) { | 202 | if (!d->env) { |
203 | return; | 203 | return false; |
204 | } | 204 | } |
205 | 205 | ||
206 | int rc; | 206 | int rc; |
@@ -215,14 +215,14 @@ void Database::read(const std::string &sKey, const std::function<void(void *ptr, | |||
215 | if (implicitTransaction) { | 215 | if (implicitTransaction) { |
216 | // TODO: if this fails, still try the write below? | 216 | // TODO: if this fails, still try the write below? |
217 | if (!startTransaction(ReadOnly)) { | 217 | if (!startTransaction(ReadOnly)) { |
218 | return; | 218 | return false; |
219 | } | 219 | } |
220 | } | 220 | } |
221 | 221 | ||
222 | rc = mdb_cursor_open(d->transaction, d->dbi, &cursor); | 222 | rc = mdb_cursor_open(d->transaction, d->dbi, &cursor); |
223 | if (rc) { | 223 | if (rc) { |
224 | std::cerr << "mdb_cursor_get: " << rc << " " << mdb_strerror(rc) << std::endl; | 224 | std::cerr << "mdb_cursor_get: " << rc << " " << mdb_strerror(rc) << std::endl; |
225 | return; | 225 | return false; |
226 | } | 226 | } |
227 | 227 | ||
228 | if (sKey.empty()) { | 228 | if (sKey.empty()) { |
@@ -246,6 +246,7 @@ void Database::read(const std::string &sKey, const std::function<void(void *ptr, | |||
246 | 246 | ||
247 | if (rc) { | 247 | if (rc) { |
248 | std::cerr << "mdb_cursor_get: " << rc << " " << mdb_strerror(rc) << std::endl; | 248 | std::cerr << "mdb_cursor_get: " << rc << " " << mdb_strerror(rc) << std::endl; |
249 | return false; | ||
249 | } | 250 | } |
250 | 251 | ||
251 | mdb_cursor_close(cursor); | 252 | mdb_cursor_close(cursor); |
@@ -256,6 +257,7 @@ void Database::read(const std::string &sKey, const std::function<void(void *ptr, | |||
256 | abortTransaction(); | 257 | abortTransaction(); |
257 | } | 258 | } |
258 | */ | 259 | */ |
260 | return true; | ||
259 | } | 261 | } |
260 | 262 | ||
261 | qint64 Database::diskUsage() const | 263 | qint64 Database::diskUsage() const |