Refactor db code 52/134152/27
authorMyungki Lee <mk5004.lee@samsung.com>
Thu, 15 Jun 2017 04:16:37 +0000 (13:16 +0900)
committerMyungki Lee <mk5004.lee@samsung.com>
Thu, 6 Jul 2017 01:54:14 +0000 (10:54 +0900)
- noti_list, notification_setting, notification_system_setting

Change-Id: I5a9518d0f74eb8e2b48856d5bc25f1492e51e15a
Signed-off-by: Myungki Lee <mk5004.lee@samsung.com>
Signed-off-by: jusung son <jusung07.son@samsung.com>
CMakeLists.txt
include/notification_private.h
src/notification_db.c
src/notification_db_query.h [new file with mode: 0755]
src/notification_noti.c
src/notification_setting.c
src/notification_setting_service.c [changed mode: 0644->0755]

index a28eb0389c764c5ee8ab78233a8080efdc9bd7f9..9c84b72454cfe2e7164f106f00b19e38c075db6f 100755 (executable)
@@ -18,6 +18,7 @@ SET(SRCS
        ./src/notification_ongoing.c
        ./src/notification_group.c
        ./src/notification_db.c
+       ./src/notification_db_query.h
        ./src/notification_list.c
        ./src/notification_status.c
        ./src/notification_ipc.c
index 44cd62f56bf190a312356d2df901bb4a6be07336..b3e1185728922f1dc2747c0b3a375a56d060d4bb 100644 (file)
                }                       \
        } while (0)
 
-#define NOTIFICATION_SETTING_DB_TABLE "notification_setting"
-#define NOTIFICATION_SYSTEM_SETTING_DB_TABLE "notification_system_setting"
-#define NOTIFICATION_DND_ALLOW_EXCEPTION "dnd_allow_exception"
-
 struct _notification {
        notification_type_e type;
        notification_ly_type_e layout;
index 2bd1ddae7827a35750c20053ef2ef5f26215138c..c9ae09510d59b1ac6757817ab2457d229d032f92 100755 (executable)
 #include <notification_error.h>
 #include <notification_debug.h>
 #include <notification_db.h>
-
-#define NOTIFICATION_DB_NAME ".notification.db"
-#define CREATE_NOTIFICATION_TABLE " \
-PRAGMA journal_mode = PERSIST; \
-PRAGMA synchronous = FULL; \
-create table if not exists noti_list ( \
-                       type INTEGER NOT NULL, \
-                       layout INTEGER NOT NULL default 0, \
-                       pkg_id TEXT NOT NULL, \
-                       caller_app_id TEXT NOT NULL, \
-                       launch_app_id TEXT, \
-                       image_path TEXT, \
-                       group_id INTEGER default 0,  \
-                       internal_group_id INTEGER default 0,  \
-                       priv_id INTEGER PRIMARY KEY AUTOINCREMENT,  \
-                       title_key TEXT, \
-                       b_text TEXT, \
-                       b_key TEXT, \
-                       tag TEXT, \
-                       b_format_args TEXT, \
-                       num_format_args INTEGER default 0, \
-                       text_domain TEXT, \
-                       text_dir TEXT, \
-                       time INTEGER default 0, \
-                       insert_time INTEGER default 0, \
-                       args TEXT, \
-                       group_args TEXT, \
-                       b_execute_option TEXT, \
-                       b_service_responding TEXT, \
-                       b_service_single_launch TEXT, \
-                       b_service_multi_launch TEXT, \
-                       b_event_handler_click_on_button_1 TEXT, \
-                       b_event_handler_click_on_button_2 TEXT, \
-                       b_event_handler_click_on_button_3 TEXT, \
-                       b_event_handler_click_on_button_4 TEXT, \
-                       b_event_handler_click_on_button_5 TEXT, \
-                       b_event_handler_click_on_button_6 TEXT, \
-                       b_event_handler_click_on_icon TEXT, \
-                       b_event_handler_click_on_thumbnail TEXT, \
-                       b_event_handler_click_on_text_input_button TEXT, \
-                       sound_type INTEGER default 0, \
-                       sound_path TEXT, \
-                       vibration_type INTEGER default 0, \
-                       vibration_path TEXT, \
-                       led_operation INTEGER default 0, \
-                       led_argb INTEGER default 0, \
-                       led_on_ms INTEGER default -1, \
-                       led_off_ms INTEGER default -1, \
-                       flags_for_property INTEGER default 0, \
-                       flag_simmode INTEGER default 0, \
-                       display_applist INTEGER, \
-                       progress_size DOUBLE default 0, \
-                       progress_percentage DOUBLE default 0, \
-                       ongoing_flag INTEGER default 0, \
-                       ongoing_value_type INTEGER default 0, \
-                       ongoing_current INTEGER default 0, \
-                       ongoing_duration INTEGER default 0, \
-                       auto_remove INTEGER default 1, \
-                       default_button_index INTEGER default 0, \
-                       hide_timeout INTEGER default 0, \
-                       delete_timeout INTEGER default 0, \
-                       text_input_max_length INTEGER default 0, \
-                       event_flag INTEGER default 0, \
-                       extension_image_size INTEGER default 0, \
-                       uid INTEGER \
-               ); \
-               create table if not exists noti_group_data ( \
-                       caller_app_id TEXT NOT NULL, \
-                       group_id INTEGER default 0, \
-                       badge INTEGER default 0, \
-                       title TEXT, \
-                       content TEXT, \
-                       loc_title TEXT, \
-                       loc_content TEXT, \
-                       count_display_title INTEGER, \
-                       count_display_content INTEGER, \
-                       rowid INTEGER PRIMARY KEY AUTOINCREMENT, \
-                       UNIQUE (caller_app_id, group_id) \
-               ); \
-               create table if not exists ongoing_list ( \
-                       caller_app_id TEXT NOT NULL, \
-                       launch_app_id TEXT, \
-                       icon_path TEXT, \
-                       group_id INTEGER default 0, \
-                       internal_group_id INTEGER default 0, \
-                       priv_id INTERGER NOT NULL, \
-                       title TEXT, \
-                       content TEXT, \
-                       default_content TEXT, \
-                       loc_title TEXT, \
-                       loc_content TEXT, \
-                       loc_default_content TEXT, \
-                       text_domain TEXT, \
-                       text_dir TEXT, \
-                       args TEXT, \
-                       group_args TEXT, \
-                       flag INTEGER default 0, \
-                       progress_size DOUBLE default 0, \
-                       progress_percentage DOUBLE default 0, \
-                       rowid INTEGER PRIMARY KEY AUTOINCREMENT, \
-                       UNIQUE (caller_app_id, priv_id) \
-               ); \
-               CREATE TABLE IF NOT EXISTS notification_setting ( \
-                       uid INTEGER, \
-                       package_name TEXT NOT NULL, \
-                       app_id TEXT NOT NULL, \
-                       allow_to_notify INTEGER DEFAULT 1, \
-                       do_not_disturb_except INTEGER DEFAULT 0, \
-                       visibility_class INTEGER DEFAULT 0, \
-                       pop_up_notification INTEGER DEFAULT 1, \
-                       lock_screen_content_level INTEGER DEFAULT 0, \
-                       app_disabled INTEGER DEFAULT 0, \
-                       UNIQUE (uid, package_name, app_id) \
-               ); \
-               CREATE TABLE IF NOT EXISTS notification_system_setting ( \
-                       uid INTEGER, \
-                       do_not_disturb INTEGER DEFAULT 0, \
-                       visibility_class INTEGER DEFAULT 0, \
-                       dnd_schedule_enabled INTEGER DEFAULT 0, \
-                       dnd_schedule_day INTEGER DEFAULT 62, \
-                       dnd_start_hour INTEGER DEFAULT 22, \
-                       dnd_start_min INTEGER DEFAULT 0, \
-                       dnd_end_hour INTEGER DEFAULT 8, \
-                       dnd_end_min INTEGER DEFAULT 0, \
-                       lock_screen_content_level INTEGER DEFAULT 0, \
-                       UNIQUE (uid) \
-               ); \
-               CREATE TABLE IF NOT EXISTS dnd_allow_exception ( \
-                       uid INTEGER, \
-                       type INTEGER DEFAULT 0, \
-                       value INTEGER DEFAULT 0, \
-                       UNIQUE (uid, type) \
-               ); \
-               CREATE TABLE IF NOT EXISTS noti_template ( \
-                       type INTEGER NOT NULL, \
-                       layout INTEGER NOT NULL default 0, \
-                       pkg_id TEXT NOT NULL, \
-                       caller_app_id TEXT NOT NULL, \
-                       launch_app_id TEXT, \
-                       image_path TEXT, \
-                       group_id INTEGER default 0,  \
-                       internal_group_id INTEGER default 0,  \
-                       priv_id INTEGER PRIMARY KEY AUTOINCREMENT,  \
-                       title_key TEXT, \
-                       b_text TEXT, \
-                       b_key TEXT, \
-                       tag TEXT, \
-                       b_format_args TEXT, \
-                       num_format_args INTEGER default 0, \
-                       text_domain TEXT, \
-                       text_dir TEXT, \
-                       time INTEGER default 0, \
-                       insert_time INTEGER default 0, \
-                       args TEXT, \
-                       group_args TEXT, \
-                       b_execute_option TEXT, \
-                       b_service_responding TEXT, \
-                       b_service_single_launch TEXT, \
-                       b_service_multi_launch TEXT, \
-                       b_event_handler_click_on_button_1 TEXT, \
-                       b_event_handler_click_on_button_2 TEXT, \
-                       b_event_handler_click_on_button_3 TEXT, \
-                       b_event_handler_click_on_button_4 TEXT, \
-                       b_event_handler_click_on_button_5 TEXT, \
-                       b_event_handler_click_on_button_6 TEXT, \
-                       b_event_handler_click_on_icon TEXT, \
-                       b_event_handler_click_on_thumbnail TEXT, \
-                       b_event_handler_click_on_text_input_button TEXT, \
-                       sound_type INTEGER default 0, \
-                       sound_path TEXT, \
-                       vibration_type INTEGER default 0, \
-                       vibration_path TEXT, \
-                       led_operation INTEGER default 0, \
-                       led_argb INTEGER default 0, \
-                       led_on_ms INTEGER default -1, \
-                       led_off_ms INTEGER default -1, \
-                       flags_for_property INTEGER default 0, \
-                       flag_simmode INTEGER default 0, \
-                       display_applist INTEGER, \
-                       progress_size DOUBLE default 0, \
-                       progress_percentage DOUBLE default 0, \
-                       ongoing_flag INTEGER default 0, \
-                       ongoing_value_type INTEGER default 0, \
-                       ongoing_current INTEGER default 0, \
-                       ongoing_duration INTEGER default 0, \
-                       auto_remove INTEGER default 1, \
-                       default_button_index INTEGER default 0, \
-                       hide_timeout INTEGER default 0, \
-                       delete_timeout INTEGER default 0, \
-                       text_input_max_length INTEGER default 0, \
-                       event_flag INTEGER default 0, \
-                       extension_image_size INTEGER default 0, \
-                       uid INTEGER, \
-                       template_name TEXT, \
-                       UNIQUE (caller_app_id, template_name) \
-               );"
-
+#include "notification_db_query.h"
 
 EXPORT_API int notification_db_init()
 {
@@ -309,44 +113,38 @@ int notification_db_close(sqlite3 **db)
 
 int notification_db_exec(sqlite3 *db, const char *query, int *num_changes)
 {
-       int ret = 0;
+       int ret = NOTIFICATION_ERROR_NONE;
        sqlite3_stmt *stmt = NULL;
 
-       if (db == NULL)
-               return NOTIFICATION_ERROR_INVALID_PARAMETER;
-
-       if (query == NULL)
+       if (db == NULL || query == NULL)
                return NOTIFICATION_ERROR_INVALID_PARAMETER;
 
        ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
        if (ret != SQLITE_OK) {
                /* LCOV_EXCL_START */
-               NOTIFICATION_ERR("DB err(%d) : %s", ret,
-                                sqlite3_errmsg(db));
+               NOTIFICATION_ERR("DB err(%d) : %s", ret, sqlite3_errmsg(db));
                return NOTIFICATION_ERROR_FROM_DB;
                /* LCOV_EXCL_STOP */
        }
 
-       if (stmt != NULL) {
-               ret = sqlite3_step(stmt);
-               if (ret == SQLITE_OK || ret == SQLITE_DONE) {
-                       if (num_changes != NULL)
-                               *num_changes = sqlite3_changes(db);
+       ret = sqlite3_step(stmt);
+       if (ret == SQLITE_OK || ret == SQLITE_DONE) {
+               if (num_changes != NULL)
+                       *num_changes = sqlite3_changes(db);
 
-                       sqlite3_finalize(stmt);
-               } else {
-                       /* LCOV_EXCL_START */
-                       NOTIFICATION_ERR("DB err(%d) : %s", ret,
-                                        sqlite3_errmsg(db));
-                       sqlite3_finalize(stmt);
-                       return NOTIFICATION_ERROR_FROM_DB;
-                       /* LCOV_EXCL_STOP */
-               }
+               ret = NOTIFICATION_ERROR_NONE;
        } else {
-                       return NOTIFICATION_ERROR_FROM_DB;
+               /* LCOV_EXCL_START */
+               NOTIFICATION_ERR("DB err(%d) : %s", ret,
+                                sqlite3_errmsg(db));
+               ret = NOTIFICATION_ERROR_FROM_DB;
+               /* LCOV_EXCL_STOP */
        }
 
-       return NOTIFICATION_ERROR_NONE;
+       if (stmt)
+               sqlite3_finalize(stmt);
+
+       return ret;
 }
 
 char *notification_db_column_text(sqlite3_stmt * stmt, int col)
diff --git a/src/notification_db_query.h b/src/notification_db_query.h
new file mode 100755 (executable)
index 0000000..5067fad
--- /dev/null
@@ -0,0 +1,339 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define NOTIFICATION_DB_NAME ".notification.db"
+#define NOTIFICATION_SETTING_DB_TABLE "notification_setting"
+#define NOTIFICATION_SYSTEM_SETTING_DB_TABLE "notification_system_setting"
+#define NOTIFICATION_DND_ALLOW_EXCEPTION "dnd_allow_exception"
+
+#define CREATE_NOTIFICATION_TABLE "\
+PRAGMA journal_mode = PERSIST; \
+PRAGMA synchronous = FULL; \
+CREATE TABLE IF NOT EXISTS noti_list ( \
+       type INTEGER NOT NULL, \
+       layout INTEGER NOT NULL DEFAULT 0, \
+       pkg_id TEXT NOT NULL, \
+       caller_app_id TEXT NOT NULL, \
+       launch_app_id TEXT, \
+       image_path TEXT, \
+       group_id INTEGER DEFAULT 0,  \
+       internal_group_id INTEGER DEFAULT 0, \
+       priv_id INTEGER PRIMARY KEY AUTOINCREMENT, \
+       title_key TEXT, \
+       b_text TEXT, \
+       b_key TEXT, \
+       tag TEXT, \
+       b_format_args TEXT, \
+       num_format_args INTEGER DEFAULT 0, \
+       text_domain TEXT, \
+       text_dir TEXT, \
+       time INTEGER DEFAULT 0, \
+       insert_time INTEGER DEFAULT 0, \
+       args TEXT, \
+       group_args TEXT, \
+       b_execute_option TEXT, \
+       b_service_responding TEXT, \
+       b_service_single_launch TEXT, \
+       b_service_multi_launch TEXT, \
+       b_event_handler_click_on_button_1 TEXT, \
+       b_event_handler_click_on_button_2 TEXT, \
+       b_event_handler_click_on_button_3 TEXT, \
+       b_event_handler_click_on_button_4 TEXT, \
+       b_event_handler_click_on_button_5 TEXT, \
+       b_event_handler_click_on_button_6 TEXT, \
+       b_event_handler_click_on_icon TEXT, \
+       b_event_handler_click_on_thumbnail TEXT, \
+       b_event_handler_click_on_text_input_button TEXT, \
+       sound_type INTEGER DEFAULT 0, \
+       sound_path TEXT, \
+       vibration_type INTEGER DEFAULT 0, \
+       vibration_path TEXT, \
+       led_operation INTEGER DEFAULT 0, \
+       led_argb INTEGER DEFAULT 0, \
+       led_on_ms INTEGER DEFAULT -1, \
+       led_off_ms INTEGER DEFAULT -1, \
+       flags_for_property INTEGER DEFAULT 0, \
+       flag_simmode INTEGER DEFAULT 0, \
+       display_applist INTEGER, \
+       progress_size DOUBLE DEFAULT 0, \
+       progress_percentage DOUBLE DEFAULT 0, \
+       ongoing_flag INTEGER DEFAULT 0, \
+       ongoing_value_type INTEGER DEFAULT 0, \
+       ongoing_current INTEGER DEFAULT 0, \
+       ongoing_duration INTEGER DEFAULT 0, \
+       auto_remove INTEGER DEFAULT 1, \
+       default_button_index INTEGER DEFAULT 0, \
+       hide_timeout INTEGER DEFAULT 0, \
+       delete_timeout INTEGER DEFAULT 0, \
+       text_input_max_length INTEGER DEFAULT 0, \
+       event_flag INTEGER DEFAULT 0, \
+       extension_image_size INTEGER DEFAULT 0, \
+       uid INTEGER \
+); \
+CREATE TABLE IF NOT EXISTS noti_group_data ( \
+       caller_app_id TEXT NOT NULL, \
+       group_id INTEGER DEFAULT 0, \
+       badge INTEGER DEFAULT 0, \
+       title TEXT, \
+       content TEXT, \
+       loc_title TEXT, \
+       loc_content TEXT, \
+       count_display_title INTEGER, \
+       count_display_content INTEGER, \
+       rowid INTEGER PRIMARY KEY AUTOINCREMENT, \
+       UNIQUE (caller_app_id, group_id) \
+); \
+CREATE TABLE IF NOT EXISTS ongoing_list ( \
+       caller_app_id TEXT NOT NULL, \
+       launch_app_id TEXT, \
+       icon_path TEXT, \
+       group_id INTEGER DEFAULT 0, \
+       internal_group_id INTEGER DEFAULT 0, \
+       priv_id INTERGER NOT NULL, \
+       title TEXT, \
+       content TEXT, \
+       default_content TEXT, \
+       loc_title TEXT, \
+       loc_content TEXT, \
+       loc_default_content TEXT, \
+       text_domain TEXT, \
+       text_dir TEXT, \
+       args TEXT, \
+       group_args TEXT, \
+       flag INTEGER DEFAULT 0, \
+       progress_size DOUBLE DEFAULT 0, \
+       progress_percentage DOUBLE DEFAULT 0, \
+       rowid INTEGER PRIMARY KEY AUTOINCREMENT, \
+       UNIQUE (caller_app_id, priv_id) \
+); \
+CREATE TABLE IF NOT EXISTS notification_setting ( \
+       uid INTEGER, \
+       package_name TEXT NOT NULL, \
+       app_id TEXT NOT NULL, \
+       allow_to_notify INTEGER DEFAULT 1, \
+       do_not_disturb_except INTEGER DEFAULT 0, \
+       visibility_class INTEGER DEFAULT 0, \
+       pop_up_notification INTEGER DEFAULT 1, \
+       lock_screen_content_level INTEGER DEFAULT 0, \
+       app_disabled INTEGER DEFAULT 0, \
+       UNIQUE (uid, package_name, app_id) \
+); \
+CREATE TABLE IF NOT EXISTS notification_system_setting ( \
+       uid INTEGER, \
+       do_not_disturb INTEGER DEFAULT 0, \
+       visibility_class INTEGER DEFAULT 0, \
+       dnd_schedule_enabled INTEGER DEFAULT 0, \
+       dnd_schedule_day INTEGER DEFAULT 62, \
+       dnd_start_hour INTEGER DEFAULT 22, \
+       dnd_start_min INTEGER DEFAULT 0, \
+       dnd_end_hour INTEGER DEFAULT 8, \
+       dnd_end_min INTEGER DEFAULT 0, \
+       lock_screen_content_level INTEGER DEFAULT 0, \
+       UNIQUE (uid) \
+); \
+CREATE TABLE IF NOT EXISTS dnd_allow_exception ( \
+       uid INTEGER, \
+       type INTEGER DEFAULT 0, \
+       value INTEGER DEFAULT 0, \
+       UNIQUE (uid, type) \
+); \
+CREATE TABLE IF NOT EXISTS noti_template ( \
+       type INTEGER NOT NULL, \
+       layout INTEGER NOT NULL DEFAULT 0, \
+       pkg_id TEXT NOT NULL, \
+       caller_app_id TEXT NOT NULL, \
+       launch_app_id TEXT, \
+       image_path TEXT, \
+       group_id INTEGER DEFAULT 0, \
+       internal_group_id INTEGER DEFAULT 0, \
+       priv_id INTEGER PRIMARY KEY AUTOINCREMENT, \
+       title_key TEXT, \
+       b_text TEXT, \
+       b_key TEXT, \
+       tag TEXT, \
+       b_format_args TEXT, \
+       num_format_args INTEGER DEFAULT 0, \
+       text_domain TEXT, \
+       text_dir TEXT, \
+       time INTEGER DEFAULT 0, \
+       insert_time INTEGER DEFAULT 0, \
+       args TEXT, \
+       group_args TEXT, \
+       b_execute_option TEXT, \
+       b_service_responding TEXT, \
+       b_service_single_launch TEXT, \
+       b_service_multi_launch TEXT, \
+       b_event_handler_click_on_button_1 TEXT, \
+       b_event_handler_click_on_button_2 TEXT, \
+       b_event_handler_click_on_button_3 TEXT, \
+       b_event_handler_click_on_button_4 TEXT, \
+       b_event_handler_click_on_button_5 TEXT, \
+       b_event_handler_click_on_button_6 TEXT, \
+       b_event_handler_click_on_icon TEXT, \
+       b_event_handler_click_on_thumbnail TEXT, \
+       b_event_handler_click_on_text_input_button TEXT, \
+       sound_type INTEGER DEFAULT 0, \
+       sound_path TEXT, \
+       vibration_type INTEGER DEFAULT 0, \
+       vibration_path TEXT, \
+       led_operation INTEGER DEFAULT 0, \
+       led_argb INTEGER DEFAULT 0, \
+       led_on_ms INTEGER DEFAULT -1, \
+       led_off_ms INTEGER DEFAULT -1, \
+       flags_for_property INTEGER DEFAULT 0, \
+       flag_simmode INTEGER DEFAULT 0, \
+       display_applist INTEGER, \
+       progress_size DOUBLE DEFAULT 0, \
+       progress_percentage DOUBLE DEFAULT 0, \
+       ongoing_flag INTEGER DEFAULT 0, \
+       ongoing_value_type INTEGER DEFAULT 0, \
+       ongoing_current INTEGER DEFAULT 0, \
+       ongoing_duration INTEGER DEFAULT 0, \
+       auto_remove INTEGER DEFAULT 1, \
+       default_button_index INTEGER DEFAULT 0, \
+       hide_timeout INTEGER DEFAULT 0, \
+       delete_timeout INTEGER DEFAULT 0, \
+       text_input_max_length INTEGER DEFAULT 0, \
+       event_flag INTEGER DEFAULT 0, \
+       extension_image_size INTEGER DEFAULT 0, \
+       uid INTEGER, \
+       template_name TEXT, \
+       UNIQUE (caller_app_id, template_name) \
+);"
+
+#define NOTI_LIST_DB_ATTRIBUTES_SELECT \
+       "type, layout, pkg_id, caller_app_id, launch_app_id, image_path, " \
+       "group_id, priv_id, b_text, b_key, " \
+       "tag, b_format_args, num_format_args, text_domain, text_dir, " \
+       "time, insert_time, args, group_args, b_execute_option, " \
+       "b_service_responding, b_service_single_launch, b_service_multi_launch, " \
+       "b_event_handler_click_on_button_1, b_event_handler_click_on_button_2, " \
+       "b_event_handler_click_on_button_3, b_event_handler_click_on_button_4, " \
+       "b_event_handler_click_on_button_5, b_event_handler_click_on_button_6, " \
+       "b_event_handler_click_on_icon, b_event_handler_click_on_thumbnail, " \
+       "b_event_handler_click_on_text_input_button, " \
+       "sound_type, sound_path, vibration_type, vibration_path, " \
+       "led_operation, led_argb, led_on_ms, led_off_ms, " \
+       "flags_for_property, display_applist, " \
+       "progress_size, progress_percentage, ongoing_flag, ongoing_value_type, "\
+       "ongoing_current, ongoing_duration, auto_remove, default_button_index, "\
+       "hide_timeout, delete_timeout, text_input_max_length, event_flag, "\
+       "extension_image_size, uid"
+
+#define NOTI_LIST_DB_ATTRIBUTES_INSERT \
+       "type, layout, pkg_id, caller_app_id, launch_app_id, image_path, " \
+       "group_id, internal_group_id, title_key, b_text, b_key, " \
+       "tag, b_format_args, num_format_args, text_domain, text_dir, " \
+       "time, insert_time, args, group_args, b_execute_option, " \
+       "b_service_responding, b_service_single_launch, b_service_multi_launch, " \
+       "b_event_handler_click_on_button_1, b_event_handler_click_on_button_2, " \
+       "b_event_handler_click_on_button_3, b_event_handler_click_on_button_4, " \
+       "b_event_handler_click_on_button_5, b_event_handler_click_on_button_6, " \
+       "b_event_handler_click_on_icon, b_event_handler_click_on_thumbnail, " \
+       "b_event_handler_click_on_text_input_button, " \
+       "sound_type, sound_path, vibration_type, vibration_path, " \
+       "led_operation, led_argb, led_on_ms, led_off_ms, " \
+       "flags_for_property, flag_simmode, display_applist, " \
+       "progress_size, progress_percentage, ongoing_flag, ongoing_value_type, " \
+       "ongoing_current, ongoing_duration, auto_remove, default_button_index, " \
+       "hide_timeout, delete_timeout, text_input_max_length, event_flag, " \
+       "extension_image_size, uid"
+
+#define NOTI_LIST_INSERT_VALUES \
+       "?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, " \
+       "?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, " \
+       "?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?"
+
+#define NOTI_LIST_DB_ATTRIBUTES_UPDATE \
+       "type = ?, layout = ?, launch_app_id = ?, image_path = ?, " \
+       "b_text = ?, b_key = ?, tag = ?, b_format_args = ?, " \
+       "num_format_args = ?, text_domain = ?, text_dir = ?, time = ?, " \
+       "insert_time = ?, args = ?, group_args = ?, " \
+       "b_execute_option = ?, b_service_responding = ?, " \
+       "b_service_single_launch = ?, b_service_multi_launch = ?, " \
+       "b_event_handler_click_on_button_1 = ?, " \
+       "b_event_handler_click_on_button_2 = ?, " \
+       "b_event_handler_click_on_button_3 = ?, " \
+       "b_event_handler_click_on_button_4 = ?, " \
+       "b_event_handler_click_on_button_5 = ?, " \
+       "b_event_handler_click_on_button_6 = ?, " \
+       "b_event_handler_click_on_icon = ?, " \
+       "b_event_handler_click_on_thumbnail = ?, " \
+       "b_event_handler_click_on_text_input_button = ?, " \
+       "sound_type = ?, sound_path = ?, " \
+       "vibration_type = ?, vibration_path = ?, " \
+       "led_operation = ?, led_argb = ?, led_on_ms = ?, led_off_ms = ?, " \
+       "flags_for_property = ?, flag_simmode = ?, display_applist = ?, " \
+       "progress_size = ?, progress_percentage = ?, " \
+       "ongoing_flag = ?, ongoing_value_type = ?, " \
+       "ongoing_current = ?, ongoing_duration = ?, " \
+       "auto_remove = ?, default_button_index = ?, " \
+       "hide_timeout = ?, delete_timeout = ?, " \
+       "text_input_max_length = ?, event_flag = ?, extension_image_size = ?"
+
+#define NOTIFICATION_SETTING_DB_ATTRIBUTES \
+       "package_name, app_id, allow_to_notify, do_not_disturb_except, "\
+       "visibility_class, pop_up_notification, lock_screen_content_level, "\
+       "app_disabled"
+
+#define NOTIFICATION_SYSTEM_SETTING_DB_ATTRIBUTES \
+       "do_not_disturb, visibility_class, dnd_schedule_enabled, " \
+       "dnd_schedule_day, dnd_start_hour, dnd_start_min, dnd_end_hour, " \
+       "dnd_end_min, lock_screen_content_level"
+
+#define __BIND_TEXT(db, stmt, i, text, ret, label) \
+do { \
+       ret = sqlite3_bind_text(stmt, i, text, -1, SQLITE_TRANSIENT); \
+       if (ret != SQLITE_OK) { \
+               NOTIFICATION_ERR("bind error(index %d): [%d][%s]", i, ret, \
+                               sqlite3_errmsg(db)); \
+               ret = NOTIFICATION_ERROR_FROM_DB; \
+               goto label; \
+       } \
+} while (0)
+
+#define __BIND_TEXT_STATIC(db, stmt, i, text, ret, label) \
+do { \
+       ret = sqlite3_bind_text(stmt, i, text, -1, SQLITE_STATIC); \
+       if (ret != SQLITE_OK) { \
+               NOTIFICATION_ERR("bind error(index %d): [%d][%s]", i, ret, \
+                               sqlite3_errmsg(db)); \
+               ret = NOTIFICATION_ERROR_FROM_DB; \
+               goto label; \
+       } \
+} while (0)
+
+#define __BIND_INT(db, stmt, i, int, ret, label) \
+do { \
+       ret = sqlite3_bind_int(stmt, i, int); \
+       if (ret != SQLITE_OK) { \
+               NOTIFICATION_ERR("bind error(index %d): [%d][%s]", i, ret, \
+                               sqlite3_errmsg(db)); \
+               ret = NOTIFICATION_ERROR_FROM_DB; \
+               goto label; \
+       } \
+} while (0)
+
+#define __BIND_DOUBLE(db, stmt, i, double, ret, label) \
+do { \
+       ret = sqlite3_bind_double(stmt, i, double); \
+       if (ret != SQLITE_OK) { \
+               NOTIFICATION_ERR("bind error(index %d): [%d][%s]", i, ret, \
+                               sqlite3_errmsg(db)); \
+               ret = NOTIFICATION_ERROR_FROM_DB; \
+               goto label; \
+       } \
+} while (0)
index 49680701a45c957bc3491925bb957c410d324350..0d27fd3a1a5b198bf4cfdf2ee4205194ab09adbf 100755 (executable)
@@ -35,6 +35,7 @@
 #include <notification_setting.h>
 #include <notification_setting_internal.h>
 #include <notification_setting_service.h>
+#include "notification_db_query.h"
 
 #define NOTI_BURST_DELETE_UNIT 10
 #define ERR_BUFFER_SIZE                1024
@@ -49,69 +50,105 @@ static void __free_and_set(void **target_ptr, void *new_ptr)
        }
 }
 
-static int _notification_noti_bind_query_text(sqlite3_stmt *stmt, const char *name,
-                                        const char *str)
+static void __free_encoded_data(char *encoded_data)
 {
-       int ret = 0;
-       int index = 0;
+       if (encoded_data)
+               bundle_free_encoded_rawdata((bundle_raw **)&encoded_data);
+}
 
-       index = sqlite3_bind_parameter_index(stmt, name);
-       if (index == 0) {
-               NOTIFICATION_ERR("Insert : invalid column name");
-               return NOTIFICATION_ERROR_FROM_DB;
-       }
+static void __notification_noti_populate_from_stmt(sqlite3_stmt *stmt, notification_h noti)
+{
+       int col = 0;
+       int i = 0;
 
-       ret = sqlite3_bind_text(stmt, index, NOTIFICATION_CHECK_STR(str), -1,
-                             SQLITE_STATIC);
-       if (ret != SQLITE_OK) {
-               NOTIFICATION_ERR("Insert text : %s",
-                                NOTIFICATION_CHECK_STR(str));
-               return NOTIFICATION_ERROR_FROM_DB;
-       }
+       if (stmt == NULL || noti == NULL)
+               return ;
 
-       return NOTIFICATION_ERROR_NONE;
-}
+       noti->type = sqlite3_column_int(stmt, col++);
+       noti->layout = sqlite3_column_int(stmt, col++);
+       __free_and_set((void **)&(noti->pkg_id), notification_db_column_text(stmt, col++));
+       __free_and_set((void **)&(noti->caller_app_id), notification_db_column_text(stmt, col++));
+       __free_and_set((void **)&(noti->launch_app_id), notification_db_column_text(stmt, col++));
+       noti->b_image_path = notification_db_column_bundle(stmt, col++);
+       noti->group_id = sqlite3_column_int(stmt, col++);
+       noti->internal_group_id = 0;
+       noti->priv_id = sqlite3_column_int(stmt, col++);
+       noti->b_text = notification_db_column_bundle(stmt, col++);
+       noti->b_key = notification_db_column_bundle(stmt, col++);
+       __free_and_set((void **)&(noti->tag), notification_db_column_text(stmt, col++));
+       noti->b_format_args = notification_db_column_bundle(stmt, col++);
+       noti->num_format_args = sqlite3_column_int(stmt, col++);
 
-static int _notification_noti_bind_query_double(sqlite3_stmt *stmt, const char *name,
-                                        double val)
-{
-       int ret = 0;
-       int index = 0;
+       __free_and_set((void **)&(noti->domain), notification_db_column_text(stmt, col++));
+       __free_and_set((void **)&(noti->dir), notification_db_column_text(stmt, col++));
+       noti->time = sqlite3_column_int(stmt, col++);
+       noti->insert_time = sqlite3_column_int(stmt, col++);
+       noti->args = notification_db_column_bundle(stmt, col++);
+       noti->group_args = notification_db_column_bundle(stmt, col++);
 
-       index = sqlite3_bind_parameter_index(stmt, name);
-       if (index == 0) {
-               NOTIFICATION_ERR("Insert : invalid column name");
-               return NOTIFICATION_ERROR_FROM_DB;
-       }
+       noti->b_execute_option = notification_db_column_bundle(stmt, col++);
+       noti->b_service_responding = notification_db_column_bundle(stmt, col++);
+       noti->b_service_single_launch =
+           notification_db_column_bundle(stmt, col++);
+       noti->b_service_multi_launch =
+           notification_db_column_bundle(stmt, col++);
 
-       ret = sqlite3_bind_double(stmt, index, val);
-       if (ret != SQLITE_OK) {
-               NOTIFICATION_ERR("Insert double : %f", val);
-               return NOTIFICATION_ERROR_FROM_DB;
-       }
+       for (i = 0; i <= NOTIFICATION_EVENT_TYPE_MAX; i++)
+               noti->b_event_handler[i] = notification_db_column_bundle(stmt, col++);
 
-       return NOTIFICATION_ERROR_NONE;
+       noti->sound_type = sqlite3_column_int(stmt, col++);
+       __free_and_set((void **)&(noti->sound_path), notification_db_column_text(stmt, col++));
+       noti->vibration_type = sqlite3_column_int(stmt, col++);
+       __free_and_set((void **)&(noti->vibration_path), notification_db_column_text(stmt, col++));
+       noti->led_operation = sqlite3_column_int(stmt, col++);
+       noti->led_argb = sqlite3_column_int(stmt, col++);
+       noti->led_on_ms = sqlite3_column_int(stmt, col++);
+       noti->led_off_ms = sqlite3_column_int(stmt, col++);
+
+       noti->flags_for_property = sqlite3_column_int(stmt, col++);
+       noti->display_applist = sqlite3_column_int(stmt, col++);
+       noti->progress_size = sqlite3_column_double(stmt, col++);
+       noti->progress_percentage = sqlite3_column_double(stmt, col++);
+
+       noti->ongoing_flag = sqlite3_column_int(stmt, col++);
+       noti->ongoing_value_type = sqlite3_column_int(stmt, col++);
+       noti->ongoing_current = sqlite3_column_int(stmt, col++);
+       noti->ongoing_duration = sqlite3_column_int(stmt, col++);
+       noti->auto_remove = sqlite3_column_int(stmt, col++);
+       noti->default_button_index = sqlite3_column_int(stmt, col++);
+       noti->hide_timeout = sqlite3_column_int(stmt, col++);
+       noti->delete_timeout = sqlite3_column_int(stmt, col++);
+       noti->text_input_max_length = sqlite3_column_int(stmt, col++);
+       noti->event_flag = sqlite3_column_int(stmt, col++);
+       noti->extension_image_size = sqlite3_column_int(stmt, col++);
+       noti->uid = sqlite3_column_int(stmt, col++);
+
+       noti->app_icon_path = NULL;
+       noti->app_name = NULL;
+       noti->temp_title = NULL;
+       noti->temp_content = NULL;
 }
 
 static int _notification_noti_check_priv_id(notification_h noti, sqlite3 *db)
 {
+       sqlite3_stmt *stmt = NULL;
+       char *query = NULL;
        int result = 0;
        int ret = NOTIFICATION_ERROR_NONE;
-       char *query = NULL;
-       sqlite3_stmt *stmt = NULL;
 
-       /* Make query to check priv_id exist */
-       query = sqlite3_mprintf("SELECT count(*) FROM noti_list WHERE caller_app_id = '%s' AND priv_id = %d",
-                noti->caller_app_id, noti->priv_id);
+       query = sqlite3_mprintf("SELECT count(*) FROM noti_list "
+                               "WHERE caller_app_id = %Q AND priv_id = %d",
+                               noti->caller_app_id, noti->priv_id);
        if (query == NULL) {
+               NOTIFICATION_ERR("fail to alloc query"); /* LCOV_EXCL_LINE */
                ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
                goto err;
        }
 
-       ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
+       ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
        if (ret != SQLITE_OK) {
-               NOTIFICATION_ERR("Get count DB err(%d) : %s", ret,
-                                sqlite3_errmsg(db));
+               NOTIFICATION_ERR("sqlite3_prepare_v2 failed [%d][%s]", ret,
+                               sqlite3_errmsg(db));
                ret = NOTIFICATION_ERROR_FROM_DB;
                goto err;
        }
@@ -122,13 +159,14 @@ static int _notification_noti_check_priv_id(notification_h noti, sqlite3 *db)
        else
                result = 0;
 
-       sqlite3_finalize(stmt);
-
        /* If result > 0, there is priv_id in DB */
        if (result > 0)
                ret = NOTIFICATION_ERROR_ALREADY_EXIST_ID;
 
 err:
+       if (stmt)
+               sqlite3_finalize(stmt);
+
        if (query)
                sqlite3_free(query);
 
@@ -136,24 +174,27 @@ err:
 }
 
 static int _notification_noti_get_internal_group_id_by_priv_id(const char *app_id,
-                                                              int priv_id,
-                                                              sqlite3 *db)
+                                                       int priv_id,
+                                                       sqlite3 *db)
 {
-       char *query = NULL;
        sqlite3_stmt *stmt = NULL;
-       int ret = NOTIFICATION_ERROR_NONE, result = 0;
+       char *query = NULL;
+       int ret = NOTIFICATION_ERROR_NONE;
+       int result = 0;
 
-       query = sqlite3_mprintf("SELECT internal_group_id FROM noti_list WHERE caller_app_id = '%s' AND priv_id = %d",
-                app_id, priv_id);
+       query = sqlite3_mprintf("SELECT internal_group_id FROM noti_list "
+                               "WHERE caller_app_id = %Q AND priv_id = %d",
+                               app_id, priv_id);
        if (query == NULL) {
+               NOTIFICATION_ERR("fail to alloc query"); /* LCOV_EXCL_LINE */
                ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
                goto err;
        }
 
-       ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
+       ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
        if (ret != SQLITE_OK) {
-               NOTIFICATION_ERR("Get count DB err(%d) : %s", ret,
-                                sqlite3_errmsg(db));
+               NOTIFICATION_ERR("sqlite3_prepare_v2 failed [%d][%s]", ret,
+                               sqlite3_errmsg(db));
                ret = NOTIFICATION_ERROR_FROM_DB;
                goto err;
        }
@@ -177,10 +218,13 @@ err:
        return result;
 }
 
