From 516f2cac8297abb49abe655b8c45dfac153c401f Mon Sep 17 00:00:00 2001 From: einhverfr Date: Fri, 4 Apr 2008 20:18:11 +0000 Subject: Adding infrastructure for form tracking git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@2125 4979c152-3d1c-0410-bac9-87ea11338e46 --- sql/Pg-database.sql | 5 +++++ sql/modules/Session.sql | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+) (limited to 'sql') 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 $$ -- cgit v1.2.3