Subject Re: Complex generators?
Author ivoras
--- In firebird-support@yahoogroups.com, "Alan McDonald" <alan@m...>
wrote:
> Does it matter to the person entering the data of the sales bill,
that they
> know the ID of the bill as they enter it? They can enter the type
presumably
> but the ID can often remain greyed out in the entery form until a
commit is
> actioned.

You're right. I solved the problem by unsing this trigger:

----
IF (NEW.SIFRA IS NULL) THEN BEGIN

genname = 'GEN_MASTER_' || new.type;

update my$gen set val = val + 1 where name=:genname; /* locks
record, if any */

select val from my$gen where name=:genname into :num;
if (num is null) then begin /* no such counter exists */
insert into my$gen values(:genname, 1);
num = 1;
end
new.sifra = :num;

END
----

That, and CachingUpdates works as I initialy thought - Thanks
everyone, I learned much in the process :)