X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 82389D1B577 for ; Tue, 27 Apr 2004 07:14:37 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 09950-06 for ; Tue, 27 Apr 2004 07:14:33 -0300 (ADT) Received: from news.hub.org (news.hub.org [200.46.204.72]) by svr1.postgresql.org (Postfix) with ESMTP id 78F89D1B4F6 for ; Tue, 27 Apr 2004 07:14:30 -0300 (ADT) Received: from news.hub.org (news.hub.org [200.46.204.72]) by news.hub.org (8.12.9/8.12.9) with ESMTP id i3RAETSx070072 for ; Tue, 27 Apr 2004 10:14:30 GMT (envelope-from news@news.hub.org) Received: (from news@localhost) by news.hub.org (8.12.9/8.12.9/Submit) id i3R9vpRv047834 for pgsql-sql@postgresql.org; Tue, 27 Apr 2004 09:57:51 GMT From: Marcus Krause X-Newsgroups: comp.databases.postgresql.sql Subject: Problem with a "blocking period" Trigger Date: Tue, 27 Apr 2004 11:55:33 +0200 Organization: Hub.Org Networking Services Lines: 51 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@news.hub.org User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.6) Gecko/20040113 X-Accept-Language: de-at, en-us, en, fr-fr To: pgsql-sql@postgresql.org X-Virus-Scanned: by amavisd-new at postgresql.org X-Spam-Status: No, hits=2.0 tagged_above=0.0 required=5.0 tests=FROM_ENDS_IN_NUMS, NO_DNS_FOR_FROM X-Spam-Level: * X-Archive-Number: 200405/20 X-Sequence-Number: 17734 Since some days i've been working on a "blocking period" trigger. Before customer's login data will be checked, the system should be look, if there's set a timetook-FIELD(TIMESTAMP) in the future. Then, login trial will be denied! Besides, if login fails due to wrong login data, a loginattempts-FIELD(integer) will be increased! The following Trigger calculates the intervaltime & restarts the loginattempts count! But somewhere in the code is a syntax error, i cannot find: ERROR: syntax error at or near "$1" at character 39 Would you please open my eyes? I'm open to other scripts handling this situation with a loginattempts-FIELD(integer) & timetook-FIELD(TIMESTAMP)! ----------WITHIN_A_TRIGGER----------- DECLARE -- sets intervaltime of blocking period intervaltime CONSTANT integer:= 3; -- sets maximum access trials loginattempts CONSTANT integer:= 3; tmpinterval interval; minutes integer; BEGIN -- blocking condition: -- CUST_LOGINATTEMPTS=0 & CUST_TIMETOOK is in future tmpinterval:= CURRENT_TIMESTAMP - old.cust_timetook; minutes:= extract(minute FROM INTERVAL tmpinterval)::integer; -- maximum trials has been made -- setting blocking period IF old.cust_loginattempts=0 AND old.cust_timetook IS NULL THEN UPDATE Customer SET cust_timetook= CURRENT_TIMESTAMP + (intervaltime::integer || 'hours')::interval WHERE cust_id= old.cust_id; -- maximum trials has been made & CUST_TIMETOOK is in past -- setting blocking period ELSIF old.cust_loginattempts=0 AND minutes>0 THEN UPDATE Customer SET cust_timetook= CURRENT_TIMESTAMP + (intervaltime::integer || 'hours')::interval WHERE cust_id= old.cust_id; ELSIF (new.cust_loginattempts= loginattempts) THEN UPDATE Customer SET cust_loginattempts=0 WHERE cust_id= old.cust_id; END IF; -- returning irrelevant result RETURN NULL; END; ----------WITHIN_A_TRIGGER-----------