modify sql functions
This commit is contained in:
45
sql/insert_url_with_custom_artist.sql
Normal file
45
sql/insert_url_with_custom_artist.sql
Normal file
@ -0,0 +1,45 @@
|
||||
CREATE OR REPLACE FUNCTION public.insert_url_with_custom_artist(in_url text, in_artist_name text) RETURNS integer
|
||||
LANGUAGE plpgsql STRICT
|
||||
AS $$
|
||||
DECLARE
|
||||
ret_value integer;
|
||||
temp_artist_id integer;
|
||||
BEGIN
|
||||
PERFORM * FROM artist_website aw
|
||||
WHERE aw.url = in_url;
|
||||
|
||||
IF FOUND THEN
|
||||
RETURN 1;
|
||||
END IF;
|
||||
|
||||
PERFORM * FROM artist a
|
||||
WHERE a.name = in_artist_name;
|
||||
|
||||
IF FOUND THEN
|
||||
RETURN 1;
|
||||
END IF;
|
||||
|
||||
INSERT INTO artist_website (url) VALUES (in_url);
|
||||
INSERT INTO artist (name) VALUES (in_artist_name);
|
||||
|
||||
SELECT artist.id INTO temp_artist_id FROM artist
|
||||
WHERE artist.name = in_artist_name;
|
||||
|
||||
UPDATE artist_website SET artist_id = temp_artist_id
|
||||
WHERE url = in_url;
|
||||
|
||||
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;
|
||||
$$;
|
Reference in New Issue
Block a user