diff options
Diffstat (limited to 'sql')
-rw-r--r-- | sql/Pg-database.sql | 5 | ||||
-rw-r--r-- | sql/modules/Session.sql | 21 |
2 files changed, 26 insertions, 0 deletions
diff --git a/sql/Pg-database.sql b/sql/Pg-database.sql index 384e39eb..757567ed 100644 --- a/sql/Pg-database.sql +++ b/sql/Pg-database.sql @@ -68,6 +68,11 @@ users_id INTEGER NOT NULL references users(id), transaction_id INTEGER NOT NULL ); +CREATE TABLE open_forms ( +id SERIAL PRIMARY KEY, +session_id int REFERENCES session(session_id) ON DELETE CASCADE +); + -- CREATE TABLE transactions ( id int PRIMARY KEY, diff --git a/sql/modules/Session.sql b/sql/modules/Session.sql index 8b8b65c6..f8f0500e 100644 --- a/sql/modules/Session.sql +++ b/sql/modules/Session.sql @@ -1,3 +1,24 @@ +CREATE OR REPLACE FUNCTION form_check(in_session_id int, in_form_id int) +RETURNS BOOL AS +$$ +BEGIN + SELECT * FROM open_forms + WHERE session_id = in_session_id AND id = in_form_id; + + IF FOUND THEN RETURN TRUE; + ELSE RETURN FALSE; +END; +$$ language plpgsql; + +CREATE OR REPLACE FUNCTION form_open(in_session_id int) +RETURNS INT AS +$$ +BEGIN + INSERT INTO open_forms (session_id) VALUES (in_session_id); + RETURN currval('form_id_seq'); +END; +$$ LANGUAGE PLPGSQL + CREATE OR REPLACE FUNCTION session_check(in_session_id int, in_token text) RETURNS session AS $$ |