CREATE OR REPLACE FUNCTION insert_pkg (TEXT,                        -- category
                                       TEXT,                        -- portname
                                       TEXT,                        -- pkgname
                                       TIMESTAMP(0) WITH TIME ZONE, -- start
                                       TIMESTAMP(0) WITH TIME ZONE) -- finished
                                      RETURNS VOID AS $$
BEGIN
  INSERT INTO portsbuildstats (category, portname, pkgname, start, finished) VALUES ($1, $2, $3, $4, $5);
END;
$$ LANGUAGE plpgsql;


CREATE OR REPLACE FUNCTION insert_pkg (TEXT,                        -- category
                                       TEXT,                        -- portname
                                       TEXT,                        -- flavor
                                       TEXT,                        -- pkgname
                                       TIMESTAMP(0) WITH TIME ZONE, -- start
                                       TIMESTAMP(0) WITH TIME ZONE) -- finished
                                      RETURNS VOID AS $$
BEGIN
  INSERT INTO portsbuildstats (category, portname, flavor, pkgname, start, finished) VALUES ($1, $2, $3, $4, $5, $6);
END;
$$ LANGUAGE plpgsql;


CREATE OR REPLACE FUNCTION create_logfilenames (TIMESTAMP(0) WITH TIME ZONE, -- start
                                                TIMESTAMP(0) WITH TIME ZONE) -- finished
                                               RETURNS SETOF TEXT AS $$
DECLARE
  r portsbuildstats%rowtype;
BEGIN
  FOR r IN SELECT * FROM portsbuildstats WHERE start >= $1 AND finished <= $2 ORDER BY category, portname, flavor LOOP
    IF r.flavor IS NULL THEN
      RETURN NEXT r.category || '___' || r.portname || '.log';
    ELSE
      RETURN NEXT r.category || '___' || r.portname || '@' || r.flavor || '.log';
    END IF;
  END LOOP;

  RETURN;
END;
$$ LANGUAGE plpgsql;

-- EOF