-static int _insertion_query_create(notification_h noti, char **query)
+static int _create_insertion_query(sqlite3 *db, notification_h noti, sqlite3_stmt *stmt, int *index)
 {
-       int i = 0;
-       int b_encode_len = 0;
+       char buf_key[32] = { 0, };
+       char *title_key = NULL;
+       char *b_text = NULL;
+       char *b_key = NULL;
+       char *b_format_args = NULL;
        char *args = NULL;
        char *group_args = NULL;
        char *b_image_path = NULL;
@@ -189,237 +233,220 @@ static int _insertion_query_create(notification_h noti, char **query)
        char *b_service_single_launch = NULL;
        char *b_service_multi_launch = NULL;
        char *b_event_handler[NOTIFICATION_EVENT_TYPE_MAX+1] = { NULL , };
-       char *b_text = NULL;
-       char *b_key = NULL;
-       char *b_format_args = NULL;
        int flag_simmode = 0;
+       int idx = 1;
+       int i = 0;
+       int b_encode_len = 0;
+       int ret = NOTIFICATION_ERROR_NONE;
 
-       if (query == NULL)
+       if (noti == NULL || stmt == NULL)
                return NOTIFICATION_ERROR_INVALID_PARAMETER;
 
-       /* Decode bundle to insert DB */
+       if (noti->b_image_path)
+               bundle_encode(noti->b_image_path, (bundle_raw **)&b_image_path,
+                               &b_encode_len);
+
+       /* Get title key */
+       if (noti->b_key != NULL) {
+               snprintf(buf_key, sizeof(buf_key), "%d",
+                                       NOTIFICATION_TEXT_TYPE_TITLE);
+
+               bundle_get_str(noti->b_key, buf_key, &title_key);
+       }
+
+       if (title_key == NULL && noti->b_text != NULL) {
+               snprintf(buf_key, sizeof(buf_key), "%d",
+                                       NOTIFICATION_TEXT_TYPE_TITLE);
+
+               bundle_get_str(noti->b_text, buf_key, &title_key);
+       }
+
+       if (title_key == NULL)
+               title_key = noti->caller_app_id;
+
+       if (noti->b_text)
+               bundle_encode(noti->b_text, (bundle_raw **)&b_text, &b_encode_len);
+
+       if (noti->b_key)
+               bundle_encode(noti->b_key, (bundle_raw **)&b_key, &b_encode_len);
+
+       if (noti->b_format_args)
+               bundle_encode(noti->b_format_args,
+                       (bundle_raw **)&b_format_args, &b_encode_len);
+
        if (noti->args)
                bundle_encode(noti->args, (bundle_raw **)&args, &b_encode_len);
 
        if (noti->group_args)
                bundle_encode(noti->group_args, (bundle_raw **)&group_args,
-                             &b_encode_len);
+                       &b_encode_len);
 
        if (noti->b_execute_option)
                bundle_encode(noti->b_execute_option,
-                             (bundle_raw **)&b_execute_option, &b_encode_len);
+                       (bundle_raw **)&b_execute_option, &b_encode_len);
 
        if (noti->b_service_responding)
                bundle_encode(noti->b_service_responding,
-                             (bundle_raw **)&b_service_responding, &b_encode_len);
+                       (bundle_raw **)&b_service_responding, &b_encode_len);
 
        if (noti->b_service_single_launch)
                bundle_encode(noti->b_service_single_launch,
-                             (bundle_raw **)&b_service_single_launch, &b_encode_len);
+                       (bundle_raw **)&b_service_single_launch, &b_encode_len);
 
        if (noti->b_service_multi_launch)
                bundle_encode(noti->b_service_multi_launch,
-                             (bundle_raw **)&b_service_multi_launch, &b_encode_len);
+                       (bundle_raw **)&b_service_multi_launch, &b_encode_len);
 
 
        for (i = 0; i <= NOTIFICATION_EVENT_TYPE_MAX; i++) {
                if (noti->b_event_handler[i])
                        bundle_encode(noti->b_event_handler[i],
-                                       (bundle_raw **)&b_event_handler[i], &b_encode_len);
+                               (bundle_raw **)&b_event_handler[i], &b_encode_len);
        }
 
-       if (noti->b_text)
-               bundle_encode(noti->b_text, (bundle_raw **)&b_text, &b_encode_len);
-
-       if (noti->b_key)
-               bundle_encode(noti->b_key, (bundle_raw **)&b_key, &b_encode_len);
-
-       if (noti->b_format_args)
-               bundle_encode(noti->b_format_args,
-                             (bundle_raw **)&b_format_args, &b_encode_len);
-
-       if (noti->b_image_path)
-               bundle_encode(noti->b_image_path,
-                             (bundle_raw **)&b_image_path, &b_encode_len);
-
        /* Check only simmode property is enable */
        if (noti->flags_for_property & NOTIFICATION_PROP_DISPLAY_ONLY_SIMMODE)
                flag_simmode = 1;
 
-       *query = sqlite3_mprintf("INSERT INTO noti_list ("
-               "type, "
-               "layout, "
-               "pkg_id, caller_app_id, launch_app_id, "
-               "image_path, "
-               "group_id, internal_group_id,"
-               "title_key, "
-               "b_text, b_key, tag, b_format_args, num_format_args, "
-               "text_domain, text_dir, "
-               "time, insert_time, "
-               "args, group_args, "
-               "b_execute_option, "
-               "b_service_responding, b_service_single_launch, b_service_multi_launch, "
-               "b_event_handler_click_on_button_1, b_event_handler_click_on_button_2, b_event_handler_click_on_button_3, "
-               "b_event_handler_click_on_button_4, b_event_handler_click_on_button_5, b_event_handler_click_on_button_6, "
-               "b_event_handler_click_on_icon, b_event_handler_click_on_thumbnail, b_event_handler_click_on_text_input_button, "
-               "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, "
-               "flags_for_property, flag_simmode, display_applist, "
-               "progress_size, progress_percentage, "
-               "ongoing_flag, ongoing_value_type, ongoing_current, ongoing_duration, "
-               "auto_remove, default_button_index, hide_timeout, delete_timeout, "
-               "text_input_max_length, event_flag, extension_image_size, uid) values ("
-               "%d, "
-               "%d, "
-               "'%s', '%s', '%s', "
-               "'%s', "
-               "%d, %d,"
-               "$title_key, "
-               "'%s', '%s', $tag, '%s', %d, "
-               "'%s', '%s', "
-               "%d, %d, "
-               "'%s', '%s', "
-               "'%s', "
-               "'%s', '%s', '%s', "
-               "'%s', '%s', '%s', "
-               "'%s', '%s', '%s', "
-               "'%s', '%s', '%s', "
-               "%d, '%s', %d, '%s', %d, %d, %d, %d,"
-               "%d, %d, %d, "
-               "$progress_size, $progress_percentage, "
-               "%d, %d, %d, %d, %d,"
-               "%d, %d, %d, %d, %d, %d, %d)",
-               noti->type,
-               noti->layout,
-               NOTIFICATION_CHECK_STR(noti->pkg_id),
-               NOTIFICATION_CHECK_STR(noti->caller_app_id),
-               NOTIFICATION_CHECK_STR(noti->launch_app_id),
-               NOTIFICATION_CHECK_STR(b_image_path), noti->group_id,
-               noti->internal_group_id,
-               NOTIFICATION_CHECK_STR(b_text), NOTIFICATION_CHECK_STR(b_key),
-               NOTIFICATION_CHECK_STR(b_format_args), noti->num_format_args,
-               NOTIFICATION_CHECK_STR(noti->domain),
-               NOTIFICATION_CHECK_STR(noti->dir), (int)noti->time,
-               (int)noti->insert_time, NOTIFICATION_CHECK_STR(args),
-               NOTIFICATION_CHECK_STR(group_args),
-               NOTIFICATION_CHECK_STR(b_execute_option),
-               NOTIFICATION_CHECK_STR(b_service_responding),
-               NOTIFICATION_CHECK_STR(b_service_single_launch),
-               NOTIFICATION_CHECK_STR(b_service_multi_launch),
-               NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1]),
-               NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_2]),
-               NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_3]),
-               NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_4]),
-               NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_5]),
-               NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_6]),
-               NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_ICON]),
-               NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_THUMBNAIL]),
-               NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_TEXT_INPUT_BUTTON]),
-               noti->sound_type, NOTIFICATION_CHECK_STR(noti->sound_path),
-               noti->vibration_type,
-               NOTIFICATION_CHECK_STR(noti->vibration_path),
-               noti->led_operation,
-               noti->led_argb,
-               noti->led_on_ms,
-               noti->led_off_ms,
-               noti->flags_for_property, flag_simmode, noti->display_applist,
-               noti->ongoing_flag,
-               noti->ongoing_value_type,
-               noti->ongoing_current,
-               noti->ongoing_duration,
-               noti->auto_remove,
-               noti->default_button_index,
-               noti->hide_timeout,
-               noti->delete_timeout,
-               noti->text_input_max_length,
-               noti->event_flag,
-               noti->extension_image_size,
-               noti->uid);
-
-       /* Free decoded data */
-       if (args)
-               free(args);
-
-       if (group_args)
-               free(group_args);
-
-       if (b_execute_option)
-               free(b_execute_option);
-
-       if (b_service_responding)
-               free(b_service_responding);
-
-       if (b_service_single_launch)
-               free(b_service_single_launch);
-
-       if (b_service_multi_launch)
-               free(b_service_multi_launch);
-
-       for (i = 0; i <= NOTIFICATION_EVENT_TYPE_MAX; i++) {
-               if (b_event_handler[i])
-                       bundle_free_encoded_rawdata((bundle_raw **)&b_event_handler[i]);
-       }
+       __BIND_INT(db, stmt, idx++, noti->type, ret, out);
+       __BIND_INT(db, stmt, idx++, noti->layout, ret, out);
+       __BIND_TEXT(db, stmt, idx++, NOTIFICATION_CHECK_STR(noti->pkg_id), ret, out);
+       __BIND_TEXT(db, stmt, idx++, NOTIFICATION_CHECK_STR(noti->caller_app_id), ret, out);
+       __BIND_TEXT(db, stmt, idx++, NOTIFICATION_CHECK_STR(noti->launch_app_id), ret, out);
+       __BIND_TEXT(db, stmt, idx++, NOTIFICATION_CHECK_STR(b_image_path), ret, out);
+       __BIND_INT(db, stmt, idx++, noti->group_id, ret, out);
+       __BIND_INT(db, stmt, idx++, noti->internal_group_id, ret, out);
+       __BIND_TEXT_STATIC(db, stmt, idx++, NOTIFICATION_CHECK_STR(title_key), ret, out);
+       __BIND_TEXT(db, stmt, idx++, NOTIFICATION_CHECK_STR(b_text), ret, out);
+       __BIND_TEXT(db, stmt, idx++, NOTIFICATION_CHECK_STR(b_key), ret, out);
+       __BIND_TEXT_STATIC(db, stmt, idx++, NOTIFICATION_CHECK_STR(noti->tag), ret, out);
+       __BIND_TEXT(db, stmt, idx++, NOTIFICATION_CHECK_STR(b_format_args), ret, out);
+       __BIND_INT(db, stmt, idx++, noti->num_format_args, ret, out);
+       __BIND_TEXT(db, stmt, idx++, NOTIFICATION_CHECK_STR(noti->domain), ret, out);
+       __BIND_TEXT(db, stmt, idx++, NOTIFICATION_CHECK_STR(noti->dir), ret, out);
+       __BIND_INT(db, stmt, idx++, (int)noti->time, ret, out);
+       __BIND_INT(db, stmt, idx++, (int)noti->insert_time, ret, out);
+       __BIND_TEXT(db, stmt, idx++, NOTIFICATION_CHECK_STR(args), ret, out);
+       __BIND_TEXT(db, stmt, idx++, NOTIFICATION_CHECK_STR(group_args), ret, out);
+       __BIND_TEXT(db, stmt, idx++, NOTIFICATION_CHECK_STR(b_execute_option), ret, out);
+       __BIND_TEXT(db, stmt, idx++, NOTIFICATION_CHECK_STR(b_service_responding), ret, out);
+       __BIND_TEXT(db, stmt, idx++, NOTIFICATION_CHECK_STR(b_service_single_launch), ret, out);
+       __BIND_TEXT(db, stmt, idx++, NOTIFICATION_CHECK_STR(b_service_multi_launch), ret, out);
+       __BIND_TEXT(db, stmt, idx++, NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1]), ret, out);
+       __BIND_TEXT(db, stmt, idx++, NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_2]), ret, out);
+       __BIND_TEXT(db, stmt, idx++, NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_3]), ret, out);
+       __BIND_TEXT(db, stmt, idx++, NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_4]), ret, out);
+       __BIND_TEXT(db, stmt, idx++, NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_5]), ret, out);
+       __BIND_TEXT(db, stmt, idx++, NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_6]), ret, out);
+       __BIND_TEXT(db, stmt, idx++, NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_ICON]), ret, out);
+       __BIND_TEXT(db, stmt, idx++, NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_THUMBNAIL]), ret, out);
+       __BIND_TEXT(db, stmt, idx++, NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_TEXT_INPUT_BUTTON]), ret, out);
+       __BIND_INT(db, stmt, idx++, noti->sound_type, ret, out);
+       __BIND_TEXT(db, stmt, idx++, NOTIFICATION_CHECK_STR(noti->sound_path), ret, out);
+       __BIND_INT(db, stmt, idx++, noti->vibration_type, ret, out);
+       __BIND_TEXT(db, stmt, idx++, NOTIFICATION_CHECK_STR(noti->vibration_path), ret, out);
+       __BIND_INT(db, stmt, idx++, noti->led_operation, ret, out);
+       __BIND_INT(db, stmt, idx++, noti->led_argb, ret, out);
+       __BIND_INT(db, stmt, idx++, noti->led_on_ms, ret, out);
+       __BIND_INT(db, stmt, idx++, noti->led_off_ms, ret, out);
+       __BIND_INT(db, stmt, idx++, noti->flags_for_property, ret, out);
+       __BIND_INT(db, stmt, idx++, flag_simmode, ret, out);
+       __BIND_INT(db, stmt, idx++, noti->display_applist, ret, out);
+       __BIND_DOUBLE(db, stmt, idx++, noti->progress_size, ret, out);
+       __BIND_DOUBLE(db, stmt, idx++, noti->progress_percentage, ret, out);
+       __BIND_INT(db, stmt, idx++, noti->ongoing_flag, ret, out);
+       __BIND_INT(db, stmt, idx++, noti->ongoing_value_type, ret, out);
+       __BIND_INT(db, stmt, idx++, noti->ongoing_current, ret, out);
+       __BIND_INT(db, stmt, idx++, noti->ongoing_duration, ret, out);
+       __BIND_INT(db, stmt, idx++, noti->auto_remove, ret, out);
+       __BIND_INT(db, stmt, idx++, noti->default_button_index, ret, out);
+       __BIND_INT(db, stmt, idx++, noti->hide_timeout, ret, out);
+       __BIND_INT(db, stmt, idx++, noti->delete_timeout, ret, out);
+       __BIND_INT(db, stmt, idx++, noti->text_input_max_length, ret, out);
+       __BIND_INT(db, stmt, idx++, noti->event_flag, ret, out);
+       __BIND_INT(db, stmt, idx++, noti->extension_image_size, ret, out);
+       __BIND_INT(db, stmt, idx++, noti->uid, ret, out);
 
