Removes dependency of db-util 41/138341/2
authorMyungki Lee <mk5004.lee@samsung.com>
Wed, 12 Jul 2017 01:43:03 +0000 (10:43 +0900)
committerMyungki Lee <mk5004.lee@samsung.com>
Wed, 12 Jul 2017 02:42:13 +0000 (11:42 +0900)
- use sqlite func instead of db-util func

Change-Id: I6733b2abeb065d2c9392fa91695bca337e06fcd0
Signed-off-by: Myungki Lee <mk5004.lee@samsung.com>
CMakeLists.txt
packaging/notification.spec
src/notification_db.c
src/notification_setting.c
src/notification_setting_service.c

index cbb9221..dc3d38a 100755 (executable)
@@ -55,7 +55,6 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
 INCLUDE(FindPkgConfig)
 pkg_check_modules(pkgs REQUIRED
        sqlite3
-       db-util
        vconf
        bundle
        dlog
index 6078d61..2f5e201 100755 (executable)
@@ -7,7 +7,6 @@ Group:      TBD
 License:    Apache-2.0
 Source0:    %{name}-%{version}.tar.gz
 BuildRequires: pkgconfig(sqlite3)
-BuildRequires: pkgconfig(db-util)
 BuildRequires: pkgconfig(vconf)
 BuildRequires: pkgconfig(bundle)
 BuildRequires: pkgconfig(dbus-1)
index 4e12e2e..bd02d53 100755 (executable)
@@ -20,9 +20,7 @@
 #include <string.h>
 
 #include <sqlite3.h>
-#include <db-util.h>
 #include <tizen.h>
-#include <tzplatform_config.h>
 
 #include <notification_error.h>
 #include <notification_debug.h>
 
 EXPORT_API int notification_db_init()
 {
-       int r;
+       int ret;
        sqlite3 *db = NULL;
        char *errmsg = NULL;
-       char defname[FILENAME_MAX];
-       char *query = NULL;
-       const char *db_path = tzplatform_getenv(TZ_SYS_DB);
-       if (db_path == NULL) {
-               NOTIFICATION_ERR("fail to get db_path"); /* LCOV_EXCL_LINE */
-               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) {
+       ret = sqlite3_open_v2(DBPATH, &db,
+                       SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE, NULL);
+       if (ret != SQLITE_OK) {
                /* LCOV_EXCL_START */
-               db_util_close(db);
-               NOTIFICATION_ERR("fail to open notification db %d", r);
-               return NOTIFICATION_ERROR_IO_ERROR;
+               NOTIFICATION_ERR("fail to open notification db %d", ret);
+               ret = NOTIFICATION_ERROR_FROM_DB;
+               goto out;
                /* LCOV_EXCL_STOP */
        }
-       query = sqlite3_mprintf(CREATE_NOTIFICATION_TABLE, tzplatform_getuid(TZ_SYS_DEFAULT_USER));
-       NOTIFICATION_DBG("@@@ query : %s", query);
 
-       r = sqlite3_exec(db, CREATE_NOTIFICATION_TABLE, NULL, NULL, &errmsg);
-       if (query)
-               sqlite3_free(query);
-       if (r != SQLITE_OK) {
+       ret = sqlite3_exec(db, CREATE_NOTIFICATION_TABLE, NULL, NULL, &errmsg);
+       if (ret != SQLITE_OK) {
                /* LCOV_EXCL_START */
-               NOTIFICATION_ERR("query error(%d)(%s)", r, errmsg);
-               sqlite3_free(errmsg);
-               db_util_close(db);
-               return NOTIFICATION_ERROR_IO_ERROR;
+               NOTIFICATION_ERR("sqlite3_exec error(%d)(%s)", ret, errmsg);
+               ret = NOTIFICATION_ERROR_FROM_DB;
+               goto out;
                /* LCOV_EXCL_STOP */
        }
 
-       db_util_close(db);
-       return NOTIFICATION_ERROR_NONE;
+       ret = NOTIFICATION_ERROR_NONE;
+
+out:
+       if (errmsg)
+               sqlite3_free(errmsg);
+
+       if (db)
+               sqlite3_close(db);
+
+       return ret;
 }
 
 sqlite3 *notification_db_open(const char *dbfile)
@@ -104,7 +97,7 @@ int notification_db_close(sqlite3 **db)
        if (db == NULL || *db == NULL)
                return NOTIFICATION_ERROR_INVALID_PARAMETER;
 
-       ret = db_util_close(*db);
+       ret = sqlite3_close(*db);
        if (ret != SQLITE_OK) {
                /* LCOV_EXCL_START */
                NOTIFICATION_ERR("DB close error(%d)", ret);
index 840a5f5..997d849 100755 (executable)
@@ -17,7 +17,6 @@
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
-#include <db-util.h>
 #include <package_manager.h>
 #include <pkgmgr-info.h>
 #include <tizen_type.h>
index e486abe..70a7001 100755 (executable)
@@ -18,9 +18,9 @@
 #include <unistd.h>
 #include <stdio.h>
 #include <string.h>
+#include <stdlib.h>
 
 #include <sqlite3.h>
-#include <db-util.h>
 #include <tizen.h>
 
 #include <notification.h>