SET ":content" = (
  SELECT content
  FROM clip
  WHERE hash = :hash AND :tool = 'clip'
  UNION
  SELECT content
  FROM goto
  WHERE hash = :hash AND :tool = 'goto'
  UNION
  SELECT content
  FROM upload
  WHERE hash = :hash AND :tool = 'upload'
);

SET ":qr" = (
  SELECT qr
  FROM clip
  WHERE hash = :hash AND :tool = 'clip'
  UNION
  SELECT qr
  FROM goto
  WHERE hash = :hash AND :tool = 'goto'
  UNION
  SELECT qr
  FROM upload
  WHERE hash = :hash AND :tool = 'upload'
);

SET ":preview" = (SELECT preview FROM goto WHERE hash = :hash AND :tool = 'goto');
SET ":file_name" = (SELECT name FROM upload WHERE hash = :hash AND :tool = 'upload');
SET ":mime_type" = (SELECT mime FROM upload WHERE hash = :hash AND :tool = 'upload');

SELECT 'dynamic' AS component, sqlpage.run_sql('sqlpage/QR.sql') AS properties
WHERE COALESCE (:hash, '') <> '';

SET ":inner" = CASE COALESCE(:content,'')
  WHEN '' THEN 'sqlpage/alert.sql'
  ELSE :tool||'/form.sql'
END;

SET ":icon" = 'error-404';
SET ":status" = '404';
SET ":title" = :status||' - Not found';
SET ":description" = 'No such '||:tool||': '||:hash;
SELECT 'dynamic' AS component, sqlpage.run_sql(:inner) AS properties;