Subject RE: [firebird-support] Re: Legitimate generator reset
Author Alan McDonald
> > Alan wrote:
> >
> > Any ideas for this system oriented VIEW from any system table gurus?
> > thanks
>
> The problem, essentially, is that generators are a general purpose
> mechanism for creating unique values - not the exact equivalent of
> autonumber fields. There's talk of creating some language for
> specialized generators in a future version, but for now, the best
> hope is to track generators through the RDB$DEPENDENCIES table,
> though I don't think you can coerce the generator value from this
> technique.
>
> Here's a very simple example:
>
> SQL> create database 'foo.fdb';
> SQL> create table t1 (f1 integer not null primary key);
> SQL> set term ^;
> SQL> create generator f1_t1^
> SQL> create trigger t1_bi_0 for t1 before insert position 0
> CON> as begin
> CON> if (new.f1 is null) then
> CON> new.f1 = gen_id (f1_t1, 1);
> CON> end^
> SQL> commit^
> SQL> set term ;^
> SQL> set list;
> SQL> select * from rdb$dependencies;
>
> RDB$DEPENDENT_NAME T1_BI_0
> RDB$DEPENDED_ON_NAME T1
> RDB$FIELD_NAME F1
> RDB$DEPENDENT_TYPE 2
> RDB$DEPENDED_ON_TYPE 0
>
> RDB$DEPENDENT_NAME T1_BI_0
> RDB$DEPENDED_ON_NAME F1_T1
> RDB$FIELD_NAME <null>
> RDB$DEPENDENT_TYPE 2
> RDB$DEPENDED_ON_TYPE 14
>
>
>
> A view that joins RDB$DEPENDENCIES on itself
> will get the relationship between tables and generators -
>
> select distinct d1.rdb$depended_on_name,
> d1.rdb$field_name,
> d2.rdb$depended_on_name
> from rdb$dependencies d1
> join rdb$dependencies d2
> on d1.rdb$dependent_name = d2.rdb$dependent_name
> where d1.rdb$dependent_type = 2
> and d2.rdb$dependent_type = 2
> and d1.rdb$depended_on_type = 0
> and d2.rdb$depended_on_type = 14
>
>
> Regards
>
>
> Ann

thanks Ann, this almost gives me the correspondance table I have now created
anyway. This join gives up fields which are additionally referenced by the
triggers which contain the generators, but it's a simple matter of deleting
these rows.
Alan