From 110c65cb3df37993d8a11e18b44c71605f10ba53 Mon Sep 17 00:00:00 2001 From: sinikang Date: Thu, 13 Dec 2018 18:13:26 +0900 Subject: [PATCH] Remove db-util dependency - use sqlite3 library directly Change-Id: I314206375c3598c0c6979b68519d8d8373b0c279 --- CMakeLists.txt | 2 +- packaging/tel-plugin-database.spec | 5 +++-- src/database_main.c | 32 ++++++++++++++++++++++++++++---- 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 92c204b..8a451b4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,7 +12,7 @@ SET(CMAKE_INSTALL_PREFIX "${PREFIX}") # Set required packages INCLUDE(FindPkgConfig) -pkg_check_modules(pkgs REQUIRED glib-2.0 tcore db-util) +pkg_check_modules(pkgs REQUIRED glib-2.0 tcore sqlite3 dlog) FOREACH(flag ${pkgs_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") diff --git a/packaging/tel-plugin-database.spec b/packaging/tel-plugin-database.spec index 5dd2721..8f2bd59 100644 --- a/packaging/tel-plugin-database.spec +++ b/packaging/tel-plugin-database.spec @@ -1,6 +1,6 @@ %define major 0 %define minor 1 -%define patchlevel 44 +%define patchlevel 45 Name: tel-plugin-database Version: %{major}.%{minor}.%{patchlevel} @@ -10,7 +10,8 @@ Summary: Telephony DataBase storage plugin Group: System/Libraries Source0: tel-plugin-database-%{version}.tar.gz BuildRequires: cmake -BuildRequires: pkgconfig(db-util) +BuildRequires: pkgconfig(sqlite3) +BuildRequires: pkgconfig(dlog) BuildRequires: pkgconfig(glib-2.0) BuildRequires: pkgconfig(tcore) BuildRequires: pkgconfig(libtzplatform-config) diff --git a/src/database_main.c b/src/database_main.c index 707358d..9756a3d 100644 --- a/src/database_main.c +++ b/src/database_main.c @@ -25,7 +25,8 @@ #include #include -#include +#include +#include #include #include @@ -92,14 +93,37 @@ static gboolean __update_query_database(Storage *strg, void *handle, const char return TRUE; } +static int _busy_handler(void *pData, int count) +{ + if (5 - count > 0) { + dbg("Busy Handler Called! : CNT(%d)\n", count + 1); + usleep((count + 1) * 100000); + return 1; + } else { + dbg("Busy Handler will be returned SQLITE_BUSY error\n"); + return 0; + } +} + static void *create_handle(Storage *strg, const char *path) { int rv = 0; sqlite3 *handle = NULL; - rv = db_util_open(path, &handle, 0); + if (path == NULL) { + err("Invalid input param error"); + return NULL; + } + + rv = sqlite3_open(path, &handle); + if (rv != SQLITE_OK) { + err("fail to connect database err(%d), errmsg(%s)", rv, sqlite3_errmsg(handle)); + return NULL; + } + + rv = sqlite3_busy_handler(handle, _busy_handler, NULL); if (rv != SQLITE_OK) { - err("fail to connect database err(%d)", rv); + err("fail to register busy handler err(%d), errmsg(%s)", rv, sqlite3_errmsg(handle)); return NULL; } @@ -114,7 +138,7 @@ static gboolean remove_handle(Storage *strg, void *handle) if (!handle) return FALSE; - rv = db_util_close(handle); + rv = sqlite3_close(handle); if (rv != SQLITE_OK) { err("fail to close database err(%d)", rv); handle = NULL; -- 2.7.4