Subject Re: [firebird-support] Check in Trigger.
Author Martijn Tonies
Hi,

> I need to realize a trigger to grant that before delete a row, check if
> it can be deleted, but I don't know how do it.
>
> CREATE TRIGGER comprueba_fechas FOR ofertas
> BEFORE DELETE
> AS
> DECLARE VARIABLE :nfecha_sistema;
> BEGIN
> SELECT CURRENT_TIMESTAMP
> FROM RDB$Database INTO :nfecha_sistema;

You know, CURRENT_TIMESTAMP is a function, you can do:

nfecha_sistema = CURRENT_TIMESTAMP;

> IF (OLD.FECHA_VALIDEZ<= :nfecha_sistema) THEN
> /* DOES NOT DELETE THE ROW */

Raise an exception.

> ELSE
> /* DOES DELETE THE ROW */

Do nothing.

> END

With regards,

Martijn Tonies
Database Workbench - developer tool for InterBase, Firebird, MySQL & MS SQL
Server.
Upscene Productions
http://www.upscene.com