Subject Wrong calculations inside trigger
Author Wojciech Materna
Fiesta
I have problem in bad calculations inside trigger.
We use:
Server : Linux RedHat 7.2, IB 6.0.1, on 1.2GHz PIII, 512MB RAM, 2xHDD SCSI,
GDB size about 600MB, 15 connected users, many transactions every hour,

trigger after insert have to update cost of item, so if it can't calculate
properly all is wrong, tragedy etc.

trigger body (partial):

ALTER TRIGGER NG90035
AFTER INSERT
POSITION 0
AS
DECLARE VARIABLE STANW DECIMAL(18,3);
DECLARE VARIABLE STANI DECIMAL(18,3);
DECLARE VARIABLE CENANOWA DECIMAL(18,3);
DECLARE VARIABLE CENASTARA DECIMAL(18,3);
BEGIN
IF (NEW.STRONA=1) THEN
BEGIN
SELECT SP_WI+ON_WI-ON_MI,(SP_WI+ON_WI-ON_MI)*CENA,CENA FROM M9003 WHERE
M9003.INDEKS=NEW.INDEKS
INTO :STANI,:STANW,:CENASTARA;
IF (STANI+NEW.ILOSC>0.0) THEN
CENANOWA=(STANW+NEW.ILOSC*NEW.CENA)/(STANI+NEW.ILOSC);
/* here!!!*/
ELSE
CENANOWA=NEW.CENA;
UPDATE M9003 SET ON_WI=ON_WI+NEW.ILOSC,CENA=:CENANOWA WHERE
M9003.INDEKS=NEW.INDEKS;
END
..............
rest is not interesting

So:
in line /* here!!!*/
calculation of variable CENANOWA failed - after calculation
NEW.ILOSC*NEW.CENA is equal to 0, really it isn't true
becouse if I post this values into control table - everytime are not 0 both
(they can't be 0). This problems I have noticed when I increase numer of
post events
from tables, and set in isc_config low value of EVENT_MEM_SIZE.
After that, inserts works ok, database ok, etc. byt that calculations very
often
fails. When I increase this parameter and delete some of events from
triggers this problem appears not often, but appears.
I do everything what I can imagine, change trigger text on many ways and
nothing can solve problem.

Any suggestions very welcome, here, or private szef@...
Wojtek