Add db create API and remove db create logic from .spec file 93/68693/2 accepted/tizen/common/20160511.141829 accepted/tizen/ivi/20160511.080520 accepted/tizen/mobile/20160511.080420 accepted/tizen/tv/20160511.080439 accepted/tizen/wearable/20160511.080456 submit/tizen/20160510.090610
authorHyunho Kang <hhstark.kang@samsung.com>
Mon, 9 May 2016 10:13:57 +0000 (19:13 +0900)
committerHyunho Kang <hhstark.kang@samsung.com>
Tue, 10 May 2016 01:51:23 +0000 (10:51 +0900)
- data-provider-master will create notification db

Change-Id: Ie40657d9bbf3e3e5bd5066af1aa06ee304c6791f
Signed-off-by: Hyunho Kang <hhstark.kang@samsung.com>
CMakeLists.txt
include/notification_db.h
packaging/notification.spec
src/notification_db.c

index 47c8de0..f05b92e 100755 (executable)
@@ -26,6 +26,7 @@ SET(SRCS
 SET(HEADERS-DEVEL
        ./include/notification.h
        ./include/notification_internal.h
+       ./include/notification_db.h
        ./include/notification_error.h
        ./include/notification_type.h
        ./include/notification_list.h
index 3616a80..0515f87 100644 (file)
@@ -31,6 +31,7 @@ int notification_db_close(sqlite3 **db);
 int notification_db_exec(sqlite3 *db, const char *query, int *num_changes);
 char *notification_db_column_text(sqlite3_stmt *stmt, int col);
 bundle *notification_db_column_bundle(sqlite3_stmt *stmt, int col);
+int notification_db_init();
 
 #endif /* __NOTIFICATION_DB_H__ */
 
index b3f12dd..91c32dc 100755 (executable)
@@ -85,124 +85,6 @@ then
        mkdir %{TZ_SYS_DB}
 fi
 
-if [ ! -f %{TZ_SYS_DB}/.notification.db ]
-then
-       sqlite3 %{TZ_SYS_DB}/.notification.db 'PRAGMA journal_mode = PERSIST;
-               create  table if not exists noti_list ( 
-                       type INTEGER NOT NULL,
-                       layout INTEGER NOT NULL default 0,
-                       caller_pkgname TEXT NOT NULL,
-                       launch_pkgname TEXT,
-                       image_path TEXT,
-                       group_id INTEGER default 0,  
-                       internal_group_id INTEGER default 0,  
-                       priv_id INTERGER NOT NULL,  
-                       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,
-                       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,
-                       rowid INTEGER PRIMARY KEY AUTOINCREMENT,
-                       ongoing_flag INTEGER default 0,
-                       auto_remove INTEGER default 1,
-                       UNIQUE (caller_pkgname, priv_id)  
-               ); 
-               create table if not exists noti_group_data (
-                       caller_pkgname 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_pkgname, group_id)
-               );
-               create table if not exists ongoing_list ( 
-                       caller_pkgname TEXT NOT NULL,
-                       launch_pkgname 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_pkgname, priv_id)
-               ); 
-               CREATE TABLE IF NOT EXISTS notification_setting ( 
-                       priv_id INTEGER PRIMARY KEY AUTOINCREMENT,
-                       package_name TEXT NOT NULL,
-                       allow_to_notify INTEGER DEFAULT 1,
-                       do_not_disturb_except INTEGER DEFAULT 0,
-                       visibility_class INTEGER DEFAULT 0,
-                       UNIQUE (priv_id, package_name)
-               ); 
-               CREATE TABLE IF NOT EXISTS notification_system_setting ( 
-                       priv_id INTERGER PRIMARY KEY,
-                       do_not_disturb INTEGER DEFAULT 0,
-                       visibility_class INTEGER DEFAULT 0,
-                       UNIQUE (priv_id)
-               ); 
-
-               INSERT INTO notification_system_setting (priv_id, do_not_disturb, visibility_class) VALUES (0, 0, 0);
-
-               CREATE UNIQUE INDEX package_name_idx1 ON notification_setting (package_name);
-       '
-else
-       echo %{TZ_SYS_DB}/.notification.db ": DB file is already exists"
-fi
-
-chown app_fw:app_fw %{TZ_SYS_DB}/.notification.db
-chown app_fw:app_fw %{TZ_SYS_DB}/.notification.db-journal
-chmod 644 %{TZ_SYS_DB}/.notification.db
-chmod 644 %{TZ_SYS_DB}/.notification.db-journal
-
 %postun -p /sbin/ldconfig
 
 %files
