Re: Salut à tous, un

From: Stéphane Schildknecht <sas(at)atosc(dot)org>
To: metan(at)fr(dot)vu
Cc: pgsql-fr-generale(at)postgresql(dot)org
Subject: Re: Salut à tous, un
Date: 2005-06-24 08:33:26
Message-ID: 42BBC556.2090008@atosc.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-fr-generale

met(at)n wrote:

>
> Salut à tous, j'ai écris un petit code pl/pgsql qui
> ne fonctionne pas de façon catholique!
> A vous qui, a vu d'oeil savez détecter une erreur,
> voici le code et le problème.
>
> La premiere fonction (gov_only()) est booléenne, et
> renvoie TRUE si la ligne contenanant name_ existe
> dans
> la table, ou si elle n'existe pas et holder =
> government ou ministry.
> Dans le cas contraire , renvoie FALSE.
>
> La 2 ème fonction utilise la première. Elle permet
> de
> passer à la création d'un domaine(un trigger
> exécutera
> cette fonction à chaque insertion de domaines), si
> la
> 1 ère est TRUE, sinon on ne pourra créer le domaine
> en
> question (Execption).
>
> Merci de voir si un problème de syntaxe
> cloche.Urgent.
>
> --Suitable for condition column of Reserved_words.
> --Indded, for each reserved word added, its
> associated
> functions
> --action and condition have to be written by the
> registry.
> --Set conditon to true if the holder the government,
> else, set it
> --to false.
> CREATE OR REPLACE FUNCTION gov_only(TEXT, TEXT)
> RETURNS BOOLEAN
> AS 'DECLARE
> name_ ALIAS FOR $1;
> holder ALIAS FOR $2;
> isrow RECORD;
> BEGIN
> --checks that the row containing name_
> really
> exists
> SELECT INTO isrow * FROM Reserved_words WHERE name
> =
> name_;
> IF NOT FOUND THEN
> RETURN TRUE;
> ELSE
> IF (holder = ''government'') OR (holder =
> ''ministry'') THEN
> RETURN TRUE;
> ELSE
> RETURN FALSE;
> END IF;
> END IF;
> END;'
> LANGUAGE PLPGSQL;
>
> --Suitable for the ''action'' corresponding to
> gov_only function;
> --Specifies what to do with the state of
> ''condition''.
> CREATE OR REPLACE FUNCTION create_gov_only()
> RETURNS
> TRIGGER
> AS 'DECLARE
> action_ TEXT;
> condition_ TEXT;
> name_ TEXT;
> isrow RECORD;
> BEGIN
> name_ = ''defense.example'';
> condition_ = ''gov_only'';
> action_ = ''create_gov_only'';
> SELECT INTO isrow * FROM Reserved_words WHERE
> ((name = name_) AND (action = action_) AND
> (condition
> = condition_));
> IF ( FOUND ) AND (NEW.name = name_) THEN
> IF (gov_only(name_, ''ministry'') = FALSE) AND
> (gov_only(name_,''government'') = FALSE) THEN
> RAISE EXCEPTION '' This word (%) is reserved
> for government only, You have No authorization to
> create it.'', name_;
> ELSE
> RETURN NEW
> END IF;
> END IF;
> END;'
> LANGUAGE PLPGSQL;
>
>
>
>
>
>
>
>
>
>___________________________________________________________________________
>Appel audio GRATUIT partout dans le monde avec le nouveau Yahoo! Messenger
>Téléchargez cette version sur http://fr.messenger.yahoo.com
>
>---------------------------(end of broadcast)---------------------------
>TIP 2: you can get off all lists at once with the unregister command
> (send "unregister YourEmailAddressHere" to majordomo(at)postgresql(dot)org)
>
>
Salut,

Pourrais-tu nous en dire un peu plus sur ce que tu appelles un
comportement "non catholique" ?

D'autre part, question traditionnelle, quelle version de PG utilises-tu ?

Salutations
--
Stéphane SCHILDKNECHT
Président de PostgreSQLFr

In response to

Browse pgsql-fr-generale by date

  From Date Subject
Next Message Guillaume LELARGE 2005-06-28 07:07:04 ECPG et le type Bytea
Previous Message met@n 2005-06-23 17:00:41 Salut à tous, un problème avec mon petit code pl/pgsql