handling deleted account query 93/207993/3 accepted/tizen/unified/20190617.111959 accepted/tizen/unified/20190619.051542 submit/tizen/20190615.084842 submit/tizen/20190618.091110
authorAbhishek Vijay <abhishek.v@samsung.com>
Fri, 14 Jun 2019 13:52:33 +0000 (19:22 +0530)
committerAbhishek Vijay <abhishek.v@samsung.com>
Sat, 15 Jun 2019 08:26:00 +0000 (13:56 +0530)
Change-Id: I759b696e53730b8fd49354f4db2a24e675a823e7
Signed-off-by: Abhishek Vijay <abhishek.v@samsung.com>
common/include/account_db_helper.h
common/src/account_db_helper.c

index 09239d7f46ce14b062585c6db29029f85e76d1bf..1e31862a4b4662c5d8d5bf920da247648b72fe37 100644 (file)
 "Value TEXT "\
 ");"
 
-/* DELETED_TRIGGER_QUERY */
-/* ACCOUNT_TABLE */
+/* TRIGGER FOR DELETED_ACCOUNT_TABLE */
 #define TRIGGER_QUERY_DEL_ACC_TAB "create trigger aft_acc_del \n"\
 "after delete on account \n"\
 "begin \n"\
 ");"\
 "end;"
 
-/* CAPABILITY_TABLE */
+/* TRIGGER FOR DELETED_CAPABILITY_TABLE */
 #define TRIGGER_QUERY_DEL_CAP_TAB "create trigger aft_capa_del \n"\
 "after delete on capability \n"\
 "begin \n"\
 ");"\
 "end;"
 
-/* ACCOUNT_CUSTOM_TABLE */
+/* TRIGGER_FOR_ACCOUNT_CUSTOM_TABLE */
 #define TRIGGER_QUERY_DEL_ACUST_TAB "create trigger aft_cust_del \n"\
 "after delete on account_custom \n"\
 "begin \n"\
@@ -284,8 +283,9 @@ void _account_get_appid_from_db(pkgmgrinfo_appinfo_h *ahandle, pkgmgrinfo_pkginf
 int _account_get_represented_appid_from_db(sqlite3 *account_user_db, sqlite3 *account_global_db, const char *appid, uid_t uid, char **verified_appid);
 int _account_check_appid_group_with_package_name(const char *appid, char *package_name, uid_t uid);
 
-int _account_query_capability_by_account_id(sqlite3 *account_db_handle, account_add_capability_cb callback, int account_id, void *user_data);
-int _account_query_custom_by_account_id(sqlite3 *account_db_handle, account_add_custom_cb callback, int account_id, void *user_data);
+int _account_query_by_account_id(sqlite3 *account_db_handle, account_add_capability_cb capability_cb, account_add_custom_cb custom_cb, int account_id, void *user_data, bool is_deleted);
+int _account_query_capability_by_account_id(sqlite3 *account_db_handle, account_add_capability_cb callback, int account_id, void *user_data, bool is_deleted);
+int _account_query_custom_by_account_id(sqlite3 *account_db_handle, account_add_custom_cb callback, int account_id, void *user_data, bool is_deleted);
 GList *_account_query_account_by_package_name(sqlite3 *account_db_handle, const char *package_name, int *error_code, int pid, uid_t uid);
 
 int _account_check_duplicated(sqlite3 *account_db_handle, account_s *data, const char *verified_appid, uid_t uid);
index a818f9256bfd7d741116cc805a5e5c6cf6032733..c0429b6fc64cd187e0042546a6bfdad502f6e699 100644 (file)
@@ -1183,7 +1183,7 @@ static bool _account_add_custom_to_account_cb(const char *key, const char *value
 }
 
 int _account_query_by_account_id(sqlite3 *account_db_handle, account_add_capability_cb capability_cb,
-                                       account_add_custom_cb custom_cb, int account_id, void *user_data)
+                                       account_add_custom_cb custom_cb, int account_id, void *user_data, bool is_deleted)
 {
        _INFO("_account_query_by_account_id start");
 
@@ -1201,12 +1201,22 @@ int _account_query_by_account_id(sqlite3 *account_db_handle, account_add_capabil
 
        /*check in proper tables of Capability & Account_Custom*/
        if (capability_cb != NULL) {
-               _INFO("account query capability by account-id - original table");
-               ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE _id = %d", CAPABILITY_TABLE, account_id);
+               if (!is_deleted) {
+                       _INFO("account query capability by account-id - original capability table");
+                       ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE account_id = %d", CAPABILITY_TABLE, account_id);
+               } else {
+                       _INFO("account query capability by account-id - deleted capability table");
+                       ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE account_id = %d", DELETED_CAPABILITY_TABLE, account_id);
+               }
                query_for_capability = true;
        } else if (custom_cb != NULL) {
-               _INFO("account query custom by account-id - original table");
-               ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE AccountId = %d", ACCOUNT_CUSTOM_TABLE, account_id);
+               if (!is_deleted) {
+                       _INFO("account query capability by account-id - original custom table");
+                       ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE AccountId = %d", ACCOUNT_CUSTOM_TABLE, account_id);
+               } else {
+                       _INFO("account query capability by account-id - deleted custom table");
+                       ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE AccountId = %d", DELETED_ACCOUNT_CUSTOM_TABLE, account_id);
+               }
                query_for_custom = true;
        }
 
@@ -1218,30 +1228,7 @@ int _account_query_by_account_id(sqlite3 *account_db_handle, account_add_capabil
        }
 
        rc = _account_query_step(hstmt);
-       if (rc != SQLITE_ROW) {
-               rc = _account_query_finalize(hstmt);
-               ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
-               hstmt = NULL;
-       }
-
-       if ((rc != SQLITE_ROW) && query_for_capability) {
-               _INFO("account query capability by account-id - deleted capability table");
-               ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
-               ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE _id = %d", DELETED_CAPABILITY_TABLE, account_id);
-       } else if ((rc != SQLITE_ROW) && query_for_custom) {
-               _INFO("account query capability by account-id - deleted account_custom table");
-               ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
-               ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE AccountId = %d", DELETED_ACCOUNT_CUSTOM_TABLE, account_id);
-       }
-
-       hstmt = _account_prepare_query(account_db_handle, query);
-
-       if (_account_db_err_code(account_db_handle) == SQLITE_PERM) {
-               ACCOUNT_ERROR("Access failed(%s)", _account_db_err_msg(account_db_handle));
-               return _ACCOUNT_ERROR_PERMISSION_DENIED;
-       }
-
-       rc = _account_query_step(hstmt);
+       ACCOUNT_CATCH_ERROR(rc == SQLITE_ROW, {}, _ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
 
        if (query_for_capability) {
                account_capability_s *capability_record = NULL;
@@ -1302,22 +1289,22 @@ CATCH:
        return error_code;
 }
 
-int _account_query_capability_by_account_id(sqlite3 *account_db_handle, account_add_capability_cb callback, int account_id, void *user_data)
+int _account_query_capability_by_account_id(sqlite3 *account_db_handle, account_add_capability_cb callback, int account_id, void *user_data, bool is_deleted)
 {
        int error_code = _ACCOUNT_ERROR_NONE;
 
-       error_code = _account_query_by_account_id(account_db_handle, callback, NULL, account_id, user_data);
+       error_code = _account_query_by_account_id(account_db_handle, callback, NULL, account_id, user_data, is_deleted);
 
        ACCOUNT_RETURN_VAL((error_code == _ACCOUNT_ERROR_NONE), {}, error_code, ("_account_query_by_account_id failed for capability"));
 
        return error_code;
 }
 
-int _account_query_custom_by_account_id(sqlite3 *account_db_handle, account_add_custom_cb callback, int account_id, void *user_data)
+int _account_query_custom_by_account_id(sqlite3 *account_db_handle, account_add_custom_cb callback, int account_id, void *user_data, bool is_deleted)
 {
        int error_code = _ACCOUNT_ERROR_NONE;
 
-       error_code = _account_query_by_account_id(account_db_handle, NULL, callback, account_id, user_data);
+       error_code = _account_query_by_account_id(account_db_handle, NULL, callback, account_id, user_data, is_deleted);
 
        ACCOUNT_RETURN_VAL((error_code == _ACCOUNT_ERROR_NONE), {}, error_code, ("_account_query_by_account_id failed for custom"));
 
@@ -1403,8 +1390,8 @@ GList *_account_query_account_by_package_name(sqlite3 *account_db_handle, const
        for (iter = account_head->account_list; iter != NULL; iter = g_list_next(iter)) {
                account_s *testaccount = (account_s *)iter->data;
 
-               _account_query_capability_by_account_id(account_db_handle, _account_add_capability_to_account_cb, testaccount->id, (void *)testaccount);
-               _account_query_custom_by_account_id(account_db_handle, _account_add_custom_to_account_cb, testaccount->id, (void *)testaccount);
+               _account_query_capability_by_account_id(account_db_handle, _account_add_capability_to_account_cb, testaccount->id, (void *)testaccount, false);
+               _account_query_custom_by_account_id(account_db_handle, _account_add_custom_to_account_cb, testaccount->id, (void *)testaccount, false);
        }
 
        *error_code = _ACCOUNT_ERROR_NONE;