From: Abhay agarwal Date: Fri, 13 Sep 2019 07:13:49 +0000 (+0530) Subject: Add database API to clear adv table X-Git-Tag: accepted/tizen/unified/20190917.034055~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b953971b73e59493f23e7399afc2d9d0728a442e;p=platform%2Fcore%2Fconnectivity%2Fua-manager.git Add database API to clear adv table Change-Id: I1fa74d4d5adff3e3121e6357c54f4a997f3e5478 Signed-off-by: Abhay agarwal --- diff --git a/ua-daemon/include/ua-manager-database.h b/ua-daemon/include/ua-manager-database.h index caf8d3c..167c7c7 100644 --- a/ua-daemon/include/ua-manager-database.h +++ b/ua-daemon/include/ua-manager-database.h @@ -205,8 +205,12 @@ int _uam_adv_db_deinitialize(void); /* insert */ int _uam_db_insert_adv_info(unsigned int adv_len, const char *ibeacon_adv); +/* select operations */ GSList *_uam_db_get_all_advs(void); +/* delete operations */ +int _uam_adv_db_clear(void); + #ifdef __cplusplus } #endif diff --git a/ua-daemon/src/ua-manager-adv-db.c b/ua-daemon/src/ua-manager-adv-db.c index 618e753..a3e8882 100644 --- a/ua-daemon/src/ua-manager-adv-db.c +++ b/ua-daemon/src/ua-manager-adv-db.c @@ -31,6 +31,11 @@ #define INSERT_IBEACON_ADV "insert into ibeacon_adv (ibeacon_id, ibeacon_adv, adv_len) " \ "values (?, ?, ?)" +#define DELETE_ALL_ADV_DATA "delete from ibeacon_adv " + +/* DELETE statements */ +static sqlite3_stmt *delete_all_adv_data; + /* SELECT statements */ static sqlite3_stmt *select_max_ibeacon_id; static sqlite3_stmt *select_all_advs; @@ -41,6 +46,15 @@ static sqlite3_stmt *insert_ibeacon_adv; extern sqlite3 *database; static int max_ibeacon_id; +static void __uam_adv_finalize_delete(void) +{ + FUNC_ENTRY; + + FINALIZE(delete_all_adv_data); + + FUNC_EXIT; +} + static void __uam_adv_finalize_select(void) { FUNC_ENTRY; @@ -60,6 +74,26 @@ static void __uam_adv_finalize_insert(void) FUNC_EXIT; } +static int __uam_adv_prepare_delete(sqlite3 *db) +{ + FUNC_ENTRY; + int rc; + static int initialized; + + if (initialized) { + FUNC_EXIT; + return SQLITE_OK; + } + + PREPARE_QUERY(rc, db, delete_all_adv_data, + DELETE_ALL_ADV_DATA, __uam_adv_finalize_delete); + + initialized = 1; + FUNC_EXIT; + return rc; +} + + static int __uam_adv_prepare_select(sqlite3 *db) { FUNC_ENTRY; @@ -111,6 +145,7 @@ static int __uam_adv_table_info_prepare(sqlite3 *db) return UAM_ERROR_DB_FAILED; } + DB_ACTION(__uam_adv_prepare_delete(db), error_code, handle_error); DB_ACTION(__uam_adv_prepare_select(db), error_code, handle_error); DB_ACTION(__uam_adv_prepare_insert(db), error_code, handle_error); @@ -123,6 +158,8 @@ handle_error: static void __uam_adv_table_info_finalize(void) { FUNC_ENTRY; + __uam_adv_finalize_delete(); + __uam_adv_finalize_select(); __uam_adv_finalize_insert(); FUNC_EXIT; } @@ -256,3 +293,21 @@ GSList *_uam_db_get_all_advs(void) FUNC_EXIT; return adv_list; } + +int _uam_adv_db_clear(void) +{ + int error_code = UAM_ERROR_NONE; + sqlite3_stmt *stmt = delete_all_adv_data; + + if (sqlite3_step(stmt) != SQLITE_DONE) { + UAM_ERR("Failed to delete user data %s", + sqlite3_errmsg(__uam_db_recover_database())); + error_code = UAM_ERROR_DB_FAILED; + goto handle_error; + } + UAM_DBG("User data deleted "); + +handle_error: + sqlite3_reset(stmt); + return error_code; +} diff --git a/ua-daemon/src/ua-manager-db.c b/ua-daemon/src/ua-manager-db.c index 6c91c7a..95c9866 100644 --- a/ua-daemon/src/ua-manager-db.c +++ b/ua-daemon/src/ua-manager-db.c @@ -384,6 +384,7 @@ int _uam_db_clear(void) EXEC(UAM_ERROR_NONE, _uam_device_db_clear(), handle_error); EXEC(UAM_ERROR_NONE, _ua_service_db_clear(), handle_error); EXEC(UAM_ERROR_NONE, _ua_device_service_db_clear(), handle_error); + EXEC(UAM_ERROR_NONE, _uam_adv_db_clear(), handle_error); UAM_DBG("Table data deleted "); error_code = UAM_ERROR_NONE; diff --git a/ua-daemon/src/ua-manager-device-db.c b/ua-daemon/src/ua-manager-device-db.c index ba10af0..ddac6b1 100644 --- a/ua-daemon/src/ua-manager-device-db.c +++ b/ua-daemon/src/ua-manager-device-db.c @@ -237,7 +237,6 @@ static int __ua_device_table_devicesinfo_prepare(sqlite3 *db) DB_ACTION(__ua_device_prepare_insert(db), error_code, handle_error); handle_error: - FUNC_EXIT; return error_code; } @@ -501,7 +500,7 @@ int _ua_device_db_insert_device_info(int user_id, if (sqlite3_step(stmt) != SQLITE_DONE) { UAM_ERR("Failed to insert device info: %s", - sqlite3_errmsg(__uam_db_recover_database())); + sqlite3_errmsg(__uam_db_recover_database())); error_code = UAM_ERROR_DB_FAILED; goto handle_error; } diff --git a/ua-daemon/src/ua-manager-device-service-db.c b/ua-daemon/src/ua-manager-device-service-db.c index 4b9a9dc..ce8645c 100644 --- a/ua-daemon/src/ua-manager-device-service-db.c +++ b/ua-daemon/src/ua-manager-device-service-db.c @@ -183,7 +183,6 @@ static int __ua_device_service_table_deviceservicesinfo_prepare(sqlite3 *db) DB_ACTION(__ua_device_service_prepare_insert(db), error_code, handle_error); handle_error: - FUNC_EXIT; return error_code; } diff --git a/ua-daemon/src/ua-manager-user-db.c b/ua-daemon/src/ua-manager-user-db.c index e8eec14..5a30e85 100644 --- a/ua-daemon/src/ua-manager-user-db.c +++ b/ua-daemon/src/ua-manager-user-db.c @@ -175,7 +175,6 @@ static int __ua_table_usersinfo_prepare(sqlite3 *db) DB_ACTION(__ua_prepare_insert(db), error_code, handle_error); handle_error: - FUNC_EXIT; return error_code; } @@ -336,7 +335,7 @@ int _ua_db_get_user(int user_id, db_user_info_t *info) UAM_INFO("%d-%s-%s", info->user_id, info->name, info->account); - UAM_DBG("User info deleted"); + UAM_DBG("User info found"); } handle_error: