User Defined variables and Triggers

Ruslan Zasukhin sunshine at public.kherson.ua
Fri Jun 1 11:22:13 CDT 2007


On 1/6/07 5:24 PM, "Bart Pietercil" <bart.pietercil at gmail.com> wrote:

Hi Bart,

> Is there a way to use User Defined Variables (ie. @MyName) inside
> triggers.
> 
> The idea is to first pass the userid to the database with SET @userid
> = anID
 
> and then inside a trigger use the variable @userid to store the ID in
> the fields created_by and updated_by

Yes should work.
 
> like this:
> 
>      CREATE OR REPLACE TRIGGER trig_ratingsystems_BI BEFORE INSERT ON
> rating_systems FOR EACH ROW " + _
>      "BEGIN " + _
>      "NEW.created_datetime = NOW();" + _
>      "NEW.created_by = @userid ;" + _
>      "NEW.updated_datetime = Now();" + _
>      "NEW.updated_by = @userid;" + _
>      "END;" + EndOfLine + _

>      "CREATE OR REPLACE TRIGGER trig_ratingsystems_BU BEFORE UPDATE
> ON rating_systems FOR EACH ROW " + _
>      "BEGIN "+ _
>      "NEW.updated_datetime = Now();" + _
>      "NEW.updated_by = @userid;" + _
>      "END;"
> 
> I can see a problem that the @userid would not be set (but that's up
> to the programmer of course) before the trigger is triggered
> 
> Thanks for looking into this

-- 
Best regards,

Ruslan Zasukhin
VP Engineering and New Technology
Paradigma Software, Inc

Valentina - Joining Worlds of Information
http://www.paradigmasoft.com

[I feel the need: the need for speed]




More information about the Valentina mailing list