Fix bug for deleting history from previous patch
[platform/core/appfw/librua.git] / src / rua_internal.c
index b3b94af..f39df16 100644 (file)
@@ -88,12 +88,11 @@ static int __delete_history_with_pkg_name(sqlite3 *db, const char *pkg_name,
        r = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
        if (r != SQLITE_OK) {
                LOGE("prepare failed: %s", sqlite3_errmsg(db));
-               sqlite3_close_v2(db);
                return -1;
        }
 
        __BIND_TEXT(db, stmt, idx++, pkg_name);
-       __BIND_TEXT(db, stmt, idx++, instance_id);
+       __BIND_TEXT(db, stmt, idx++, instance_id ? instance_id : "");
 
        r = sqlite3_step(stmt);
        if (r != SQLITE_DONE) {
@@ -119,12 +118,35 @@ static int __delete_history_with_app_path(sqlite3 *db, const char *app_path,
        r = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
        if (r != SQLITE_OK) {
                LOGE("prepare failed: %s", sqlite3_errmsg(db));
-               sqlite3_close_v2(db);
                return -1;
        }
 
        __BIND_TEXT(db, stmt, idx++, app_path);
-       __BIND_TEXT(db, stmt, idx++, instance_id);
+       __BIND_TEXT(db, stmt, idx++, instance_id ? instance_id : "");
+
+       r = sqlite3_step(stmt);
+       if (r != SQLITE_DONE) {
+               LOGE("step failed: %s", sqlite3_errmsg(db));
+               sqlite3_finalize(stmt);
+               return -1;
+       }
+
+       sqlite3_finalize(stmt);
+
+       return 0;
+}
+
+static int __clear_history(sqlite3 *db)
+{
+       static const char query[] = "DELETE FROM rua_history";
+       sqlite3_stmt *stmt;
+       int r;
+
+       r = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
+       if (r != SQLITE_OK) {
+               LOGE("prepare failed: %s", sqlite3_errmsg(db));
+               return -1;
+       }
 
        r = sqlite3_step(stmt);
        if (r != SQLITE_DONE) {
@@ -165,12 +187,17 @@ API int rua_usr_db_delete_history(bundle *b, uid_t uid)
                LOGI("rua_delete_history_from_db : %s", app_path);
                r = __delete_history_with_app_path(db, app_path, instance_id);
        } else {
-               LOGE("No data to delete history");
-               return -1;
+               LOGI("rua clear history");
+               r = __clear_history(db);
        }
 
        sqlite3_close_v2(db);
 
+       if (r == -1) {
+               LOGE("Failed to delete history");
+               return -1;
+       }
+
        r = rua_dbus_send_update_signal(DELETE);
        if (r == -1) {
                LOGE("[RUA SEND SIGNAL ERROR] \n");