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)
+{
+ _INFO("_account_delete_table start - table[%s]", table);
+ int error_code = _ACCOUNT_ERROR_NONE;
+ account_stmt hstmt = *phstmt;
+ int binding_count = 1;
+ 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!"));
+ if ((g_strcmp0(table, CAPABILITY_TABLE) == 0) || (g_strcmp0(table, ACCOUNT_TABLE) == 0)) {
+ ACCOUNT_SNPRINTF(query, sizeof(query), "DELETE FROM %s WHERE package_name = ?", table);
+ } else { /*ACCOUNT_CUSTOM_TABLE, LABEL_TABLE, PROVIDER_FEATURE_TABLE, ACCOUNT_TYPE_TABLE*/
+ ACCOUNT_SNPRINTF(query, sizeof(query), "DELETE FROM %s WHERE AppId = ?", table);
+ }
+
+ hstmt = _account_prepare_query(account_db_handle, query);
+
+ if ((_account_db_err_code(account_db_handle) == SQLITE_PERM) && (g_strcmp0(table, ACCOUNT_CUSTOM_TABLE) == 0)) {
+ _account_end_transaction(account_db_handle, false);
+ ACCOUNT_ERROR("Access failed(%s)", _account_db_err_msg(account_db_handle));
+ g_slist_free_full(account_id_list, g_free);
+ return _ACCOUNT_ERROR_PERMISSION_DENIED;
+ }
+
+ if (hstmt == NULL) {
+ _ERR("_account_svc_query_prepare(%s) failed(%s).\n", query, _account_db_err_msg(account_db_handle));
+ error_code = _ACCOUNT_ERROR_DB_FAILED;
+ goto END;
+ }
+
+ if (package_name != NULL)
+ _account_query_bind_text(hstmt, binding_count++, package_name);
+ else if (app_id != NULL)
+ _account_query_bind_text(hstmt, binding_count++, app_id);
+
+ rc = _account_query_step(hstmt);
+ if (rc != SQLITE_DONE) {
+ _ERR("The record isn't found - package_name[%s]\n", package_name);
+ error_code = _ACCOUNT_ERROR_RECORD_NOT_FOUND;
+ goto END;
+ }
+
+ rc = _account_query_finalize(hstmt);
+ if (rc != _ACCOUNT_ERROR_NONE) {
+ if (package_name != NULL) {
+ _account_end_transaction(account_db_handle, false);
+ g_slist_free_full(account_id_list, g_free);
+ }
+ _ERR("finalize error");
+ error_code = rc;
+ goto END;
+ }
+
+ hstmt = NULL;
+ _INFO("_account_delete_table end");
+END:
+ return error_code;
+}
int _account_delete_account_by_package_name(sqlite3 *account_db_handle, const char *package_name, gboolean permission, int pid, uid_t uid)
{
_INFO("_account_delete_account_by_package_name");
int error_code = _ACCOUNT_ERROR_NONE;
account_stmt hstmt = NULL;
- char query[ACCOUNT_SQL_LEN_MAX] = {0, };
int rc = 0;
int ret_transaction = 0;
bool is_success = FALSE;
- int binding_count = 1;
GSList *account_id_list = NULL;
int ret = -1;
}
_INFO("start delete custom table");
- /* delete custom table */
- ACCOUNT_MEMSET(query, 0, sizeof(query));
- ACCOUNT_SNPRINTF(query, sizeof(query), "DELETE FROM %s WHERE AppId = ?", ACCOUNT_CUSTOM_TABLE);
- hstmt = _account_prepare_query(account_db_handle, query);
-
- if (_account_db_err_code(account_db_handle) == SQLITE_PERM) {
- _account_end_transaction(account_db_handle, false);
- ACCOUNT_ERROR("Access failed(%s)", _account_db_err_msg(account_db_handle));
- g_slist_free_full(account_id_list, g_free);
- return _ACCOUNT_ERROR_PERMISSION_DENIED;
+ /* delete custom table */
+ error_code = _account_delete_table(account_db_handle, &hstmt, account_id_list, package_name, NULL, 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[%s]", error_code);
+ goto CATCH;
+ } else if (error_code != _ACCOUNT_ERROR_NONE) {
+ _ERR("account-custom-table deletion failed - error[%s]", error_code);
+ return error_code;
}
- ACCOUNT_CATCH_ERROR(hstmt != NULL, {}, _ACCOUNT_ERROR_DB_FAILED,
- ("_account_svc_query_prepare(%s) failed(%s).\n", query, _account_db_err_msg(account_db_handle)));
-
- binding_count = 1;
- _account_query_bind_text(hstmt, binding_count++, package_name);
-
- rc = _account_query_step(hstmt);
- ACCOUNT_CATCH_ERROR(rc == SQLITE_DONE, {}, _ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
-
- rc = _account_query_finalize(hstmt);
- ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE),
- { _account_end_transaction(account_db_handle, false); g_slist_free_full(account_id_list, g_free); }, rc, ("finalize error"));
- hstmt = NULL;
-
_INFO("start delete capability table");
- /* delete capability table */
- ACCOUNT_MEMSET(query, 0, sizeof(query));
- ACCOUNT_SNPRINTF(query, sizeof(query), "DELETE FROM %s WHERE package_name = ?", CAPABILITY_TABLE);
- hstmt = _account_prepare_query(account_db_handle, query);
-
- ACCOUNT_CATCH_ERROR(hstmt != NULL, {}, _ACCOUNT_ERROR_DB_FAILED,
- ("_account_svc_query_prepare(%s) failed(%s).\n", query, _account_db_err_msg(account_db_handle)));
-
- binding_count = 1;
- _account_query_bind_text(hstmt, binding_count++, package_name);
-
- rc = _account_query_step(hstmt);
- ACCOUNT_CATCH_ERROR(rc == SQLITE_DONE, {}, _ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
-
- rc = _account_query_finalize(hstmt);
- ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE),
- { _account_end_transaction(account_db_handle, false); g_slist_free_full(account_id_list, g_free); }, rc, ("finalize error"));
- hstmt = NULL;
+ /* delete capability table */
+ error_code = _account_delete_table(account_db_handle, &hstmt, account_id_list, package_name, NULL, CAPABILITY_TABLE);
+ if ((error_code == _ACCOUNT_ERROR_DB_FAILED) || (error_code == _ACCOUNT_ERROR_RECORD_NOT_FOUND)) {
+ _ERR("account-custom-table deletion failed - db error[%s]", error_code);
+ goto CATCH;
+ } else if (error_code != _ACCOUNT_ERROR_NONE) {
+ _ERR("account-custom-table deletion failed - error[%s]", error_code);
+ return error_code;
+ }
_INFO("start delete account table");
/* delete account table */
- ACCOUNT_MEMSET(query, 0, sizeof(query));
-
- ACCOUNT_SNPRINTF(query, sizeof(query), "DELETE FROM %s WHERE package_name = ?", ACCOUNT_TABLE);
-
- hstmt = _account_prepare_query(account_db_handle, query);
- ACCOUNT_CATCH_ERROR(hstmt != NULL, {}, _ACCOUNT_ERROR_DB_FAILED,
- ("_account_svc_query_prepare(%s) failed(%s).\n", query, _account_db_err_msg(account_db_handle)));
-
- binding_count = 1;
- _account_query_bind_text(hstmt, binding_count++, package_name);
-
- rc = _account_query_step(hstmt);
- ACCOUNT_CATCH_ERROR(rc == SQLITE_DONE, {}, _ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found, rc=%d\n", rc));
-
- rc = _account_query_finalize(hstmt);
- ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE),
- { _account_end_transaction(account_db_handle, false); g_slist_free_full(account_id_list, g_free); }, rc, ("finalize error"));
+ error_code = _account_delete_table(account_db_handle, &hstmt, account_id_list, package_name, NULL, ACCOUNT_TABLE);
+ if ((error_code == _ACCOUNT_ERROR_DB_FAILED) || (error_code == _ACCOUNT_ERROR_RECORD_NOT_FOUND)) {
+ _ERR("account-custom-table deletion failed - db error[%s]", error_code);
+ goto CATCH;
+ } else if (error_code != _ACCOUNT_ERROR_NONE) {
+ _ERR("account-custom-table deletion failed - error[%s]", error_code);
+ return error_code;
+ }
is_success = TRUE;
- hstmt = NULL;
-
CATCH:
if (hstmt != NULL) {
rc = _account_query_finalize(hstmt);
int rc = 0;
int count = -1;
int ret_transaction = 0;
- int binding_count = 1;
bool is_success = FALSE;
ACCOUNT_RETURN_VAL((account_db_handle != NULL), {}, _ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
return ret_transaction;
}
- ACCOUNT_SNPRINTF(query, sizeof(query), "DELETE FROM %s WHERE AppId = ?", LABEL_TABLE);
-
- 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;
+ /*delete label table*/
+ error_code = _account_delete_table(account_db_handle, &hstmt, NULL, NULL, app_id, LABEL_TABLE);
+ if ((error_code == _ACCOUNT_ERROR_DB_FAILED) || (error_code == _ACCOUNT_ERROR_RECORD_NOT_FOUND)) {
+ _ERR("account-custom-table deletion failed - db error[%s]", error_code);
+ goto CATCH;
+ } else if (error_code != _ACCOUNT_ERROR_NONE) {
+ _ERR("account-custom-table deletion failed - error[%s]", error_code);
+ return error_code;
}
- ACCOUNT_CATCH_ERROR(hstmt != NULL, {}, _ACCOUNT_ERROR_DB_FAILED,
- ("_account_svc_query_prepare(%s) failed(%s).\n", query, _account_db_err_msg(account_db_handle)));
-
- _account_query_bind_text(hstmt, binding_count++, app_id);
-
- rc = _account_query_step(hstmt);
- ACCOUNT_CATCH_ERROR(rc == SQLITE_DONE, {}, _ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
-
- rc = _account_query_finalize(hstmt);
- ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
- hstmt = NULL;
-
- binding_count = 1;
- ACCOUNT_MEMSET(query, 0, sizeof(query));
-
- ACCOUNT_SNPRINTF(query, sizeof(query), "DELETE FROM %s WHERE app_id = ? ", PROVIDER_FEATURE_TABLE);
-
- hstmt = _account_prepare_query(account_db_handle, query);
- ACCOUNT_CATCH_ERROR(hstmt != NULL, {}, _ACCOUNT_ERROR_DB_FAILED,
- ("_account_svc_query_prepare(%s) failed(%s).\n", query, _account_db_err_msg(account_db_handle)));
-
- _account_query_bind_text(hstmt, binding_count++, app_id);
-
- rc = _account_query_step(hstmt);
- ACCOUNT_CATCH_ERROR(rc == SQLITE_DONE, {}, _ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found. AppId=%s, rc=%d\n", app_id, rc));
-
- rc = _account_query_finalize(hstmt);
- ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
+ /*delete provider feature table*/
+ error_code = _account_delete_table(account_db_handle, &hstmt, NULL, NULL, app_id, PROVIDER_FEATURE_TABLE);
+ if ((error_code == _ACCOUNT_ERROR_DB_FAILED) || (error_code == _ACCOUNT_ERROR_RECORD_NOT_FOUND)) {
+ _ERR("account-custom-table deletion failed - db error[%s]", error_code);
+ goto CATCH;
+ } else if (error_code != _ACCOUNT_ERROR_NONE) {
+ _ERR("account-custom-table deletion failed - error[%s]", error_code);
+ return error_code;
+ }
is_success = TRUE;
- hstmt = NULL;
-
- binding_count = 1;
- ACCOUNT_MEMSET(query, 0, sizeof(query));
-
- ACCOUNT_SNPRINTF(query, sizeof(query), "DELETE FROM %s WHERE AppId = ? ", ACCOUNT_TYPE_TABLE);
-
- hstmt = _account_prepare_query(account_db_handle, query);
- ACCOUNT_CATCH_ERROR(hstmt != NULL, {}, _ACCOUNT_ERROR_DB_FAILED,
- ("_account_svc_query_prepare(%s) failed(%s).\n", query, _account_db_err_msg(account_db_handle)));
-
- _account_query_bind_text(hstmt, binding_count++, app_id);
-
- rc = _account_query_step(hstmt);
- ACCOUNT_CATCH_ERROR(rc == SQLITE_DONE, {}, _ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found. AppId=%s, rc=%d\n", app_id, rc));
-
- rc = _account_query_finalize(hstmt);
- ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
+ /*delete account type table*/
+ error_code = _account_delete_table(account_db_handle, &hstmt, NULL, NULL, app_id, ACCOUNT_TYPE_TABLE);
+ if ((error_code == _ACCOUNT_ERROR_DB_FAILED) || (error_code == _ACCOUNT_ERROR_RECORD_NOT_FOUND)) {
+ _ERR("account-custom-table deletion failed - db error[%s]", error_code);
+ goto CATCH;
+ } else if (error_code != _ACCOUNT_ERROR_NONE) {
+ _ERR("account-custom-table deletion failed - error[%s]", error_code);
+ return error_code;
+ }
is_success = TRUE;
- hstmt = NULL;
-
CATCH:
if (hstmt != NULL) {
rc = _account_query_finalize(hstmt);