Add logs into db handlers for debugging purpose
authorJunghyun Yeon <jungh.yeon@samsung.com>
Sat, 6 Mar 2021 02:27:01 +0000 (11:27 +0900)
committerJunghyun Yeon <jungh.yeon@samsung.com>
Sat, 6 Mar 2021 02:27:01 +0000 (11:27 +0900)
Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
src/common/database/cert_get_db_handler.cc
src/common/database/depinfo_db_handler.cc
src/common/database/pkg_get_db_handler.cc
src/common/database/pkg_set_db_handler.cc
src/common/database/query_handler.cc

index cf5076f..172283e 100644 (file)
@@ -16,6 +16,7 @@
 
 #include "cert_get_db_handler.hh"
 
+#include "pkgmgrinfo_debug.h"
 #include "pkgmgrinfo_internal.h"
 
 namespace pkgmgr_common {
@@ -35,8 +36,10 @@ void CertGetDBHandler::SetPkgID(std::string pkgid) {
 int CertGetDBHandler::Execute() {
   SetOpType(OPERATION_TYPE_READ);
   SetDBType(DB_TYPE_FILE_CERTDB);
-  if (!Connect())
+  if (!Connect()) {
+    _LOGE("Failed to connect database");
     return PMINFO_R_ERROR;
+  }
 
   pkgmgrinfo_certinfo_h handle;
   int ret = pkgmgrinfo_pkginfo_create_certinfo(&handle);
index 5ca5320..5ada699 100644 (file)
@@ -16,6 +16,7 @@
 
 #include "depinfo_db_handler.hh"
 
+#include "pkgmgrinfo_debug.h"
 #include "pkgmgrinfo_internal.h"
 
 namespace pkgmgr_common {
@@ -38,7 +39,10 @@ int DepInfoGetDBHandler::Execute() {
   SetOpType(OPERATION_TYPE_READ);
   SetDBType(DB_TYPE_FILE_PKGDB);
 
-  if (!Connect()) return PMINFO_R_ERROR;
+  if (!Connect()) {
+    _LOGE("Failed to connect database");
+    return PMINFO_R_ERROR;
+  }
   GList *list = nullptr;
   int ret = pkginfo_internal_filter_get_depends_on(
       GetConnection(), pkgid_.c_str(), &list);
index cf9c1fa..f348b7f 100644 (file)
@@ -16,6 +16,7 @@
 
 #include "pkg_get_db_handler.hh"
 
+#include "pkgmgrinfo_debug.h"
 #include "pkgmgrinfo_internal.h"
 
 namespace {
@@ -48,7 +49,10 @@ void PkgGetDBHandler::SetFilter(pkgmgrinfo_filter_x* filter) {
 int PkgGetDBHandler::Execute() {
   SetOpType(OPERATION_TYPE_READ);
   SetDBType(DB_TYPE_FILE_PKGDB);
-  if (!Connect()) return PMINFO_R_ERROR;
+  if (!Connect()) {
+    _LOGE("Failed to connect database");
+    return PMINFO_R_ERROR;
+  }
 
   // TODO: db handle should be delivered
   GHashTable* list;
index 8b5cd26..bcc7876 100644 (file)
@@ -17,6 +17,7 @@
 #include "db_handle_provider.hh"
 #include "pkg_set_db_handler.hh"
 
+#include "pkgmgrinfo_debug.h"
 #include "pkgmgr_parser_db.h"
 
 namespace pkgmgr_common {
@@ -56,7 +57,7 @@ int PkgSetDBHandler::Execute() {
   } else if (write_type_ == Delete) {
     ret = pkgmgr_parser_delete_pkg_info(GetConnection(), package_->package, uid_);
   } else {
-
+    _LOGE("Unknown db write type");
   }
 
   if (ret != PM_PARSER_R_OK) {
index 6d81daa..6d2fb42 100644 (file)
@@ -16,6 +16,7 @@
 
 #include "query_handler.hh"
 
+#include "pkgmgrinfo_debug.h"
 #include "pkgmgrinfo_internal.h"
 
 namespace pkgmgr_common {
@@ -38,19 +39,23 @@ std::vector<std::vector<std::string>>&& QueryHandler::GetResult() {
 }
 
 int QueryHandler::Execute() {
-  if (!Connect()) return PMINFO_R_ERROR;
+  if (!Connect()) {
+    _LOGE("Failed to connect database");
+    return PMINFO_R_ERROR;
+  }
 
-  // TODO: db handle should be delivered
   GList* list =nullptr;
   int row = 0;
   int col = 0;
-  if (query_.size() == 0)
+  if (query_.size() == 0) {
+    _LOGE("Empty query");
     return PMINFO_R_ERROR;
+  }
 
   if (GetOpType() == OPERATION_TYPE_READ) {
     int ret = get_query_result(GetConnection(), query_[0].c_str(), &list, &row, &col);
     if (ret != PMINFO_R_OK) {
-      // TODO: error log
+      _LOGE("Failed to execute query");
       return ret;
     }
 
@@ -68,8 +73,10 @@ int QueryHandler::Execute() {
     return ret;
   } else {
     const char **queries = (const char **)calloc(query_.size(), sizeof(char *));
-    if (queries == nullptr)
+    if (queries == nullptr) {
+      _LOGE("Out of memory");
       return PMINFO_R_ERROR;
+    }
 
     int i = 0;
     for (const auto& query : query_)