diff options
Diffstat (limited to 'common/storage_lmdb.cpp')
-rw-r--r-- | common/storage_lmdb.cpp | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/common/storage_lmdb.cpp b/common/storage_lmdb.cpp index 7d06f96..13a6853 100644 --- a/common/storage_lmdb.cpp +++ b/common/storage_lmdb.cpp | |||
@@ -333,19 +333,28 @@ void Storage::scan(const char *keyData, uint keySize, | |||
333 | 333 | ||
334 | void Storage::remove(void const *keyData, uint keySize) | 334 | void Storage::remove(void const *keyData, uint keySize) |
335 | { | 335 | { |
336 | remove(keyData, keySize, basicErrorHandler()); | ||
337 | } | ||
338 | |||
339 | void Storage::remove(void const *keyData, uint keySize, const std::function<void(const Storage::Error &error)> &errorHandler) | ||
340 | { | ||
336 | if (!d->env) { | 341 | if (!d->env) { |
342 | Error error(d->name.toStdString(), -1, "Not open"); | ||
343 | errorHandler(error); | ||
337 | return; | 344 | return; |
338 | } | 345 | } |
339 | 346 | ||
340 | if (d->mode == ReadOnly) { | 347 | if (d->mode == ReadOnly) { |
341 | std::cerr << "tried to write in read-only mode." << std::endl; | 348 | Error error(d->name.toStdString(), -3, "Tried to write in read-only mode"); |
349 | errorHandler(error); | ||
342 | return; | 350 | return; |
343 | } | 351 | } |
344 | 352 | ||
345 | const bool implicitTransaction = !d->transaction || d->readTransaction; | 353 | const bool implicitTransaction = !d->transaction || d->readTransaction; |
346 | if (implicitTransaction) { | 354 | if (implicitTransaction) { |
347 | // TODO: if this fails, still try the write below? | ||
348 | if (!startTransaction()) { | 355 | if (!startTransaction()) { |
356 | Error error(d->name.toStdString(), -2, "Could not start transaction"); | ||
357 | errorHandler(error); | ||
349 | return; | 358 | return; |
350 | } | 359 | } |
351 | } | 360 | } |
@@ -357,7 +366,8 @@ void Storage::remove(void const *keyData, uint keySize) | |||
357 | rc = mdb_del(d->transaction, d->dbi, &key, 0); | 366 | rc = mdb_del(d->transaction, d->dbi, &key, 0); |
358 | 367 | ||
359 | if (rc) { | 368 | if (rc) { |
360 | std::cerr << "mdb_del: " << rc << " " << mdb_strerror(rc) << std::endl; | 369 | Error error(d->name.toStdString(), -1, QString("Error on mdb_del: %1 %2").arg(rc).arg(mdb_strerror(rc)).toStdString()); |
370 | errorHandler(error); | ||
361 | } | 371 | } |
362 | 372 | ||
363 | if (implicitTransaction) { | 373 | if (implicitTransaction) { |