Merge remote-tracking branch 'origin/master' into deliver_pid
[platform/core/appfw/pkgmgr-info.git] / src / common / database / pkg_set_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 "db_handle_provider.hh"
18 #include "pkg_set_db_handler.hh"
19
20 #include <vector>
21
22 #include "pkgmgrinfo_debug.h"
23 #include "pkgmgrinfo_internal.h"
24
25 namespace pkgmgr_common {
26 namespace database {
27
28 PkgSetDBHandler::PkgSetDBHandler(uid_t uid, int pid)
29     : AbstractDBHandler(uid, pid), uid_(uid) {}
30
31 PkgSetDBHandler::~PkgSetDBHandler() {}
32
33 void PkgSetDBHandler::SetPkgInfo(package_x* package) { package_ = package; }
34 void PkgSetDBHandler::SetPkgID(std::string pkgid) { pkgid = std::move(pkgid); }
35 void PkgSetDBHandler::SetWriteType(WriteType write_type) { write_type_ = write_type; }
36
37 std::vector<std::vector<std::string>>&& PkgSetDBHandler::GetResult() {
38   return std::move(result_);
39 }
40
41 int PkgSetDBHandler::Execute() {
42   SetOpType(OPERATION_TYPE_WRITE);
43   SetDBType(DB_TYPE_FILE_PKGDB);
44   //result_.clear();
45   //result_.resize(1);
46
47   if (!Connect()) {
48     //result_[0].emplace_back("FAIL");
49     return PMINFO_R_ERROR;
50   }
51
52   int ret = 0;
53
54   DBHandleProvider::GetInst(uid_).SetMemoryMode(GetPID(), true);
55   std::vector<sqlite3*> conn_list = GetConnection();
56   sqlite3* conn = conn_list.front();
57   if (write_type_ == Insert) {
58     ret = pkgmgr_parser_insert_pkg_info(conn, package_, uid_);
59   } else if (write_type_ == Update) {
60     ret = pkgmgr_parser_update_pkg_info(conn, package_, uid_);
61   } else if (write_type_ == Delete) {
62     ret = pkgmgr_parser_delete_pkg_info(conn, package_->package, uid_);
63   } else {
64     _LOGE("Unknown db write type");
65   }
66
67   if (ret != PM_PARSER_R_OK) {
68     //result_[0].emplace_back("FAIL");
69     return ret;
70   }
71
72   //result_[0].emplace_back("SUCCESS");
73
74   return ret;
75 }
76
77 }  // namespace database
78 }  // namespace pkgmgr_common