Subject Re: possible to CREATE a TRIGGER from a INSIDE?
Author Svein Erling Tysvær
--- In firebird-support@yahoogroups.com, "Martijn Tonies" answered:
> > I'm trying to create a new trigger from INSIDE the database, into
> > a procedure using the EXECUTE STATEMENT
> >
> > I create a string with all the syntax (really only a command)
> >
> > EXECUTE STATEMENT
> > 'CREATE TRIGGER TRIAL_TRIGGER for TABLE1 '||
> > 'AFTER INSERT '||
> > 'POSITION 100 '||
> > 'AS BEGIN '||
> > 'EXECUTE PROCEDURE MY_PROCEDURE; '
> > 'END';
> >
> > but when I try I get an ERROR.. very confusing, I think in
> > semicolon.
> >
> > Any idea to do or really not possible to do?
>
> Ey, back again :-)
>
> I'll ask again, WHAT error are you getting?

Hi,
I have no experience in doing what you are trying to do, but to me it
sounds crazy to write a stored procedure that uses EXECUTE STATEMENT
to dynamically do DDL.

I'll rephrase what I think you're trying to do (in pseudocode, I'm not
going to install Firebird at this machine to syntax check), and then
Martijn hopefully can tell you why not to do this even though he's
still 17 days away from any Bamsemums:

CREATE PROCEDURE DynamicDDL(DDLcommand: String)
AS
BEGIN
EXECUTE STATEMENT :DDLcommand;
END;

and then you put your string with CREATE TRIGGER into DDLcommand and
calls EXECUTE PROCEDURE DynamicDDL(DDLcommand).

A procedure that dynamically creates a trigger that includes calling
another procedure (or worse: itself) seriously confuse me. I'd be
impressed if Firebird was able to do this, I certainly do not think
that was the purpose of the EXECUTE STATEMENT command.

Set