CREATE OR REPLACE FUNCTION public.insert_url(in_url text) RETURNS integer
	LANGUAGE plpgsql STRICT
	AS $$
DECLARE
	ret_value integer;
BEGIN
	PERFORM * FROM artist_website aw
	WHERE aw.url = in_url;

    IF FOUND THEN
        RETURN 1;
    END IF;

	INSERT INTO artist_website (url) VALUES (in_url);
	
	SELECT * INTO ret_value FROM set_artist_name(in_url);
	IF ret_value <> 0 THEN
		DELETE FROM artist_website WHERE url = in_url;
		RETURN 1;
	END IF;
	
	SELECT * INTO ret_value FROM set_website_name(in_url);
	IF ret_value <> 0 THEN
		DELETE FROM artist_website WHERE url = in_url;
		RETURN 1;
	END IF;
	
	SELECT * INTO ret_value FROM set_folder_path(in_url);
	IF ret_value <> 0 THEN
		DELETE FROM artist_website WHERE url = in_url;
		RETURN 1;
	END IF;

	RETURN 0;
END;
$$;
