9ba37382db74161884f9a7976cc917943b1c7f23
[platform/core/appfw/pkgmgr-info.git] / src / server / database / query_handler.hh
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 #ifndef QUERY_HANDLER_HH_
18 #define QUERY_HANDLER_HH_
19
20 #include <string>
21 #include <vector>
22
23 #include <sys/types.h>
24
25 #include "abstract_db_handler.hh"
26 #include "db_type.hh"
27 #include "pkgmgrinfo_basic.h"
28 #include "pkgmgrinfo_private.h"
29 #include "query_parcelable.hh"
30
31 namespace pkgmgr_server {
32 namespace database {
33
34 #ifndef EXPORT_API
35 #define EXPORT_API __attribute__((visibility("default")))
36 #endif
37
38 enum class CacheChangeFlag {
39   NONE,
40   PKG,
41   APP,
42   APPBYPKG
43 };
44
45 class EXPORT_API QueryHandler : public AbstractDBHandler {
46  public:
47   QueryHandler(uid_t uid, int pid);
48   ~QueryHandler();
49   void SetQueryArgs(std::vector<pkgmgr_common::parcel::QueryArgs> query_args);
50   bool BindString(std::string value);
51   bool BindInt(int value);
52   std::string GetString();
53   int GetInt();
54   int GetRecordCount();
55   int Execute() override;
56   std::vector<pkgmgr_common::parcel::StrArgs> GetResult();
57
58  private:
59   int ExecuteReadQuery(GList* queries, GList* args_list);
60   int ExecuteWriteQuery(GList* queries, GList* args_list,
61       const std::vector<std::pair<CacheChangeFlag, std::string>>& changes);
62
63   uid_t uid_;
64   std::vector<std::string> query_;
65   std::vector<pkgmgr_common::parcel::QueryArgs> query_args_;
66   std::vector<pkgmgr_common::parcel::StrArgs> result_;
67 };
68
69 }  // namespace database
70 }  // namespace pkgmgr_server
71
72 #endif  // QUERY_HANDLER_HH_
73