Subject Re: [firebird-support] Re: newbie on SPs: How to imlement a wlhile not eof loop
Author Carol Milius
Thak you for your comments.

>Forgive me if I have interpreted your pseudo code wrong. As I
>understand, you want to insert each tc value into tb alongside the
>current ta id?

Adam, this is a situation a have to implement. Thanks again.

The scenario is this.
1. The 'Admin' defines a set of records that accomplish a 'situation'.
2. The number of 'situation' is unlimited, so we have unlimited set of records.
3. Every time the 'situation' occurs, the records should be inserted - based on previous definition, the SP!.

The fact is that the situation occurs every hour, at least, 50 times.
The good news is that the set of records range from 10 to 30 :)

The code you provided now makes senses for me.

Thanks again!

Carol





Hi Carol,

After reading your initial post, I was not quite sure what you were
trying to accomplish. You seemed pretty confident that you were after
a trigger, but I for one am not sure whether that will best suit your
purpse. Perhaps if you can provide an example with a couple of
records and your desired behaviour, we can be a bit more assistance.

> A question: The SUSPEND stops the routine? (Like an EXIT in code?)

Nope, suspend does not exit the routine. It just adds another row to
the returned records. I don't think you will need suspend though if
you are only using a trigger.

> A Question: Is common a SP crash the Server?

No, not unless your SP calls a UDF function which crashes, BUT

SPs can have undesirable consequences. For example, if you call a SP
from a trigger, and then that SP inserts / updates / deletes
something, another trigger (or even the same one) will fire, and if
you are not careful, you may get into an infinite loop (although from
memory FB gives up after a while).

Forgive me if I have interpreted your pseudo code wrong. As I
understand, you want to insert each tc value into tb alongside the
current ta id?

Your before insert trigger code could look like:

begin
for select distinct campo
from tc
into :campo
do
begin
insert into tb (id, campo) values (new.id, :campo);
end
end
^

You would need to make sure that tc wasn't too big though, as every
insert into ta would need to then read the entire tc, and then insert
that many records into tb

Adam