Subject Re: [ib-support] view and generator
Author Martijn Tonies
Hi Jef,

Easiest way:

change your BEFORE INSERT triggers to:

if ((id1 is null) or (id1 = 0))
then id1 = gen_id(gen1,1);

Then, in the trigger on the view, do this:

:TEMP=GEN_ID(GEN1,1);

insert into table1 (id1, text1, type) values (:temp, 'text', yourtype)

insert into table2 (id2, code_tbl1, text2) values (gen_id(gen2, 1), :temp,
'text')


Martijn Tonies
InterBase Workbench - the developer tool for InterBase and Firebird
http://www.interbaseworkbench.com

Upscene Productions
http://www.upscene.com

"This is an object-oriented system.
If we change anything, the users object."


> I have two tables and a view based on them.
> table 1
> id1 integer
> text1 char(30)
> type integer
>
> table 2
> id2 integer
> code_tbl1 integer
> text2 char(10)
>
> view1
> select text1, text2
> from table1,table2
> where type=1 and code_tbl1=id1
>
> trigger before insert on table1
> id1 = gen_id(gen1,1);
>
> trigger before insert on table2
> id2 = gen_id(gen2,1);
>
> the view alow to see informations about elements of table1 wich are
> of the type1 (for this type there is only 1 dependant line in the
> table2)
>
> a trigger on the view allow to insert data and put it in table 1 and
> table2
>
> but how to recover the value of id1 after the insertion in the table1
> to put it in code_tbl1 in the table2.
>
> at this time I use a variable :TEMP=GEN_ID(GEN1,0);
> after the insertion in the trigger of the view, but I'm not sure to
> recover the good value if another insertion in the table1 occured at
> the same time.
>
> Thanks for youor help.
> Jef
>
>
>
> To unsubscribe from this group, send an email to:
> ib-support-unsubscribe@egroups.com
>
>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>