Subject Creating Trigger in code
Author Phillip Finckler

I am trying to create a number of triggers in code but not sure how to go about doing that with IBO.

I have tried using TIB_Script but I get an EIB_StatementError saying “Invalid Create, Connect or Drop Database syntax”.  This is what the code looks like.

 

    With IB_Script1 Do

    Begin

      SQL.Clear;

      SQL.Add('CREATE TRIGGER T_BI_'+DataSet.FieldByName('ID').AsString+'_FTS FOR '+DataSet.FieldByName('ID').AsString);

      SQL.Add('ACTIVE BEFORE INSERT');

      SQL.Add('POSITION 0');

      SQL.Add('as');

      SQL.Add('declare variable Parser integer;');

      SQL.Add('declare variable i integer;');

      SQL.Add('begin');

      SQL.Add('if (exists(select * from TS$OPT where Enable>0)) then begin');

      SQL.Add('Parser=Parser_Create();');

      SQL.Add('i=Parser_AddBlob(Parser,new.KEYWORDS);');

      SQL.Add('i=Parser_AddBlob(Parser,new.OCR);');

      SQL.Add('execute procedure TS$UPDATE(new.FTS_ID, '+''''+DataSet.FieldByName('ID').AsString+''''+', :Parser)');

      SQL.Add('RETURNING_VALUES new.FTS_ID;');

      SQL.Add('i=Parser_Free(Parser);');

      SQL.Add('end');

      SQL.Add('end;');

      Execute;

End;