From 77e64210026aa9948efed67648eab10df6359377 Mon Sep 17 00:00:00 2001 From: Inkyun Kil Date: Tue, 18 Apr 2017 17:01:35 +0900 Subject: [PATCH] Fix bug for deleting history from previous patch Change-Id: I313e491ae27aa620f6422f8c2c358c24754b473f Signed-off-by: Inkyun Kil --- src/rua_internal.c | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/src/rua_internal.c b/src/rua_internal.c index b3b94af..f39df16 100644 --- a/src/rua_internal.c +++ b/src/rua_internal.c @@ -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"); -- 2.7.4