-       if (b_text)
-               free(b_text);
-
-       if (b_key)
-               free(b_key);
-
-       if (b_format_args)
-               free(b_format_args);
+out:
+       __free_encoded_data(b_image_path);
+       __free_encoded_data(b_text);
+       __free_encoded_data(b_key);
+       __free_encoded_data(b_format_args);
+       __free_encoded_data(args);
+       __free_encoded_data(group_args);
+       __free_encoded_data(b_execute_option);
+       __free_encoded_data(b_service_responding);
+       __free_encoded_data(b_service_single_launch);
+       __free_encoded_data(b_service_multi_launch);
 
-       if (b_image_path)
-               free(b_image_path);
+       for (i = 0; i <= NOTIFICATION_EVENT_TYPE_MAX; i++)
+               __free_encoded_data(b_event_handler[i]);
 
-       if (*query == NULL)
-               return NOTIFICATION_ERROR_OUT_OF_MEMORY;
+       if (index != NULL && ret == NOTIFICATION_ERROR_NONE)
+               *index = idx;
 
-       return NOTIFICATION_ERROR_NONE;
+       return ret;
 }
 
-static int _update_query_create(notification_h noti, char **query)
+static int _create_update_query(sqlite3 *db, notification_h noti, sqlite3_stmt *stmt)
 {
-       int i = 0;
-       int b_encode_len = 0;
+       char *b_image_path = NULL;
+       char *b_text = NULL;
+       char *b_key = NULL;
+       char *b_format_args = NULL;
        char *args = NULL;
        char *group_args = NULL;
-       char *b_image_path = NULL;
        char *b_execute_option = NULL;
        char *b_service_responding = NULL;
        char *b_service_single_launch = NULL;
        char *b_service_multi_launch = NULL;
        char *b_event_handler[NOTIFICATION_EVENT_TYPE_MAX+1] = { NULL , };
-       char *b_text = NULL;
-       char *b_key = NULL;
-       char *b_format_args = NULL;
        int flag_simmode = 0;
+       int idx = 1;
+       int i = 0;
+       int b_encode_len = 0;
+       int ret = NOTIFICATION_ERROR_NONE;
 
-       if (query == NULL)
+       if (noti == NULL || stmt == NULL)
                return NOTIFICATION_ERROR_INVALID_PARAMETER;
 
        /* Decode bundle to update DB */
+       if (noti->b_image_path)
+               bundle_encode(noti->b_image_path,
+                       (bundle_raw **)&b_image_path, &b_encode_len);
+
+       if (noti->b_text)
+               bundle_encode(noti->b_text, (bundle_raw **)&b_text, &b_encode_len);
+
+       if (noti->b_key)
+               bundle_encode(noti->b_key, (bundle_raw **)&b_key, &b_encode_len);
+
+       if (noti->b_format_args)
+               bundle_encode(noti->b_format_args,
+                       (bundle_raw **)&b_format_args, &b_encode_len);
+
        if (noti->args)
                bundle_encode(noti->args, (bundle_raw **)&args, &b_encode_len);
 
        if (noti->group_args)
                bundle_encode(noti->group_args, (bundle_raw **)&group_args,
-                             &b_encode_len);
+                       &b_encode_len);
 
        if (noti->b_execute_option)
                bundle_encode(noti->b_execute_option,
-                             (bundle_raw **)&b_execute_option, &b_encode_len);
+                       (bundle_raw **)&b_execute_option, &b_encode_len);
 
        if (noti->b_service_responding)
                bundle_encode(noti->b_service_responding,
-                             (bundle_raw **)&b_service_responding, &b_encode_len);
+                       (bundle_raw **)&b_service_responding, &b_encode_len);
 
        if (noti->b_service_single_launch)
                bundle_encode(noti->b_service_single_launch,
-                             (bundle_raw **)&b_service_single_launch, &b_encode_len);
+                       (bundle_raw **)&b_service_single_launch, &b_encode_len);
 
        if (noti->b_service_multi_launch)
                bundle_encode(noti->b_service_multi_launch,
-                             (bundle_raw **)&b_service_multi_launch, &b_encode_len);
+                       (bundle_raw **)&b_service_multi_launch, &b_encode_len);
 
        for (i = 0; i <= NOTIFICATION_EVENT_TYPE_MAX; i++) {
                if (noti->b_event_handler[i])
@@ -427,224 +454,194 @@ static int _update_query_create(notification_h noti, char **query)
                                        (bundle_raw **)&b_event_handler[i], &b_encode_len);
        }
 
-       if (noti->b_text)
-               bundle_encode(noti->b_text, (bundle_raw **)&b_text, &b_encode_len);
+       /* Check only simmode property is enable */
+       if (noti->flags_for_property & NOTIFICATION_PROP_DISPLAY_ONLY_SIMMODE)
+               flag_simmode = 1;
 
-       if (noti->b_key)
-               bundle_encode(noti->b_key, (bundle_raw **)&b_key, &b_encode_len);
+       __BIND_INT(db, stmt, idx++, noti->type, ret, out);
+       __BIND_INT(db, stmt, idx++, noti->layout, ret, out);
+       __BIND_TEXT(db, stmt, idx++, NOTIFICATION_CHECK_STR(noti->launch_app_id), ret, out);
+       __BIND_TEXT(db, stmt, idx++, NOTIFICATION_CHECK_STR(b_image_path), ret, out);
+       __BIND_TEXT(db, stmt, idx++, NOTIFICATION_CHECK_STR(b_text), ret, out);
+       __BIND_TEXT(db, stmt, idx++, NOTIFICATION_CHECK_STR(b_key), ret, out);
+       __BIND_TEXT_STATIC(db, stmt, idx++, NOTIFICATION_CHECK_STR(noti->tag), ret, out);
+       __BIND_TEXT(db, stmt, idx++, NOTIFICATION_CHECK_STR(b_format_args), ret, out);
+       __BIND_INT(db, stmt, idx++, noti->num_format_args, ret, out);
+       __BIND_TEXT(db, stmt, idx++, NOTIFICATION_CHECK_STR(noti->domain), ret, out);
+       __BIND_TEXT(db, stmt, idx++, NOTIFICATION_CHECK_STR(noti->dir), ret, out);
+       __BIND_INT(db, stmt, idx++, (int)noti->time, ret, out);
+       __BIND_INT(db, stmt, idx++, (int)noti->insert_time, ret, out);
+       __BIND_TEXT(db, stmt, idx++, NOTIFICATION_CHECK_STR(args), ret, out);
+       __BIND_TEXT(db, stmt, idx++, NOTIFICATION_CHECK_STR(group_args), ret, out);
+       __BIND_TEXT(db, stmt, idx++, NOTIFICATION_CHECK_STR(b_execute_option), ret, out);
+       __BIND_TEXT(db, stmt, idx++, NOTIFICATION_CHECK_STR(b_service_responding), ret, out);
+       __BIND_TEXT(db, stmt, idx++, NOTIFICATION_CHECK_STR(b_service_single_launch), ret, out);
+       __BIND_TEXT(db, stmt, idx++, NOTIFICATION_CHECK_STR(b_service_multi_launch), ret, out);
+       __BIND_TEXT(db, stmt, idx++, NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1]), ret, out);
+       __BIND_TEXT(db, stmt, idx++, NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_2]), ret, out);
+       __BIND_TEXT(db, stmt, idx++, NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_3]), ret, out);
+       __BIND_TEXT(db, stmt, idx++, NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_4]), ret, out);
+       __BIND_TEXT(db, stmt, idx++, NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_5]), ret, out);
+       __BIND_TEXT(db, stmt, idx++, NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_6]), ret, out);
+       __BIND_TEXT(db, stmt, idx++, NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_ICON]), ret, out);
+       __BIND_TEXT(db, stmt, idx++, NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_THUMBNAIL]), ret, out);
+       __BIND_TEXT(db, stmt, idx++, NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_TEXT_INPUT_BUTTON]), ret, out);
+       __BIND_INT(db, stmt, idx++, noti->sound_type, ret, out);
+       __BIND_TEXT(db, stmt, idx++, NOTIFICATION_CHECK_STR(noti->sound_path), ret, out);
+       __BIND_INT(db, stmt, idx++, noti->vibration_type, ret, out);
+       __BIND_TEXT(db, stmt, idx++, NOTIFICATION_CHECK_STR(noti->vibration_path), ret, out);
+       __BIND_INT(db, stmt, idx++, noti->led_operation, ret, out);
+       __BIND_INT(db, stmt, idx++, noti->led_argb, ret, out);
+       __BIND_INT(db, stmt, idx++, noti->led_on_ms, ret, out);
+       __BIND_INT(db, stmt, idx++, noti->led_off_ms, ret, out);
+       __BIND_INT(db, stmt, idx++, noti->flags_for_property, ret, out);
+       __BIND_INT(db, stmt, idx++, flag_simmode, ret, out);
+       __BIND_INT(db, stmt, idx++, noti->display_applist, ret, out);
+       __BIND_DOUBLE(db, stmt, idx++, noti->progress_size, ret, out);
+       __BIND_DOUBLE(db, stmt, idx++, noti->progress_percentage, ret, out);
+       __BIND_INT(db, stmt, idx++, noti->ongoing_flag, ret, out);
+       __BIND_INT(db, stmt, idx++, noti->ongoing_value_type, ret, out);
+       __BIND_INT(db, stmt, idx++, noti->ongoing_current, ret, out);
+       __BIND_INT(db, stmt, idx++, noti->ongoing_duration, ret, out);
+       __BIND_INT(db, stmt, idx++, noti->auto_remove, ret, out);
+       __BIND_INT(db, stmt, idx++, noti->default_button_index, ret, out);
+       __BIND_INT(db, stmt, idx++, noti->hide_timeout, ret, out);
+       __BIND_INT(db, stmt, idx++, noti->delete_timeout, ret, out);
+       __BIND_INT(db, stmt, idx++, noti->text_input_max_length, ret, out);
+       __BIND_INT(db, stmt, idx++, noti->event_flag, ret, out);
+       __BIND_INT(db, stmt, idx++, noti->extension_image_size, ret, out);
 
-       if (noti->b_format_args)
-               bundle_encode(noti->b_format_args,
-                             (bundle_raw **)&b_format_args, &b_encode_len);
+out:
+       __free_encoded_data(b_image_path);
+       __free_encoded_data(b_text);
+       __free_encoded_data(b_key);
+       __free_encoded_data(b_format_args);
+       __free_encoded_data(args);
+       __free_encoded_data(group_args);
+       __free_encoded_data(b_execute_option);
+       __free_encoded_data(b_service_responding);
+       __free_encoded_data(b_service_single_launch);
+       __free_encoded_data(b_service_multi_launch);
 
-       if (noti->b_image_path)
-               bundle_encode(noti->b_image_path,
-                             (bundle_raw **)&b_image_path, &b_encode_len);
+       for (i = 0; i <= NOTIFICATION_EVENT_TYPE_MAX; i++)
+               __free_encoded_data(b_event_handler[i]);
 
-       /* Check only simmode property is enable */
-       if (noti->flags_for_property & NOTIFICATION_PROP_DISPLAY_ONLY_SIMMODE)
-               flag_simmode = 1;
+       return ret;
+}
 
-       *query = sqlite3_mprintf("UPDATE noti_list SET "
-               "type = %d, "
-               "layout = %d, "
-               "launch_app_id = '%s', "
-               "image_path = '%s', "
-               "b_text = '%s', b_key = '%s', tag = $tag, "
-               "b_format_args = '%s', num_format_args = %d, "
-               "text_domain = '%s', text_dir = '%s', "
-               "time = %d, insert_time = %d, "
-               "args = '%s', group_args = '%s', "
-               "b_execute_option = '%s', "
-               "b_service_responding = '%s', "
-               "b_service_single_launch = '%s', "
-               "b_service_multi_launch = '%s', "
-               "b_event_handler_click_on_button_1 = '%s', "
-               "b_event_handler_click_on_button_2= '%s', "
-               "b_event_handler_click_on_button_3= '%s', "
-               "b_event_handler_click_on_button_4= '%s', "
-               "b_event_handler_click_on_button_5= '%s', "
-               "b_event_handler_click_on_button_6= '%s', "
-               "b_event_handler_click_on_icon= '%s', "
-               "b_event_handler_click_on_thumbnail= '%s', "
-               "b_event_handler_click_on_text_input_button= '%s', "
-               "sound_type = %d, sound_path = '%s', "
-               "vibration_type = %d, vibration_path = '%s', "
-               "led_operation = %d, led_argb = %d, "
-               "led_on_ms = %d, led_off_ms = %d, "
-               "flags_for_property = %d, flag_simmode = %d, "
-               "display_applist = %d, "
-               "progress_size = $progress_size, progress_percentage = $progress_percentage, "
-               "ongoing_flag = %d, ongoing_value_type = %d, ongoing_current = %d, ongoing_duration = %d, "
-               "auto_remove = %d, default_button_index = %d, hide_timeout = %d, "
-               "delete_timeout = %d, text_input_max_length = %d, event_flag = %d, extension_image_size = %d "
-               "where priv_id = %d ",
-               noti->type,
-               noti->layout,
-               NOTIFICATION_CHECK_STR(noti->launch_app_id),
-               NOTIFICATION_CHECK_STR(b_image_path),
-               NOTIFICATION_CHECK_STR(b_text), NOTIFICATION_CHECK_STR(b_key),
-               NOTIFICATION_CHECK_STR(b_format_args), noti->num_format_args,
-               NOTIFICATION_CHECK_STR(noti->domain),
-               NOTIFICATION_CHECK_STR(noti->dir),
-               (int)noti->time, (int)noti->insert_time,
-               NOTIFICATION_CHECK_STR(args), NOTIFICATION_CHECK_STR(group_args),
-               NOTIFICATION_CHECK_STR(b_execute_option),
-               NOTIFICATION_CHECK_STR(b_service_responding),
-               NOTIFICATION_CHECK_STR(b_service_single_launch),
-               NOTIFICATION_CHECK_STR(b_service_multi_launch),
-               NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1]),
-               NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_2]),
-               NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_3]),
-               NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_4]),
-               NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_5]),
-               NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_6]),
-               NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_ICON]),
-               NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_THUMBNAIL]),
-               NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_TEXT_INPUT_BUTTON]),
-               noti->sound_type, NOTIFICATION_CHECK_STR(noti->sound_path),
-               noti->vibration_type,
-               NOTIFICATION_CHECK_STR(noti->vibration_path),
-               noti->led_operation,
-               noti->led_argb,
-               noti->led_on_ms,
-               noti->led_off_ms,
-               noti->flags_for_property, flag_simmode, noti->display_applist,
-               noti->ongoing_flag, noti->ongoing_value_type,
-               noti->ongoing_current, noti->ongoing_duration,
-               noti->auto_remove, noti->default_button_index, noti->hide_timeout,
-               noti->delete_timeout, noti->text_input_max_length, noti->event_flag,
-               noti->extension_image_size, noti->priv_id);
-
-       /* Free decoded data */
-       if (args)
-               free(args);
-
-       if (group_args)
-               free(group_args);
-
-       if (b_execute_option)
-               free(b_execute_option);
-
-       if (b_service_responding)
-               free(b_service_responding);
-
-       if (b_service_single_launch)
-               free(b_service_single_launch);
-
-       if (b_service_multi_launch)
-               free(b_service_multi_launch);
+static int _get_notification(char *query_where, notification_h noti)
+{
+       int ret;
+       char *query = NULL;
+       sqlite3 *db = NULL;
+       sqlite3_stmt *stmt = NULL;
 
-       for (i = 0; i <= NOTIFICATION_EVENT_TYPE_MAX; i++) {
-               if (b_event_handler[i])
-                       bundle_free_encoded_rawdata((bundle_raw **)&b_event_handler[i]);
-       }
+       if (query_where == NULL || noti == NULL)
+               return NOTIFICATION_ERROR_INVALID_PARAMETER;
 
-       if (b_text)
-               free(b_text);
+       db = notification_db_open(DBPATH);
+       if (!db)
+               return get_last_result();
 
-       if (b_key)
-               free(b_key);
+       query = sqlite3_mprintf("SELECT %s FROM %s",
+                               NOTI_LIST_DB_ATTRIBUTES_SELECT, query_where);
+       if (query == NULL) {
+               ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
+               goto err;
+       }
 
-       if (b_format_args)
-               free(b_format_args);
+       ret = sqlite3_prepare_v2(db, query, -1, &stmt, NULL);
+       if (ret != SQLITE_OK) {
+               NOTIFICATION_ERR("sqlite3_prepare_v2 failed [%d][%s]", ret,
+                               sqlite3_errmsg(db));
+               ret = NOTIFICATION_ERROR_FROM_DB;
+               goto err;
+       }
 
-       if (b_image_path)
-               free(b_image_path);
+       ret = sqlite3_step(stmt);
+       if (ret == SQLITE_ROW) {
+               __notification_noti_populate_from_stmt(stmt, noti);
+               ret = NOTIFICATION_ERROR_NONE;
+       } else {
+               ret = NOTIFICATION_ERROR_FROM_DB;
+       }
 
-       if (*query == NULL)
-               return NOTIFICATION_ERROR_OUT_OF_MEMORY;
+err:
+       if (stmt)
+               sqlite3_finalize(stmt);
 
-       return NOTIFICATION_ERROR_NONE;
+       if (db != NULL)
+               notification_db_close(&db);
+
+       return ret;
 }
 
-static void _notification_noti_populate_from_stmt(sqlite3_stmt *stmt, notification_h noti)
+static int _get_notification_list(char *query_where, notification_list_h *list, int count)
 {
-       int col = 0;
-       int i = 0;
-
-       if (stmt == NULL || noti == NULL)
-               return ;
-
-       noti->type = sqlite3_column_int(stmt, col++);
-       noti->layout = sqlite3_column_int(stmt, col++);
-       __free_and_set((void **)&(noti->pkg_id), notification_db_column_text(stmt, col++));
-       __free_and_set((void **)&(noti->caller_app_id), notification_db_column_text(stmt, col++));
-       __free_and_set((void **)&(noti->launch_app_id), notification_db_column_text(stmt, col++));
-       noti->b_image_path = notification_db_column_bundle(stmt, col++);
-       noti->group_id = sqlite3_column_int(stmt, col++);
-       noti->internal_group_id = 0;
-       noti->priv_id = sqlite3_column_int(stmt, col++);
-       __free_and_set((void **)&(noti->tag), notification_db_column_text(stmt, col++));
+       int ret;
+       int internal_count = 0;
+       char *query = NULL;
+       sqlite3 *db = NULL;
+       sqlite3_stmt *stmt = NULL;
+       notification_list_h get_list = NULL;
+       notification_h noti = NULL;
 
-       noti->b_text = notification_db_column_bundle(stmt, col++);
-       noti->b_key = notification_db_column_bundle(stmt, col++);
-       noti->b_format_args = notification_db_column_bundle(stmt, col++);
-       noti->num_format_args = sqlite3_column_int(stmt, col++);
+       if (query_where == NULL || list == NULL)
+               return NOTIFICATION_ERROR_INVALID_PARAMETER;
 
-       __free_and_set((void **)&(noti->domain), notification_db_column_text(stmt, col++));
-       __free_and_set((void **)&(noti->dir), notification_db_column_text(stmt, col++));
-       noti->time = sqlite3_column_int(stmt, col++);
-       noti->insert_time = sqlite3_column_int(stmt, col++);
-       noti->args = notification_db_column_bundle(stmt, col++);
-       noti->group_args = notification_db_column_bundle(stmt, col++);
+       db = notification_db_open(DBPATH);
+       if (!db)
+               return get_last_result();
 
-       noti->b_execute_option = notification_db_column_bundle(stmt, col++);
-       noti->b_service_responding = notification_db_column_bundle(stmt, col++);
-       noti->b_service_single_launch =
-           notification_db_column_bundle(stmt, col++);
-       noti->b_service_multi_launch =
-           notification_db_column_bundle(stmt, col++);
+       query = sqlite3_mprintf("SELECT %s FROM %s",
+                               NOTI_LIST_DB_ATTRIBUTES_SELECT, query_where);
+       if (query == NULL) {
+               ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
+               goto err;
+       }
 
-       for (i = 0; i <= NOTIFICATION_EVENT_TYPE_MAX; i++)
-               noti->b_event_handler[i] = notification_db_column_bundle(stmt, col++);
+       ret = sqlite3_prepare_v2(db, query, -1, &stmt, NULL);
+       if (ret != SQLITE_OK) {
+               NOTIFICATION_ERR("sqlite3_prepare_v2 failed [%d][%s]", ret,
+                               sqlite3_errmsg(db));
+               ret = NOTIFICATION_ERROR_FROM_DB;
+               goto err;
+       }
 
-       noti->sound_type = sqlite3_column_int(stmt, col++);
-       __free_and_set((void **)&(noti->sound_path), notification_db_column_text(stmt, col++));
-       noti->vibration_type = sqlite3_column_int(stmt, col++);
-       __free_and_set((void **)&(noti->vibration_path), notification_db_column_text(stmt, col++));
-       noti->led_operation = sqlite3_column_int(stmt, col++);
-       noti->led_argb = sqlite3_column_int(stmt, col++);
-       noti->led_on_ms = sqlite3_column_int(stmt, col++);
-       noti->led_off_ms = sqlite3_column_int(stmt, col++);
+       while (sqlite3_step(stmt) == SQLITE_ROW) {
+               noti = (notification_h)calloc(1, sizeof(struct _notification));
+               if (noti == NULL) {
+                       ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
+                       goto err;
+               }
 
-       noti->flags_for_property = sqlite3_column_int(stmt, col++);
-       noti->display_applist = sqlite3_column_int(stmt, col++);
-       noti->progress_size = sqlite3_column_double(stmt, col++);
-       noti->progress_percentage = sqlite3_column_double(stmt, col++);
+               __notification_noti_populate_from_stmt(stmt, noti);
+               if (noti != NULL) {
+                       internal_count++;
 
-       noti->ongoing_flag = sqlite3_column_int(stmt, col++);
-       noti->ongoing_value_type = sqlite3_column_int(stmt, col++);
-       noti->ongoing_current = sqlite3_column_int(stmt, col++);
-       noti->ongoing_duration = sqlite3_column_int(stmt, col++);
-       noti->auto_remove = sqlite3_column_int(stmt, col++);
-       noti->default_button_index = sqlite3_column_int(stmt, col++);
-       noti->hide_timeout = sqlite3_column_int(stmt, col++);
-       noti->delete_timeout = sqlite3_column_int(stmt, col++);
-       noti->text_input_max_length = sqlite3_column_int(stmt, col++);
-       noti->event_flag = sqlite3_column_int(stmt, col++);
-       noti->extension_image_size = sqlite3_column_int(stmt, col++);
-       noti->uid = sqlite3_column_int(stmt, col++);
+                       get_list = notification_list_append(get_list, noti);
 
-       noti->app_icon_path = NULL;
-       noti->app_name = NULL;
-       noti->temp_title = NULL;
-       noti->temp_content = NULL;
-}
+                       if (count != -1 && internal_count >= count) {
+                               NOTIFICATION_INFO
+                               ("internal count %d >= count %d",
+                               internal_count, count);
+                               break;
+                       }
+               }
+       }
 
-static notification_h _notification_noti_get_item(sqlite3_stmt *stmt)
-{
-       notification_h noti = NULL;
+err:
+       if (stmt)
+               sqlite3_finalize(stmt);
 
-       noti = (notification_h) calloc(1, sizeof(struct _notification));
-       if (noti == NULL)
-               return NULL;
+       if (db != NULL)
+               notification_db_close(&db);
 
-       _notification_noti_populate_from_stmt(stmt, noti);
+       if (get_list != NULL)
+               *list = notification_list_get_head(get_list);
 
-       return noti;
+       return ret;
 }
