Subject | Re: trigger on system table |
---|---|
Author | Adam |
Post date | 2006-10-01T01:35:06Z |
--- In firebird-support@yahoogroups.com, "legrand_legrand_63"
<grand.brun.63@...> wrote:
gbak will not backup triggers etc on the system tables, so your work
would be lost every time you restored the database.
Adam
<grand.brun.63@...> wrote:
>Quite a novel approach. Unfortunately, even if you do get it to work,
> Hello,
> I'm trying to port a PostgreSQL application to FB.
>
> PG as the following Autoincrement syntax:
>
> Create table A (id SERIAL not null, ... , primary key(id));
>
> I have created a domain SERIAL as integer, and a trigger on
> rdb$relation_fields to create the usual sequence and trigger on table
> A to emulate autoincrement feature as follow:
>
> SET TERM ^ ;
>
> CREATE TRIGGER RDB$RELATION_FIELDS_AI0 FOR RDB$RELATION_FIELDS
> ACTIVE AFTER INSERT POSITION 0
> AS
> begin
> if (NEW.rdb$field_source='SERIAL') then
> begin
> execute statement 'CREATE GENERATOR
> '||NEW.rdb$relation_name||'_'||NEW.rdb$field_name||'_SEQ';
> execute statement 'CREATE TRIGGER
> '||NEW.rdb$relation_name||'_'||NEW.rdb$field_name||'_TRIG FOR
> '||NEW.rdb$relation_name||'
> ACTIVE BEFORE INSERT POSITION 0
> AS
> BEGIN
> IF (NEW.'||new.rdb$field_name||' IS NULL) THEN
> NEW.'||NEW.rdb$field_name||' =
> GEN_ID('||NEW.rdb$relation_name||'_'||NEW.rdb$field_name||'_SEQ, 1);
> END';
> end
>
> end
> ^
>
> But this doesn't work, as if NEW.fields on a system table were not
> populated :o(
>
> Any Idea ?
gbak will not backup triggers etc on the system tables, so your work
would be lost every time you restored the database.
Adam