static GError *
__del_container_properties(struct sqlx_sqlite3_s *sq3, struct oio_url_s *url,
		gchar **names)
{
	GError *err = NULL;
	gchar **p_name;

	if (!names || !*names)
		__exec_cid(sq3->db, "DELETE FROM properties WHERE cid = ?", oio_url_get_id(url));
	else {
		for (p_name=names; !err && p_name && *p_name ;p_name++) {
			sqlite3_stmt *stmt = NULL;
			gint rc;

			sqlite3_prepare_debug(rc, sq3->db, "DELETE FROM properties WHERE cid = ? AND name = ?", -1, &stmt, NULL);
			if (rc != SQLITE_OK && rc != SQLITE_DONE)
				err = M1_SQLITE_GERROR(sq3->db, rc);
			else {
				(void) sqlite3_bind_blob(stmt, 1, oio_url_get_id(url), oio_url_get_id_size(url), NULL);
				(void) sqlite3_bind_text(stmt, 2, *p_name, strlen(*p_name), NULL);
				sqlite3_step_debug_until_end (rc, stmt);
				if (rc != SQLITE_DONE)
					GRID_WARN("SQLite error rc=%d", rc);
				sqlite3_finalize_debug(rc, stmt);
			}
		}
	}

	return err;
}
Пример #2
0
GError*
__destroy_container(struct sqlx_sqlite3_s *sq3, struct hc_url_s *url,
                    gboolean force, gboolean *done)
{
    GError *err = NULL;
    gint count_actions = 0;
    struct sqlx_repctx_s *repctx = NULL;

    EXTRA_ASSERT(sq3 != NULL);
    EXTRA_ASSERT(sq3->db != NULL);

    err = sqlx_transaction_begin(sq3, &repctx);
    if (NULL != err)
        return err;

    if (force) {
        __exec_cid (sq3->db, "DELETE FROM services WHERE cid = ?", hc_url_get_id (url));
        count_actions += sqlite3_changes(sq3->db);
        __exec_cid (sq3->db, "DELETE FROM properties WHERE cid = ?", hc_url_get_id (url));
        count_actions += sqlite3_changes(sq3->db);
    } else {
        guint count_services = 0, count_properties = 0;

        /* No forced op, we count the services belonging to the container. */
        err = __count_FK(sq3, url, "services", &count_services);
        if (!err)
            err = __count_FK(sq3, url, "properties", &count_properties);

        /* If any service is found, this is an error. */
        if (!err && count_services > 0)
            err = NEWERROR(CODE_USER_INUSE, "User still linked to services");
        if (!err && count_properties > 0)
            err = NEWERROR(CODE_USER_INUSE, "User still has properties");
    }

    if (!err) {
        __exec_cid(sq3->db, "DELETE FROM users WHERE cid = ?", hc_url_get_id (url));
        count_actions += sqlite3_changes(sq3->db);
    }

    *done = !err && (count_actions > 0);

    if (!err && !*done)
        err = NEWERROR(CODE_USER_NOTFOUND, "User not found");

    return sqlx_transaction_end(repctx, err);
}