2 * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include "pkg_set_db_handler.hh"
21 #include "db_handle_provider.hh"
22 #include "utils/logging.hh"
24 #include "pkgmgrinfo_debug.h"
25 #include "pkgmgrinfo_internal.h"
27 namespace pkgmgr_server {
30 PkgSetDBHandler::PkgSetDBHandler(uid_t uid, int pid)
31 : AbstractDBHandler(uid, pid), uid_(uid) {}
33 PkgSetDBHandler::~PkgSetDBHandler() {}
35 void PkgSetDBHandler::SetPkgInfo(package_x* package) {
39 void PkgSetDBHandler::SetPkgID(std::string pkgid) {
40 pkgid = std::move(pkgid);
43 void PkgSetDBHandler::SetWriteType(pkgmgr_common::PkgWriteType write_type) {
44 write_type_ = write_type;
47 std::vector<std::vector<std::string>> PkgSetDBHandler::GetResult() {
48 return std::move(result_);
51 int PkgSetDBHandler::Execute() {
52 std::unique_lock<std::shared_timed_mutex> u(lock_);
53 SetOpType(pkgmgr_common::DBOperationType::OPERATION_TYPE_WRITE);
54 SetDBType(pkgmgr_common::DBType::DB_TYPE_FILE_PKGDB);
57 return PMINFO_R_ERROR;
59 DBHandleProvider::GetInst(uid_).SetMemoryMode(GetPID());
60 std::vector<std::pair<sqlite3*, uid_t>> conn_list = GetConnection();
61 sqlite3* conn = conn_list.front().first;
64 if (write_type_ == pkgmgr_common::PkgWriteType::Insert)
65 ret = pkgmgr_parser_insert_pkg_info(conn, package_, uid_);
66 else if (write_type_ == pkgmgr_common::PkgWriteType::Update)
67 ret = pkgmgr_parser_update_pkg_info(conn, package_, uid_);
68 else if (write_type_ == pkgmgr_common::PkgWriteType::Delete)
69 ret = pkgmgr_parser_delete_pkg_info(conn, package_->package, uid_);
71 LOG(ERROR) << "Unknown db write type";
73 if (ret != PM_PARSER_R_OK)
79 } // namespace database
80 } // namespace pkgmgr_server