Fix Metadata Plugin Parser
[platform/core/appfw/aul-1.git] / parser / metadata / allowed-appid / appsvc_db.cc
index f5a32a5..500dd18 100644 (file)
@@ -31,6 +31,28 @@ AppSvcDB::AppSvcDB(uid_t uid) : Database(GetDBPath(uid)) {
 
 AppSvcDB::~AppSvcDB() = default;
 
+std::vector<std::shared_ptr<AllowedInfo>> AppSvcDB::Select(
+    const std::string& appid) {
+  static const char query[] = "SELECT allowed_appid FROM "
+    "allowed_info WHERE appid = ?;";
+  sqlite3_stmt* stmt;
+  __PREPARE_V2(GetHandle(), query, strlen(query), stmt);
+  auto stmt_ptr = std::unique_ptr<sqlite3_stmt, decltype(sqlite3_finalize)*>(
+      stmt, sqlite3_finalize);
+  __BIND_TEXT(GetHandle(), stmt, 1, appid.c_str());
+
+  std::vector<std::shared_ptr<AllowedInfo>> allowed_infos;
+  while (sqlite3_step(stmt) == SQLITE_ROW) {
+    std::string allowed_appid = ColumnText(stmt, 0);
+    if (!allowed_appid.empty()) {
+      allowed_infos.emplace_back(
+          new (std::nothrow) AllowedInfo(appid, allowed_appid));
+    }
+  }
+
+  return allowed_infos;
+}
+
 void AppSvcDB::Insert(const std::string& appid,
     const std::string& allowed_appid) {
   static const char query[] = "INSERT OR REPLACE INTO "