select sql_users_insert();
select sql_users_update(1,'Username1','Password1',1,1);
select sql_users_insert();
select sql_users_update(2,'Username2','Password2',1,2);

drop function sql_users_verify(text,text);

select sql_users_verify('Username1','Password1');

drop function sql_users_exists(text);
CREATE FUNCTION sql_users_exists (text) RETURNS int4 AS '
DECLARE
    record1 record;  id int4 :=0;
    username text; password text;
BEGIN
   username := clean_text($1);

   FOR record1 IN SELECT users_id FROM users
        where users.username = username
      LOOP
      id := record1.users_id;
   END LOOP;

     -- Everything has passed, return id as users_id.
   return (id);
END;
' LANGUAGE 'plpgsql';
select sql_users_exists('Username1');

drop function sql_users_active(text);
CREATE FUNCTION sql_users_active (text) RETURNS int4 AS '
DECLARE
    record1 record;  id int4 :=0;
    username text; password text;
BEGIN
   username := clean_text($1);

   FOR record1 IN SELECT users_id FROM users where users.username = username
      LOOP
      id := record1.users_id;
   END LOOP;

     -- Everything has passed, return id as users_id.
   return (id);
END;
' LANGUAGE 'plpgsql';
select sql_users_active('Username1');


