From 71b613bc7c43d37b444e5531241c355e23de925c Mon Sep 17 00:00:00 2001 From: Martchus Date: Sat, 9 Mar 2024 12:11:52 +0100 Subject: [PATCH] Avoid error when rebuilding database --- lmdb-typed.hh | 3 ++- tests/typed.cc | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lmdb-typed.hh b/lmdb-typed.hh index dd6f9bf..fc7121e 100644 --- a/lmdb-typed.hh +++ b/lmdb-typed.hh @@ -157,7 +157,8 @@ template struct LMDB_SAFE_EXPORT L void del(MDBRWTransaction &txn, const Class &t, IDType id) { - if (const auto rc = txn->del(d_idx, keyConv(d_parent->getMember(t)), id)) { + const auto rc = txn->del(d_idx, keyConv(d_parent->getMember(t)), id); + if (rc && rc != MDB_NOTFOUND) { throw LMDBError("Error deleting from index: ", rc); } } diff --git a/tests/typed.cc b/tests/typed.cc index 3bb3bd6..bc8449b 100644 --- a/tests/typed.cc +++ b/tests/typed.cc @@ -104,5 +104,13 @@ TEST_CASE("Basic typed tests", "[basictyped]") REQUIRE(out.lastName == "testperson"); REQUIRE(out.enrolled == m.enrolled); + // rebuild the database + txn.rebuild([] (IDType, Member *member) { + return member->firstName != "bertus"; + }); + REQUIRE(txn.size() == 2); + REQUIRE(txn.size<0>() == txn.size()); + REQUIRE(!txn.get<0>("bertus", out)); + txn.abort(); }