Insertion package privileges info to db 51/128351/2
authorBartlomiej Kunikowski <b.kunikowski@partner.samsung.com>
Tue, 9 May 2017 10:11:42 +0000 (12:11 +0200)
committerBartlomiej Kunikowski <b.kunikowski@partner.samsung.com>
Tue, 9 May 2017 10:37:21 +0000 (10:37 +0000)
After refactoring there was any code responsible for
adding package privileges info to database. This patch
add required code.

Change-Id: I874fca516ca85fe5945da56295db30f188f4aaa6
Signed-off-by: Bartlomiej Kunikowski <b.kunikowski@partner.samsung.com>
parser/src/pkgmgr_parser_db.c

index 6620f28..307724d 100644 (file)
@@ -1412,6 +1412,47 @@ static int __insert_app_localized_info(sqlite3 *db, application_x *app)
        return 0;
 }
 
+static int __insert_package_privilege_info(sqlite3 *db, manifest_x *mfx)
+{
+       static const char query[] =
+               "INSERT INTO package_privilege_info (package, privilege, type) "
+               "VALUES (?, ?, ?)";
+       int ret;
+       sqlite3_stmt *stmt;
+       int idx;
+       GList *tmp;
+       privilege_x *priv;
+
+       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 = mfx->privileges; tmp; tmp = tmp->next) {
+               priv = (privilege_x *)tmp->data;
+               if (priv == NULL)
+                       continue;
+
+               idx = 1;
+               __BIND_TEXT(db, stmt, idx++, mfx->package);
+               __BIND_TEXT(db, stmt, idx++, priv->value);
+               __BIND_TEXT(db, stmt, idx++, priv->type);
+
+               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;
+}
+
 /* _PRODUCT_LAUNCHING_ENHANCED_
  *  app->indicatordisplay, app->portraitimg, app->landscapeimg,
  *  app->guestmode_appstatus
@@ -1715,6 +1756,8 @@ static int __insert_package_info(sqlite3 *db, manifest_x *mfx)
                return -1;
        if (__insert_application_info(db, mfx))
                return -1;
+       if (__insert_package_privilege_info(db, mfx))
+               return -1;
 
        return 0;
 }
@@ -1774,6 +1817,8 @@ static int __delete_package_info(sqlite3 *db, const char *pkgid)
                return -1;
        }
 
+       sqlite3_finalize(stmt);
+
        return 0;
 }