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 "query_handler.hh"
19 #include "pkgmgrinfo_internal.h"
21 namespace pkgmgr_common {
24 QueryHandler::QueryHandler(uid_t uid) : AbstractDBHandler(uid), uid_(uid) {}
26 QueryHandler::~QueryHandler() {}
28 void QueryHandler::SetQuery(std::vector<std::string> query) {
32 std::string QueryHandler::GetString() { return std::string(); }
33 int QueryHandler::GetInt() { return 0; }
34 int QueryHandler::GetRecordCount() { return 0; }
36 std::vector<std::vector<std::string>>&& QueryHandler::GetResult() {
37 return std::move(result_);
40 bool QueryHandler::Execute() {
41 if (!Connect()) return false;
43 // TODO: db handle should be delivered
47 if (query_.size() == 0)
50 if (GetOpType() == OPERATION_TYPE_READ) {
51 int ret = get_query_result(GetConnection(), query_[0].c_str(), &list, &row, &col);
52 if (ret != PMINFO_R_OK) {
60 for (int i = 0; i < row; ++i) {
61 for (int j = 0; j < col; ++j) {
62 result_[i].emplace_back(reinterpret_cast<char *>(tmp->data));
72 const char **queries = (const char **)calloc(query_.size(), sizeof(char *));
74 for (const auto& query : query_)
75 queries[i++] = query.c_str();
77 int ret = execute_write_queries(GetConnection(), queries, query_.size());
79 result_[0].emplace_back("FAIL");
81 result_[0].emplace_back("SUCCESS");
87 } // namespace database
88 } // namespace pkgmgr_common