Add logic for init notification_system_setting table in notification db 53/85453/5 accepted/tizen/common/20160829.135824 accepted/tizen/common/20160830.150113 accepted/tizen/ivi/20160830.061200 accepted/tizen/mobile/20160830.060922 accepted/tizen/tv/20160830.061022 accepted/tizen/wearable/20160830.061115 submit/tizen/20160829.010716 submit/tizen/20160830.010724
authorseungha.son <seungha.son@samsung.com>
Thu, 25 Aug 2016 07:05:04 +0000 (16:05 +0900)
committerSon seungha <seungha.son@samsung.com>
Sat, 27 Aug 2016 00:38:41 +0000 (17:38 -0700)
Signed-off-by: seungha.son <seungha.son@samsung.com>
Change-Id: I7270e66b6073b0fa821dc807092a3c9c76192a54

include/notification_setting.h
src/notification_init.c
src/notification_setting.c

index 76de7ca..851fbe6 100644 (file)
@@ -171,6 +171,7 @@ int notification_setting_update_setting(notification_setting_h setting);
 int notification_setting_free_notification(notification_setting_h setting);
 
 int notification_setting_refresh_setting_table(uid_t uid);
+int notification_system_setting_init_system_setting_table(uid_t uid);
 
 #ifdef __cplusplus
 }
index c637fde..d2c0101 100644 (file)
@@ -64,5 +64,16 @@ int main(int argc, char *argv[])
        if (argc > 2)
                uid = (uid_t)atoi(argv[2]);
        ret = notification_setting_refresh_setting_table(uid);
+       if (ret != NOTIFICATION_ERROR_NONE) {
+               _E("notification setting table refresh fail.");
+               return ret;
+       }
+
+       ret = notification_system_setting_init_system_setting_table(uid);
+       if (ret != NOTIFICATION_ERROR_NONE) {
+               _E("notification system setting table init fail.");
+               return ret;
+       }
+
        return ret;
 }
index 23f680c..f085a63 100755 (executable)
@@ -824,3 +824,90 @@ EXPORT_API int notification_unregister_system_setting_dnd_changed_cb(dnd_changed
 {
        return notification_unregister_system_setting_dnd_changed_cb_for_uid(callback, getuid());
 }
+
+static bool _is_uid_in_system_setting_table(sqlite3 *db, uid_t uid)
+{
+       bool err = true;
+       sqlite3_stmt *db_statement = NULL;
+       int sqlite3_ret = SQLITE_OK;
+       int field_index = 1;
+
+       sqlite3_ret = sqlite3_prepare_v2(db, "SELECT uid FROM notification_system_setting WHERE uid = ?", -1, &db_statement, NULL);
+       if (sqlite3_ret != SQLITE_OK) {
+               NOTIFICATION_ERR("sqlite3_prepare_v2 failed [%d][%s]", sqlite3_ret, sqlite3_errmsg(db));
+               err = false;
+               goto out;
+       }
+
+       sqlite3_bind_int(db_statement, field_index++, uid);
+
+       sqlite3_ret = sqlite3_step(db_statement);
+       if (sqlite3_ret == SQLITE_DONE) {
+               NOTIFICATION_INFO("no matched uid found[%d][%d]", uid, sqlite3_ret);
+               err = false;
+               goto out;
+       }
+
+       if (sqlite3_ret != SQLITE_OK && sqlite3_ret != SQLITE_ROW) {
+               NOTIFICATION_ERR("sqlite3_step failed [%d][%s]", sqlite3_ret, sqlite3_errmsg(db));
+               err = false;
+               goto out;
+       }
+
+out:
+       if (db_statement)
+               sqlite3_finalize(db_statement);
+
+       return err;
+}
+
+EXPORT_API int notification_system_setting_init_system_setting_table(uid_t uid)
+{
+       int err = NOTIFICATION_ERROR_NONE;
+       int sqlite3_ret = SQLITE_OK;
+       int field_index = 1;
+       sqlite3 *db = NULL;
+       sqlite3_stmt *db_statement = NULL;
+
+       NOTIFICATION_INFO("init system setting table [%d]", uid);
+       db = notification_db_open(DBPATH);
+       if (db == NULL)
+               return get_last_result();
+
+       /* if notification system setting don't init. */
+       if (_is_uid_in_system_setting_table(db, uid) == true) {
+               NOTIFICATION_DBG("Notification system setting table is already initialized.");
+       } else {
+               NOTIFICATION_DBG("Notification system setting table is not initialized yet");
+               sqlite3_ret = sqlite3_prepare_v2(db, "INSERT INTO notification_system_setting (uid) VALUES (?) ", -1, &db_statement, NULL);
+               if (sqlite3_ret != SQLITE_OK) {
+                       NOTIFICATION_ERR("sqlite3_prepare_v2 failed [%d][%s]", sqlite3_ret, sqlite3_errmsg(db));
+                       err = NOTIFICATION_ERROR_FROM_DB;
+                       goto out;
+               }
+
+               sqlite3_bind_int(db_statement, field_index++, uid);
+
+               sqlite3_ret = sqlite3_step(db_statement);
+               if (sqlite3_ret != SQLITE_OK && sqlite3_ret != SQLITE_DONE) {
+                       NOTIFICATION_ERR("sqlite3_step failed [%d][%s]", sqlite3_ret, sqlite3_errmsg(db));
+                       err = NOTIFICATION_ERROR_FROM_DB;
+                       goto out;
+               }
+       }
+
+       NOTIFICATION_DBG("Notification system setting tables initialization is success.");
+
+out:
+       if (db) {
+               if (err == NOTIFICATION_ERROR_NONE)
+                       sqlite3_exec(db, "END;", NULL, NULL, NULL);
+               else
+                       sqlite3_exec(db, "ROLLBACK;", NULL, NULL, NULL);
+               notification_db_close(&db);
+       }
+       if (db_statement)
+               sqlite3_finalize(db_statement);
+
+       return err;
+}