@@ -214,6 +96,7 @@ chmod 644 %{TZ_SYS_DB}/.notification.db-journal
 %files devel
 %defattr(-,root,root,-)
 %{_includedir}/notification/notification.h
+%{_includedir}/notification/notification_db.h
 %{_includedir}/notification/notification_internal.h
 %{_includedir}/notification/notification_error.h
 %{_includedir}/notification/notification_type.h
index e74c75b..bfa9382 100755 (executable)
 #include <sqlite3.h>
 #include <db-util.h>
 #include <tizen.h>
+#include <tzplatform_config.h>
 
 #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; \
+create table if not exists noti_list ( \
+                       type INTEGER NOT NULL, \
+                       layout INTEGER NOT NULL default 0, \
+                       caller_pkgname TEXT NOT NULL, \
+                       launch_pkgname TEXT, \
+                       image_path TEXT, \
+                       group_id INTEGER default 0,  \
+                       internal_group_id INTEGER default 0,  \
+                       priv_id INTERGER NOT NULL,  \
+                       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, \
+                       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, \
+                       rowid INTEGER PRIMARY KEY AUTOINCREMENT, \
+                       ongoing_flag INTEGER default 0, \
+                       auto_remove INTEGER default 1, \
+                       UNIQUE (caller_pkgname, priv_id)  \
+               ); \
+               create table if not exists noti_group_data ( \
+                       caller_pkgname 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_pkgname, group_id) \
+               ); \
+               create table if not exists ongoing_list ( \
+                       caller_pkgname TEXT NOT NULL, \
+                       launch_pkgname 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_pkgname, priv_id) \
+               ); \
+               CREATE TABLE IF NOT EXISTS notification_setting ( \
+                       priv_id INTEGER PRIMARY KEY AUTOINCREMENT, \
+                       package_name TEXT NOT NULL, \
+                       allow_to_notify INTEGER DEFAULT 1, \
+                       do_not_disturb_except INTEGER DEFAULT 0, \
+                       visibility_class INTEGER DEFAULT 0, \
+                       UNIQUE (priv_id, package_name) \
+               ); \
+               CREATE TABLE IF NOT EXISTS notification_system_setting ( \
+                       priv_id INTERGER PRIMARY KEY, \
+                       do_not_disturb INTEGER DEFAULT 0, \
+                       visibility_class INTEGER DEFAULT 0 \
+               ); \
+               INSERT INTO notification_system_setting (priv_id, do_not_disturb, visibility_class) VALUES (0, 0, 0); \
+               CREATE UNIQUE INDEX package_name_idx1 ON notification_setting (package_name);"
+
+EXPORT_API int notification_db_init()
+{
+       int r;
+       sqlite3 *db = NULL;
+       char *errmsg = NULL;
+       char defname[FILENAME_MAX];
+       const char *db_path = tzplatform_getenv(TZ_SYS_DB);
+       if (db_path == NULL) {
+               NOTIFICATION_ERR("fail to get db_path");
+               return NOTIFICATION_ERROR_OUT_OF_MEMORY;
+       }
+       snprintf(defname, sizeof(defname), "%s/%s", db_path, NOTIFICATION_DB_NAME);
+
+       NOTIFICATION_DBG("db path : %s", defname);
+       r = sqlite3_open_v2(defname, &db, SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE, NULL);
+       if (r) {
+               db_util_close(db);
+               NOTIFICATION_ERR("fail to open notification db %d", r);
+               return NOTIFICATION_ERROR_IO_ERROR;
+       }
+
+       r = sqlite3_exec(db, CREATE_NOTIFICATION_TABLE, NULL, NULL, &errmsg);
+       if (r != SQLITE_OK) {
+               NOTIFICATION_ERR("query error(%d)(%s)", r, errmsg);
+               sqlite3_free(errmsg);
+               db_util_close(db);
+               return NOTIFICATION_ERROR_IO_ERROR;
+       }
+
+       db_util_close(db);
+       return NOTIFICATION_ERROR_NONE;
+}
+
 sqlite3 *notification_db_open(const char *dbfile)
 {
        int ret = 0;