summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormk5004.lee <mk5004.lee@samsung.com>2018-01-17 06:51:41 (GMT)
committermk5004.lee <mk5004.lee@samsung.com>2018-01-17 08:02:23 (GMT)
commitf2e7814f767a2605929a764496f8b279b5cb2cda (patch)
tree1392859545603f72ecd6a81f27dac5b4c2041d83
parent4de49eb7421fcabb34cbc411df26f92a3a683eef (diff)
downloadbadge-f2e7814f767a2605929a764496f8b279b5cb2cda.zip
badge-f2e7814f767a2605929a764496f8b279b5cb2cda.tar.gz
badge-f2e7814f767a2605929a764496f8b279b5cb2cda.tar.bz2
Add a api to organize db's data and option tablerefs/changes/45/167345/2
- If pkgname does not exist in the setting table, delete it. Change-Id: Ic9357a9a9950e9daa3556585898c7317f6f4e179 Signed-off-by: mk5004.lee <mk5004.lee@samsung.com>
-rwxr-xr-xinclude/badge_db.h2
-rw-r--r--include/badge_setting_service.h1
-rwxr-xr-xsrc/badge_internal.c2
-rw-r--r--src/badge_setting_service.c61
4 files changed, 64 insertions, 2 deletions
diff --git a/include/badge_db.h b/include/badge_db.h
index 1f342cf..f469574 100755
--- a/include/badge_db.h
+++ b/include/badge_db.h
@@ -32,6 +32,8 @@ extern "C" {
#define BADGE_DB_PATH tzplatform_mkpath(TZ_SYS_DB, ".badge.db")
#define BADGE_SETTING_DB_TABLE "badge_setting"
+#define BADGE_TABLE_NAME "badge_data"
+#define BADGE_OPTION_TABLE_NAME "badge_option"
int badge_db_insert(const char *pkgname, const char *writable_pkg, const char *caller, uid_t uid);
int badge_db_delete(const char *pkgname, const char *caller_pkg, uid_t uid, pid_t pid);
diff --git a/include/badge_setting_service.h b/include/badge_setting_service.h
index 130ca2e..11d9e03 100644
--- a/include/badge_setting_service.h
+++ b/include/badge_setting_service.h
@@ -44,6 +44,7 @@ int badge_setting_delete_package_for_uid(const char *pkgname, uid_t uid);
int badge_setting_refresh_setting_table(uid_t uid);
int badge_db_update_setting(char *pkgname, char *appid, int allow_to_display, uid_t uid);
int badge_setting_is_existed_appid(const char *appid, bool *is_existed, uid_t uid);
+int badge_setting_arrange_tables(uid_t uid);
/**
* @}
diff --git a/src/badge_internal.c b/src/badge_internal.c
index b625a28..7945f08 100755
--- a/src/badge_internal.c
+++ b/src/badge_internal.c
@@ -40,8 +40,6 @@
#include "badge_setting_service.h"
#define BADGE_PKGNAME_LEN 512
-#define BADGE_TABLE_NAME "badge_data"
-#define BADGE_OPTION_TABLE_NAME "badge_option"
#define BADGE_CHANGED_NOTI "badge_changed"
diff --git a/src/badge_setting_service.c b/src/badge_setting_service.c
index 3a5e7f4..9a61b7d 100644
--- a/src/badge_setting_service.c
+++ b/src/badge_setting_service.c
@@ -693,3 +693,64 @@ out:
return ret;
}
+EXPORT_API int badge_setting_arrange_tables(uid_t uid)
+{
+ int ret = BADGE_ERROR_NONE;
+ int sqlret;
+ sqlite3 *db = NULL;
+ char *sqlbuf = NULL;
+
+ sqlret = db_util_open(BADGE_DB_PATH, &db, 0);
+ if (sqlret != SQLITE_OK || !db) {
+ ERR("Failed to db_util_open [%d]", sqlret);
+ if (sqlret == SQLITE_PERM)
+ return BADGE_ERROR_PERMISSION_DENIED;
+ return BADGE_ERROR_FROM_DB;
+ }
+
+ sqlbuf = sqlite3_mprintf("DELETE FROM %Q WHERE pkgname not in "
+ "(SELECT pkgname FROM %Q) AND uid = %d",
+ BADGE_TABLE_NAME, BADGE_SETTING_DB_TABLE, uid);
+ if (sqlbuf == NULL) {
+ /* LCOV_EXCL_START */
+ ERR("Failed to alloc query");
+ ret = BADGE_ERROR_OUT_OF_MEMORY;
+ goto out;
+ /* LCOV_EXCL_STOP */
+ }
+
+ ret = badge_db_exec(db, sqlbuf, NULL);
+ if (ret != BADGE_ERROR_NONE)
+ goto out;
+
+ if (sqlbuf) {
+ sqlite3_free(sqlbuf);
+ sqlbuf = NULL;
+ }
+
+ sqlbuf = sqlite3_mprintf("DELETE FROM %Q WHERE pkgname not in "
+ "(SELECT pkgname FROM %Q) AND uid = %d",
+ BADGE_OPTION_TABLE_NAME, BADGE_SETTING_DB_TABLE,
+ uid);
+ if (sqlbuf == NULL) {
+ /* LCOV_EXCL_START */
+ ERR("Failed to alloc query");
+ ret = BADGE_ERROR_OUT_OF_MEMORY;
+ goto out;
+ /* LCOV_EXCL_STOP */
+ }
+
+ ret = badge_db_exec(db, sqlbuf, NULL);
+
+out:
+ if (sqlbuf)
+ sqlite3_free(sqlbuf);
+
+ if (db) {
+ sqlret = db_util_close(db);
+ if (sqlret != SQLITE_OK)
+ WARN("Failed to db_util_close [%d]", sqlret);
+ }
+
+ return ret;
+}