From 6f470c60b6c3f9737ac951806a3fcea9ac62e1b4 Mon Sep 17 00:00:00 2001 From: florian <f.spreckelsen@inidscale.com> Date: Fri, 6 Aug 2021 11:14:50 +0200 Subject: [PATCH] ENH: Add switch for type of retrieve response --- include/caosdb/transaction.h | 2 +- src/caosdb/transaction.cpp | 26 +++++++++++++++++++++----- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/include/caosdb/transaction.h b/include/caosdb/transaction.h index c04e38b..1ebba4f 100644 --- a/include/caosdb/transaction.h +++ b/include/caosdb/transaction.h @@ -405,7 +405,7 @@ private: MultiTransactionRequest *request; mutable MultiTransactionResponse *response; std::string error_message; - int query_count; + mutable long query_count; }; template <class InputIterator> diff --git a/src/caosdb/transaction.cpp b/src/caosdb/transaction.cpp index 1b19925..28ad666 100644 --- a/src/caosdb/transaction.cpp +++ b/src/caosdb/transaction.cpp @@ -96,6 +96,8 @@ using caosdb::entity::v1alpha1::MultiTransactionRequest; using caosdb::entity::v1alpha1::MultiTransactionResponse; using WrappedResponseCase = caosdb::entity::v1alpha1::TransactionResponse::WrappedResponseCase; +using QueryResponseCase = + caosdb::entity::v1alpha1::RetrieveResponse::QueryResponseCase; using caosdb::utility::get_arena; using grpc::ClientAsyncResponseReader; using ProtoEntity = caosdb::entity::v1alpha1::Entity; @@ -303,12 +305,26 @@ auto Transaction::WaitForIt() const noexcept -> TransactionStatus { auto *responses = this->response->mutable_responses(0); switch (responses->wrapped_response_case()) { case WrappedResponseCase::kRetrieveResponse: { - auto *entity = responses->mutable_retrieve_response()->release_entity(); - if (!entity->errors().empty()) { - this->status = TransactionStatus::TRANSACTION_ERROR( - "The request returned with errors."); + auto *retrieve_response = responses->mutable_retrieve_response(); + switch (retrieve_response->query_response_case()) { + case QueryResponseCase::kEntity: { + auto *entity = retrieve_response->release_entity(); + if (!entity->errors().empty()) { + this->status = TransactionStatus::TRANSACTION_ERROR( + "The request returned with errors."); + } + this->result_set = std::make_unique<UniqueResult>(entity); + } break; + case QueryResponseCase::kSelectResult: { + // TODO(tf) Select queries + } break; + case QueryResponseCase::kCountResult: { + this->query_count = retrieve_response->count_result(); + } break; + default: + // TODO(tf) Error + break; } - this->result_set = std::make_unique<UniqueResult>(entity); } break; case WrappedResponseCase::kUpdateResponse: { auto *updatedIdResponse = responses->mutable_update_response(); -- GitLab