Subject Re: Adding trigger dynamically
Author Adam
--- In firebird-support@yahoogroups.com, Harriv <harriv@...> wrote:
>
> Hi,
>
> Is it possible to check if table has trigger defined and if trigger
> is missing add it? I'd like to my program to add it's own trigger when
> started if it doesn't exist.

Use the standard CREATE TRIGGER syntax, but instead change it to
CREATE OR ALTER TRIGGER


>
> Also, are there any pitfalls when doing this kind of operation? I'm
> only used to modify database structure manually..

I do not know whether exclusive use of the table is required to add a
trigger, or whether it requires a disconnect/reconnect before becoming
active. You certainly would need to commit the DDL.

>
> I'm using Python and kinterbasdb if it matters.
>

Our approach is different, we have a productversion table. Every
script adds a new record to this table, and the executable checks
whether the version is recent enough at launch time. In our case it
just refuses to launch and gives an informative error message. For it
to occur however, the upgrader must have really broken something, so
we only ever see this in development or testing when a newer or older
production database is put alongside some binary we are testing with.

Adam