Subject RE: [ib-support] Wrong calculations inside trigger
Author Alan McDonald
Why aren't you doing this before insert with all the new values?
not sure but does after insert have the "new" context variables?
In any case I would do it all before insert and before update, then I would
not be updating the record again, just assigning the new calculated values
which depend on the known inserted values
You also do not need to select anything since you will have all the new
values at hand in their new. context without having to select.

Alan

> -----Original Message-----
> From: Wojciech Materna [mailto:szef@...]
> Sent: Monday, 12 May 2003 6:18 PM
> To: ib-support@yahoogroups.com
> Subject: [ib-support] Wrong calculations inside trigger
>
>
> 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
>
>
>
>
>
> 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/
>
>