From 3ffd3f515ff941a5e6222c1d102cb59fd7cf5278 Mon Sep 17 00:00:00 2001
From: Daniel <d.hornung@indiscale.com>
Date: Wed, 25 Aug 2021 17:25:04 +0200
Subject: [PATCH] ENH: Better cli and documentation.

---
 doc/README_SETUP.md  |  4 +++-
 src/cxxcaosdbcli.cpp | 38 ++++++++++++++++++++++++++++----------
 2 files changed, 31 insertions(+), 11 deletions(-)

diff --git a/doc/README_SETUP.md b/doc/README_SETUP.md
index f73190c..8549214 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 5e89995..0a4dfcf 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;
-- 
GitLab