summaryrefslogtreecommitdiff
path: root/src/notification_setting_service.c
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 /src/notification_setting_service.c
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
Diffstat (limited to 'src/notification_setting_service.c')
-rw-r--r--src/notification_setting_service.c52
1 files changed, 34 insertions, 18 deletions
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;
}