diff --git a/include/caosdb/transaction.h b/include/caosdb/transaction.h index f479683e434329f6c13799c6f8a59f866e149b36..1b89ecbec2c4e7c15bbe9739809ee0ee1af04cac 100644 --- a/include/caosdb/transaction.h +++ b/include/caosdb/transaction.h @@ -253,17 +253,6 @@ private: std::unique_ptr<Entity> entity; }; -// TODO(fspreck) One possibility for count-queries: Transaction gets a -// GetQueryCount function that returns exactly this. In case of a -// single FIND Query this will be equivalent to the Size of the -// ResultSet, but it may be different in case of Query + RetrieveById, -// and in case of COUNT queries which have an empty ResultSet. We have -// to think about how to extend this to transactions with more than -// one query in the future. My suggestion is to treat a transaction -// with more than one query as the union of the query results in which -// case the query count would return the cumulative number of -// results. This would even allow the combination of FIND, FIND -// unique, and COUNT, albeit a little strangely. /** * @brief Create a transaction via `CaosDBConnection.createTransaction()` */ @@ -391,7 +380,7 @@ public: * this transaction. In all other cases, the return value will be * -1. */ - [[nodiscard]] inline auto GetCountResult() const -> int { + [[nodiscard]] inline auto GetCountResult() const -> long { return query_count; } @@ -406,7 +395,7 @@ public: } /** - * Get a JSON representation of the respone. + * Get a JSON representation of the response. * * For debugging. */ diff --git a/src/caosdb/transaction.cpp b/src/caosdb/transaction.cpp index 5d5387c6f5d0e51cbd9dacdec6db259e140a762b..e6b22583f9a018faa048e688f4824dc25cd81938 100644 --- a/src/caosdb/transaction.cpp +++ b/src/caosdb/transaction.cpp @@ -169,8 +169,6 @@ Transaction::Transaction( return this->status.GetCode(); } -// TODO(fspreck) What about count queries (mixed with retrievals), -// what about unique queries? auto Transaction::Query(const std::string &query) noexcept -> StatusCode { ASSERT_CAN_ADD_QUERY @@ -190,7 +188,7 @@ auto Transaction::DeleteById(const std::string &id) noexcept -> StatusCode { auto *sub_request = this->request->add_requests(); sub_request->mutable_delete_request()->set_id(id); - this->status = TransactionStatus::READY(); + this->status = TransactionStatus::GO_ON(); return this->status.GetCode(); } diff --git a/test/test_transaction.cpp b/test/test_transaction.cpp index 86d3294e13166867ef7a409f9ceb7513753d6bae..6e04976d7d203e29c0ba084896e2f897c6121d48 100644 --- a/test/test_transaction.cpp +++ b/test/test_transaction.cpp @@ -177,4 +177,16 @@ TEST(test_transaction, test_update_entity) { EXPECT_EQ(error, StatusCode::ORIGINAL_ENTITY_MISSING_ID); } +TEST(test_transaction, test_multi_deletion) { + const auto *host = "localhost"; + auto configuration = InsecureConnectionConfiguration(host, 8000); + Connection connection(configuration); + auto transaction = connection.CreateTransaction(); + EXPECT_EQ(transaction.GetStatus().GetCode(), StatusCode::INITIAL); + for (int i = 0; i < 3; i++) { + auto status = transaction->DeleteById("asdf"); + EXPECT_EQ(status, StatusCode::GO_ON); + } +} + } // namespace caosdb::transaction