19:
  20:-- This example uses a trigger to generate an EXECUTE STATEMENT
  21:-- based on the contents of the inserted record.
  22:-- Note that this technique is particularly unsuitable for a live
  23:-- multi-user environment. However, it is fine if there is
  24:-- exclusive access to the database and each insert is committed.
  25:
  26:create table revisions(
  27: revisions_code integer not null,
  28: sql_text varchar(2048) not null,
  29: exec_time timestamp default 'now',
  30: exec_by varchar(31) default CURRENT_USER,
  31: constraint pk_revisions primary key (revisions_code)
  32: );
  33:
  34:
  35:-- Create a trigger to do the work for us.
  36:create generator REVISIONS_GEN;
  37:set term ^;
  38:create trigger tib_revisions for revisions
  39:active before insert position 0 as
  40:DECLARE VARIABLE Sql VARCHAR(2048);
  41:
  42:begin
  43:/* Generate id on Primary key*/
  44:if (New.REVISIONS_CODE is null) then
  45:  New.REVISIONS_CODE=Gen_Id(REVISIONS_GEN,1);
  46:
  47:sql = new.sql_text;
  48:execute statement sql;
  49:
  50:end^
  51:set term ;^
  52:
  53:commit;
  54:
  55: