querying deleted tables of capability & account_custom 24/205924/1
authorAbhishek Vijay <abhishek.v@samsung.com>
Fri, 10 May 2019 10:26:25 +0000 (15:56 +0530)
committerAbhishek Vijay <abhishek.v@samsung.com>
Fri, 10 May 2019 10:26:25 +0000 (15:56 +0530)
Change-Id: I625a3e3b81102a034a0a40692ddaa10013d4cd3e
Signed-off-by: Abhishek Vijay <abhishek.v@samsung.com>
common/src/account_db_helper.c

index 3be9c5f..a818f92 100644 (file)
@@ -1182,7 +1182,8 @@ static bool _account_add_custom_to_account_cb(const char *key, const char *value
        return TRUE;
 }
 
-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)
+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)
 {
        _INFO("_account_query_by_account_id start");
 
@@ -1198,15 +1199,41 @@ int _account_query_by_account_id(sqlite3 *account_db_handle, account_add_capabil
 
        ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
 
+       /*check in proper tables of Capability & Account_Custom*/
        if (capability_cb != NULL) {
-               _INFO("account query capability by account-id");
-               ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE account_id = %d", CAPABILITY_TABLE, account_id);
+               _INFO("account query capability by account-id - original table");
+               ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE _id = %d", CAPABILITY_TABLE, account_id);
                query_for_capability = true;
        } else if (custom_cb != NULL) {
-               _INFO("account query custom by account-id");
+               _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);
                query_for_custom = true;
        }
+
+       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);
+       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) {
@@ -1215,7 +1242,6 @@ int _account_query_by_account_id(sqlite3 *account_db_handle, account_add_capabil
        }
 
        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;
@@ -1480,8 +1506,8 @@ int _account_check_duplicated(sqlite3 *account_db_handle, account_s *data, const
        return _ACCOUNT_ERROR_NONE;
 }
 
-int _account_delete_table(sqlite3 *account_db_handle, account_stmt *phstmt,
-               GSList *account_id_list, const char *package_name, const char *app_id, const char* table)
+int _account_delete_table(sqlite3 *account_db_handle, account_stmt *phstmt, GSList *account_id_list,
+                                       const char *package_name, const char *app_id, const char* table)
 {
        _INFO("_account_delete_table start - table[%s]", table);
        int error_code = _ACCOUNT_ERROR_NONE;
@@ -1490,9 +1516,6 @@ int _account_delete_table(sqlite3 *account_db_handle, account_stmt *phstmt,
        int rc = 0;
        char query[ACCOUNT_SQL_LEN_MAX] = {0, };
 
-       /*function params like "phstmt", "account_id_list", "package_name" & "app_id" can be NULL in
-        * case of table deletion performed either by package_name or app_id; hence no need to check them for NULL*/
-
        ACCOUNT_RETURN_VAL((account_db_handle != NULL), {}, _ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
        ACCOUNT_RETURN_VAL((table != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("table is null!"));
 
@@ -1653,7 +1676,7 @@ int _account_delete_account_by_package_name(sqlite3 *account_db_handle, const ch
        _INFO("start delete custom table");
 
        /* delete custom table */
-       error_code = _account_delete_table(account_db_handle, &hstmt, account_id_list, package_name, NULL, ACCOUNT_CUSTOM_TABLE);
+       error_code = _account_delete_table(account_db_handle, &hstmt, account_id_list, NULL, package_name, ACCOUNT_CUSTOM_TABLE);
        if ((error_code == _ACCOUNT_ERROR_DB_FAILED) || (error_code == _ACCOUNT_ERROR_RECORD_NOT_FOUND)) {
                _ERR("account-custom-table deletion failed - db error[%d]", error_code);
                goto CATCH;