diff --git a/doc/README_SETUP.md b/doc/README_SETUP.md index f73190cad3386518361a9d76dac2f1825d5f3f28..8549214ec483acede205f7badf1b8184c01bd7ed 100644 --- a/doc/README_SETUP.md +++ b/doc/README_SETUP.md @@ -79,7 +79,9 @@ For the tests there is a slightly different setup required (with option `-D CMAK 3. `cmake -B . -D CMAKE_BUILD_TYPE=Debug ..` * If your clang-format version is too old, formatting, linting etc. can be skipped: `cmake -B . -D CMAKE_BUILD_TYPE=Debug -D SKIP_LINTING=ON ..` -4. `cmake --build .` + * Depending on the clang version it might be necessary to also add + `-DCMAKE_CXX_FLAGS="-Wno-unused-parameter"` +5. `cmake --build .` ### Run diff --git a/src/cxxcaosdbcli.cpp b/src/cxxcaosdbcli.cpp index 5e899953232f4be4e800150e139196e78bf70198..0a4dfcf46c3cc0c475c16a501b8cfc8bdaaf59f1 100644 --- a/src/cxxcaosdbcli.cpp +++ b/src/cxxcaosdbcli.cpp @@ -26,11 +26,14 @@ #include "caosdb/entity.h" // for Entity #include "caosdb/exceptions.h" // for ConfigurationError #include "caosdb/info.h" // for VersionInfo +#include "caosdb/logging.h" // for CAOSDB_LOG_TRACE #include "caosdb/transaction.h" // for Transaction, ResultSet #include <iostream> // for operator<<, basic_ostream, basic_ost... #include <memory> // for unique_ptr, allocator, __shared_ptr_... #include <string> // for operator<<, char_traits +auto logger_name = "libcaosdb"; + auto main() -> int { std::cout << "CaosDB C++ client (libcaosdb " << caosdb::LIBCAOSDB_VERSION_MINOR << "." @@ -51,19 +54,34 @@ auto main() -> int { // retrieve an entity auto transaction(connection->CreateTransaction()); transaction->RetrieveById("120"); - transaction->Execute(); + transaction->ExecuteAsynchronously(); + auto t_stat = transaction->WaitForIt(); + CAOSDB_LOG_INFO(logger_name) << "status: " << t_stat.GetCode() + << " // " << t_stat.GetDescription(); const auto &result_set = transaction->GetResultSet(); - - // print information - const auto &ent = result_set.at(0); - const auto &props = ent.GetProperties(); - std::cout << "Entity Name: " << ent.GetName() << std::endl; - std::cout << "Entity Description: " << ent.GetDescription() << std::endl; - std::cout << "Entity Properties: " << std::endl; - for (const auto &prop : props) { - std::cout << "----------\n" << prop.ToString() << std::endl; + if (result_set.size() > 0) { + // print information + const auto &ent = result_set.at(0); + const auto &props = ent.GetProperties(); + std::cout << "Entity Name: " << ent.GetName() << std::endl; + std::cout << "Entity Description: " << ent.GetDescription() << std::endl; + std::cout << "Entity Properties: " << std::endl; + for (const auto &prop : props) { + std::cout << "----------\n" << prop.ToString() << std::endl; + } + } else { + std::cout << "No entity \"120\" retrieved, maybe it does not exist?\n" << std::endl; } + // execute a query + std::string query("FIND Property \"Prop *\""); + std::cout << "Trying to execute a query:\n" << query << std::endl; + auto q_transaction(connection->CreateTransaction()); + q_transaction->Query(query); + q_transaction->ExecuteAsynchronously(); + t_stat = q_transaction->WaitForIt(); + CAOSDB_LOG_INFO(logger_name) << "status: " << t_stat.GetCode() + << " // " << t_stat.GetDescription(); return 0; } catch (const caosdb::exceptions::ConfigurationError &exc) { std::cout << "ConfigurationError: " << exc.what() << std::endl;