Add new elements for component-based application
[platform/core/appfw/pkgmgr-info.git] / parser / src / pkgmgr_parser_db.c
index b6db523..185aecb 100644 (file)
@@ -331,6 +331,7 @@ static const char *parser_init_queries[] = {
        QUERY_CREATE_TABLE_PACKAGE_APP_SPLASH_SCREEN,
        QUERY_CREATE_TABLE_PACKAGE_DEPENDENCY_INFO,
        QUERY_CREATE_TABLE_PACKAGE_PLUGIN_INFO,
+       QUERY_CREATE_TABLE_PACKAGE_APP_COMPONENT_INFO,
        NULL,
 };
 
@@ -1210,6 +1211,51 @@ static int __insert_splashscreen_info(sqlite3 *db, application_x *app,
        return 0;
 }
 
+static int __insert_component_info(sqlite3 *db, application_x *app)
+{
+       static const char query[] =
+               "INSERT INTO package_app_component_info (app_id, component_id, "
+               "type, launch_mode) VALUES(?, ?, ?, ?)";
+       int ret;
+       sqlite3_stmt *stmt;
+       int idx;
+       GList *tmp;
+       component_x *c;
+
+       if (app->components == NULL)
+               return 0;
+
+       ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
+       if (ret != SQLITE_OK) {
+               _LOGE("prepare failed: %s", sqlite3_errmsg(db));
+               return -1;
+       }
+
+       for (tmp = app->components; tmp; tmp = tmp->next) {
+               c = (component_x *)tmp->data;
+               if (c == NULL)
+                       continue;
+
+               idx = 1;
+               __BIND_TEXT(db, stmt, idx++, app->appid);
+               __BIND_TEXT(db, stmt, idx++, c->id);
+               __BIND_TEXT(db, stmt, idx++, c->type);
+               __BIND_TEXT(db, stmt, idx++, c->launch_mode);
+
+               ret = sqlite3_step(stmt);
+               if (ret != SQLITE_DONE) {
+                       _LOGE("step failed: %s", sqlite3_errmsg(db));
+                       sqlite3_finalize(stmt);
+                       return -1;
+               }
+               sqlite3_reset(stmt);
+       }
+
+       sqlite3_finalize(stmt);
+
+       return 0;
+}
+
 static void __trimfunc(GList *trim_list)
 {
        char *trim_data;
@@ -2029,6 +2075,13 @@ static int __insert_application_info(sqlite3 *db, manifest_x *mfx)
                        sqlite3_finalize(stmt);
                        return -1;
                }
+
+               if (!strcmp(app->component_type, "componentbasedapp")) {
+                       if (__insert_component_info(db, app)) {
+                               sqlite3_finalize(stmt);
+                               return -1;
+                       }
+               }
        }
 
        sqlite3_finalize(stmt);
@@ -3231,4 +3284,4 @@ API int pkgmgr_parser_unregister_pkg_plugin_info_in_usr_db(
 API int pkgmgr_parser_unregister_pkg_plugin_info_in_db(const char *pkgid)
 {
        return pkgmgr_parser_unregister_pkg_plugin_info_in_usr_db(pkgid, __getuid());
-}
\ No newline at end of file
+}