summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorseungha.son <seungha.son@samsung.com>2016-09-29 18:05:07 +0900
committerseungha.son <seungha.son@samsung.com>2016-09-30 11:24:26 +0900
commit76fc92a8b28d7e2c140fd091377e523b20ffd91e (patch)
tree2a8de27d3fa82fc93a9db6e725b6c8730f4f8b0b
parentcbffc84de17c5f50527dece86f75c8edfc5f72e1 (diff)
downloadnotification-76fc92a8b28d7e2c140fd091377e523b20ffd91e.tar.gz
notification-76fc92a8b28d7e2c140fd091377e523b20ffd91e.tar.bz2
notification-76fc92a8b28d7e2c140fd091377e523b20ffd91e.zip
- Modify GList find method. - Modify DB query in dnd_allow_exception db table. Signed-off-by: seungha.son <seungha.son@samsung.com> Change-Id: I2c042fa99b2443d23fc83187eaafe197a4a1cd0b
-rwxr-xr-xsrc/notification_setting.c29
-rw-r--r--src/notification_setting_service.c52
2 files changed, 47 insertions, 34 deletions
diff --git a/src/notification_setting.c b/src/notification_setting.c
index eb55c67..013efdd 100755
--- a/src/notification_setting.c
+++ b/src/notification_setting.c
@@ -765,7 +765,7 @@ EXPORT_API int notification_system_setting_get_dnd_allow_exceptions(notification
return NOTIFICATION_ERROR_INVALID_PARAMETER;
}
- list = g_list_find_custom(system_setting->dnd_allow_exceptions, (gconstpointer)type, _dnd_allow_exception_compare);
+ list = g_list_find_custom(system_setting->dnd_allow_exceptions, (gconstpointer)type, (GCompareFunc)_dnd_allow_exception_compare);
if (list) {
dnd_allow_exception_data = (dnd_allow_exception_h)list->data;
*value = dnd_allow_exception_data->value;
@@ -780,7 +780,7 @@ EXPORT_API int notification_system_setting_get_dnd_allow_exceptions(notification
EXPORT_API int notification_system_setting_set_dnd_allow_exceptions(notification_system_setting_h system_setting, dnd_allow_exception_type_e type, int value)
{
dnd_allow_exception_h dnd_allow_exception_data;
- GList *list;
+ GList *list = NULL;
if (system_setting == NULL) {
NOTIFICATION_ERR("Invalid parameter");
@@ -788,23 +788,20 @@ EXPORT_API int notification_system_setting_set_dnd_allow_exceptions(notification
}
list = g_list_first(system_setting->dnd_allow_exceptions);
+ list = g_list_find_custom(list, (gconstpointer)type, (GCompareFunc)_dnd_allow_exception_compare);
- for (; list != NULL; list = list->next) {
+ if (list) {
dnd_allow_exception_data = (dnd_allow_exception_h)list->data;
- if (dnd_allow_exception_data->type == type) {
- dnd_allow_exception_data->value = value;
- return NOTIFICATION_ERROR_NONE;
- }
- }
-
- dnd_allow_exception_data = (dnd_allow_exception_h)malloc(sizeof(struct notification_system_setting_dnd_allow_exception));
- if (dnd_allow_exception_data == NULL)
- return NOTIFICATION_ERROR_OUT_OF_MEMORY;
-
- dnd_allow_exception_data->type = type;
- dnd_allow_exception_data->value = value;
+ dnd_allow_exception_data->value = value;
+ } else {
+ dnd_allow_exception_data = (dnd_allow_exception_h)malloc(sizeof(struct notification_system_setting_dnd_allow_exception));
+ if (dnd_allow_exception_data == NULL)
+ return NOTIFICATION_ERROR_OUT_OF_MEMORY;
- system_setting->dnd_allow_exceptions = g_list_append(system_setting->dnd_allow_exceptions, dnd_allow_exception_data);
+ dnd_allow_exception_data->type = type;
+ dnd_allow_exception_data->value = value;
+ system_setting->dnd_allow_exceptions = g_list_append(list, dnd_allow_exception_data);
+ }
return NOTIFICATION_ERROR_NONE;
}
diff --git a/src/notification_setting_service.c b/src/notification_setting_service.c
index 03a7d51..f5d7382 100644
--- a/src/notification_setting_service.c
+++ b/src/notification_setting_service.c
@@ -740,31 +740,47 @@ EXPORT_API int notification_system_setting_update_dnd_allow_exception(int type,
{
int ret = NOTIFICATION_ERROR_NONE;
int sqlret;
+ int field_index = 1;
sqlite3 *db = NULL;
- char *sqlbuf = NULL;
+ sqlite3_stmt *db_statement = NULL;
- sqlret = db_util_open(DBPATH, &db, 0);
- if (sqlret != SQLITE_OK || db == NULL) {
- NOTIFICATION_ERR("db_util_open failed [%s][%d]", DBPATH, sqlret);
- return NOTIFICATION_ERROR_FROM_DB;
- }
+ db = notification_db_open(DBPATH);
+ if (db == NULL)
+ return get_last_result();
- sqlbuf = sqlite3_mprintf("UPDATE dnd_allow_exception SET value = %d WHERE type = %d AND uid = %d", value, type, uid);
- if (!sqlbuf) {
- NOTIFICATION_ERR("fail to alloc query");
- ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
- goto return_close_db;
+ sqlite3_exec(db, "BEGIN immediate;", NULL, NULL, NULL);
+
+ sqlret = sqlite3_prepare_v2(db, "INSERT OR REPLACE INTO dnd_allow_exception (uid, type, value) VALUES(?, ?, ?) ", -1, &db_statement, NULL);
+
+ if (sqlret != SQLITE_OK) {
+ NOTIFICATION_ERR("sqlite3_prepare_v2 failed [%d][%s]", sqlret, sqlite3_errmsg(db));
+ ret = NOTIFICATION_ERROR_FROM_DB;
+ goto out;
}
- ret = notification_db_exec(db, sqlbuf, NULL);
+ sqlite3_bind_int(db_statement, field_index++, uid);
+ sqlite3_bind_int(db_statement, field_index++, type);
+ sqlite3_bind_int(db_statement, field_index++, value);
-return_close_db:
- if (sqlbuf)
- sqlite3_free(sqlbuf);
+ sqlret = sqlite3_step(db_statement);
+ if (sqlret != SQLITE_OK && sqlret != SQLITE_DONE) {
+ NOTIFICATION_ERR("sqlite3_step failed [%d][%s]", sqlret, sqlite3_errmsg(db));
+ ret = NOTIFICATION_ERROR_FROM_DB;
+ goto out;
+ }
- sqlret = db_util_close(db);
- if (sqlret != SQLITE_OK)
- NOTIFICATION_WARN("fail to db_util_close - [%d]", sqlret);
+ sqlret = sqlite3_changes(db);
+
+ if (sqlret == 0)
+ NOTIFICATION_WARN("No changes on DB");
+out:
+ if (db_statement)
+ sqlite3_finalize(db_statement);
+ if (ret == NOTIFICATION_ERROR_NONE)
+ sqlite3_exec(db, "END;", NULL, NULL, NULL);
+ else
+ sqlite3_exec(db, "ROLLBACK;", NULL, NULL, NULL);
+ notification_db_close(&db);
return ret;
}