Add pid as default parameter of dbhandler
[platform/core/appfw/pkgmgr-info.git] / src / common / database / depinfo_db_handler.cc
1 /*
2  * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include "depinfo_db_handler.hh"
18
19 #include <vector>
20
21 #include "pkgmgrinfo_debug.h"
22 #include "pkgmgrinfo_internal.h"
23
24 namespace pkgmgr_common {
25 namespace database {
26
27 DepInfoGetDBHandler::DepInfoGetDBHandler(uid_t uid, int pid)
28     : AbstractDBHandler(uid, pid), uid_(uid) {}
29
30 DepInfoGetDBHandler::~DepInfoGetDBHandler() {}
31
32 std::vector<dependency_x*> DepInfoGetDBHandler::GetDependencyList() {
33   return std::move(dependency_list_);
34 }
35
36 void DepInfoGetDBHandler::SetPkgID(const std::string& pkgid) {
37   pkgid_ = pkgid;
38 }
39
40 int DepInfoGetDBHandler::Execute() {
41   SetOpType(OPERATION_TYPE_READ);
42   SetDBType(DB_TYPE_FILE_PKGDB);
43
44   if (!Connect()) {
45     _LOGE("Failed to connect database");
46     return PMINFO_R_ERROR;
47   }
48   GList *list = nullptr;
49   std::vector<sqlite3*> conn_list = GetConnection();
50   int ret;
51   for (auto& conn : conn_list) {
52     ret = pkginfo_internal_filter_get_depends_on(
53         conn, pkgid_.c_str(), &list);
54     if (ret == PMINFO_R_ERROR)
55       break;
56   }
57   return ret;
58 }
59
60 }  // namespace database
61 }  // namespace pkgmgr_common