-
 int notification_noti_set_tag(const char *tag, char *value, char *buf, int buf_len)
 {
        int len_total = 0;
@@ -711,9 +708,9 @@ static int __get_setting_from_app_control(notification_h noti, notification_sett
        int ret;
 
        ret = notification_get_execute_option(noti,
-                               NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH,
-                               NULL,
-                               &b);
+                                       NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH,
+                                       NULL,
+                                       &b);
        if (ret != NOTIFICATION_ERROR_NONE || b == NULL) {
                NOTIFICATION_WARN("Can't get or no the excute option [%x]", ret);
                return NOTIFICATION_ERROR_INVALID_PARAMETER;
@@ -764,7 +761,8 @@ static bool _is_allowed_to_notify(notification_h noti)
        bool ret = true;
        int err;
 
-       err = noti_setting_service_get_setting_by_app_id(noti->caller_app_id, &setting, noti->uid);
+       err = noti_setting_service_get_setting_by_app_id(noti->caller_app_id,
+                                                       &setting, noti->uid);
        if (err != NOTIFICATION_ERROR_NONE) {
                err = __get_setting_from_app_control(noti, &setting);
                if (err != NOTIFICATION_ERROR_NONE)
@@ -813,7 +811,8 @@ static int _handle_do_not_disturb_option(notification_h noti)
                goto out;
        }
 
-       err = notification_system_setting_get_do_not_disturb(system_setting, &do_not_disturb);
+       err = notification_system_setting_get_do_not_disturb(system_setting,
+                                                       &do_not_disturb);
        if (err != NOTIFICATION_ERROR_NONE) {
                NOTIFICATION_ERR("_get_do_not_disturb failed [%d]", err);
                goto out;
@@ -838,7 +837,9 @@ static int _handle_do_not_disturb_option(notification_h noti)
                if (do_not_disturb_exception == false) {
                        /* do_not_disturb is ON and do_not_disturb_exception is OFF */
                        /* Then add this notification only on quick panel and indicator */
-                       noti->display_applist = noti->display_applist & (NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY | NOTIFICATION_DISPLAY_APP_INDICATOR);
+                       noti->display_applist = noti->display_applist &
+                                               (NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY |
+                                               NOTIFICATION_DISPLAY_APP_INDICATOR);
                        /* and reset all sound and vibration and led options */
                        noti->sound_type = NOTIFICATION_SOUND_TYPE_NONE;
                        SAFE_FREE(noti->sound_path);
@@ -904,264 +905,143 @@ static int _check_text_input(notification_h noti)
                }
        }
 
-       return NOTIFICATION_ERROR_NONE;
-}
-
-EXPORT_API int notification_noti_insert(notification_h noti)
-{
-       int ret = 0;
-       sqlite3 *db = NULL;
-       sqlite3_stmt *stmt = NULL;
-       char *query = NULL;
-       char buf_key[32] = { 0, };
-       char *title_key = NULL;
-
-       if (noti == NULL) {
-               NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
-               return NOTIFICATION_ERROR_INVALID_PARAMETER;
-       }
-
-       if (_is_allowed_to_notify(noti) == false) {
-               NOTIFICATION_DBG("[%s] is not allowed to notify", noti->caller_app_id);
-               return NOTIFICATION_ERROR_PERMISSION_DENIED;
-       }
-
-       if (_handle_do_not_disturb_option(noti) != NOTIFICATION_ERROR_NONE)
-               NOTIFICATION_WARN("_handle_do_not_disturb_option failed");
-
-       if (_is_pop_up_notification((const char *)noti->caller_app_id, noti->uid) == false) {
-               noti->display_applist = (noti->display_applist & (~NOTIFICATION_DISPLAY_APP_ACTIVE));
-               NOTIFICATION_DBG("notification display applist - app_id [%s], applist [%d]", noti->caller_app_id, noti->display_applist);
-       }
-
-       if (_check_text_input(noti) != NOTIFICATION_ERROR_NONE)
-               return NOTIFICATION_ERROR_INVALID_PARAMETER;
-
-       db = notification_db_open(DBPATH);
-       if (!db)
-               return get_last_result();
-
-       /* Initialize private ID */
-       noti->group_id = NOTIFICATION_GROUP_ID_NONE;
-       noti->internal_group_id = NOTIFICATION_GROUP_ID_NONE;
-
-       ret = _insertion_query_create(noti, &query);
-       if (ret != NOTIFICATION_ERROR_NONE)
-               goto err;
-
-       ret = sqlite3_prepare_v2(db, query, -1, &stmt, NULL);
-       if (ret != SQLITE_OK) {
-               NOTIFICATION_ERR("Insert Query : %s", query);
-               NOTIFICATION_ERR("Insert DB error(%d) : %s", ret,
-                                sqlite3_errmsg(db));
-               ret = NOTIFICATION_ERROR_FROM_DB;
-               goto err;
-       }
-
-       /* Get title key */
-       if (noti->b_key != NULL) {
-               snprintf(buf_key, sizeof(buf_key), "%d",
-                        NOTIFICATION_TEXT_TYPE_TITLE);
-
-               bundle_get_str(noti->b_key, buf_key, &title_key);
-       }
-
-       if (title_key == NULL && noti->b_text != NULL) {
-               snprintf(buf_key, sizeof(buf_key), "%d",
-                        NOTIFICATION_TEXT_TYPE_TITLE);
-
-               bundle_get_str(noti->b_text, buf_key, &title_key);
-       }
-
-       if (title_key == NULL)
-               title_key = noti->caller_app_id;
-
-       /* Bind query */
-       ret = _notification_noti_bind_query_text(stmt, "$tag", noti->tag);
-       if (ret != NOTIFICATION_ERROR_NONE) {
-               NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
-               goto err;
-       }
-       ret = _notification_noti_bind_query_text(stmt, "$title_key", title_key);
-       if (ret != NOTIFICATION_ERROR_NONE) {
-               NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
-               goto err;
-       }
-       ret = _notification_noti_bind_query_double(stmt, "$progress_size", noti->progress_size);
-       if (ret != NOTIFICATION_ERROR_NONE) {
-               NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
-               goto err;
-       }
-       ret = _notification_noti_bind_query_double(stmt, "$progress_percentage", noti->progress_percentage);
-       if (ret != NOTIFICATION_ERROR_NONE) {
-               NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
-               goto err;
-       }
-
-       ret = sqlite3_step(stmt);
-       if (ret == SQLITE_OK || ret == SQLITE_DONE) {
-               noti->priv_id = (int)sqlite3_last_insert_rowid(db);
-               ret = NOTIFICATION_ERROR_NONE;
-       } else {
-               ret = NOTIFICATION_ERROR_FROM_DB;
-       }
-
-err:
-       if (stmt)
-               sqlite3_finalize(stmt);
-
-       if (db)
-               notification_db_close(&db);
-
-       if (query)
-               sqlite3_free(query);
-
-       return ret;
+       return NOTIFICATION_ERROR_NONE;
 }
 
-/* LCOV_EXCL_START */
-EXPORT_API int notification_noti_get_by_priv_id(notification_h noti, int priv_id)
+EXPORT_API int notification_noti_insert(notification_h noti)
 {
        int ret = 0;
-       char *query = NULL;
        sqlite3 *db = NULL;
        sqlite3_stmt *stmt = NULL;
+       char *query = NULL;
 
-       if (priv_id < 0 || noti == NULL) {
-               ret = NOTIFICATION_ERROR_INVALID_PARAMETER;
-               goto err;
+       if (noti == NULL) {
+               NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
+               return NOTIFICATION_ERROR_INVALID_PARAMETER;
+       }
+
+       if (_is_allowed_to_notify(noti) == false) {
+               NOTIFICATION_DBG("[%s] is not allowed to notify", noti->caller_app_id);
+               return NOTIFICATION_ERROR_PERMISSION_DENIED;
        }
 
+       if (_handle_do_not_disturb_option(noti) != NOTIFICATION_ERROR_NONE)
+               NOTIFICATION_WARN("_handle_do_not_disturb_option failed");
+
+       if (_is_pop_up_notification((const char *)noti->caller_app_id, noti->uid) == false) {
+               noti->display_applist = (noti->display_applist & (~NOTIFICATION_DISPLAY_APP_ACTIVE));
+               NOTIFICATION_DBG("notification display applist - app_id [%s], applist [%d]",
+                               noti->caller_app_id, noti->display_applist);
+       }
+
+       if (_check_text_input(noti) != NOTIFICATION_ERROR_NONE)
+               return NOTIFICATION_ERROR_INVALID_PARAMETER;
+
+       /* Initialize private ID */
+       noti->group_id = NOTIFICATION_GROUP_ID_NONE;
+       noti->internal_group_id = NOTIFICATION_GROUP_ID_NONE;
+
        db = notification_db_open(DBPATH);
        if (!db)
                return get_last_result();
 
-       char *base_query = "select "
-                        "type, layout, pkg_id, caller_app_id, launch_app_id, image_path, group_id, priv_id, "
-                        "tag, b_text, b_key, b_format_args, num_format_args, "
-                        "text_domain, text_dir, time, insert_time, args, group_args, "
-                        "b_execute_option, b_service_responding, b_service_single_launch, b_service_multi_launch, "
-                        "b_event_handler_click_on_button_1, b_event_handler_click_on_button_2, b_event_handler_click_on_button_3, "
-                        "b_event_handler_click_on_button_4, b_event_handler_click_on_button_5, b_event_handler_click_on_button_6, "
-                        "b_event_handler_click_on_icon, b_event_handler_click_on_thumbnail, b_event_handler_click_on_text_input_button, "
-                        "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, "
-                        "flags_for_property, display_applist, progress_size, progress_percentage, ongoing_flag, ongoing_value_type, "
-                        "ongoing_current, ongoing_duration, auto_remove, default_button_index, hide_timeout, delete_timeout, "
-                        "text_input_max_length, event_flag, extension_image_size, uid "
-                        "from noti_list";
-
-       query = sqlite3_mprintf("%s where priv_id = %d", base_query, priv_id);
-
+       query = sqlite3_mprintf("INSERT INTO noti_list (%s) VALUES (%s)",
+                       NOTI_LIST_DB_ATTRIBUTES_INSERT, NOTI_LIST_INSERT_VALUES);
        if (query == NULL) {
+               NOTIFICATION_ERR("sqlite3_mprintf failed");
                ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
                goto err;
        }
 
        ret = sqlite3_prepare_v2(db, query, -1, &stmt, NULL);
        if (ret != SQLITE_OK) {
-               NOTIFICATION_ERR("select Query : %s", query);
-               NOTIFICATION_ERR("select DB error(%d) : %s", ret,
+               NOTIFICATION_ERR("sqlite3_prepare_v2 failed [%d][%s]", ret,
                                 sqlite3_errmsg(db));
                ret = NOTIFICATION_ERROR_FROM_DB;
                goto err;
        }
 
+       ret = _create_insertion_query(db, noti, stmt, NULL);
+       if (ret != NOTIFICATION_ERROR_NONE)
+               goto err;
+
        ret = sqlite3_step(stmt);
-       if (ret == SQLITE_ROW) {
-               _notification_noti_populate_from_stmt(stmt, noti);
+       if (ret == SQLITE_OK || ret == SQLITE_DONE) {
+               noti->priv_id = (int)sqlite3_last_insert_rowid(db);
                ret = NOTIFICATION_ERROR_NONE;
        } else {
                ret = NOTIFICATION_ERROR_FROM_DB;
        }
 
 err:
-       if (query)
-               sqlite3_free(query);
-
        if (stmt)
                sqlite3_finalize(stmt);
 
-       if (db != NULL)
+       if (query)
+               sqlite3_free(query);
+
+       if (db)
                notification_db_close(&db);
 
        return ret;
 }
-/* LCOV_EXCL_STOP */
 
-EXPORT_API int notification_noti_get_by_tag(notification_h noti, char *app_id, char *tag, uid_t uid)
+/* LCOV_EXCL_START */
+EXPORT_API int notification_noti_get_by_priv_id(notification_h noti, int priv_id)
 {
-       int ret = 0;
-       sqlite3 *db = NULL;
-       sqlite3_stmt *stmt = NULL;
+       int ret = NOTIFICATION_ERROR_NONE;
+       char *query_where = NULL;
 
-       if (tag == NULL || noti == NULL) {
+       if (priv_id < 0 || noti == NULL) {
                NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
                return NOTIFICATION_ERROR_INVALID_PARAMETER;
        }
 
-       db = notification_db_open(DBPATH);
-       if (!db)
-               return get_last_result();
-
-       ret = sqlite3_prepare_v2(db, "select "
-                "type, layout, pkg_id, caller_app_id, launch_app_id, image_path, group_id, priv_id, "
-                "tag, b_text, b_key, b_format_args, num_format_args, "
-                "text_domain, text_dir, time, insert_time, args, group_args, "
-                "b_execute_option, b_service_responding, b_service_single_launch, b_service_multi_launch, "
-                "b_event_handler_click_on_button_1, b_event_handler_click_on_button_2, b_event_handler_click_on_button_3, "
-                "b_event_handler_click_on_button_4, b_event_handler_click_on_button_5, b_event_handler_click_on_button_6, "
-                "b_event_handler_click_on_icon, b_event_handler_click_on_thumbnail, b_event_handler_click_on_text_input_button, "
-                "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, "
-                "flags_for_property, display_applist, progress_size, progress_percentage, ongoing_flag, ongoing_value_type, "
-                "ongoing_current, ongoing_duration, auto_remove, default_button_index, hide_timeout, delete_timeout, "
-                "text_input_max_length, event_flag, extension_image_size, uid "
-                "from noti_list where caller_app_id = ? and tag = ? and uid = ?", -1, &stmt, NULL);
-       if (ret != SQLITE_OK) {
-               NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
+       query_where = sqlite3_mprintf("noti_list WHERE priv_id = %d", priv_id);
+       if (query_where == NULL) {
                ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
                goto err;
        }
 
-       ret = sqlite3_bind_text(stmt, 1, app_id, -1, SQLITE_TRANSIENT);
-       if (ret != SQLITE_OK) {
-               NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
-               goto err;
-       }
+       ret = _get_notification(query_where, noti);
 
-       ret = sqlite3_bind_text(stmt, 2,  tag, -1, SQLITE_TRANSIENT);
-       if (ret != SQLITE_OK) {
-               NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
-               goto err;
+err:
+       if (query_where)
+               sqlite3_free(query_where);
+
+       return ret;
+}
+/* LCOV_EXCL_STOP */
+
+EXPORT_API int notification_noti_get_by_tag(notification_h noti, char *app_id, char *tag, uid_t uid)
+{
+       int ret = NOTIFICATION_ERROR_NONE;
+       char *query_where;
+
+       if (tag == NULL || noti == NULL) {
+               NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
+               return NOTIFICATION_ERROR_INVALID_PARAMETER;
        }
 
-       ret = sqlite3_bind_int(stmt, 3, uid);
-       if (ret != SQLITE_OK) {
-               NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
+       query_where = sqlite3_mprintf("noti_list WHERE caller_app_id = %Q "
+                       "AND tag = %Q AND uid = %d", app_id, tag, uid);
+       if (query_where == NULL) {
+               ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
                goto err;
        }
 
-       ret = sqlite3_step(stmt);
-       if (ret == SQLITE_ROW) {
-               _notification_noti_populate_from_stmt(stmt, noti);
-               ret = NOTIFICATION_ERROR_NONE;
-       } else {
-               ret = NOTIFICATION_ERROR_FROM_DB;
-       }
+       ret = _get_notification(query_where, noti);
 
 err:
-
-       if (stmt)
-               sqlite3_finalize(stmt);
-
-       if (db != NULL)
-               notification_db_close(&db);
+       if (query_where)
+               sqlite3_free(query_where);
 
        return ret;
 }
 
 EXPORT_API int notification_noti_update(notification_h noti)
 {
-       int ret = 0;
+       int ret = NOTIFICATION_ERROR_NONE;
        sqlite3 *db;
        sqlite3_stmt *stmt = NULL;
        char *query = NULL;
@@ -1181,7 +1061,8 @@ EXPORT_API int notification_noti_update(notification_h noti)
 
        if (_is_pop_up_notification((const char *)noti->caller_app_id, noti->uid) == false) {
                noti->display_applist = (noti->display_applist & (~NOTIFICATION_DISPLAY_APP_ACTIVE));
-               NOTIFICATION_DBG("notification display applist - app_id [%s], applist [%d]", noti->caller_app_id, noti->display_applist);
+               NOTIFICATION_DBG("notification display applist - app_id [%s], applist [%d]",
+                               noti->caller_app_id, noti->display_applist);
        }
 
        db = notification_db_open(DBPATH);
@@ -1191,41 +1072,29 @@ EXPORT_API int notification_noti_update(notification_h noti)
        /* Check private ID is exist */
        ret = _notification_noti_check_priv_id(noti, db);
        if (ret != NOTIFICATION_ERROR_ALREADY_EXIST_ID) {
+               NOTIFICATION_ERR("NOTIFICATION_ERROR_NOT_EXIST_ID");
                ret = NOTIFICATION_ERROR_NOT_EXIST_ID;
                goto err;
        }
 
-       /* make update query */
-       ret = _update_query_create(noti, &query);
-       if (ret != NOTIFICATION_ERROR_NONE)
+       query = sqlite3_mprintf("UPDATE noti_list SET %s WHERE priv_id = %d ",
+                               NOTI_LIST_DB_ATTRIBUTES_UPDATE, noti->priv_id);
+       if (query == NULL) {
+               ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
                goto err;
+       }
 
        ret = sqlite3_prepare_v2(db, query, -1, &stmt, NULL);
        if (ret != SQLITE_OK) {
-               NOTIFICATION_ERR("Insert Query : %s", query);
-               NOTIFICATION_ERR("Insert DB error(%d) : %s", ret,
+               NOTIFICATION_ERR("sqlite3_prepare_v2 failed [%d][%s]", ret,
                                 sqlite3_errmsg(db));
                ret = NOTIFICATION_ERROR_FROM_DB;
                goto err;
        }
 
-       ret = _notification_noti_bind_query_text(stmt, "$tag", noti->tag);
-       if (ret != NOTIFICATION_ERROR_NONE) {
-               NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
-               goto err;
-       }
-
-       ret = _notification_noti_bind_query_double(stmt, "$progress_size", noti->progress_size);
-       if (ret != NOTIFICATION_ERROR_NONE) {
-               NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
-               goto err;
-       }
-
-       ret = _notification_noti_bind_query_double(stmt, "$progress_percentage", noti->progress_percentage);
-       if (ret != NOTIFICATION_ERROR_NONE) {
-               NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
+       ret = _create_update_query(db, noti, stmt);
+       if (ret != NOTIFICATION_ERROR_NONE)
                goto err;
-       }
 
        ret = sqlite3_step(stmt);
        if (ret == SQLITE_OK || ret == SQLITE_DONE)
@@ -1237,45 +1106,63 @@ err:
        if (stmt)
                sqlite3_finalize(stmt);
 
-       if (db)
-               notification_db_close(&db);
-
        if (query)
                sqlite3_free(query);
 
+       if (db)
+               notification_db_close(&db);
+
        return ret;
 }
 
-EXPORT_API int notification_noti_delete_all(notification_type_e type, const char *app_id, int *num_deleted, int **list_deleted_rowid, uid_t uid)
+EXPORT_API int notification_noti_delete_all(notification_type_e type,
+                                       const char *app_id, int *num_deleted,
+                                       int **list_deleted_rowid, uid_t uid)
 {
-       int ret = NOTIFICATION_ERROR_NONE;
-       int ret_tmp = NOTIFICATION_ERROR_NONE;
-       int i = 0;
-       int data_cnt = 0;
        sqlite3 *db = NULL;
        sqlite3_stmt *stmt = NULL;
        char buf[128] = { 0, };
-       char query[NOTIFICATION_QUERY_MAX] = { 0, };
-       char query_base[NOTIFICATION_QUERY_MAX] = { 0, };
-       char query_where[NOTIFICATION_QUERY_MAX] = { 0, };
+       char *query = NULL;
+       char *query_base = NULL;
+       char *query_where = NULL;
        char err_buf[ERR_BUFFER_SIZE];
+       int ret = NOTIFICATION_ERROR_NONE;
+       int ret_tmp = NOTIFICATION_ERROR_NONE;
+       int i = 0;
+       int data_cnt = 0;
 
        db = notification_db_open(DBPATH);
        if (!db)
                return get_last_result();
 
+       query_base = sqlite3_mprintf("DELETE FROM noti_list");
+       if (query_base == NULL) {
+               ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
+               goto err;
+       }
+
        if (app_id == NULL || strlen(app_id) == 0) {
-               if (type != NOTIFICATION_TYPE_NONE)
-                       snprintf(query_where, sizeof(query_where),
-                                "where type = %d and uid = %d", type, uid);
+               if (type != NOTIFICATION_TYPE_NONE) {
+                       query_where = sqlite3_mprintf("WHERE type = %d "
+                                               "AND uid = %d", type, uid);
+                       if (query_where == NULL) {
+                               ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
+                               goto err;
+                       }
+               }
        } else {
                if (type == NOTIFICATION_TYPE_NONE)
-                       snprintf(query_where, sizeof(query_where),
-                                "where caller_app_id = '%s' and uid = %d", app_id, uid);
+                       query_where = sqlite3_mprintf("WHERE caller_app_id = %Q "
+                                               "AND uid = %d", app_id, uid);
                else
-                       snprintf(query_where, sizeof(query_where),
-                                "where caller_app_id = '%s' and type = %d and uid = %d",
-                                app_id, type, uid);
+                       query_where = sqlite3_mprintf("WHERE caller_app_id = %Q "
+                                               "AND type = %d AND uid = %d",
+                                               app_id, type, uid);
+
+               if (query_where == NULL) {
+                       ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
+                       goto err;
+               }
        }
 
        if (num_deleted != NULL)
@@ -1283,12 +1170,15 @@ EXPORT_API int notification_noti_delete_all(notification_type_e type, const char
 
        if (list_deleted_rowid != NULL) {
                *list_deleted_rowid = NULL;
-               snprintf(query, sizeof(query),
-                               "select priv_id from noti_list %s ", query_where);
 
-               ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
+               query = sqlite3_mprintf("SELECT priv_id FROM noti_list %s ", query_where);
+               if (query == NULL) {
+                       ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
+                       goto err;
+               }
+
+               ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
                if (ret != SQLITE_OK) {
-                       NOTIFICATION_ERR("Select Query : %s", query);
                        NOTIFICATION_ERR("Select DB error(%d) : %s", ret,
                                         sqlite3_errmsg(db));
 
@@ -1319,27 +1209,36 @@ EXPORT_API int notification_noti_delete_all(notification_type_e type, const char
                        data_cnt++;
                }
 
-               if (stmt) {
-                       sqlite3_finalize(stmt);
-                       stmt = NULL;
-               }
-
                if (data_cnt > 0) {
                        query_where[0] = '\0';
-                       snprintf(query_base, sizeof(query_base) - 1, "delete from noti_list");
+
                        for (i = 0; i < data_cnt ; i++) {
                                if (i % NOTI_BURST_DELETE_UNIT == 0 && i != 0) {
-                                       snprintf(query, sizeof(query) - 1, "%s where priv_id in (%s)", query_base, query_where);
+                                       query = sqlite3_mprintf("%s WHERE priv_id in (%s)", query_base, query_where);
+                                       if (query == NULL) {
+                                               ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
+                                               goto err;
+                                       }
                                        ret_tmp = notification_db_exec(db, query, NULL);
                                        query_where[0] = '\0';
                                        if (ret == NOTIFICATION_ERROR_NONE)
                                                ret = ret_tmp;
                                }
                                snprintf(buf, sizeof(buf) - 1, "%s%d", (i % NOTI_BURST_DELETE_UNIT == 0) ? "" : ",", *((*list_deleted_rowid) + i));
-                               strncat(query_where, buf, sizeof(query_where) - strlen(query_where) - 1);
+                               query_where = sqlite3_mprintf("%s%s", query_where, buf);
+                               if (query_where == NULL) {
+                                       ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
+                                       goto err;
+                               }
                        }
+
                        if ((i <= NOTI_BURST_DELETE_UNIT) || ((i % NOTI_BURST_DELETE_UNIT) > 0)) {
-                               snprintf(query, sizeof(query) - 1, "%s where priv_id in (%s)", query_base, query_where);
+                               query = sqlite3_mprintf("%s WHERE priv_id in (%s)", query_base, query_where);
+                               if (query == NULL) {
+                                       ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
+                                       goto err;
+                               }
+
                                ret_tmp = notification_db_exec(db, query, NULL);
                                if (ret == NOTIFICATION_ERROR_NONE)
                                        ret = ret_tmp;
@@ -1353,19 +1252,28 @@ EXPORT_API int notification_noti_delete_all(notification_type_e type, const char
                        *num_deleted = data_cnt;
        } else {
                /* Make main query */
-               snprintf(query_base, sizeof(query_base), "delete from noti_list ");
-               snprintf(query, sizeof(query), "%s %s", query_base, query_where);
-
-               ret = notification_db_exec(db, query, NULL);
+               query = sqlite3_mprintf("%s %s", query_base, query_where);
+               if (query == NULL) {
+                       ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
+                       goto err;
+               }
 
-               if (num_deleted != NULL)
-                       *num_deleted = sqlite3_changes(db);
+               ret = notification_db_exec(db, query, num_deleted);
        }
 
 err:
        if (stmt)
                sqlite3_finalize(stmt);
 
+       if (query)
+               sqlite3_free(query);
+
+       if (query_base)
+               sqlite3_free(query_base);
+
+       if (query_where)
+               sqlite3_free(query_where);
+
        if (db)
                notification_db_close(&db);
 
@@ -1376,8 +1284,8 @@ err:
 EXPORT_API int notification_noti_delete_by_priv_id(const char *app_id, int priv_id)
 {
        sqlite3 *db = NULL;
-       char query[NOTIFICATION_QUERY_MAX] = { 0, };
-       int ret;
+       char *query = NULL;
+       int ret = NOTIFICATION_ERROR_NONE;
 
        if (app_id == NULL)
                return NOTIFICATION_ERROR_INVALID_PARAMETER;
@@ -1386,12 +1294,19 @@ EXPORT_API int notification_noti_delete_by_priv_id(const char *app_id, int priv_
        if (!db)
                return get_last_result();
 
-       snprintf(query, sizeof(query), "delete from noti_list "
-                "where caller_app_id = '%s' and priv_id = %d", app_id,
-                priv_id);
+       query = sqlite3_mprintf("DELETE FROM noti_list WHERE caller_app_id = %Q "
+                               "AND priv_id = %d", app_id, priv_id);
+       if (query == NULL) {
+               ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
+               goto err;
+       }
 
        ret = notification_db_exec(db, query, NULL);
 
+err:
+       if (query)
+               sqlite3_free(query);
+
        if (db)
                notification_db_close(&db);
 
@@ -1399,24 +1314,32 @@ EXPORT_API int notification_noti_delete_by_priv_id(const char *app_id, int priv_
 }
 /* LCOV_EXCL_STOP */
 
-EXPORT_API int notification_noti_delete_by_priv_id_get_changes(const char *app_id, int priv_id, int *num_changes, uid_t uid)
+EXPORT_API int notification_noti_delete_by_priv_id_get_changes(const char *app_id,
+                                                       int priv_id,
+                                                       int *num_changes,
+                                                       uid_t uid)
 {
        sqlite3 *db = NULL;
-       char query[NOTIFICATION_QUERY_MAX] = { 0, };
-       int ret;
+       char *query = NULL;
+       int ret = NOTIFICATION_ERROR_NONE;
 
        db = notification_db_open(DBPATH);
        if (!db)
                return get_last_result();
 
-       snprintf(query, sizeof(query), "delete from noti_list "
-               "where caller_app_id = '%s' and priv_id = %d and uid = %d",
-               app_id, priv_id, uid);
+       query = sqlite3_mprintf("DELETE FROM noti_list WHERE caller_app_id = %Q "
+                               "AND priv_id = %d AND uid = %d",
+                               app_id, priv_id, uid);
+       if (query == NULL) {
+               ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
+               goto err;
+       }
 
-       ret = notification_db_exec(db, query, num_changes);
+       ret = notification_db_exec(db, query, NULL);
 
-       if (num_changes != NULL)
-               NOTIFICATION_DBG("deleted num:%d", *num_changes);
+err:
+       if (query)
+               sqlite3_free(query);
 
        if (db)
                notification_db_close(&db);
@@ -1427,89 +1350,101 @@ EXPORT_API int notification_noti_delete_by_priv_id_get_changes(const char *app_i
 /* todo refactoring */
 /* LCOV_EXCL_START */
 EXPORT_API int notification_noti_get_count(notification_type_e type,
-                                                const char *app_id,
-                                                int group_id, int priv_id,
-                                                int *count, uid_t uid)
+                                       const char *app_id,
+                                       int group_id, int priv_id,
+                                       int *count, uid_t uid)
 {
        sqlite3 *db = NULL;
        sqlite3_stmt *stmt = NULL;
-       char query[NOTIFICATION_QUERY_MAX] = { 0, };
-       char query_base[NOTIFICATION_QUERY_MAX] = { 0, };
-       char query_where[NOTIFICATION_QUERY_MAX] = { 0, };
-       char query_where_more[NOTIFICATION_QUERY_MAX] = { 0, };
-
-       int ret = 0, get_count = 0, internal_group_id = 0;
+       char *query = NULL;
+       char *query_base = NULL;
+       char *query_where = NULL;
+       char *query_where_more = NULL;
+       int ret = NOTIFICATION_ERROR_NONE;
+       int get_count = 0;
+       int internal_group_id = 0;
        int status = VCONFKEY_TELEPHONY_SIM_UNKNOWN;
-       int flag_where_more = 0;
-       int ret_vconf = 0;
+
+       /* Check current sim status */
+       ret = vconf_get_int(VCONFKEY_TELEPHONY_SIM_SLOT, &status);
+       if (ret < 0)
+               return NOTIFICATION_ERROR_IO_ERROR;
 
        db = notification_db_open(DBPATH);
        if (!db)
                return get_last_result();
 
-       /* Check current sim status */
-       ret_vconf = vconf_get_int(VCONFKEY_TELEPHONY_SIM_SLOT, &status);
+       query_base = sqlite3_mprintf("SELECT count(*) FROM noti_list ");
+       if (query_base == NULL) {
+               ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
+               goto err;
+       }
 
-       snprintf(query_base, sizeof(query_base),
-                "select count(*) from noti_list ");
+       internal_group_id =
+               _notification_noti_get_internal_group_id_by_priv_id(app_id, priv_id, db);
 
        if (group_id == NOTIFICATION_GROUP_ID_NONE) {
-               if (priv_id == NOTIFICATION_PRIV_ID_NONE) {
-                       snprintf(query_where, sizeof(query_where),
-                                "where caller_app_id = '%s' and uid = %d ",
-                                app_id, uid);
-               } else {
-                       internal_group_id =
-                           _notification_noti_get_internal_group_id_by_priv_id
-                           (app_id, priv_id, db);
-                       snprintf(query_where, sizeof(query_where),
-                                "where caller_app_id = '%s' and internal_group_id = %d and uid = %d ",
-                                app_id, internal_group_id, uid);
-               }
+               if (priv_id == NOTIFICATION_PRIV_ID_NONE)
+                       query_where = sqlite3_mprintf("WHERE caller_app_id = %Q "
+                                       "AND uid = %d ", app_id, uid);
+               else
+                       query_where = sqlite3_mprintf("WHERE caller_app_id = %Q "
+                                       "AND internal_group_id = %d AND uid = %d ",
+                                       app_id, internal_group_id, uid);
        } else {
-               if (priv_id == NOTIFICATION_PRIV_ID_NONE) {
-                       snprintf(query_where, sizeof(query_where),
-                                "where caller_app_id = '%s' and group_id = %d and uid = %d ",
-                                app_id, group_id, uid);
-               } else {
-                       internal_group_id =
-                           _notification_noti_get_internal_group_id_by_priv_id
-                           (app_id, priv_id, db);
-                       snprintf(query_where, sizeof(query_where),
-                                "where caller_app_id = '%s' and internal_group_id = %d and uid = %d ",
-                                app_id, internal_group_id, uid);
-               }
+               if (priv_id == NOTIFICATION_PRIV_ID_NONE)
+                       query_where = sqlite3_mprintf("WHERE caller_app_id = %Q "
+                                       "AND group_id = %d AND uid = %d ",
+                                       app_id, group_id, uid);
+               else
+                       query_where = sqlite3_mprintf("WHERE caller_app_id = %Q "
+                                       "AND internal_group_id = %d AND uid = %d ",
+                                       app_id, internal_group_id, uid);
+       }
+
+       if (query_where == NULL) {
+               ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
+               goto err;
        }
 
-       if (ret_vconf == 0 && status == VCONFKEY_TELEPHONY_SIM_INSERTED) {
+       if (status == VCONFKEY_TELEPHONY_SIM_INSERTED) {
                if (type != NOTIFICATION_TYPE_NONE) {
-                       snprintf(query_where_more, sizeof(query_where_more),
-                                "type = %d ", type);
-                       flag_where_more = 1;
+                       query_where_more = sqlite3_mprintf("type = %d ", type);
+                       if (query_where_more == NULL) {
+                               ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
+                               goto err;
+                       }
                }
        } else {
-               if (type != NOTIFICATION_TYPE_NONE) {
-                       snprintf(query_where_more, sizeof(query_where_more),
-                                "type = %d and flag_simmode = 0 ", type);
-                       flag_where_more = 1;
-               } else {
-                       snprintf(query_where_more, sizeof(query_where_more),
-                                "flag_simmode = 0 ");
-                       flag_where_more = 1;
+               if (type != NOTIFICATION_TYPE_NONE)
+                       query_where_more = sqlite3_mprintf("type = %d AND "
+                                       "flag_simmode = 0 ", type);
+               else
+                       query_where_more = sqlite3_mprintf("flag_simmode = 0 ");
+
+               if (query_where_more == NULL) {
+                       ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
+                       goto err;
                }
        }
 
-       if (flag_where_more == 1) {
-               snprintf(query, sizeof(query), "%s %s and %s",
-                        query_base, query_where, query_where_more);
+       if (query_where_more) {
+               query = sqlite3_mprintf("%s %s AND %s", query_base, query_where,
+                               query_where_more);
+               if (query == NULL) {
+                       ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
+                       goto err;
+               }
        } else {
-               snprintf(query, sizeof(query), "%s %s", query_base,
-                        query_where);
+               query = sqlite3_mprintf("%s %s", query_base, query_where);
+               if (query == NULL) {
+                       ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
+                       goto err;
+               }
        }
 
-       ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
+       ret = sqlite3_prepare_v2(db, query, -1, &stmt, NULL);
        if (ret != SQLITE_OK) {
-               NOTIFICATION_ERR("Select Query : %s", query);
                NOTIFICATION_ERR("Select DB error(%d) : %s", ret,
                                 sqlite3_errmsg(db));
 
@@ -1527,6 +1462,18 @@ err:
        if (stmt)
                sqlite3_finalize(stmt);
 
+       if (query)
+               sqlite3_free(query);
+
+       if (query_base)
+               sqlite3_free(query_base);
+
+       if (query_where)
+               sqlite3_free(query_where);
+
+       if (query_where_more)
+               sqlite3_free(query_where_more);
+
        if (db)
                notification_db_close(&db);
 
@@ -1537,221 +1484,149 @@ err:
 /* LCOV_EXCL_STOP */
 
 EXPORT_API int notification_noti_get_grouping_list(notification_type_e type,
-                                                        int count,
-                                                        notification_list_h *list,
-                                                        uid_t uid)
+                                                       int count,
+                                                       notification_list_h *list,
+                                                       uid_t uid)
 {
-       sqlite3 *db = NULL;
-       sqlite3_stmt *stmt = NULL;
-       char query[NOTIFICATION_QUERY_MAX] = { 0, };
-       char query_base[NOTIFICATION_QUERY_MAX] = { 0, };
-       char query_uid[NOTIFICATION_QUERY_MAX] = { 0, };
-       char query_where[NOTIFICATION_QUERY_MAX] = { 0, };
-
-       int ret = 0;
-       notification_list_h get_list = NULL;
-       notification_h noti = NULL;
-       int internal_count = 0;
+       char *query = NULL;
+       char *query_uid = NULL;
+       char *query_where = NULL;
+       int ret = NOTIFICATION_ERROR_NONE;
        int status;
 
-       db = notification_db_open(DBPATH);
-       if (!db)
-               return get_last_result();
-
        /* Check current sim status */
        ret = vconf_get_int(VCONFKEY_TELEPHONY_SIM_SLOT, &status);
-
-       snprintf(query_base, sizeof(query_base), "select "
-                "type, layout, pkg_id, caller_app_id, launch_app_id, image_path, group_id, priv_id, "
-                "tag, b_text, b_key, b_format_args, num_format_args, "
-                "text_domain, text_dir, time, insert_time, args, group_args, "
-                "b_execute_option, b_service_responding, b_service_single_launch, b_service_multi_launch, "
-                "b_event_handler_click_on_button_1, b_event_handler_click_on_button_2, b_event_handler_click_on_button_3, "
-                "b_event_handler_click_on_button_4, b_event_handler_click_on_button_5, b_event_handler_click_on_button_6, "
-                "b_event_handler_click_on_icon, b_event_handler_click_on_thumbnail, b_event_handler_click_on_text_input_button, "
-                "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, "
-                "flags_for_property, display_applist, progress_size, progress_percentage, ongoing_flag, ongoing_value_type, "
-                "ongoing_current, ongoing_duration, auto_remove, default_button_index, hide_timeout, delete_timeout, "
-                "text_input_max_length, event_flag, extension_image_size, uid "
-                "from noti_list where 1 > 0 ");
+       if (ret < 0)
+               ret = NOTIFICATION_ERROR_IO_ERROR;
 
        if (status == VCONFKEY_TELEPHONY_SIM_INSERTED) {
-               if (type != NOTIFICATION_TYPE_NONE)
-                       snprintf(query_where, sizeof(query_where),
-                                " and type = %d ", type);
+               if (type != NOTIFICATION_TYPE_NONE) {
+                       query_where = sqlite3_mprintf(" AND type = %d ", type);
+                       if (query_where == NULL)
+                               return NOTIFICATION_ERROR_OUT_OF_MEMORY;
+               }
        } else {
                if (type != NOTIFICATION_TYPE_NONE)
-                       snprintf(query_where, sizeof(query_where),
-                                " and type = %d and flag_simmode = 0 ", type);
+                       query_where = sqlite3_mprintf(" AND type = %d AND "
+                                       "flag_simmode = 0 ", type);
                else
-                       snprintf(query_where, sizeof(query_where),
-                                " and flag_simmode = 0 ");
-       }
-
-       if (uid != NOTIFICATION_GLOBAL_UID)
-               snprintf(query_uid, sizeof(query_uid), " and uid = %d ", uid);
-
-       snprintf(query, sizeof(query),
-                "%s %s %s "
-                "order by rowid desc, time desc", query_base, query_where, query_uid);
-
-       ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
-       if (ret != SQLITE_OK) {
-               NOTIFICATION_ERR("Select Query : %s", query);
-               NOTIFICATION_ERR("Select DB error(%d) : %s", ret,
-                                sqlite3_errmsg(db));
+                       query_where = sqlite3_mprintf(" AND flag_simmode = 0 ");
 
-               ret = NOTIFICATION_ERROR_FROM_DB;
-               goto err;
+               if (query_where == NULL)
+                       return NOTIFICATION_ERROR_OUT_OF_MEMORY;
        }
-
-       while (sqlite3_step(stmt) == SQLITE_ROW) {
-               /* Make notification list */
-               noti = _notification_noti_get_item(stmt);
-               if (noti != NULL) {
-                       internal_count++;
-
-                       get_list = notification_list_append(get_list, noti);
-
-                       if (count != -1 && internal_count >= count) {
-                               NOTIFICATION_INFO
-                                   ("internal count %d >= count %d",
-                                    internal_count, count);
-                               break;
-                       }
+
+       if (uid != NOTIFICATION_GLOBAL_UID) {
+               query_uid = sqlite3_mprintf(" AND uid = %d ", uid);
+               if (query_uid == NULL) {
+                       ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
+                       goto err;
                }
        }
 
-       ret = NOTIFICATION_ERROR_NONE;
+       query = sqlite3_mprintf("noti_list WHERE 1 > 0 %s %s "
+                       "ORDER BY rowid DESC, time DESC", query_where, query_uid);
+       if (query == NULL) {
+               ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
+               goto err;
+       }
+
+       ret = _get_notification_list(query, list, count);
 
 err:
-       if (stmt)
-               sqlite3_finalize(stmt);
+       if (query_where)
+               sqlite3_free(query_where);
 
-       if (db)
-               notification_db_close(&db);
+       if (query_uid)
+               sqlite3_free(query_uid);
 
-       if (get_list != NULL)
-               *list = notification_list_get_head(get_list);
+       if (query)
+               sqlite3_free(query);
 
        return ret;
 }
 
 EXPORT_API int notification_noti_get_detail_list(const char *app_id,
-                                                      int group_id,
-                                                      int priv_id, int count,
-                                                      notification_list_h *list,
-                                                      uid_t uid)
+                                               int group_id,
+                                               int priv_id, int count,
+                                               notification_list_h *list,
+                                               uid_t uid)
 {
+       char *query_where = NULL;
+       char *query = NULL;
+       int ret = NOTIFICATION_ERROR_NONE;
+       int internal_group_id = 0;
+       int status = 0;
        sqlite3 *db = NULL;
-       sqlite3_stmt *stmt = NULL;
-       char query_base[NOTIFICATION_QUERY_MAX] = { 0, };
-       char query_where[NOTIFICATION_QUERY_MAX] = { 0, };
 
-       char query[NOTIFICATION_QUERY_MAX] = { 0, };
-       int ret = 0;
-       notification_list_h get_list = NULL;
-       notification_h noti = NULL;
-       int internal_count = 0;
-       int internal_group_id = 0;
-       int status = 0; /* If the vconf_get_int failed, the status will be the garbage value */
+       /* Check current sim status */
+       ret = vconf_get_int(VCONFKEY_TELEPHONY_SIM_SLOT, &status);
+       if (ret < 0)
+               return NOTIFICATION_ERROR_IO_ERROR;
 
        db = notification_db_open(DBPATH);
        if (!db)
                return get_last_result();
 
-       /* Check current sim status */
-       ret = vconf_get_int(VCONFKEY_TELEPHONY_SIM_SLOT, &status);
-
-       snprintf(query_base, sizeof(query_base), "select "
-                "type, layout, pkg_id, caller_app_id, launch_app_id, image_path, group_id, priv_id, "
-                "tag, b_text, b_key, b_format_args, num_format_args, "
-                "text_domain, text_dir, time, insert_time, args, group_args, "
-                "b_execute_option, b_service_responding, b_service_single_launch, b_service_multi_launch, "
-                "b_event_handler_click_on_button_1, b_event_handler_click_on_button_2, b_event_handler_click_on_button_3, "
-                "b_event_handler_click_on_button_4, b_event_handler_click_on_button_5, b_event_handler_click_on_button_6, "
-                "b_event_handler_click_on_icon, b_event_handler_click_on_thumbnail, b_event_handler_click_on_text_input_button, "
-                "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, "
-                "flags_for_property, display_applist, progress_size, progress_percentage, ongoing_flag, ongoing_value_type, "
-                "ongoing_current, ongoing_duration, auto_remove, default_button_index, hide_timeout, delete_timeout, "
-                "text_input_max_length, event_flag, extension_image_size, uid "
-                "from noti_list ");
-
-       if (priv_id == NOTIFICATION_PRIV_ID_NONE && group_id == NOTIFICATION_GROUP_ID_NONE) {
+       if (priv_id == NOTIFICATION_PRIV_ID_NONE &&
+               group_id == NOTIFICATION_GROUP_ID_NONE) {
                if (status == VCONFKEY_TELEPHONY_SIM_INSERTED)
-                       snprintf(query_where, sizeof(query_where),
-                                "where  caller_app_id = '%s' and uid = %d ", app_id, uid);
+                       query_where = sqlite3_mprintf("WHERE  caller_app_id = %Q "
+                               "AND uid = %d ", app_id, uid);
                else
-                       snprintf(query_where, sizeof(query_where),
-                                "where  caller_app_id = '%s' and flag_simmode = 0 and uid = %d ", app_id, uid);
+                       query_where = sqlite3_mprintf("WHERE  caller_app_id = %Q "
+                               "AND flag_simmode = 0 AND uid = %d ", app_id, uid);
 
        } else {
                internal_group_id =
-                   _notification_noti_get_internal_group_id_by_priv_id(app_id,
-                                                                       priv_id, db);
+                       _notification_noti_get_internal_group_id_by_priv_id(app_id,
+                                                               priv_id, db);
 
                if (status == VCONFKEY_TELEPHONY_SIM_INSERTED)
-                       snprintf(query_where, sizeof(query_where),
-                                "where  caller_app_id = '%s' and internal_group_id = %d and uid = %d ",
+                       query_where = sqlite3_mprintf("WHERE  caller_app_id = %Q "
+                               "AND internal_group_id = %d AND uid = %d ",
                                 app_id, internal_group_id, uid);
                else
-                       snprintf(query_where, sizeof(query_where),
-                                "where  caller_app_id = '%s' and internal_group_id = %d and flag_simmode = 0 and uid = %d ",
+                       query_where = sqlite3_mprintf("WHERE  caller_app_id = %Q "
+                               "AND internal_group_id = %d AND flag_simmode = 0 "
+                               "AND uid = %d ",
                                 app_id, internal_group_id, uid);
        }
 
-       snprintf(query, sizeof(query),
-                "%s %s "
-                "order by rowid desc, time desc", query_base, query_where);
-
-       ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
-       if (ret != SQLITE_OK) {
-               NOTIFICATION_ERR("Select Query : %s", query);
-               NOTIFICATION_ERR("Select DB error(%d) : %s", ret,
-                                sqlite3_errmsg(db));
-
-               ret = NOTIFICATION_ERROR_FROM_DB;
+       if (query_where == NULL) {
+               ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
                goto err;
        }
 
-       while (sqlite3_step(stmt) == SQLITE_ROW) {
-               /* Make notification list */
-               noti = _notification_noti_get_item(stmt);
-               if (noti != NULL) {
-                       internal_count++;
-
-                       get_list = notification_list_append(get_list, noti);
-
-                       if (count != -1 && internal_count >= count) {
-                               NOTIFICATION_INFO
-                                   ("internal count %d >= count %d",
-                                    internal_count, count);
-                               break;
-                       }
-               }
+       query = sqlite3_mprintf("noti_list %s ORDER BY rowid DESC, time DESC",
+                       query_where);
+       if (query == NULL) {
+               ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
+               goto err;
        }
 
-       ret = NOTIFICATION_ERROR_NONE;
+       ret = _get_notification_list(query, list, count);
 
 err:
-       if (stmt)
-               sqlite3_finalize(stmt);
+       if (query_where)
+               sqlite3_free(query_where);
+
+       if (query)
+               sqlite3_free(query);
 
        if (db)
                notification_db_close(&db);
 
-       if (get_list != NULL)
-               *list = notification_list_get_head(get_list);
-
        return ret;
 }
 
 EXPORT_API int notification_noti_check_tag(notification_h noti)
 {
-       int result = 0;
-       int ret = NOTIFICATION_ERROR_NONE;
        sqlite3 *db;
        sqlite3_stmt *stmt = NULL;
+       char *query = NULL;
+       int ret = NOTIFICATION_ERROR_NONE;
+       int result = 0;
 
        if (noti->tag == NULL)
                return NOTIFICATION_ERROR_NOT_EXIST_ID;
@@ -1760,23 +1635,19 @@ EXPORT_API int notification_noti_check_tag(notification_h noti)
        if (!db)
                return get_last_result();
 
-       ret = sqlite3_prepare_v2(db, "SELECT priv_id FROM noti_list WHERE caller_app_id = ? and tag = ?", -1, &stmt, NULL);
-       if (ret != SQLITE_OK) {
-               NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
-               if (db)
-                       notification_db_close(&db);
-               return NOTIFICATION_ERROR_OUT_OF_MEMORY;
-       }
-
-       ret = sqlite3_bind_text(stmt, 1, noti->caller_app_id, -1, SQLITE_TRANSIENT);
-       if (ret != SQLITE_OK) {
-               NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
+       query = sqlite3_mprintf("SELECT priv_id FROM noti_list "
+                       "WHERE caller_app_id = %Q AND tag = %Q",
+                       NOTIFICATION_CHECK_STR(noti->caller_app_id),
+                       NOTIFICATION_CHECK_STR(noti->tag));
+       if (query == NULL) {
+               ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
                goto err;
        }
 
-       ret = sqlite3_bind_text(stmt, 2, noti->tag, -1, SQLITE_TRANSIENT);
+       ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
        if (ret != SQLITE_OK) {
-               NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
+               NOTIFICATION_ERR("sqlite3_prepare_v2 failed [%d][%s]", ret,
+                       sqlite3_errmsg(db));
                goto err;
        }
 
@@ -1786,7 +1657,6 @@ EXPORT_API int notification_noti_check_tag(notification_h noti)
        else
                result = 0;
 
-
        /* If result > 0, there is priv_id in DB */
        if (result > 0) {
                noti->priv_id = result;
@@ -1796,8 +1666,12 @@ EXPORT_API int notification_noti_check_tag(notification_h noti)
        }
 
 err:
-       if (stmt != NULL)
+       if (stmt)
                sqlite3_finalize(stmt);
+
+       if (query)
+               sqlite3_free(query);
+
        if (db)
                notification_db_close(&db);
 
@@ -1806,10 +1680,11 @@ err:
 
 EXPORT_API int notification_noti_check_count_for_template(notification_h noti, int *count)
 {
-       int result = 0;
-       int ret = NOTIFICATION_ERROR_NONE;
        sqlite3 *db;
        sqlite3_stmt *stmt = NULL;
+       char *query = NULL;
+       int ret = NOTIFICATION_ERROR_NONE;
+       int result = 0;
 
        if (noti == NULL || count == NULL)
                return NOTIFICATION_ERROR_INVALID_PARAMETER;
@@ -1818,17 +1693,19 @@ EXPORT_API int notification_noti_check_count_for_template(notification_h noti, i
        if (!db)
                return get_last_result();
 
-       ret = sqlite3_prepare_v2(db, "SELECT COUNT(caller_app_id) FROM noti_template WHERE caller_app_id = ?", -1, &stmt, NULL);
-       if (ret != SQLITE_OK) {
-               NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
-               if (db)
-                       notification_db_close(&db);
-               return NOTIFICATION_ERROR_OUT_OF_MEMORY;
+       query = sqlite3_mprintf("SELECT COUNT(caller_app_id) FROM noti_template "
+                               "WHERE caller_app_id = %Q",
+                               NOTIFICATION_CHECK_STR(noti->caller_app_id));
+       if (query == NULL) {
+               ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
+               goto err;
        }
 
-       ret = sqlite3_bind_text(stmt, 1, noti->caller_app_id, -1, SQLITE_TRANSIENT);
+       ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
        if (ret != SQLITE_OK) {
-               NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
+               NOTIFICATION_ERR("sqlite3_prepare_v2 failed [%d][%s]", ret,
+                       sqlite3_errmsg(db));
+               ret = NOTIFICATION_ERROR_FROM_DB;
                goto err;
        }
 
@@ -1841,288 +1718,60 @@ EXPORT_API int notification_noti_check_count_for_template(notification_h noti, i
        *count = result;
 
 err:
-       if (stmt != NULL)
+       if (stmt)
                sqlite3_finalize(stmt);
+
+       if (query)
+               sqlite3_free(query);
+
        if (db)
                notification_db_close(&db);
 
        return ret;
 }
 
-static int _template_query_create(notification_h noti, char *template_name, char **query)
-{
-       int i = 0;
-       int b_encode_len = 0;
-       char *args = NULL;
-       char *group_args = NULL;
-       char *b_image_path = NULL;
-       char *b_execute_option = NULL;
-       char *b_service_responding = NULL;
-       char *b_service_single_launch = NULL;
-       char *b_service_multi_launch = NULL;
-       char *b_event_handler[NOTIFICATION_EVENT_TYPE_MAX+1] = { NULL , };
-       char *b_text = NULL;
-       char *b_key = NULL;
-       char *b_format_args = NULL;
-       int flag_simmode = 0;
-
-       if (query == NULL || template_name == NULL)
-               return NOTIFICATION_ERROR_INVALID_PARAMETER;
-
-       /* Decode bundle to insert DB */
-       if (noti->args)
-               bundle_encode(noti->args, (bundle_raw **)&args, &b_encode_len);
-
-       if (noti->group_args)
-               bundle_encode(noti->group_args, (bundle_raw **)&group_args,
-                             &b_encode_len);
-
-       if (noti->b_execute_option)
-               bundle_encode(noti->b_execute_option,
-                             (bundle_raw **)&b_execute_option, &b_encode_len);
-
-       if (noti->b_service_responding)
-               bundle_encode(noti->b_service_responding,
-                             (bundle_raw **)&b_service_responding, &b_encode_len);
-
-       if (noti->b_service_single_launch)
-               bundle_encode(noti->b_service_single_launch,
-                             (bundle_raw **)&b_service_single_launch, &b_encode_len);
-
-       if (noti->b_service_multi_launch)
-               bundle_encode(noti->b_service_multi_launch,
-                             (bundle_raw **)&b_service_multi_launch, &b_encode_len);
-
-
-       for (i = 0; i <= NOTIFICATION_EVENT_TYPE_MAX; i++) {
-               if (noti->b_event_handler[i])
-                       bundle_encode(noti->b_event_handler[i],
-                                       (bundle_raw **)&b_event_handler[i], &b_encode_len);
-       }
-
-       if (noti->b_text)
-               bundle_encode(noti->b_text, (bundle_raw **)&b_text, &b_encode_len);
-
-       if (noti->b_key)
-               bundle_encode(noti->b_key, (bundle_raw **)&b_key, &b_encode_len);
-
-       if (noti->b_format_args)
-               bundle_encode(noti->b_format_args,
-                             (bundle_raw **)&b_format_args, &b_encode_len);
-
-       if (noti->b_image_path)
-               bundle_encode(noti->b_image_path,
-                             (bundle_raw **)&b_image_path, &b_encode_len);
-
-       /* Check only simmode property is enable */
-       if (noti->flags_for_property & NOTIFICATION_PROP_DISPLAY_ONLY_SIMMODE)
-               flag_simmode = 1;
-
-       *query = sqlite3_mprintf("INSERT OR REPLACE INTO noti_template ("
-               "type, "
-               "layout, "
-               "pkg_id, caller_app_id, launch_app_id, "
-               "image_path, "
-               "group_id, internal_group_id,"
-               "title_key, "
-               "b_text, b_key, tag, b_format_args, num_format_args, "
-               "text_domain, text_dir, "
-               "time, insert_time, "
-               "args, group_args, "
-               "b_execute_option, "
-               "b_service_responding, b_service_single_launch, b_service_multi_launch, "
-               "b_event_handler_click_on_button_1, b_event_handler_click_on_button_2, b_event_handler_click_on_button_3, "
-               "b_event_handler_click_on_button_4, b_event_handler_click_on_button_5, b_event_handler_click_on_button_6, "
-               "b_event_handler_click_on_icon, b_event_handler_click_on_thumbnail, b_event_handler_click_on_text_input_button, "
-               "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, "
-               "flags_for_property, flag_simmode, display_applist, progress_size, progress_percentage, "
-               "ongoing_flag, ongoing_value_type, ongoing_current, ongoing_duration, "
-               "auto_remove, default_button_index, hide_timeout, delete_timeout, text_input_max_length, "
-               "event_flag, extension_image_size, uid, template_name) values ("
-               "%d, "
-               "%d, "
-               "'%s', '%s', '%s', "
-               "'%s', "
-               "%d, %d,"
-               "$title_key, "
-               "'%s', '%s', $tag, '%s', %d, "
-               "'%s', '%s', "
-               "%d, %d, "
-               "'%s', '%s', "
-               "'%s', "
-               "'%s', '%s', '%s', "
-               "'%s', '%s', '%s', "
-               "'%s', '%s', '%s', "
-               "'%s', '%s', '%s', "
-               "%d, '%s', %d, '%s', %d, %d, %d, %d, "
-               "%d, %d, %d, $progress_size, $progress_percentage, "
-               "%d, %d, %d, %d, "
-               "%d, %d, %d, %d, %d, "
-               "%d, %d, %d, '%s')",
-               noti->type,
-               noti->layout,
-               NOTIFICATION_CHECK_STR(noti->pkg_id),
-               NOTIFICATION_CHECK_STR(noti->caller_app_id),
-               NOTIFICATION_CHECK_STR(noti->launch_app_id),
-               NOTIFICATION_CHECK_STR(b_image_path), noti->group_id,
-               noti->internal_group_id,
-               NOTIFICATION_CHECK_STR(b_text), NOTIFICATION_CHECK_STR(b_key),
-               NOTIFICATION_CHECK_STR(b_format_args), noti->num_format_args,
-               NOTIFICATION_CHECK_STR(noti->domain),
-               NOTIFICATION_CHECK_STR(noti->dir), (int)noti->time,
-               (int)noti->insert_time, NOTIFICATION_CHECK_STR(args),
-               NOTIFICATION_CHECK_STR(group_args),
-               NOTIFICATION_CHECK_STR(b_execute_option),
-               NOTIFICATION_CHECK_STR(b_service_responding),
-               NOTIFICATION_CHECK_STR(b_service_single_launch),
-               NOTIFICATION_CHECK_STR(b_service_multi_launch),
-               NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1]),
-               NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_2]),
-               NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_3]),
-               NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_4]),
-               NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_5]),
-               NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_6]),
-               NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_ICON]),
-               NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_THUMBNAIL]),
-               NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_TEXT_INPUT_BUTTON]),
-               noti->sound_type, NOTIFICATION_CHECK_STR(noti->sound_path),
-               noti->vibration_type,
-               NOTIFICATION_CHECK_STR(noti->vibration_path),
-               noti->led_operation,
-               noti->led_argb,
-               noti->led_on_ms,
-               noti->led_off_ms,
-               noti->flags_for_property, flag_simmode, noti->display_applist,
-               noti->ongoing_flag,
-               noti->ongoing_value_type,
-               noti->ongoing_current,
-               noti->ongoing_duration,
-               noti->auto_remove,
-               noti->default_button_index,
-               noti->hide_timeout,
-               noti->delete_timeout,
-               noti->text_input_max_length,
-               noti->event_flag,
-               noti->extension_image_size,
-               noti->uid,
-               template_name);
-
-       /* Free decoded data */
-       if (args)
-               free(args);
-
-       if (group_args)
-               free(group_args);
-
-       if (b_execute_option)
-               free(b_execute_option);
-
-       if (b_service_responding)
-               free(b_service_responding);
-
-       if (b_service_single_launch)
-               free(b_service_single_launch);
-
-       if (b_service_multi_launch)
-               free(b_service_multi_launch);
-
-       for (i = 0; i <= NOTIFICATION_EVENT_TYPE_MAX; i++) {
-               if (b_event_handler[i])
-                       bundle_free_encoded_rawdata((bundle_raw **)&b_event_handler[i]);
-       }
-
-       if (b_text)
-               free(b_text);
-
-       if (b_key)
-               free(b_key);
-
-       if (b_format_args)
-               free(b_format_args);
-
-       if (b_image_path)
-               free(b_image_path);
-
-       if (*query == NULL)
-               return NOTIFICATION_ERROR_OUT_OF_MEMORY;
-
-       return NOTIFICATION_ERROR_NONE;
-}
-
 EXPORT_API int notification_noti_add_template(notification_h noti, char *template_name)
 {
-       int ret = 0;
        sqlite3 *db = NULL;
        sqlite3_stmt *stmt = NULL;
        char *query = NULL;
-       char buf_key[32] = { 0, };
-       char *title_key = NULL;
+       int idx = 1;
+       int ret = NOTIFICATION_ERROR_NONE;
 
        if (noti == NULL || template_name == NULL) {
                NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
                return NOTIFICATION_ERROR_INVALID_PARAMETER;
        }
 
-       db = notification_db_open(DBPATH);
-       if (!db)
-               return get_last_result();
-
        /* Initialize private ID */
        noti->group_id = NOTIFICATION_GROUP_ID_NONE;
        noti->internal_group_id = NOTIFICATION_GROUP_ID_NONE;
 
-       ret = _template_query_create(noti, template_name, &query);
-       if (ret != NOTIFICATION_ERROR_NONE)
+       db = notification_db_open(DBPATH);
+       if (!db)
+               return get_last_result();
+
+       query = sqlite3_mprintf("INSERT OR REPLACE INTO noti_template "
+                               "(%s, template_name) VALUES (%s, %Q)",
+                               NOTI_LIST_DB_ATTRIBUTES_INSERT,
+                               NOTI_LIST_INSERT_VALUES,
+                               template_name);
+       if (query == NULL) {
+               ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
                goto err;
+       }
 
        ret = sqlite3_prepare_v2(db, query, -1, &stmt, NULL);
        if (ret != SQLITE_OK) {
-               NOTIFICATION_ERR("Insert Query : %s", query);
-               NOTIFICATION_ERR("Insert DB error(%d) : %s", ret,
-                                sqlite3_errmsg(db));
+               NOTIFICATION_ERR("sqlite3_prepare_v2 failed [%d][%s]", ret,
+                               sqlite3_errmsg(db));
                ret = NOTIFICATION_ERROR_FROM_DB;
                goto err;
        }
 
-       /* Get title key */
-       if (noti->b_key != NULL) {
-               snprintf(buf_key, sizeof(buf_key), "%d",
-                        NOTIFICATION_TEXT_TYPE_TITLE);
-
-               bundle_get_str(noti->b_key, buf_key, &title_key);
-       }
-
-       if (title_key == NULL && noti->b_text != NULL) {
-               snprintf(buf_key, sizeof(buf_key), "%d",
-                        NOTIFICATION_TEXT_TYPE_TITLE);
-
-               bundle_get_str(noti->b_text, buf_key, &title_key);
-       }
-
-       if (title_key == NULL)
-               title_key = noti->caller_app_id;
-
-       /* Bind query */
-       ret = _notification_noti_bind_query_text(stmt, "$tag", noti->tag);
-       if (ret != NOTIFICATION_ERROR_NONE) {
-               NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
-               goto err;
-       }
-       ret = _notification_noti_bind_query_text(stmt, "$title_key", title_key);
-       if (ret != NOTIFICATION_ERROR_NONE) {
-               NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
-               goto err;
-       }
-       ret = _notification_noti_bind_query_double(stmt, "$progress_size", noti->progress_size);
-       if (ret != NOTIFICATION_ERROR_NONE) {
-               NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
-               goto err;
-       }
-       ret = _notification_noti_bind_query_double(stmt, "$progress_percentage", noti->progress_percentage);
-       if (ret != NOTIFICATION_ERROR_NONE) {
-               NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
+       ret = _create_insertion_query(db, noti, stmt, &idx);
+       if (ret != NOTIFICATION_ERROR_NONE)
                goto err;
-       }
 
        ret = sqlite3_step(stmt);
        if (ret == SQLITE_OK || ret == SQLITE_DONE)
@@ -2134,76 +1783,36 @@ err:
        if (stmt)
                sqlite3_finalize(stmt);
 
-       if (db)
-               notification_db_close(&db);
-
        if (query)
                sqlite3_free(query);
 
+       if (db)
+               notification_db_close(&db);
+
        return ret;
 }
 
 EXPORT_API int notification_noti_get_package_template(notification_h noti, char *app_id, char *template_name)
 {
-       int ret = 0;
-       sqlite3 *db = NULL;
-       sqlite3_stmt *stmt = NULL;
+       int ret = NOTIFICATION_ERROR_NONE;
+       char *query_where = NULL;
 
        if (noti == NULL || app_id == NULL || template_name == NULL) {
                NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
                return NOTIFICATION_ERROR_INVALID_PARAMETER;
        }
 
-       db = notification_db_open(DBPATH);
-       if (!db)
-               return get_last_result();
-
-       ret = sqlite3_prepare_v2(db, "select "
-               "type, layout, pkg_id, caller_app_id, launch_app_id, image_path, group_id, priv_id, "
-               "tag, b_text, b_key, b_format_args, num_format_args, "
-               "text_domain, text_dir, time, insert_time, args, group_args, "
-               "b_execute_option, b_service_responding, b_service_single_launch, b_service_multi_launch, "
-               "b_event_handler_click_on_button_1, b_event_handler_click_on_button_2, b_event_handler_click_on_button_3, "
-               "b_event_handler_click_on_button_4, b_event_handler_click_on_button_5, b_event_handler_click_on_button_6, "
-               "b_event_handler_click_on_icon, b_event_handler_click_on_thumbnail, b_event_handler_click_on_text_input_button, "
-               "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, "
-               "flags_for_property, display_applist, progress_size, progress_percentage, ongoing_flag, ongoing_value_type, "
-               "ongoing_current, ongoing_duration, auto_remove, default_button_index, hide_timeout, delete_timeout, "
-               "text_input_max_length, event_flag, extension_image_size, uid "
-               "from noti_template where caller_app_id = ? and template_name = ?", -1, &stmt, NULL);
-       if (ret != SQLITE_OK) {
-               NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
+       query_where = sqlite3_mprintf("noti_template WHERE caller_app_id = %Q "
+                       "AND template_name = %Q", app_id, template_name);
+       if (query_where == NULL)
                return NOTIFICATION_ERROR_OUT_OF_MEMORY;
-       }
-
-       ret = sqlite3_bind_text(stmt, 1,  app_id, -1, SQLITE_TRANSIENT);
-       if (ret != SQLITE_OK) {
-               NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
-               goto err;
-       }
-
-       ret = sqlite3_bind_text(stmt, 2,  template_name, -1, SQLITE_TRANSIENT);
-       if (ret != SQLITE_OK) {
-               NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
-               goto err;
-       }
-
-       ret = sqlite3_step(stmt);
-       if (ret == SQLITE_ROW) {
-               _notification_noti_populate_from_stmt(stmt, noti);
-               ret = NOTIFICATION_ERROR_NONE;
-       } else {
-               NOTIFICATION_ERR("NOTIFICATION_ERROR_FROM_DB");
-               ret = NOTIFICATION_ERROR_FROM_DB;
-       }
-
-err:
 
-       if (stmt)
-               sqlite3_finalize(stmt);
+       ret = _get_notification(query_where, noti);
+       if (ret != NOTIFICATION_ERROR_NONE)
+               NOTIFICATION_ERR("_get_notification failed, %d", ret);
 
-       if (db != NULL)
-               notification_db_close(&db);
+       if (query_where)
+               sqlite3_free(query_where);
 
        return ret;
 }
@@ -2211,8 +1820,8 @@ err:
 EXPORT_API int notification_noti_delete_template(const char *pkg_id)
 {
        sqlite3 *db = NULL;
-       char query[NOTIFICATION_QUERY_MAX] = { 0, };
-       int ret;
+       char *query = NULL;
+       int ret = NOTIFICATION_ERROR_NONE;
 
        if (pkg_id == NULL)
                return NOTIFICATION_ERROR_INVALID_PARAMETER;
@@ -2221,11 +1830,19 @@ EXPORT_API int notification_noti_delete_template(const char *pkg_id)
        if (!db)
                return get_last_result();
 
-       snprintf(query, sizeof(query), "delete from noti_template "
-                "where pkg_id = '%s'", pkg_id);
+       query = sqlite3_mprintf("DELETE FROM noti_template WHERE pkg_id = %Q",
+                               NOTIFICATION_CHECK_STR(pkg_id));
+       if (query == NULL) {
+               ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
+               goto err;
+       }
 
        ret = notification_db_exec(db, query, NULL);
 
+err:
+       if (query)
+               sqlite3_free(query);
+
        if (db)
                notification_db_close(&db);
 
index 741b2bd7e31df356be9fb3bdd18afc7909b62c4a..9eff83e2e64f0906c9f08611ca002f741c421515 100755 (executable)
@@ -32,6 +32,7 @@
 #include <notification_private.h>
 #include <notification_setting.h>
 #include <notification_setting_internal.h>
+#include "notification_db_query.h"
 
 #define NOTIFICATION_PRIVILEGE "http://tizen.org/privilege/notification"
 
@@ -299,67 +300,86 @@ EXPORT_API int notification_setting_free_notification(notification_setting_h set
 static bool _is_package_in_setting_table(sqlite3 *db, const char *package_name, const char* app_id, uid_t uid)
 {
        sqlite3_stmt *stmt = NULL;
-       int sql_ret = SQLITE_OK;
+       char *query = NULL;
+       int sql_ret;
        bool err = true;
-       int field_index = 1;
 
        if (app_id != NULL)
-               sql_ret = sqlite3_prepare_v2(db, "SELECT app_id FROM notification_setting WHERE uid = ? AND package_name = ? AND app_id = ?", -1, &stmt, NULL);
+               query = sqlite3_mprintf("SELECT app_id FROM %s WHERE uid = %d "
+                                       "AND package_name = %Q AND app_id = %Q",
+                                       NOTIFICATION_SETTING_DB_TABLE,
+                                       uid, package_name, app_id);
        else
-               sql_ret = sqlite3_prepare_v2(db, "SELECT package_name FROM notification_setting WHERE uid = ? AND package_name = ?", -1, &stmt, NULL);
+               query = sqlite3_mprintf("SELECT package_name FROM %s "
+                                       "WHERE uid = %d AND package_name = %Q",
+                                       NOTIFICATION_SETTING_DB_TABLE,
+                                       uid, package_name);
 
+       if (query == NULL) {
+               /* LCOV_EXCL_START */
+               NOTIFICATION_ERR("fail to alloc query");
+               return false;
+               /* LCOV_EXCL_STOP */
+       }
+
+       sql_ret = sqlite3_prepare_v2(db, query, -1, &stmt, NULL);
        if (sql_ret != SQLITE_OK) {
-               NOTIFICATION_ERR("sqlite3_prepare_v2 failed [%d][%s]", sql_ret, sqlite3_errmsg(db));
+               /* LCOV_EXCL_START */
+               NOTIFICATION_ERR("sqlite3_prepare_v2 failed [%d][%s]", sql_ret,
+                               sqlite3_errmsg(db));
                err = false;
                goto out;
+               /* LCOV_EXCL_STOP */
        }
 
-       sqlite3_bind_int(stmt, field_index++, uid);
-       sqlite3_bind_text(stmt, field_index++, package_name, -1, SQLITE_TRANSIENT);
-       if (app_id != NULL)
-               sqlite3_bind_text(stmt, field_index++, app_id, -1, SQLITE_TRANSIENT);
-
        sql_ret = sqlite3_step(stmt);
        if (sql_ret == SQLITE_DONE) {
-               NOTIFICATION_INFO("no matched app_id from package_name found[%s][%s][%d]", package_name, app_id, sql_ret);
+               NOTIFICATION_INFO("no matched [%s] from package_name [%s], [%d]",
+                               app_id, package_name, sql_ret);
                err = false;
                goto out;
        }
 
        if (sql_ret != SQLITE_OK && sql_ret != SQLITE_ROW) {
-               NOTIFICATION_ERR("sqlite3_step failed [%d][%s]", sql_ret, sqlite3_errmsg(db));
+               NOTIFICATION_ERR("sqlite3_step failed [%d][%s]", sql_ret,
+                               sqlite3_errmsg(db));
                err = false;
                goto out;
        }
+
 out:
        if (stmt)
                sqlite3_finalize(stmt);
 
+       if (query)
+               sqlite3_free(query);
+
        return err;
 }
 
-static int foreach_app_info_callback(const pkgmgrinfo_appinfo_h handle, void *user_data)
+static int _foreach_app_info_callback(const pkgmgrinfo_appinfo_h handle,
+                               void *user_data)
 {
        setting_local_info *info = (setting_local_info *)user_data;
        sqlite3 *db = info->db;
-       sqlite3_stmt *stmt = NULL;
-       int pkgmgr_ret = PACKAGE_MANAGER_ERROR_NONE;
+       char *query = NULL;
+       int ret;
        int err = true;
-       int field_index = 1;
-       int sql_ret = SQLITE_OK;
        char *app_id = NULL;
        char *package_name = NULL;
 
-       pkgmgr_ret = pkgmgrinfo_appinfo_get_appid(handle, &app_id);
-       if (pkgmgr_ret != PACKAGE_MANAGER_ERROR_NONE) {
-               NOTIFICATION_ERR("pkgmgrinfo_appinfo_get_appid failed [%d]", pkgmgr_ret);
+       ret = pkgmgrinfo_appinfo_get_appid(handle, &app_id);
+       if (ret != PACKAGE_MANAGER_ERROR_NONE) {
+               NOTIFICATION_ERR("pkgmgrinfo_appinfo_get_appid failed [%d]",
+                               ret);
                err = false;
                goto out;
        }
 
-       pkgmgr_ret = pkgmgrinfo_appinfo_get_pkgname(handle, &package_name);
-       if (pkgmgr_ret != PACKAGE_MANAGER_ERROR_NONE) {
-               NOTIFICATION_ERR("pkgmgrinfo_appinfo_get_pkgname failed [%d]", pkgmgr_ret);
+       ret = pkgmgrinfo_appinfo_get_pkgname(handle, &package_name);
+       if (ret != PACKAGE_MANAGER_ERROR_NONE) {
+               NOTIFICATION_ERR("pkgmgrinfo_appinfo_get_pkgname failed [%d]",
+                               ret);
                goto out;
        }
 
@@ -369,37 +389,36 @@ static int foreach_app_info_callback(const pkgmgrinfo_appinfo_h handle, void *us
                goto out;
        }
 
-       NOTIFICATION_INFO("uid %d package_name %s [%s] will be inserted", info->uid, package_name, app_id);
-       sql_ret = sqlite3_prepare_v2(db, "INSERT INTO notification_setting (uid, package_name, app_id) "
-                                        "VALUES (?, ?, ?) ", -1, &stmt, NULL);
+       NOTIFICATION_INFO("uid %d package_name %s [%s] will be inserted",
+                               info->uid, package_name, app_id);
 
-       if (sql_ret != SQLITE_OK) {
-               NOTIFICATION_ERR("sqlite3_prepare_v2 failed [%d][%s]", sql_ret, sqlite3_errmsg(db));
+       query = sqlite3_mprintf("INSERT INTO %s (uid, package_name, app_id) "
+                               "VALUES (%d, %Q, %Q) ",
+                               NOTIFICATION_SETTING_DB_TABLE,
+                               info->uid, package_name, app_id);
+       if (query == NULL) {
+               /* LCOV_EXCL_START */
+               NOTIFICATION_ERR("fail to alloc query");
                err = false;
                goto out;
+               /* LCOV_EXCL_STOP */
        }
 
-       sqlite3_bind_int(stmt, field_index++, info->uid);
-       sqlite3_bind_text(stmt, field_index++, package_name, -1, SQLITE_TRANSIENT);
-       sqlite3_bind_text(stmt, field_index++, app_id, -1, SQLITE_TRANSIENT);
-
-       sql_ret = sqlite3_step(stmt);
-       if (sql_ret != SQLITE_OK && sql_ret != SQLITE_DONE) {
-               NOTIFICATION_ERR("sqlite3_step failed [%d][%s]", sql_ret, sqlite3_errmsg(db));
+       ret = notification_db_exec(db, query, NULL);
+       if (ret != NOTIFICATION_ERROR_NONE)
                err = false;
-       }
 
 out:
-       if (stmt)
-               sqlite3_finalize(stmt);
+       if (query)
+               sqlite3_free(query);
 
        return err;
 }
 
-static int foreach_package_info_callback(const pkgmgrinfo_pkginfo_h package_info, void *user_data)
+static int _foreach_package_info_callback(const pkgmgrinfo_pkginfo_h package_info, void *user_data)
 {
        char *package_name = NULL;
-       int pkgmgr_ret = PACKAGE_MANAGER_ERROR_NONE;
+       int pkgmgr_ret;
        int err = true;
        pkgmgrinfo_appinfo_filter_h handle = NULL;
        setting_local_info *info = (setting_local_info *)user_data;
@@ -425,12 +444,13 @@ static int foreach_package_info_callback(const pkgmgrinfo_pkginfo_h package_info
                goto out;
        }
 
-       pkgmgr_ret = pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(handle, foreach_app_info_callback, info, info->uid);
+       pkgmgr_ret = pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(handle, _foreach_app_info_callback, info, info->uid);
        if (pkgmgr_ret != PMINFO_R_OK) {
                NOTIFICATION_ERR("pkgmgrinfo_pkginfo_filter_foreach_appinfo failed [%d]", pkgmgr_ret);
                err = false;
                goto out;
        }
+
 out:
        if (handle)
                pkgmgrinfo_appinfo_filter_destroy(handle);
@@ -438,33 +458,33 @@ out:
        return err;
 }
 
-EXPORT_API int notification_setting_refresh_setting_table(uid_t uid)
+static int _install_and_update_package(const char *package_name, uid_t uid)
 {
+       sqlite3 *db;
        int err = NOTIFICATION_ERROR_NONE;
-       sqlite3 *db = NULL;
-       int sql_ret = SQLITE_OK;
-       int pkgmgr_ret = PACKAGE_MANAGER_ERROR_NONE;
-       pkgmgrinfo_pkginfo_filter_h filter = NULL;
+       int pkgmgr_ret;
        setting_local_info info;
+       pkgmgrinfo_pkginfo_filter_h handle = NULL;
 
-       NOTIFICATION_INFO("refresh setting table [%d]", uid);
+       db = notification_db_open(DBPATH);
+       if (!db)
+               return get_last_result();
 
-       sql_ret = sqlite3_open_v2(DBPATH, &db, SQLITE_OPEN_READWRITE, NULL);
-       if (sql_ret != SQLITE_OK || db == NULL) {
-               NOTIFICATION_ERR("db_util_open failed [%s][%d]", DBPATH, sql_ret);
-               return NOTIFICATION_ERROR_FROM_DB;
+       pkgmgr_ret = pkgmgrinfo_pkginfo_filter_create(&handle);
+       if (pkgmgr_ret != PMINFO_R_OK) {
+               NOTIFICATION_ERR("pkgmgrinfo_pkginfo_filter_create failed [%d]", pkgmgr_ret);
+               err = NOTIFICATION_ERROR_FROM_DB;
+               goto out;
        }
 
-       sqlite3_exec(db, "BEGIN immediate;", NULL, NULL, NULL);
-
-       pkgmgr_ret = pkgmgrinfo_pkginfo_filter_create(&filter);
+       pkgmgr_ret = pkgmgrinfo_pkginfo_filter_add_string(handle, PMINFO_PKGINFO_PROP_PACKAGE_PRIVILEGE, NOTIFICATION_PRIVILEGE);
        if (pkgmgr_ret != PMINFO_R_OK) {
-               NOTIFICATION_ERR("pkgmgrinfo_pkginfo_filter_create failed [%d]", pkgmgr_ret);
+               NOTIFICATION_ERR("pkgmgrinfo_pkginfo_filter_add_string failed [%d]", pkgmgr_ret);
                err = NOTIFICATION_ERROR_FROM_DB;
                goto out;
        }
 
-       pkgmgr_ret = pkgmgrinfo_pkginfo_filter_add_string(filter, PMINFO_PKGINFO_PROP_PACKAGE_PRIVILEGE, NOTIFICATION_PRIVILEGE);
+       pkgmgr_ret = pkgmgrinfo_pkginfo_filter_add_string(handle, PMINFO_PKGINFO_PROP_PACKAGE_ID, package_name);
        if (pkgmgr_ret != PMINFO_R_OK) {
                NOTIFICATION_ERR("pkgmgrinfo_pkginfo_filter_add_string failed [%d]", pkgmgr_ret);
                err = NOTIFICATION_ERROR_FROM_DB;
@@ -473,7 +493,7 @@ EXPORT_API int notification_setting_refresh_setting_table(uid_t uid)
 
        info.db = db;
        info.uid = uid;
-       pkgmgr_ret = pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(filter, foreach_package_info_callback, &info, uid);
+       pkgmgr_ret = pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(handle, _foreach_package_info_callback, &info, uid);
        if (pkgmgr_ret != PMINFO_R_OK) {
                NOTIFICATION_ERR("pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo failed [%d]", pkgmgr_ret);
                err = NOTIFICATION_ERROR_FROM_DB;
@@ -481,140 +501,102 @@ EXPORT_API int notification_setting_refresh_setting_table(uid_t uid)
        }
 
 out:
-       if (filter)
-               pkgmgrinfo_pkginfo_filter_destroy(filter);
-
-       if (db) {
-               if (err == NOTIFICATION_ERROR_NONE)
-                       sqlite3_exec(db, "END;", NULL, NULL, NULL);
-               else
-                       sqlite3_exec(db, "ROLLBACK;", NULL, NULL, NULL);
+       if (handle)
+               pkgmgrinfo_pkginfo_filter_destroy(handle);
 
-               if ((sql_ret = db_util_close(db)) != SQLITE_OK)
-                       NOTIFICATION_WARN("fail to db_util_close - [%d]", sql_ret);
-       }
+       if (db)
+               notification_db_close(&db);
 
        return err;
 }
 
-static int _install_and_update_package(const char *package_name, uid_t uid)
+static int _delete_package_from_setting_db(const char *package_name, uid_t uid)
 {
-       sqlite3 *db;
-       int ret = NOTIFICATION_ERROR_NONE;
-       int sql_ret = SQLITE_OK;
-       int pkgmgr_ret = PACKAGE_MANAGER_ERROR_NONE;
-       setting_local_info info;
-       pkgmgrinfo_pkginfo_filter_h handle = NULL;
-
-       sql_ret = sqlite3_open_v2(DBPATH, &db, SQLITE_OPEN_READWRITE, NULL);
-       if (sql_ret != SQLITE_OK || db == NULL) {
-               NOTIFICATION_ERR("db_util_open failed [%s][%d]", DBPATH, sql_ret);
-               return NOTIFICATION_ERROR_FROM_DB;
-       }
-
-       sqlite3_exec(db, "BEGIN immediate;", NULL, NULL, NULL);
+       sqlite3 *db = NULL;
+       char *query = NULL;
+       int err = NOTIFICATION_ERROR_NONE;
+       bool is_package_in_setting_table = false;
 
-       pkgmgr_ret = pkgmgrinfo_pkginfo_filter_create(&handle);
-       if (pkgmgr_ret != PMINFO_R_OK) {
-               NOTIFICATION_ERR("pkgmgrinfo_pkginfo_filter_create failed [%d]", pkgmgr_ret);
-               ret = NOTIFICATION_ERROR_FROM_DB;
-               goto out;
-       }
+       db = notification_db_open(DBPATH);
+       if (!db)
+               return get_last_result();
 
-       pkgmgr_ret = pkgmgrinfo_pkginfo_filter_add_string(handle, PMINFO_PKGINFO_PROP_PACKAGE_PRIVILEGE, NOTIFICATION_PRIVILEGE);
-       if (pkgmgr_ret != PMINFO_R_OK) {
-               NOTIFICATION_ERR("pkgmgrinfo_pkginfo_filter_add_string failed [%d]", pkgmgr_ret);
-               ret = NOTIFICATION_ERROR_FROM_DB;
+       is_package_in_setting_table = _is_package_in_setting_table(db,
+                               package_name, NULL, uid);
+       if (is_package_in_setting_table == false) {
+               NOTIFICATION_INFO("[%s] is not exist", package_name);
                goto out;
        }
 
-       pkgmgr_ret = pkgmgrinfo_pkginfo_filter_add_string(handle, PMINFO_PKGINFO_PROP_PACKAGE_ID, package_name);
-       if (pkgmgr_ret != PMINFO_R_OK) {
-               NOTIFICATION_ERR("pkgmgrinfo_pkginfo_filter_add_string failed [%d]", pkgmgr_ret);
-               ret = NOTIFICATION_ERROR_FROM_DB;
+       query = sqlite3_mprintf("DELETE FROM %s WHERE uid = %d "
+                               "AND package_name = %Q ",
+                               NOTIFICATION_SETTING_DB_TABLE, uid,
+                               package_name);
+       if (query == NULL) {
+               /* LCOV_EXCL_START */
+               NOTIFICATION_ERR("fail to alloc query");
+               err = NOTIFICATION_ERROR_OUT_OF_MEMORY;
                goto out;
+               /* LCOV_EXCL_STOP */
        }
 
-       info.db = db;
-       info.uid = uid;
-       pkgmgr_ret = pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(handle, foreach_package_info_callback, &info, uid);
-       if (pkgmgr_ret != PMINFO_R_OK) {
-               NOTIFICATION_ERR("pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo failed [%d]", pkgmgr_ret);
-               ret = NOTIFICATION_ERROR_FROM_DB;
-               goto out;
-       }
+       err = notification_db_exec(db, query, NULL);
 
 out:
-       if (handle)
-               pkgmgrinfo_pkginfo_filter_destroy(handle);
-
-       if (db) {
-               if (ret == NOTIFICATION_ERROR_NONE)
-                       sqlite3_exec(db, "END;", NULL, NULL, NULL);
-               else
-                       sqlite3_exec(db, "ROLLBACK;", NULL, NULL, NULL);
+       if (query)
+               sqlite3_free(query);
 
-               if ((sql_ret = db_util_close(db)) != SQLITE_OK)
-                       NOTIFICATION_WARN("db_util_close failed [%d]", sql_ret);
-       }
+       if (db)
+               notification_db_close(&db);
 
-       return ret;
+       return err;
 }
 
-static int _delete_package_from_setting_db(const char *package_name, uid_t uid)
+EXPORT_API int notification_setting_refresh_setting_table(uid_t uid)
 {
+       int err = NOTIFICATION_ERROR_NONE;
        sqlite3 *db = NULL;
-       sqlite3_stmt *stmt = NULL;
-       int ret = NOTIFICATION_ERROR_NONE;
-       int sql_ret = SQLITE_OK;
-       int field_index = 1;
-       bool is_package_in_setting_table = false;
+       int pkgmgr_ret;
+       pkgmgrinfo_pkginfo_filter_h filter = NULL;
+       setting_local_info info;
 
-       sql_ret = sqlite3_open_v2(DBPATH, &db, SQLITE_OPEN_READWRITE, NULL);
-       if (sql_ret != SQLITE_OK || db == NULL) {
-               NOTIFICATION_ERR("db_util_open failed [%s][%d]", DBPATH, sql_ret);
-               return NOTIFICATION_ERROR_FROM_DB;
-       }
+       NOTIFICATION_INFO("refresh setting table [%d]", uid);
 
-       is_package_in_setting_table = _is_package_in_setting_table(db, package_name, NULL, uid);
-       if (is_package_in_setting_table == false) {
-               NOTIFICATION_INFO("[%s] is not exist", package_name);
+       db = notification_db_open(DBPATH);
+       if (!db)
+               return get_last_result();
+
+       pkgmgr_ret = pkgmgrinfo_pkginfo_filter_create(&filter);
+       if (pkgmgr_ret != PMINFO_R_OK) {
+               NOTIFICATION_ERR("pkgmgrinfo_pkginfo_filter_create failed [%d]", pkgmgr_ret);
+               err = NOTIFICATION_ERROR_FROM_DB;
                goto out;
        }
 
-       sqlite3_exec(db, "BEGIN immediate;", NULL, NULL, NULL);
-
-       sql_ret = sqlite3_prepare_v2(db, "DELETE FROM notification_setting WHERE uid = ? AND package_name = ? ", -1, &stmt, NULL);
-       if (sql_ret != SQLITE_OK) {
-               NOTIFICATION_ERR("sqlite3_prepare_v2 failed [%d][%s]", sql_ret, sqlite3_errmsg(db));
-               ret = NOTIFICATION_ERROR_FROM_DB;
+       pkgmgr_ret = pkgmgrinfo_pkginfo_filter_add_string(filter, PMINFO_PKGINFO_PROP_PACKAGE_PRIVILEGE, NOTIFICATION_PRIVILEGE);
+       if (pkgmgr_ret != PMINFO_R_OK) {
+               NOTIFICATION_ERR("pkgmgrinfo_pkginfo_filter_add_string failed [%d]", pkgmgr_ret);
+               err = NOTIFICATION_ERROR_FROM_DB;
                goto out;
        }
 
-       sqlite3_bind_int(stmt, field_index++, uid);
-       sqlite3_bind_text(stmt, field_index++, package_name, -1, SQLITE_TRANSIENT);
-
-       sql_ret = sqlite3_step(stmt);
-       if (sql_ret != SQLITE_OK && sql_ret != SQLITE_DONE) {
-               NOTIFICATION_ERR("sqlite3_step failed [%d][%s]", sql_ret, sqlite3_errmsg(db));
-               ret = NOTIFICATION_ERROR_FROM_DB;
+       info.db = db;
+       info.uid = uid;
+       pkgmgr_ret = pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(filter, _foreach_package_info_callback, &info, uid);
+       if (pkgmgr_ret != PMINFO_R_OK) {
+               NOTIFICATION_ERR("pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo failed [%d]", pkgmgr_ret);
+               err = NOTIFICATION_ERROR_FROM_DB;
+               goto out;
        }
 
 out:
-       if (stmt)
-               sqlite3_finalize(stmt);
-
-       if (db) {
-               if (ret == NOTIFICATION_ERROR_NONE)
-                       sqlite3_exec(db, "END;", NULL, NULL, NULL);
-               else
-                       sqlite3_exec(db, "ROLLBACK;", NULL, NULL, NULL);
+       if (filter)
+               pkgmgrinfo_pkginfo_filter_destroy(filter);
 
-               if ((sql_ret = db_util_close(db)) != SQLITE_OK)
-                       NOTIFICATION_WARN("db_util_close failed [%d]", sql_ret);
-       }
+       if (db)
+               notification_db_close(&db);
 
-       return ret;
+       return err;
 }
 
 EXPORT_API int notification_setting_insert_package_for_uid(const char *package_name, uid_t uid)
@@ -963,6 +945,7 @@ EXPORT_API int notification_register_system_setting_dnd_changed_cb_for_uid(dnd_c
                NOTIFICATION_ERR("notification_ipc_monitor_init error");
                return NOTIFICATION_ERROR_IO_ERROR;
        }
+
        if (_noti_dnd_cb_hash == NULL)
                _noti_dnd_cb_hash = g_hash_table_new(g_direct_hash, g_direct_equal);
 
@@ -1016,7 +999,7 @@ EXPORT_API int notification_unregister_system_setting_dnd_changed_cb_for_uid(dnd
                return NOTIFICATION_ERROR_INVALID_PARAMETER;
 
        noti_dnd_del_list = g_list_find_custom(noti_dnd_cb_list, (gconstpointer)callback,
-                                              (GCompareFunc)_noti_dnd_cb_compare);
+                                       (GCompareFunc)_noti_dnd_cb_compare);
 
        if (noti_dnd_del_list) {
                dnd_data = g_list_nth_data(noti_dnd_del_list, 0);
@@ -1046,20 +1029,30 @@ EXPORT_API int notification_unregister_system_setting_dnd_changed_cb(dnd_changed
 
 static bool _is_uid_in_system_setting_table(sqlite3 *db, uid_t uid)
 {
-       bool err = true;
        sqlite3_stmt *stmt = NULL;
-       int sql_ret = SQLITE_OK;
-       int field_index = 1;
+       char *query = NULL;
+       int sql_ret;
+       bool err = true;
+
+       query = sqlite3_mprintf("SELECT uid FROM %s WHERE uid = %d",
+                               NOTIFICATION_SYSTEM_SETTING_DB_TABLE, uid);
+       if (query == NULL) {
+               /* LCOV_EXCL_START */
+               NOTIFICATION_ERR("fail to alloc query");
+               return NOTIFICATION_ERROR_OUT_OF_MEMORY;
+               /* LCOV_EXCL_STOP */
+       }
 
-       sql_ret = sqlite3_prepare_v2(db, "SELECT uid FROM notification_system_setting WHERE uid = ?", -1, &stmt, NULL);
+       sql_ret = sqlite3_prepare_v2(db, query, -1, &stmt, NULL);
        if (sql_ret != SQLITE_OK) {
-               NOTIFICATION_ERR("sqlite3_prepare_v2 failed [%d][%s]", sql_ret, sqlite3_errmsg(db));
+               /* LCOV_EXCL_START */
+               NOTIFICATION_ERR("sqlite3_prepare_v2 failed [%d][%s]", sql_ret,
+                               sqlite3_errmsg(db));
                err = false;
                goto out;
+               /* LCOV_EXCL_STOP */
        }
 
-       sqlite3_bind_int(stmt, field_index++, uid);
-
        sql_ret = sqlite3_step(stmt);
        if (sql_ret == SQLITE_DONE) {
                NOTIFICATION_INFO("no matched uid found[%d][%d]", uid, sql_ret);
@@ -1068,87 +1061,84 @@ static bool _is_uid_in_system_setting_table(sqlite3 *db, uid_t uid)
        }
 
        if (sql_ret != SQLITE_OK && sql_ret != SQLITE_ROW) {
-               NOTIFICATION_ERR("sqlite3_step failed [%d][%s]", sql_ret, sqlite3_errmsg(db));
+               NOTIFICATION_ERR("sqlite3_step failed [%d][%s]",
+                               sql_ret, sqlite3_errmsg(db));
                err = false;
-               goto out;
        }
 
 out:
        if (stmt)
                sqlite3_finalize(stmt);
 
+       if (query)
+               sqlite3_free(query);
+
        return err;
 }
 
 EXPORT_API int notification_system_setting_init_system_setting_table(uid_t uid)
 {
-       int err = NOTIFICATION_ERROR_NONE;
-       int sql_ret = SQLITE_OK;
-       int field_index = 1;
        sqlite3 *db = NULL;
-       sqlite3_stmt *stmt = NULL;
+       char *query_system_setting = NULL;
+       char *query_dnd_allow_exception = NULL;
+       int ret = NOTIFICATION_ERROR_NONE;
 
        NOTIFICATION_INFO("init system setting table [%d]", uid);
 
        db = notification_db_open(DBPATH);
        if (db == NULL)
-               return get_last_result();
+               return get_last_result(); /* LCOV_EXCL_LINE */
 
-       /* 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");
-
-               /* notification_system_setting */
-               sql_ret = sqlite3_prepare_v2(db, "INSERT INTO notification_system_setting (uid) VALUES (?) ", -1, &stmt, NULL);
-               if (sql_ret != SQLITE_OK) {
-                       NOTIFICATION_ERR("sqlite3_prepare_v2 failed [%d][%s]", sql_ret, sqlite3_errmsg(db));
-                       err = NOTIFICATION_ERROR_FROM_DB;
-                       goto out;
-               }
-
-               sqlite3_bind_int(stmt, field_index, uid);
-
-               sql_ret = sqlite3_step(stmt);
-               if (sql_ret != SQLITE_OK && sql_ret != SQLITE_DONE) {
-                       NOTIFICATION_ERR("sqlite3_step failed [%d][%s]", sql_ret, sqlite3_errmsg(db));
-                       err = NOTIFICATION_ERROR_FROM_DB;
-                       goto out;
-               }
+               NOTIFICATION_DBG("table is already initialized.");
+               goto out;
+       }
 
-               /* dnd_allow_exception */
-               sql_ret = sqlite3_prepare_v2(db, "INSERT INTO dnd_allow_exception (uid) VALUES (?) ", -1, &stmt, NULL);
-               if (sql_ret != SQLITE_OK) {
-                       NOTIFICATION_ERR("sqlite3_prepare_v2 failed [%d][%s]", sql_ret, sqlite3_errmsg(db));
-                       err = NOTIFICATION_ERROR_FROM_DB;
-                       goto out;
-               }
+       /* notification_system_setting */
+       query_system_setting = sqlite3_mprintf("INSERT INTO %s (uid) "
+                                       "VALUES (%d) ",
+                                       NOTIFICATION_SYSTEM_SETTING_DB_TABLE,
+                                       uid);
+       if (query_system_setting == NULL) {
+               /* LCOV_EXCL_START */
+               NOTIFICATION_ERR("fail to alloc query");
+               ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
+               goto out;
+               /* LCOV_EXCL_STOP */
+       }
 
-               sqlite3_bind_int(stmt, field_index, uid);
+       ret = notification_db_exec(db, query_system_setting, NULL);
+       if (ret != NOTIFICATION_ERROR_NONE)
+               goto out;
 
-               sql_ret = sqlite3_step(stmt);
-               if (sql_ret != SQLITE_OK && sql_ret != SQLITE_DONE) {
-                       NOTIFICATION_ERR("sqlite3_step failed [%d][%s]", sql_ret, sqlite3_errmsg(db));
-                       err = NOTIFICATION_ERROR_FROM_DB;
-                       goto out;
-               }
+       /* dnd_allow_exception */
+       query_dnd_allow_exception = sqlite3_mprintf("INSERT INTO %s "
+                                       "(uid) VALUES (%d) ",
+                                       NOTIFICATION_DND_ALLOW_EXCEPTION,
+                                       uid);
+       if (query_dnd_allow_exception == NULL) {
+               /* LCOV_EXCL_START */
+               NOTIFICATION_ERR("fail to alloc query");
+               ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
+               goto out;
+               /* LCOV_EXCL_STOP */
        }
 
-       NOTIFICATION_DBG("Notification system setting tables initialization is success.");
+       ret = notification_db_exec(db, query_dnd_allow_exception, NULL);
+       if (ret != NOTIFICATION_ERROR_NONE)
+               goto out;
+
+       NOTIFICATION_DBG("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);
+       if (query_system_setting)
+               sqlite3_free(query_system_setting);
 
-               notification_db_close(&db);
-       }
+       if (query_dnd_allow_exception)
+               sqlite3_free(query_dnd_allow_exception);
 
-       if (stmt)
-               sqlite3_finalize(stmt);
+       if (db)
+               notification_db_close(&db);
 
-       return err;
+       return ret;
 }
old mode 100644 (file)
new mode 100755 (executable)
index a79c04e..e486abe
@@ -31,8 +31,9 @@
 #include <notification_setting.h>
 #include <notification_setting_internal.h>
 #include <notification_setting_service.h>
+#include "notification_db_query.h"
 
-static int _get_table_field_data_int(char  **table, int *buf, int index)
+static int _get_table_field_data_int(char **table, int *buf, int index)
 {
        if (table == NULL || buf == NULL || index < 0) {
                /* LCOV_EXCL_START */
@@ -85,18 +86,18 @@ static int _get_table_field_data_string(char **table, char **buf, int ucs2, int
        }
 
        ret = true;
-out:
 
+out:
        return ret;
 }
 
 EXPORT_API
 int noti_setting_service_get_setting_by_app_id(const char *app_id, notification_setting_h *setting, uid_t uid)
 {
-       int ret = NOTIFICATION_ERROR_NONE;
        sqlite3 *db = NULL;
        char *query = NULL;
        char **query_result = NULL;
+       int ret = NOTIFICATION_ERROR_NONE;
        int sql_ret;
        int row_count = 0;
        int column_count = 0;
@@ -109,16 +110,14 @@ int noti_setting_service_get_setting_by_app_id(const char *app_id, notification_
                return NOTIFICATION_ERROR_INVALID_PARAMETER;
        }
 
-       sql_ret = db_util_open(DBPATH, &db, 0);
-       if (sql_ret != SQLITE_OK || db == NULL) {
-               NOTIFICATION_ERR("db_util_open failed [%d]", sql_ret); /* LCOV_EXCL_LINE */
-               return NOTIFICATION_ERROR_FROM_DB;
-       }
+       db = notification_db_open(DBPATH);
+       if (!db)
+               return get_last_result();
 
-       query = sqlite3_mprintf("SELECT package_name, app_id, allow_to_notify, do_not_disturb_except, visibility_class, "
-                                   "pop_up_notification, lock_screen_content_level, app_disabled FROM %s "
-                                   "WHERE app_id = %Q AND uid = %d", NOTIFICATION_SETTING_DB_TABLE, app_id, uid);
-       if (!query) {
+       query = sqlite3_mprintf("SELECT %s FROM %s WHERE app_id = %Q AND uid = %d",
+                       NOTIFICATION_SETTING_DB_ATTRIBUTES, NOTIFICATION_SETTING_DB_TABLE,
+                       app_id, uid);
+       if (query == NULL) {
                NOTIFICATION_ERR("fail to alloc query"); /* LCOV_EXCL_LINE */
                ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
                goto out;
@@ -126,7 +125,8 @@ int noti_setting_service_get_setting_by_app_id(const char *app_id, notification_
 
        sql_ret = sqlite3_get_table(db, query, &query_result, &row_count, &column_count, NULL);
        if (sql_ret != SQLITE_OK && sql_ret != -1) {
-               NOTIFICATION_ERR("sqlite3_get_table failed [%d][%s]", sql_ret, query); /* LCOV_EXCL_LINE */
+               NOTIFICATION_ERR("sqlite3_get_table failed [%d][%s]", sql_ret,
+                               query); /* LCOV_EXCL_LINE */
                ret = NOTIFICATION_ERROR_FROM_DB;
                goto out;
        }
@@ -167,11 +167,8 @@ out:
        if (query)
                sqlite3_free(query);
 
-       if (db) {
-               sql_ret = db_util_close(db);
-               if (sql_ret != SQLITE_OK)
-                       NOTIFICATION_WARN("fail to db_util_close - [%d]", sql_ret); /* LCOV_EXCL_LINE */
-       }
+       if (db)
+               notification_db_close(&db);
 
        return ret;
 }
@@ -179,10 +176,10 @@ out:
 EXPORT_API
 int noti_setting_get_setting_array(notification_setting_h *setting_array, int *count, uid_t uid)
 {
-       int ret = NOTIFICATION_ERROR_NONE;
        sqlite3 *db = NULL;
        char *query = NULL;
        char **query_result = NULL;
+       int ret = NOTIFICATION_ERROR_NONE;
        int sql_ret;
        int row_count = 0;
        int column_count = 0;
@@ -195,16 +192,15 @@ int noti_setting_get_setting_array(notification_setting_h *setting_array, int *c
                return  NOTIFICATION_ERROR_INVALID_PARAMETER;
        }
 
-       sql_ret = db_util_open(DBPATH, &db, 0);
-       if (sql_ret != SQLITE_OK || db == NULL) {
-               NOTIFICATION_ERR("db_util_open failed [%d]", sql_ret); /* LCOV_EXCL_LINE */
-               return NOTIFICATION_ERROR_FROM_DB;
-       }
+       db = notification_db_open(DBPATH);
+       if (!db)
+               return get_last_result();
 
-       query = sqlite3_mprintf("SELECT package_name, app_id, allow_to_notify, do_not_disturb_except, visibility_class, "
-                                   "pop_up_notification, lock_screen_content_level, app_disabled FROM %s WHERE uid = %d AND app_disabled = %d "
-                                   "ORDER BY package_name, app_id ", NOTIFICATION_SETTING_DB_TABLE, uid, 0);
-       if (!query) {
+       query = sqlite3_mprintf("SELECT %s FROM %s WHERE uid = %d "
+                               "AND app_disabled = %d ORDER BY package_name, "
+                               "app_id ", NOTIFICATION_SETTING_DB_ATTRIBUTES,
+                               NOTIFICATION_SETTING_DB_TABLE, uid, 0);
+       if (query == NULL) {
                NOTIFICATION_ERR("fail to alloc query"); /* LCOV_EXCL_LINE */
                ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
                goto out;
@@ -212,7 +208,8 @@ int noti_setting_get_setting_array(notification_setting_h *setting_array, int *c
 
        sql_ret = sqlite3_get_table(db, query, &query_result, &row_count, &column_count, NULL);
        if (sql_ret != SQLITE_OK && sql_ret != -1) {
-               NOTIFICATION_ERR("NOTIFICATION_ERROR_FROM_DB failed [%d][%s]", sql_ret, query); /* LCOV_EXCL_LINE */
+               NOTIFICATION_ERR("NOTIFICATION_ERROR_FROM_DB failed [%d][%s]",
+                       sql_ret, query); /* LCOV_EXCL_LINE */
                ret = NOTIFICATION_ERROR_FROM_DB;
                goto out;
        }
@@ -254,11 +251,8 @@ out:
        if (query)
                sqlite3_free(query);
 
-       if (db) {
-               sql_ret = db_util_close(db);
-               if (sql_ret != SQLITE_OK)
-                       NOTIFICATION_WARN("fail to db_util_close - [%d]", sql_ret); /* LCOV_EXCL_LINE */
-       }
+       if (db)
+               notification_db_close(&db);
 
        return ret;
 }
@@ -267,10 +261,10 @@ out:
 EXPORT_API
 int noti_system_setting_load_system_setting(notification_system_setting_h *system_setting, uid_t uid)
 {
-       int ret = NOTIFICATION_ERROR_NONE;
        sqlite3 *db = NULL;
        char *query = NULL;
        char **query_result = NULL;
+       int ret = NOTIFICATION_ERROR_NONE;
        int sql_ret;
        int row_count = 0;
        int column_count = 0;
@@ -282,18 +276,14 @@ int noti_system_setting_load_system_setting(notification_system_setting_h *syste
                return  NOTIFICATION_ERROR_INVALID_PARAMETER;
        }
 
-       sql_ret = db_util_open(DBPATH, &db, 0);
-       if (sql_ret != SQLITE_OK || db == NULL) {
-               NOTIFICATION_ERR("db_util_open failed [%d]", sql_ret); /* LCOV_EXCL_LINE */
-               return NOTIFICATION_ERROR_FROM_DB;
-       }
+       db = notification_db_open(DBPATH);
+       if (!db)
+               return get_last_result();
 
-       query = sqlite3_mprintf("SELECT do_not_disturb, visibility_class, "
-                       "dnd_schedule_enabled, dnd_schedule_day, "
-                       "dnd_start_hour, dnd_start_min, dnd_end_hour, dnd_end_min, "
-                       "lock_screen_content_level "
-                       "FROM %s WHERE uid = %d", NOTIFICATION_SYSTEM_SETTING_DB_TABLE, uid);
-       if (!query) {
+       query = sqlite3_mprintf("SELECT %s FROM %s WHERE uid = %d",
+                       NOTIFICATION_SYSTEM_SETTING_DB_ATTRIBUTES,
+                       NOTIFICATION_SYSTEM_SETTING_DB_TABLE, uid);
+       if (query == NULL) {
                NOTIFICATION_ERR("fail to alloc query"); /* LCOV_EXCL_LINE */
                ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
                goto out;
@@ -308,7 +298,8 @@ int noti_system_setting_load_system_setting(notification_system_setting_h *syste
 
        NOTIFICATION_DBG("row_count [%d] column_count [%d]", row_count, column_count);
 
-       if (!(result_system_setting = (struct notification_system_setting *)malloc(sizeof(struct notification_system_setting)))) {
+       result_system_setting = (struct notification_system_setting *)malloc(sizeof(struct notification_system_setting));
+       if (result_system_setting == NULL) {
                NOTIFICATION_ERR("malloc failed..."); /* LCOV_EXCL_LINE */
                ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
                goto out;
@@ -344,18 +335,16 @@ int noti_system_setting_load_system_setting(notification_system_setting_h *syste
        }
 
        *system_setting = result_system_setting;
+
 out:
        if (query_result)
-                       sqlite3_free_table(query_result);
+               sqlite3_free_table(query_result);
 
        if (query)
                sqlite3_free(query);
 
-       if (db) {
-               sql_ret = db_util_close(db);
-               if (sql_ret != SQLITE_OK)
-                       NOTIFICATION_WARN("fail to db_util_close - [%d]", sql_ret); /* LCOV_EXCL_LINE */
-       }
+       if (db)
+               notification_db_close(&db);
 
        return ret;
 }
@@ -366,43 +355,40 @@ int notification_setting_db_update(const char *package_name, const char *app_id,
                                int visibility_class, int pop_up_notification,
                                int lock_screen_content_level, uid_t uid)
 {
-       int ret = NOTIFICATION_ERROR_NONE;
        sqlite3 *db = NULL;
-       char *sqlbuf = NULL;
-       int sql_ret;
+       char *query = NULL;
+       int ret = NOTIFICATION_ERROR_NONE;
 
-       if (package_name == NULL || strlen(package_name) == 0
-           || app_id == NULL || strlen(app_id) == 0)
+       if (package_name == NULL || app_id == NULL) {
+               NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER"); /* LCOV_EXCL_LINE */
                return NOTIFICATION_ERROR_INVALID_PARAMETER;
-
-       sql_ret = db_util_open(DBPATH, &db, 0);
-       if (sql_ret != SQLITE_OK || db == NULL) {
-               NOTIFICATION_ERR("db_util_open failed [%s][%d]", DBPATH, sql_ret);
-               return NOTIFICATION_ERROR_FROM_DB;
        }
 
-       sqlbuf = sqlite3_mprintf("UPDATE %s SET allow_to_notify = %d, do_not_disturb_except = %d, visibility_class = %d, " \
-                                "pop_up_notification = %d, lock_screen_content_level = %d " \
-                                "WHERE app_id = %Q AND package_name = %Q AND uid = %d",
-                       NOTIFICATION_SETTING_DB_TABLE, allow_to_notify, do_not_disturb_except, visibility_class,
-                       pop_up_notification, lock_screen_content_level, app_id, package_name, uid);
-       if (!sqlbuf) {
-               NOTIFICATION_ERR("fail to alloc query");
+       db = notification_db_open(DBPATH);
+       if (!db)
+               return get_last_result();
+
+       query = sqlite3_mprintf("UPDATE %s SET allow_to_notify = %d, "
+                       "do_not_disturb_except = %d, visibility_class = %d, "
+                       "pop_up_notification = %d, lock_screen_content_level = %d "
+                       "WHERE app_id = %Q AND package_name = %Q AND uid = %d ",
+                       NOTIFICATION_SETTING_DB_TABLE, allow_to_notify,
+                       do_not_disturb_except, visibility_class,
+                       pop_up_notification, lock_screen_content_level, app_id,
+                       package_name, uid);
+       if (query == NULL) {
                ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
                goto out;
        }
 
-       ret = notification_db_exec(db, sqlbuf, NULL);
+       ret = notification_db_exec(db, query, NULL);
 
 out:
-       if (sqlbuf)
-               sqlite3_free(sqlbuf);
+       if (query)
+               sqlite3_free(query);
 
-       if (db) {
-               sql_ret = db_util_close(db);
-               if (sql_ret != SQLITE_OK)
-                       NOTIFICATION_WARN("fail to db_util_close - [%d]", sql_ret); /* LCOV_EXCL_LINE */
-       }
+       if (db)
+               notification_db_close(&db);
 
        return ret;
 }
@@ -414,68 +400,41 @@ int notification_setting_db_update_system_setting(int do_not_disturb, int visibi
                int dnd_end_hour, int dnd_end_min,
                int lock_screen_content_level, uid_t uid)
 {
-       int ret = NOTIFICATION_ERROR_NONE;
-       int sql_ret;
-       int field_index = 1;
        sqlite3 *db = NULL;
-       sqlite3_stmt *stmt = NULL;
-
-       sql_ret = db_util_open(DBPATH, &db, 0);
-       if (sql_ret != SQLITE_OK || db == NULL) {
-               NOTIFICATION_ERR("db_util_open failed [%s][%d][%s]", DBPATH, sql_ret, sqlite3_errmsg(db));
-               return  NOTIFICATION_ERROR_FROM_DB;
-       }
-
-       sqlite3_exec(db, "BEGIN immediate;", NULL, NULL, NULL);
-
-       sql_ret = sqlite3_prepare_v2(db, "INSERT OR REPLACE INTO notification_system_setting "
-                       "(uid, do_not_disturb, visibility_class, dnd_schedule_enabled, "
-                       "dnd_schedule_day, dnd_start_hour, dnd_start_min, "
-                       "dnd_end_hour, dnd_end_min, lock_screen_content_level) "
-                       "VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ", -1, &stmt, NULL);
-       if (sql_ret != SQLITE_OK) {
-               NOTIFICATION_ERR("sqlite3_prepare_v2 failed [%d][%s]", sql_ret, sqlite3_errmsg(db));
-               ret =  NOTIFICATION_ERROR_FROM_DB;
+       char *query = NULL;
+       int ret = NOTIFICATION_ERROR_NONE;
+       int num_changes = 0;
+
+       db = notification_db_open(DBPATH);
+       if (!db)
+               return get_last_result();
+
+       query = sqlite3_mprintf("INSERT OR REPLACE INTO %s (uid, %s) "
+                       "VALUES(%d, %d, %d, %d, %d, %d, %d, %d, %d, %d) ",
+                       NOTIFICATION_SYSTEM_SETTING_DB_TABLE,
+                       NOTIFICATION_SYSTEM_SETTING_DB_ATTRIBUTES,
+                       uid, do_not_disturb, visibility_class,
+                       dnd_schedule_enabled, dnd_schedule_day, dnd_start_hour,
+                       dnd_start_min, dnd_end_hour, dnd_end_min,
+                       lock_screen_content_level);
+       if (query == NULL) {
+               ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
                goto out;
        }
 
-       sqlite3_bind_int(stmt, field_index++, uid);
-       sqlite3_bind_int(stmt, field_index++, do_not_disturb);
-       sqlite3_bind_int(stmt, field_index++, visibility_class);
-       sqlite3_bind_int(stmt, field_index++, dnd_schedule_enabled);
-       sqlite3_bind_int(stmt, field_index++, dnd_schedule_day);
-       sqlite3_bind_int(stmt, field_index++, dnd_start_hour);
-       sqlite3_bind_int(stmt, field_index++, dnd_start_min);
-       sqlite3_bind_int(stmt, field_index++, dnd_end_hour);
-       sqlite3_bind_int(stmt, field_index++, dnd_end_min);
-       sqlite3_bind_int(stmt, field_index++, lock_screen_content_level);
-
-       sql_ret = sqlite3_step(stmt);
-       if (sql_ret != SQLITE_OK && sql_ret != SQLITE_DONE) {
-               NOTIFICATION_ERR("sqlite3_step failed [%d][%s]", sql_ret, sqlite3_errmsg(db));
-               ret =  NOTIFICATION_ERROR_FROM_DB;
+       ret = notification_db_exec(db, query, &num_changes);
+       if (ret != NOTIFICATION_ERROR_NONE)
                goto out;
-       }
 
-       sql_ret = sqlite3_changes(db);
-       if (sql_ret == 0)
+       if (num_changes == 0)
                NOTIFICATION_WARN("No changes on DB");
 
 out:
-       if (stmt)
-               sqlite3_finalize(stmt);
-
-       if (db) {
-               if (ret == NOTIFICATION_ERROR_NONE)
-                       sqlite3_exec(db, "END;", NULL, NULL, NULL);
-               else
-                       sqlite3_exec(db, "ROLLBACK;", NULL, NULL, NULL);
-
-               sql_ret = db_util_close(db);
-       }
+       if (query)
+               sqlite3_free(query);
 
-       if (sql_ret != SQLITE_OK)
-               NOTIFICATION_WARN("fail to db_util_close - [%d]", sql_ret);
+       if (db)
+               notification_db_close(&db);
 
        return ret;
 }
@@ -484,35 +443,32 @@ out:
 EXPORT_API
 int notification_setting_db_update_do_not_disturb(int do_not_disturb, uid_t uid)
 {
-       int ret = NOTIFICATION_ERROR_NONE;
-       int sql_ret;
        sqlite3 *db = NULL;
-       char *sqlbuf = NULL;
+       char *query = NULL;
+       int ret = NOTIFICATION_ERROR_NONE;
 
-       sql_ret = db_util_open(DBPATH, &db, 0);
-       if (sql_ret != SQLITE_OK || db == NULL) {
-               NOTIFICATION_ERR("db_util_open failed [%s][%d]", DBPATH, sql_ret);
-               return NOTIFICATION_ERROR_FROM_DB;
-       }
+       db = notification_db_open(DBPATH);
+       if (!db)
+               return get_last_result();
 
-       sqlbuf = sqlite3_mprintf("UPDATE notification_system_setting SET do_not_disturb = %d WHERE uid = %d", do_not_disturb, uid);
-       if (!sqlbuf) {
-               NOTIFICATION_ERR("fail to alloc query");
+       query = sqlite3_mprintf("UPDATE %s SET do_not_disturb = %d "
+                               "WHERE uid = %d",
+                               NOTIFICATION_SYSTEM_SETTING_DB_TABLE,
+                               do_not_disturb, uid);
+       if (query == NULL) {
+               NOTIFICATION_ERR("fail to alloc query"); /* LCOV_EXCL_LINE */
                ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
                goto out;
        }
 
-       ret = notification_db_exec(db, sqlbuf, NULL);
+       ret = notification_db_exec(db, query, NULL);
 
 out:
-       if (sqlbuf)
-               sqlite3_free(sqlbuf);
+       if (query)
+               sqlite3_free(query);
 
-       if (db) {
-               sql_ret = db_util_close(db);
-               if (sql_ret != SQLITE_OK)
-                       NOTIFICATION_WARN("fail to db_util_close - [%d]", sql_ret); /* LCOV_EXCL_LINE */
-       }
+       if (db)
+               notification_db_close(&db);
 
        return ret;
 }
@@ -523,7 +479,6 @@ int notification_system_setting_get_dnd_schedule_enabled_uid(uid_t **uids, int *
 {
        int ret = NOTIFICATION_ERROR_NONE;
        int i;
-       int sql_ret;
        int row_count = 0;
        int column_count = 0;
        int column_index = 0;
@@ -532,13 +487,12 @@ int notification_system_setting_get_dnd_schedule_enabled_uid(uid_t **uids, int *
        sqlite3 *db = NULL;
        uid_t *result_uids;
 
-       sql_ret = db_util_open(DBPATH, &db, 0);
-       if (sql_ret != SQLITE_OK || db == NULL) {
-               NOTIFICATION_ERR("db_util_open failed [%s][%d]", DBPATH, sql_ret);
-               return NOTIFICATION_ERROR_FROM_DB;
-       }
+       db = notification_db_open(DBPATH);
+       if (!db)
+               return get_last_result();
 
-       query = sqlite3_mprintf("SELECT uid FROM %s WHERE dnd_schedule_enabled = 1",
+       query = sqlite3_mprintf("SELECT uid FROM %s "
+                               "WHERE dnd_schedule_enabled = 1",
                                NOTIFICATION_SYSTEM_SETTING_DB_TABLE);
        if (query == NULL) {
                ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
@@ -572,27 +526,24 @@ int notification_system_setting_get_dnd_schedule_enabled_uid(uid_t **uids, int *
        *count = row_count;
 
 out:
-       if (query_result)
-               sqlite3_free_table(query_result);
-
        if (query)
                sqlite3_free(query);
 
-       if (db) {
-               sql_ret = db_util_close(db);
-               if (sql_ret != SQLITE_OK)
-                       NOTIFICATION_WARN("fail to db_util_close - [%d]", sql_ret); /* LCOV_EXCL_LINE */
-       }
+       if (query_result)
+               sqlite3_free_table(query_result);
+
+       if (db)
+               notification_db_close(&db);
 
        return ret;
 }
 
 EXPORT_API
 int notification_get_dnd_and_allow_to_notify(const char *app_id,
-                                               int *do_not_disturb,
-                                               int *do_not_disturb_except,
-                                               int *allow_to_notify,
-                                               uid_t uid)
+                                       int *do_not_disturb,
+                                       int *do_not_disturb_except,
+                                       int *allow_to_notify,
+                                       uid_t uid)
 {
        int ret = NOTIFICATION_ERROR_NONE;
        int sql_ret;
@@ -608,26 +559,24 @@ int notification_get_dnd_and_allow_to_notify(const char *app_id,
        if (app_id == NULL)
                return NOTIFICATION_ERROR_INVALID_PARAMETER;
 
-       sql_ret = db_util_open(DBPATH, &db, 0);
-       if (sql_ret != SQLITE_OK || db == NULL) {
-               NOTIFICATION_ERR("db_util_open failed [%s][%d]", DBPATH, sql_ret);
-               return NOTIFICATION_ERROR_FROM_DB;
-       }
+       db = notification_db_open(DBPATH);
+       if (!db)
+               return get_last_result();
 
-       query_setting = sqlite3_mprintf("SELECT allow_to_notify, do_not_disturb_except " \
-                                       "FROM %s WHERE app_id = %Q AND (uid = %d OR uid = %d) " \
-                                       "ORDER BY uid DESC;",
-                                       NOTIFICATION_SETTING_DB_TABLE, app_id,
-                                       uid, tzplatform_getuid(TZ_SYS_GLOBALAPP_USER));
+       query_setting = sqlite3_mprintf("SELECT allow_to_notify, "
+                               "do_not_disturb_except FROM %s WHERE app_id = %Q "
+                               "AND (uid = %d OR uid = %d) ORDER BY uid DESC",
+                               NOTIFICATION_SETTING_DB_TABLE, app_id,
+                               uid, tzplatform_getuid(TZ_SYS_GLOBALAPP_USER));
        if (query_setting == NULL) {
                NOTIFICATION_ERR("fail to alloc query");
                ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
                goto out;
        }
 
-       query_system_setting = sqlite3_mprintf("SELECT do_not_disturb FROM %s WHERE uid = %d",
-                                              NOTIFICATION_SYSTEM_SETTING_DB_TABLE, uid);
-
+       query_system_setting = sqlite3_mprintf("SELECT do_not_disturb FROM %s "
+                                       "WHERE uid = %d",
+                                       NOTIFICATION_SYSTEM_SETTING_DB_TABLE, uid);
        if (query_system_setting == NULL) {
                NOTIFICATION_ERR("fail to alloc query");
                ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
@@ -640,6 +589,7 @@ int notification_get_dnd_and_allow_to_notify(const char *app_id,
                ret = NOTIFICATION_ERROR_FROM_DB;
                goto out;
        }
+
        if (row_count == 0) {
                NOTIFICATION_ERR("Invalid uid [%d] or app id [%s]", uid, app_id);
                ret = NOTIFICATION_ERROR_INVALID_PARAMETER;
@@ -656,6 +606,7 @@ int notification_get_dnd_and_allow_to_notify(const char *app_id,
                ret = NOTIFICATION_ERROR_FROM_DB;
                goto out;
        }
+
        if (row_count == 0) {
                NOTIFICATION_ERR("Invalid uid [%d]", uid);
                ret = NOTIFICATION_ERROR_INVALID_PARAMETER;
@@ -678,11 +629,8 @@ out:
        if (query_system_setting)
                sqlite3_free(query_system_setting);
 
-       if (db) {
-               sql_ret = db_util_close(db);
-               if (sql_ret != SQLITE_OK)
-                       NOTIFICATION_WARN("fail to db_util_close - [%d]", sql_ret); /* LCOV_EXCL_LINE */
-       }
+       if (db)
+               notification_db_close(&db);
 
        return ret;
 }
@@ -705,15 +653,13 @@ EXPORT_API int notification_system_setting_load_dnd_allow_exception(dnd_allow_ex
                return  NOTIFICATION_ERROR_INVALID_PARAMETER;
        }
 
-       sql_ret = db_util_open(DBPATH, &db, 0);
-       if (sql_ret != SQLITE_OK || db == NULL) {
-               NOTIFICATION_ERR("db_util_open failed [%d]", sql_ret); /* LCOV_EXCL_LINE */
-               return NOTIFICATION_ERROR_FROM_DB;
-       }
+       db = notification_db_open(DBPATH);
+       if (!db)
+               return get_last_result();
 
        query = sqlite3_mprintf("SELECT type, value FROM %s WHERE uid = %d",
                        NOTIFICATION_DND_ALLOW_EXCEPTION, uid);
-       if (!query) {
+       if (query == NULL) {
                NOTIFICATION_ERR("fail to alloc query"); /* LCOV_EXCL_LINE */
                ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
                goto out;
@@ -754,75 +700,55 @@ out:
        if (query)
                sqlite3_free(query);
 
-       if (db) {
-               sql_ret = db_util_close(db);
-               if (sql_ret != SQLITE_OK)
-                       NOTIFICATION_WARN("fail to db_util_close - [%d]", sql_ret); /* LCOV_EXCL_LINE */
-       }
+       if (db)
+               notification_db_close(&db);
 
        return ret;
 }
 
-EXPORT_API int notification_system_setting_update_dnd_allow_exception(int type, int value, uid_t uid)
+EXPORT_API
+int notification_system_setting_update_dnd_allow_exception(int type, int value, uid_t uid)
 {
-       int ret = NOTIFICATION_ERROR_NONE;
-       int sql_ret;
-       int field_index = 1;
        sqlite3 *db = NULL;
-       sqlite3_stmt *stmt = NULL;
-
-       sql_ret = db_util_open(DBPATH, &db, 0);
-       if (sql_ret != SQLITE_OK || db == NULL) {
-               NOTIFICATION_ERR("db_util_open failed [%d]", sql_ret); /* LCOV_EXCL_LINE */
-               return NOTIFICATION_ERROR_FROM_DB;
-       }
+       char *query = NULL;
+       int ret = NOTIFICATION_ERROR_NONE;
+       int num_changes = 0;
 
-       sqlite3_exec(db, "BEGIN immediate;", NULL, NULL, NULL);
+       db = notification_db_open(DBPATH);
+       if (!db)
+               return get_last_result();
 
-       sql_ret = sqlite3_prepare_v2(db, "INSERT OR REPLACE INTO dnd_allow_exception (uid, type, value) VALUES(?, ?, ?) ", -1, &stmt, NULL);
-       if (sql_ret != SQLITE_OK) {
-               NOTIFICATION_ERR("sqlite3_prepare_v2 failed [%d][%s]", sql_ret, sqlite3_errmsg(db));
-               ret = NOTIFICATION_ERROR_FROM_DB;
+       query = sqlite3_mprintf("INSERT OR REPLACE INTO %s (uid, type, value) "
+                               "VALUES(%d, %d, %d) ",
+                               NOTIFICATION_DND_ALLOW_EXCEPTION,
+                               uid, type, value);
+       if (query == NULL) {
+               NOTIFICATION_ERR("fail to alloc query"); /* LCOV_EXCL_LINE */
+               ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
                goto out;
        }
 
-       sqlite3_bind_int(stmt, field_index++, uid);
-       sqlite3_bind_int(stmt, field_index++, type);
-       sqlite3_bind_int(stmt, field_index++, value);
-
-       sql_ret = sqlite3_step(stmt);
-       if (sql_ret != SQLITE_OK && sql_ret != SQLITE_DONE) {
-               NOTIFICATION_ERR("sqlite3_step failed [%d][%s]", sql_ret, sqlite3_errmsg(db));
-               ret = NOTIFICATION_ERROR_FROM_DB;
+       ret = notification_db_exec(db, query, &num_changes);
+       if (ret != NOTIFICATION_ERROR_NONE)
                goto out;
-       }
 
-       sql_ret = sqlite3_changes(db);
-       if (sql_ret == 0)
+       if (num_changes == 0)
                NOTIFICATION_WARN("No changes on DB");
 
 out:
-       if (stmt)
-               sqlite3_finalize(stmt);
-
-       if (ret == NOTIFICATION_ERROR_NONE)
-               sqlite3_exec(db, "END;", NULL, NULL, NULL);
-       else
-               sqlite3_exec(db, "ROLLBACK;", NULL, NULL, NULL);
+       if (query)
+               sqlite3_free(query);
 
-       if (db) {
-               sql_ret = db_util_close(db);
-               if (sql_ret != SQLITE_OK)
-                       NOTIFICATION_WARN("fail to db_util_close - [%d]", sql_ret); /* LCOV_EXCL_LINE */
-       }
+       if (db)
+               notification_db_close(&db);
 
        return ret;
 }
 
-EXPORT_API int noti_system_setting_get_do_not_disturb(int *do_not_disturb, uid_t uid)
+EXPORT_API
+int noti_system_setting_get_do_not_disturb(int *do_not_disturb, uid_t uid)
 {
        int ret = NOTIFICATION_ERROR_NONE;
-       int sql_ret;
        int row_count = 0;
        int col_count = 0;
        int col_index = 0;
@@ -830,11 +756,9 @@ EXPORT_API int noti_system_setting_get_do_not_disturb(int *do_not_disturb, uid_t
        char **query_result = NULL;
        sqlite3 *db = NULL;
 
-       sql_ret = db_util_open(DBPATH, &db, 0);
-       if (sql_ret != SQLITE_OK || db == NULL) {
-               NOTIFICATION_ERR("db_util_open failed [%d]", sql_ret); /* LCOV_EXCL_LINE */
-               return NOTIFICATION_ERROR_FROM_DB;
-       }
+       db = notification_db_open(DBPATH);
+       if (!db)
+               return get_last_result();
 
        query = sqlite3_mprintf("SELECT do_not_disturb FROM %s WHERE uid = %d",
                                NOTIFICATION_SYSTEM_SETTING_DB_TABLE, uid);
@@ -867,52 +791,45 @@ out:
        if (query)
                sqlite3_free(query);
 
-       if (db) {
-               sql_ret = db_util_close(db);
-               if (sql_ret != SQLITE_OK)
-                       NOTIFICATION_WARN("fail to db_util_close - [%d]", sql_ret); /* LCOV_EXCL_LINE */
-       }
+       if (db)
+               notification_db_close(&db);
 
        return ret;
 }
 
 /* LCOV_EXCL_START */
-EXPORT_API int notification_setting_db_update_app_disabled(const char *app_id, bool value, uid_t uid)
+EXPORT_API
+int notification_setting_db_update_app_disabled(const char *app_id, bool value, uid_t uid)
 {
-       int ret = NOTIFICATION_ERROR_NONE;
-       int sql_ret;
        sqlite3 *db = NULL;
-       char *sqlbuf = NULL;
+       char *query = NULL;
+       int ret = NOTIFICATION_ERROR_NONE;
 
        if (app_id == NULL)
                return NOTIFICATION_ERROR_INVALID_PARAMETER;
 
-       sql_ret = db_util_open(DBPATH, &db, 0);
-       if (sql_ret != SQLITE_OK || db == NULL) {
-               NOTIFICATION_ERR("db_util_open failed [%s][%d]", DBPATH, sql_ret);
-               return NOTIFICATION_ERROR_FROM_DB;
-       }
+       db = notification_db_open(DBPATH);
+       if (!db)
+               return get_last_result();
 
-       sqlbuf = sqlite3_mprintf("UPDATE notification_setting SET " \
-                       "app_disabled = %d WHERE app_id = %Q AND uid = %d",
-                       value, app_id, uid);
-       if (!sqlbuf) {
-               NOTIFICATION_ERR("fail to alloc query");
+       query = sqlite3_mprintf("UPDATE %s SET app_disabled= %d "
+                               "WHERE app_id = %Q AND uid = %d",
+                               NOTIFICATION_SETTING_DB_TABLE, value,
+                               app_id, uid);
+       if (query == NULL) {
+               NOTIFICATION_ERR("fail to alloc query"); /* LCOV_EXCL_LINE */
                ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
                goto out;
        }
 
-       ret = notification_db_exec(db, sqlbuf, NULL);
+       ret = notification_db_exec(db, query, NULL);
 
 out:
-       if (sqlbuf)
-               sqlite3_free(sqlbuf);
+       if (query)
+               sqlite3_free(query);
 
-       if (db) {
-               sql_ret = db_util_close(db);
-               if (sql_ret != SQLITE_OK)
-                       NOTIFICATION_WARN("fail to db_util_close - [%d]", sql_ret);
-       }
+       if (db)
+               notification_db_close(&db);
 
        return ret;
 }